/* ==========================================================================
   BASE — shared by every device (colours, resets, generic components).
   Layout decisions that differ between PC and mobile live in their own
   clearly separated sections further down; nothing here assumes a screen
   size.
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
:root{
  --ink:#1f2430;
  --navy:#1059b8;
  --navy-deep:#0d4696;
  --accent:#d9483c;
  --paper:#ffffff;
  --panel:#f7f8fa;
  --panel-line:#e5e7eb;
  --thead:#e8f0fb;
  --muted:#64748b;
  --good:#16a34a;
  --radius:12px;
  font-size:15px;
}
*{box-sizing:border-box;}
html{overflow-x:hidden;}
body{
  margin:0;
  overflow-x:hidden;
  font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  background:var(--panel);
  color:var(--ink);
  min-height:100vh;
}

.brandmark{display:flex;align-items:center;gap:12px;min-width:0;}
.brandmark .logo-chip{
  width:42px;height:42px;border-radius:50%;
  background:radial-gradient(circle at 32% 30%, #fff 0 6px, transparent 7px), conic-gradient(from 210deg, var(--accent), var(--ink) 60%, var(--accent));
  display:flex;align-items:center;justify-content:center;
  flex-shrink:0;
}
.brandmark > div{min-width:0;}
.brandmark h1{margin:0;letter-spacing:.2px;overflow-wrap:break-word;}
.brandmark span{display:block;color:var(--muted);overflow-wrap:break-word;}

.biz-switcher{position:relative;min-width:0;}
.biz-switcher-btn{
  display:flex;align-items:center;gap:10px;min-width:0;max-width:100%;
  background:#fff;border:1px solid var(--panel-line);border-radius:12px;padding:6px 10px 6px 6px;
  cursor:pointer;box-shadow:0 1px 2px rgba(20,30,50,.06);font:inherit;
}
.biz-switcher-btn:hover{border-color:var(--navy);}
.biz-avatar{
  width:34px;height:34px;border-radius:50%;flex-shrink:0;overflow:hidden;
  background:radial-gradient(circle at 32% 30%, #fff 0 6px, transparent 7px), conic-gradient(from 210deg, var(--accent), var(--ink) 60%, var(--accent));
  color:#fff;font-size:12px;font-weight:700;display:flex;align-items:center;justify-content:center;
}
.biz-avatar.has-image{background:#fff;border:1px solid var(--panel-line);}
.biz-avatar img{width:100%;height:100%;object-fit:contain;}
.biz-switcher-label{display:flex;flex-direction:column;min-width:0;text-align:left;}
.biz-switcher-label b{font-size:13.5px;color:var(--ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:160px;}
.biz-switcher-label span{font-size:11px;color:var(--muted);}
.biz-switcher-caret{color:var(--muted);font-size:11px;margin-left:2px;}
.biz-switcher.open .biz-switcher-caret{transform:rotate(180deg);}
.biz-switcher-menu{
  position:absolute;top:calc(100% + 8px);left:0;z-index:40;width:260px;max-width:80vw;
  background:#fff;border:1px solid var(--panel-line);border-radius:12px;
  box-shadow:0 12px 32px rgba(20,30,50,.18);padding:10px;
}
.biz-switcher-title{font-size:11px;font-weight:700;color:var(--muted);text-transform:uppercase;letter-spacing:.4px;padding:2px 6px 8px;}
.biz-switcher-item{
  display:flex;align-items:center;gap:8px;width:100%;padding:8px 6px;border:none;background:transparent;
  border-radius:8px;cursor:pointer;font:inherit;text-align:left;
}
.biz-switcher-item:hover{background:var(--panel);}
.biz-switcher-item.active{background:#eef3fb;}
.biz-switcher-item-avatar{
  width:24px;height:24px;border-radius:50%;flex-shrink:0;overflow:hidden;background:var(--panel);
  display:flex;align-items:center;justify-content:center;font-size:10px;font-weight:700;color:var(--navy);
}
.biz-switcher-item-avatar img{width:100%;height:100%;object-fit:contain;}
.biz-switcher-item-name{flex:1;min-width:0;font-size:13px;color:var(--ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.biz-switcher-item-tag{font-size:10px;color:var(--good);font-weight:700;}
.biz-switcher-add{display:flex;gap:6px;padding-top:8px;margin-top:6px;border-top:1px solid var(--panel-line);}
.biz-switcher-add input{flex:1;min-width:0;padding:7px 8px;font-size:12.5px;border:1px solid var(--panel-line);border-radius:7px;}

/* ---------- Sidebar navigation ---------- */
.sidebar{display:flex;flex-direction:column;gap:16px;min-width:0;}
.sidebar .biz-switcher{width:100%;}
.sidebar .biz-switcher-btn{width:100%;}
.side-nav{display:flex;flex-direction:column;gap:2px;background:#fff;border:1px solid var(--panel-line);border-radius:12px;padding:6px;}
.side-nav-item{
  display:flex;align-items:center;gap:10px;padding:10px 12px;border:none;background:transparent;
  border-radius:8px;cursor:pointer;font:inherit;font-size:13.5px;color:var(--ink);text-align:left;font-weight:600;
}
.side-nav-item:hover{background:var(--panel);}
.side-nav-item.active{background:var(--navy);color:#fff;}
.sn-icon{font-size:15px;line-height:1;}
.side-logout{align-self:flex-start;}

/* ---------- Main content / views ---------- */
.main{min-width:0;}
.view-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px;flex-wrap:wrap;}
.view-head h2{margin:0;font-size:19px;color:var(--ink);}
.h2-actions{display:flex;align-items:center;gap:10px;}
.running-total{font-size:11px;font-weight:700;color:var(--navy);letter-spacing:.04em;}
.running-total b{font-size:13px;}

.create-grid{display:grid;grid-template-columns:400px 1fr;gap:22px;align-items:start;}

/* ---------- Document / customer tables ---------- */
.table-scroll{overflow-x:auto;}
.doc-table{width:100%;border-collapse:collapse;font-size:13.5px;}
.doc-table th{
  text-align:left;font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);
  padding:8px 10px;border-bottom:1px solid var(--panel-line);white-space:nowrap;
}
.doc-table td{padding:10px;border-bottom:1px solid var(--panel-line);vertical-align:middle;white-space:nowrap;}
.doc-table tr:last-child td{border-bottom:none;}
.doc-table td.wrap{white-space:normal;}
.doc-table .num-link{color:var(--navy);font-weight:700;cursor:pointer;background:none;border:none;padding:0;font:inherit;}
.doc-table .num-link:hover{text-decoration:underline;}
.doc-table .amt-cell{font-weight:700;color:var(--navy);text-align:right;}
.row-actions{display:flex;align-items:center;gap:2px;justify-content:flex-end;position:relative;}
.row-actions .btn.ghost{padding:5px 7px;}

.status-badge{
  display:inline-block;padding:3px 10px;border-radius:999px;font-size:11px;font-weight:700;white-space:nowrap;
}
.status-badge.draft{background:#eceff2;color:var(--muted);}
.status-badge.sent{background:var(--thead);color:var(--navy-deep);}
.status-badge.invoiced{background:#e6ddf7;color:#5a2ea6;}
.status-badge.paid{background:#dff3e8;color:var(--good);}

.status-menu{
  position:absolute;top:100%;right:0;z-index:30;min-width:150px;background:#fff;border:1px solid var(--panel-line);
  border-radius:10px;box-shadow:0 10px 28px rgba(20,30,50,.16);padding:6px;margin-top:4px;
}
.status-menu button{
  display:block;width:100%;text-align:left;padding:7px 10px;border:none;background:transparent;border-radius:6px;
  font:inherit;font-size:12.5px;color:var(--ink);cursor:pointer;
}
.status-menu button:hover{background:var(--panel);}
.status-menu .danger{color:var(--accent);}
.status-menu hr{border:none;border-top:1px solid var(--panel-line);margin:4px 0;}

.modal-box-sm{max-width:420px;}

/* ---------- List filters (Quotations/Invoices/Customers) ---------- */
.list-filters{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:8px;}
.list-filters .search-input{flex:1 1 220px;min-width:160px;margin-bottom:0;}
.list-filters select{
  padding:8px 10px;font-size:13px;border:1px solid var(--panel-line);border-radius:7px;
  background:#fff;color:var(--ink);min-width:130px;
}
.list-count{font-size:11.5px;color:var(--muted);margin-bottom:10px;}

/* ---------- Document detail (read-only) view ---------- */
.detail-toolbar{
  display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin-bottom:16px;
}
.detail-toolbar-right{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}
.status-pill-wrap{position:relative;}
.status-pill-btn{
  display:inline-flex;align-items:center;gap:6px;padding:6px 12px;border-radius:999px;font-size:12px;font-weight:700;
  border:1px solid var(--panel-line);cursor:pointer;background:#eceff2;color:var(--muted);
}
.status-pill-btn::after{content:"⌄";font-size:10px;opacity:.7;}
.status-pill-btn.sent{background:var(--thead);color:var(--navy-deep);border-color:transparent;}
.status-pill-btn.invoiced{background:#e6ddf7;color:#5a2ea6;border-color:transparent;}
.status-pill-btn.paid{background:#dff3e8;color:var(--good);border-color:transparent;}
.status-pill-btn.draft{background:#eceff2;color:var(--muted);border-color:var(--panel-line);}
.detail-body{display:flex;justify-content:center;}
.detail-body .sheet-viewport{width:100%;max-width:794px;}
.create-title{margin:2px 0 14px;font-size:19px;color:var(--ink);}

/* ---------- Customer field suggestions (replaces native <datalist>, which
   Safari/iOS support poorly or not at all) ---------- */
.cust-suggest-wrap{position:relative;}
.cust-suggest-list{
  position:absolute;top:100%;left:0;right:0;z-index:35;max-height:220px;overflow-y:auto;
  background:#fff;border:1px solid var(--panel-line);border-radius:10px;
  box-shadow:0 10px 28px rgba(20,30,50,.16);padding:6px;margin-top:4px;
}
.cust-suggest-list button{
  display:block;width:100%;text-align:left;padding:8px 10px;border:none;background:transparent;border-radius:7px;
  font:inherit;font-size:13px;color:var(--ink);cursor:pointer;
}
.cust-suggest-list button:hover{background:var(--panel);}

.doc-toggle{
  display:flex;background:#fff;border-radius:999px;padding:4px;border:1px solid var(--panel-line);
  box-shadow:0 1px 2px rgba(20,30,50,.06);max-width:100%;
}
.doc-toggle button{
  border:none;background:transparent;border-radius:999px;white-space:nowrap;min-width:0;
  font-weight:600;color:var(--muted);cursor:pointer;transition:.15s;
}
.doc-toggle button.active{background:var(--navy);color:#fff;}

.subtabs{
  display:flex;gap:6px;background:#fff;border:1px solid var(--panel-line);
  border-radius:10px;padding:4px;margin-bottom:16px;
}
.subtabs button{
  flex:1;border:none;background:transparent;padding:9px 10px;border-radius:7px;min-width:0;
  font-weight:700;font-size:13px;color:var(--muted);cursor:pointer;transition:.15s;
}
.subtabs button.active{background:var(--navy);color:#fff;}

.panel{
  background:var(--panel);
  border:1px solid var(--panel-line);
  border-radius:var(--radius);
  margin-bottom:16px;
}
.panel h2{
  font-size:12.5px;text-transform:uppercase;letter-spacing:.08em;
  color:var(--muted);margin:0 0 12px;font-weight:700;
  display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:6px;
}
.field{margin-bottom:10px;min-width:0;}
.field label{display:block;font-size:12px;color:var(--muted);margin-bottom:4px;font-weight:600;}
.field input, .field textarea, .field select{
  width:100%;max-width:100%;padding:8px 10px;border:1px solid var(--panel-line);border-radius:7px;
  font-size:13.5px;font-family:inherit;background:#fff;color:var(--ink);
}
.field textarea{resize:vertical;min-height:56px;line-height:1.4;}
.row2{display:grid;grid-template-columns:1fr 1fr;gap:10px;min-width:0;}
.row3{display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px;min-width:0;}
.checkline{display:flex;align-items:center;gap:8px;font-size:13px;color:var(--ink);margin-bottom:8px;}
.checkline input{width:auto;}

.logo-row{display:flex;align-items:center;gap:10px;min-width:0;}
.logo-row > div{min-width:0;}
.logo-preview{
  width:56px;height:56px;border-radius:8px;border:1px dashed var(--panel-line);
  display:flex;align-items:center;justify-content:center;overflow:hidden;background:#fff;flex-shrink:0;
}
.logo-preview img{width:100%;height:100%;object-fit:contain;}
.sig-preview{
  width:56px;height:40px;border-radius:6px;border:1px dashed var(--panel-line);
  display:flex;align-items:center;justify-content:center;overflow:hidden;background:#fff;flex-shrink:0;
}
.sig-preview img{width:100%;height:100%;object-fit:contain;}

.btn{
  border:none;border-radius:7px;padding:8px 14px;font-size:13px;font-weight:600;cursor:pointer;
  background:var(--navy);color:#fff;transition:.15s;
}
.btn:hover{background:var(--navy-deep);}
.btn.secondary{background:#fff;color:var(--ink);border:1px solid var(--panel-line);}
.btn.secondary:hover{background:#eef1f5;}
.btn.danger{background:#fff;color:var(--accent);border:1px solid #f0d3ce;}
.btn.danger:hover{background:#fdecea;}
.btn.ghost{background:transparent;color:var(--muted);border:1px solid transparent;padding:4px 8px;}
.btn.ghost:hover{color:var(--ink);background:#eceff2;}
.btn.block{width:100%;}
.btn-row{display:flex;gap:8px;flex-wrap:wrap;}

.item-row{
  display:grid;grid-template-columns: 1fr 70px 50px 74px 26px;gap:6px;margin-bottom:6px;align-items:center;min-width:0;
}
.item-row input{padding:7px 8px;font-size:13px;min-width:0;width:100%;}
.item-row .amt{font-size:13px;color:var(--muted);text-align:right;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.item-row-wrap{margin-bottom:6px;}
.item-row-wrap .item-row{margin-bottom:4px;}
.item-note-input{
  display:block;width:100%;border:1px solid transparent;background:transparent;padding:2px 8px 6px;
  font-style:italic;font-size:11.5px;color:var(--muted);font-family:inherit;resize:none;overflow:hidden;
  min-height:20px;line-height:1.4;
}
.item-note-input:focus{border-color:var(--panel-line);background:#fff;border-radius:6px;}
.item-note-input::placeholder{color:#b7bfca;}
.field textarea.item-note-input{
  resize:none;min-height:20px;font-style:italic;font-size:11.5px;color:var(--muted);background:transparent;border:1px solid transparent;
}
.field textarea.item-note-input:focus{border-color:var(--panel-line);background:#fff;}
.item-row .rm{
  background:none;border:none;color:var(--muted);cursor:pointer;font-size:16px;line-height:1;padding:2px;
}
.item-row .rm:hover{color:var(--accent);}
.item-row-head{font-size:11px;color:var(--muted);font-weight:700;}

/* Card layout used instead of the row/table style on mobile — see
   renderItemsEditor() in app.js, which renders one or the other depending
   on screen width. */
.item-card{
  background:#fff;border:1px solid var(--panel-line);border-radius:10px;
  padding:12px;margin-bottom:10px;
}
.item-card .field{margin-bottom:8px;}
.item-card .field:last-of-type{margin-bottom:10px;}
.item-card .field label{font-size:11px;}
.item-card .field input{padding:11px 10px;font-size:14.5px;}
.item-card-row2{display:grid;grid-template-columns:1fr 1fr;gap:8px;}
.item-card-remove{
  width:100%;padding:11px;border-radius:7px;border:1px solid #f0d3ce;
  background:#fff;color:var(--accent);font-weight:600;font-size:13px;cursor:pointer;
}
.item-card-remove:active{background:#fdecea;}

.history-list{max-height:260px;overflow-y:auto;}
/* Wraps each history item so it can be swiped left on touch devices to
   reveal a delete action — see attachSwipeToDelete() in app.js. The visible
   trash icon inside .history-item still works too, for mouse users and as
   a discoverable fallback. */
.swipe-item{position:relative;overflow:hidden;border-radius:7px;margin-bottom:6px;}
.swipe-action-delete{
  position:absolute;top:0;right:0;bottom:0;width:76px;border:none;cursor:pointer;
  background:var(--accent);color:#fff;display:flex;flex-direction:column;align-items:center;justify-content:center;
  font-weight:700;font-size:11px;gap:2px;
}
.swipe-action-delete .swipe-icon{font-size:16px;}
.history-item{
  display:flex;justify-content:space-between;align-items:center;gap:8px;
  padding:8px 10px;border-radius:7px;background:#fff;border:1px solid var(--panel-line);
  font-size:12.5px;cursor:pointer;min-width:0;position:relative;transition:transform .18s ease;touch-action:pan-y;
}
.history-item:hover{border-color:var(--navy);}
.history-item .meta{overflow:hidden;min-width:0;flex:1;}
.history-item .meta b{display:block;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.history-item .meta span{color:var(--muted);font-size:11.5px;display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.history-item .amt{font-weight:700;white-space:nowrap;color:var(--navy);flex-shrink:0;}
.history-empty{font-size:12.5px;color:var(--muted);text-align:center;padding:16px 0;}
.search-input{margin-bottom:8px;max-width:100%;}
.hint{font-size:11.5px;color:var(--muted);margin-top:2px;}

/* ---------- Bottom navigation & floating Create button (mobile only) ---------- */
.bottom-nav{
  display:none;
  position:fixed;left:0;right:0;bottom:0;z-index:80;
  background:#fff;border-top:1px solid var(--panel-line);
  box-shadow:0 -2px 10px rgba(20,30,50,.08);
  padding-bottom:env(safe-area-inset-bottom, 0px);
}
.bottom-nav button{
  flex:1;border:none;background:none;display:flex;flex-direction:column;align-items:center;gap:2px;
  padding:8px 4px 9px;font-size:11px;font-weight:600;color:var(--muted);cursor:pointer;min-width:0;
}
.bottom-nav button .bn-icon{font-size:19px;line-height:1;}
.bottom-nav button.active{color:var(--navy);}

.fab{
  display:none;
  position:fixed;z-index:90;
  width:56px;height:56px;border-radius:50%;
  background:var(--navy);color:#fff;border:none;
  font-size:26px;line-height:1;
  box-shadow:0 6px 18px rgba(15,25,45,.35);
  cursor:pointer;
  align-items:center;justify-content:center;
}
.fab:active{background:var(--navy-deep);}

::-webkit-scrollbar{width:8px;}
::-webkit-scrollbar-thumb{background:#c7cdd6;border-radius:8px;}

.toast{
  position:fixed;bottom:20px;left:50%;transform:translateX(-50%);
  background:var(--navy-deep);color:#fff;padding:10px 18px;border-radius:8px;font-size:13px;
  box-shadow:0 6px 20px rgba(0,0,0,.2);opacity:0;pointer-events:none;transition:.25s;z-index:50;
  max-width:calc(100vw - 32px);text-align:center;
}
.toast.show{opacity:1;transform:translateX(-50%) translateY(-4px);}

.modal-overlay{
  position:fixed;inset:0;background:rgba(15,25,45,.55);
  display:flex;align-items:center;justify-content:center;z-index:100;
}
.modal-box{
  background:#fff;max-height:92vh;
  display:flex;flex-direction:column;overflow:hidden;box-shadow:0 20px 60px rgba(0,0,0,.3);
}
.modal-head{
  display:flex;align-items:center;justify-content:space-between;padding:16px 20px;
  border-bottom:1px solid var(--panel-line);flex-shrink:0;gap:10px;
}
.modal-head h3{margin:0;font-size:15px;color:var(--ink);}
.modal-head .tag{
  font-size:11.5px;color:var(--good);font-weight:700;background:#e8f7ef;
  padding:3px 9px;border-radius:999px;margin-left:10px;white-space:nowrap;
}
.modal-body{overflow-y:auto;overflow-x:hidden;background:var(--panel);flex:1;}
.modal-actions{
  display:flex;justify-content:flex-end;gap:8px;padding:14px 20px;
  border-top:1px solid var(--panel-line);flex-shrink:0;flex-wrap:wrap;
}

.auth-wrap{
  min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px;
}
.auth-card{
  background:#fff;border-radius:14px;padding:34px 30px;max-width:380px;width:100%;
  box-shadow:0 10px 40px rgba(20,30,50,.16);border:1px solid var(--panel-line);
}
.auth-title{font-size:19px;margin:4px 0 6px;text-align:center;color:var(--ink);}
.auth-sub{font-size:12.5px;color:var(--muted);text-align:center;margin:0 0 18px;line-height:1.5;}
.auth-error{font-size:12.5px;color:var(--accent);min-height:16px;margin:-2px 0 10px;text-align:center;}

/* ==========================================================================
   THE DOCUMENT ITSELF — the invoice/quotation ruling. This is fixed: one set
   of sizes, fonts and spacing, identical on PC, mobile, and in print. It is
   never redefined per device — only zoomed uniformly to fit the available
   width (see scalePreview() in app.js and the print rules below), the same
   way a PDF viewer zooms a page without changing its layout.
   ========================================================================== */
.sheet{
  background:var(--paper);
  font-family:'Segoe UI',Arial,sans-serif;
  color:#222;
  position:relative;
  display:flex;
  flex-direction:column;
  width:794px;
  min-height:1123px;
  padding:52px 56px;
  transform-origin:top left;
}
.sheet-viewport{
  width:100%;overflow:hidden;margin:0 auto;max-width:850px;
  box-shadow:0 8px 30px rgba(20,30,50,.14);border-radius:2px;
}
.doc-head{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;}
.doc-head .company h3{margin:0 0 4px;color:var(--navy);font-weight:800;font-size:16px;letter-spacing:.03em;}
.doc-head .company div{color:#333;font-size:11.5px;line-height:1.55;}
.doc-logo{
  border-radius:50%;width:92px;height:92px;
  background:radial-gradient(circle at 34% 30%, #fff 0 9px, transparent 10px), conic-gradient(from 210deg, var(--accent), #14243c 60%, var(--accent));
  display:flex;align-items:center;justify-content:center;flex-shrink:0;
}
.doc-logo.has-image{border-radius:0;background:none;padding:2px;width:170px;height:125px;}
.doc-logo img{width:100%;height:100%;object-fit:contain;border-radius:inherit;}
.doc-title{text-align:center;font-weight:800;color:var(--navy);font-size:30px;letter-spacing:.06em;margin:22px 0 18px;}
.doc-meta{display:flex;justify-content:space-between;align-items:flex-start;flex-wrap:wrap;gap:10px;font-size:12px;margin-bottom:16px;}
.doc-meta .cust b{display:block;margin-bottom:2px;font-size:12.5px;}
.doc-meta .info{text-align:right;line-height:1.7;}
.doc-meta .info b{color:#222;}
table.items{width:100%;border-collapse:collapse;font-size:12px;margin-bottom:14px;}
table.items thead th{background:var(--thead);color:var(--navy-deep);text-align:left;font-weight:700;border:1px solid #c7d6e6;padding:8px 10px;font-size:11.5px;}
table.items thead th:not(:first-child){text-align:center;}
table.items tbody td{border:1px solid #dfe4ea;padding:7px 10px;font-size:12px;}
table.items tbody td:not(:first-child){text-align:center;}
table.items .item-note{display:block;font-style:italic;color:var(--muted);font-size:10.5px;margin-top:2px;line-height:1.3;}
table.items tfoot td{font-weight:800;background:#eef3f9;color:var(--navy-deep);border:1px solid #c7d6e6;padding:8px 10px;}
table.items tfoot td:first-child{text-align:right;}
table.items tfoot td:nth-child(3){text-align:center;}
table.items tfoot td:last-child{text-align:center;}
.terms{font-size:11.5px;margin-bottom:8px;}
.terms .t-head{font-weight:700;text-decoration:underline;display:block;margin-bottom:3px;}
.bank-box{border:1px solid #222;border-radius:2px;font-size:11.5px;margin:10px 0;max-width:300px;}
.bank-box .bb-head{font-weight:700;background:#fff;border-bottom:1px solid #222;padding:5px 10px;}
.bank-box .bb-body{color:var(--navy-deep);padding:6px 10px;line-height:1.6;}
.sig-block{display:flex;align-items:flex-end;margin-top:26px;gap:14px;}
.sig-line{font-family:'Brush Script MT',cursive;color:#3a3f66;transform:rotate(-3deg);font-size:26px;padding:0 18px 2px 0;min-width:90px;}
.sig-line.has-image{transform:none;font-size:0;padding:0 10px 6px 0;min-width:120px;max-width:200px;}
.sig-line.has-image img{display:block;object-fit:contain;max-height:52px;max-width:200px;}
.sig-name{font-size:12px;}
.sig-name b{display:block;color:var(--navy-deep);font-size:12.5px;}
.doc-footer{margin-top:auto;text-align:center;padding-top:28px;}
.doc-footer .contact{font-size:11px;color:#333;margin-bottom:2px;}
.doc-footer .thanks{font-weight:800;font-style:italic;color:var(--navy);font-size:12.5px;}

/* ==========================================================================
   PC / DESKTOP CONSTRUCTION  (screens wider than 820px)
   This only covers the app's own interface (editor + preview side by side,
   sticky preview column, panel spacing). The invoice/quotation document
   itself is defined once, unconditionally, above — it doesn't change here.
   ========================================================================== */
@media screen and (min-width: 821px){
  .app{
    display:grid;
    grid-template-columns: 240px 1fr;
    gap:22px;
    max-width:1400px;
    margin:0 auto;
    padding:22px;
    align-items:start;
  }
  .sidebar{position:sticky;top:22px;}
  #leftcol, .preview-wrap{min-width:0;}
  .panel{padding:16px 18px;}

  .preview-wrap{position:sticky;top:22px;}
  .preview-toolbar{display:flex;justify-content:flex-end;gap:8px;margin-bottom:12px;flex-wrap:wrap;}

  .modal-box{border-radius:12px;max-width:900px;width:100%;}
  .modal-body{padding:20px;}
  .modal-body .sheet-viewport{max-width:700px;}
  .modal-overlay{padding:20px;}
}

/* ==========================================================================
   MOBILE CONSTRUCTION  (screens 820px and narrower)
   Built separately, not a shrunk copy of the PC layout. Editor panels stack
   in a single column at native, comfortable touch sizes. This is the app's
   own interface only — the invoice/quotation document itself is defined
   once, unconditionally, above, and is never redefined per device; on
   mobile it's simply zoomed down uniformly to fit the narrower width (same
   mechanism as the PC construction), so it always matches print exactly.
   ========================================================================== */
@media screen and (max-width: 820px){
  .app{
    display:flex;flex-direction:column;gap:14px;padding:12px;padding-bottom:96px;width:100%;max-width:100%;margin:0;
  }
  .sidebar{display:none;}
  #leftcol, .preview-wrap{min-width:0;width:100%;}
  .preview-wrap{position:static;}
  .create-grid{display:flex;flex-direction:column;gap:14px;}

  .view-head{margin-bottom:10px;}
  .view-head h2{font-size:16.5px;}
  .doc-table{font-size:12.5px;}
  .doc-table th,.doc-table td{padding:8px 6px;}

  /* The column-header row only makes sense for the desktop table-style
     layout — mobile uses labeled cards instead (see .item-card). */
  .item-row-head{display:none;}

  .panel{padding:14px;}
  .row2,.row3{grid-template-columns:1fr;}
  .field input, .field textarea, .field select{padding:11px 10px;font-size:14.5px;}
  .btn{padding:12px 14px;min-height:44px;}
  .btn.ghost{min-height:auto;padding:8px 10px;}
  .btn-row .btn{flex:1 1 auto;min-width:120px;}
  .checkline input{width:20px;height:20px;}
  .preview-toolbar{display:flex;justify-content:center;gap:8px;margin-bottom:10px;}

  .bottom-nav{display:flex;}
  .fab{display:flex;right:16px;bottom:calc(76px + env(safe-area-inset-bottom, 0px));}

  .modal-overlay{padding:0;}
  .modal-box{border-radius:0;max-height:100vh;height:100vh;width:100%;max-width:100%;}
  .modal-box-sm{max-height:none;height:auto;border-radius:14px;margin:auto;}
  .modal-body{padding:12px;}
  .modal-actions{flex-wrap:wrap;}
}

/* ==========================================================================
   PRINT -- always the true, full-size A4 document, independent of whichever
   construction (PC or mobile) was on screen. Printing from a phone produces
   exactly the same PDF as printing from a desktop.
   ========================================================================== */
@media print{
  *{
    -webkit-print-color-adjust:exact !important;
    print-color-adjust:exact !important;
    color-adjust:exact !important;
  }
  body{background:#fff;}
  .app{display:block !important;padding:0 !important;max-width:none !important;margin:0 !important;}
  .sidebar,.view-head,#leftcol,.preview-toolbar,.detail-toolbar{display:none !important;}
  .preview-wrap{position:static !important;}

  .sheet-viewport{
    box-shadow:none !important;border-radius:0 !important;margin:0 !important;max-width:none !important;
    width:794px !important;overflow:visible !important;height:auto !important;
  }
  .sheet{
    box-shadow:none !important;border-radius:0 !important;margin:0 !important;
    width:794px !important;min-height:1123px !important;padding:52px 56px !important;
    transform:none !important;
  }
  .doc-head .company h3{font-size:16px !important;letter-spacing:.03em !important;}
  .doc-head .company div{font-size:11.5px !important;line-height:1.55 !important;}
  .doc-logo{width:92px !important;height:92px !important;}
  .doc-logo.has-image{width:170px !important;height:125px !important;}
  .doc-title{font-size:30px !important;letter-spacing:.06em !important;margin:22px 0 18px !important;}
  .doc-meta{font-size:12px !important;margin-bottom:16px !important;flex-wrap:nowrap !important;}
  .doc-meta .cust b{font-size:12.5px !important;}
  .doc-meta .info{line-height:1.7 !important;}
  table.items{font-size:12px !important;margin-bottom:14px !important;}
  table.items thead th{padding:8px 10px !important;font-size:11.5px !important;}
  table.items tbody td{padding:7px 10px !important;font-size:12px !important;}
  table.items .item-note{font-size:10.5px !important;}
  table.items tfoot td{padding:8px 10px !important;}
  .terms{font-size:11.5px !important;margin-bottom:8px !important;}
  .bank-box{font-size:11.5px !important;margin:10px 0 !important;max-width:300px !important;}
  .bank-box .bb-head{padding:5px 10px !important;}
  .bank-box .bb-body{padding:6px 10px !important;line-height:1.6 !important;}
  .sig-block{margin-top:26px !important;gap:14px !important;}
  .sig-line{font-size:26px !important;padding:0 18px 2px 0 !important;min-width:90px !important;}
  .sig-line.has-image{padding:0 10px 6px 0 !important;min-width:120px !important;max-width:200px !important;}
  .sig-line.has-image img{max-height:52px !important;max-width:200px !important;}
  .sig-name{font-size:12px !important;}
  .sig-name b{font-size:12.5px !important;}
  .doc-footer{padding-top:28px !important;}
  .doc-footer .contact{font-size:11px !important;}
  .doc-footer .thanks{font-size:12.5px !important;}

  @page{size:A4;margin:0;}

  /* If the Generate modal happens to be open while printing, print just the
     document itself -- not the modal's overlay, header, or buttons. */
  .modal-overlay{position:static !important;background:none !important;padding:0 !important;inset:auto;}
  .modal-box{box-shadow:none !important;max-height:none !important;height:auto !important;border-radius:0;max-width:none;}
  .modal-head,.modal-actions{display:none !important;}
  .modal-body{padding:0 !important;background:#fff !important;overflow:visible !important;}
}