:root{
  --ink:#1f2933;--muted:#7b8794;--brand:#2b6cb0;--brand-d:#234e7d;
  --line:#e4e7eb;--bg:#f5f7fa;--ok:#2f855a;--warn:#c05621;--card:#fff;
}
*{box-sizing:border-box}
body{font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif;margin:0;background:var(--bg);color:var(--ink)}
a{color:var(--brand);text-decoration:none}
a:hover{text-decoration:underline}

/* top bar */
.topbar{display:flex;align-items:center;gap:1.5rem;background:#fff;border-bottom:1px solid var(--line);padding:.75rem 1.25rem}
.brand{font-weight:700;font-size:1.05rem}
.brand span{color:var(--brand);font-weight:600}
.topbar nav{display:flex;gap:1rem;flex:1}
.topbar nav a{color:var(--ink);font-size:.95rem}
.who{font-size:.8rem;color:var(--muted)}

/* layout */
.wrap{max-width:960px;margin:2rem auto;padding:0 1.25rem}
h1{font-size:1.4rem;margin:0 0 1rem}
.flash{background:#ebf8ff;border:1px solid #bee3f8;color:#2b6cb0;padding:.6rem .9rem;border-radius:8px;margin-bottom:1rem;font-size:.9rem}

/* cards */
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:1rem}
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:1.25rem}
.card .n{font-size:2rem;font-weight:700}
.card .l{color:var(--muted);font-size:.85rem;margin-top:.25rem}
.card.soon{opacity:.6}

/* auth */
.authwrap{max-width:380px;margin:9vh auto;background:#fff;border:1px solid var(--line);border-radius:12px;padding:2rem}
.authwrap h1{font-size:1.25rem;margin:0 0 .25rem}
.authwrap .sub{color:var(--muted);font-size:.9rem;margin:0 0 1.5rem}
label{display:block;font-size:.85rem;margin:.75rem 0 .25rem;color:var(--muted)}
input,select{width:100%;padding:.6rem;border:1px solid var(--line);border-radius:8px;font-size:1rem}
button,.btn{margin-top:1.25rem;display:inline-block;padding:.65rem 1.1rem;background:var(--brand);color:#fff;border:0;border-radius:8px;font-size:1rem;cursor:pointer}
button:hover,.btn:hover{background:var(--brand-d);text-decoration:none}
.err{background:#fff5f5;border:1px solid #fed7d7;color:#c53030;padding:.55rem .8rem;border-radius:8px;font-size:.88rem;margin-bottom:.5rem}

/* tables */
table{width:100%;border-collapse:collapse;background:#fff;border:1px solid var(--line);border-radius:10px;overflow:hidden}
th,td{text-align:left;padding:.6rem .75rem;border-bottom:1px solid var(--line);font-size:.9rem}
th{background:#f8fafc;color:var(--muted);font-weight:600}
tr:last-child td{border-bottom:0}
td.r,th.r{text-align:right}
.toolbar{display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem}
.btn-sm{padding:.35rem .7rem;font-size:.82rem;margin:0}
.btn-ghost{background:#fff;color:var(--brand);border:1px solid var(--line)}
.btn-ghost:hover{background:#f8fafc}
.muted{color:var(--muted)}
.pill{display:inline-block;padding:.15rem .5rem;border-radius:999px;font-size:.72rem;font-weight:600}
.pill.none{background:#edf2f7;color:#4a5568}
.pill.queued{background:#feebc8;color:#c05621}
.pill.sent,.pill.delivered{background:#c6f6d5;color:#2f855a}
.pill.rejected{background:#fed7d7;color:#c53030}
.lowstock{color:#c05621;font-weight:600}
.row2{display:grid;grid-template-columns:1fr 1fr;gap:1rem}
.linetable input,.linetable select{margin:0}
fieldset{border:1px solid var(--line);border-radius:10px;padding:1rem;margin:0 0 1rem}
legend{color:var(--muted);font-size:.85rem;padding:0 .4rem}
.totbox{margin-top:1rem;text-align:right;font-size:.95rem}
.totbox .big{font-size:1.3rem;font-weight:700}

/* charts */
.charts{display:grid;grid-template-columns:2fr 1fr;gap:1rem;margin-top:1.5rem}
.chartcard{background:#fff;border:1px solid var(--line);border-radius:12px;padding:1.1rem}
.chartcard h3{margin:0 0 .75rem;font-size:.85rem;color:var(--muted);font-weight:600}
.chartcard canvas{max-height:250px}
@media(max-width:720px){.charts{grid-template-columns:1fr}}

/* responsive chart fix: let grid children shrink; constrain canvas to a fixed box */
.wrap{max-width:1100px}
.charts > .chartcard{min-width:0}
.chartbox{position:relative;height:260px;width:100%}
.chartbox canvas{position:absolute;inset:0;max-height:none}

/* invoice document */
.actionbar{display:flex;gap:.5rem;justify-content:flex-end;align-items:center;margin-bottom:1rem}
.actionbar .spacer{flex:1}
.invoice-doc{background:#fff;border:1px solid var(--line);border-radius:12px;padding:2.25rem}
.inv-top{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:1.75rem}
.inv-title{font-size:1.5rem;font-weight:700;letter-spacing:.03em}
.inv-seller{font-size:.85rem;color:var(--muted);margin-top:.4rem;line-height:1.5}
.inv-seller strong{color:var(--ink);font-size:.95rem}
.inv-meta{text-align:right;font-size:.88rem;line-height:1.7}
.inv-meta .muted{color:var(--muted)}
.inv-parties{margin-bottom:1.25rem;font-size:.9rem;line-height:1.5}
.inv-parties .lbl{color:var(--muted);font-size:.72rem;text-transform:uppercase;letter-spacing:.06em;margin-bottom:.3rem}
.inv-doc-table{margin-top:.5rem}
.inv-totals{margin:1.25rem 0 0 auto;width:300px;font-size:.92rem}
.inv-totals .tr{display:flex;justify-content:space-between;padding:.35rem 0;border-bottom:1px solid var(--line)}
.inv-totals .tr.grand{font-size:1.2rem;font-weight:700;border-bottom:0;border-top:2px solid var(--ink);margin-top:.3rem;padding-top:.55rem}
.inv-notes{margin-top:1.5rem;font-size:.85rem;color:var(--muted)}

@media print {
  .topbar,.actionbar,.no-print{display:none !important}
  body{background:#fff}
  .wrap{margin:0;max-width:none;padding:0}
  .invoice-doc{border:0;border-radius:0;padding:0}
  table{border:1px solid #ccc}
  th{background:#eee !important;-webkit-print-color-adjust:exact;print-color-adjust:exact}
}

/* autocomplete */
.ac{position:relative}
.ac-list{position:absolute;left:0;right:0;top:100%;z-index:30;background:#fff;border:1px solid var(--line);border-radius:0 0 8px 8px;max-height:280px;overflow:auto;display:none;box-shadow:0 8px 20px rgba(0,0,0,.10)}
.ac-list.open{display:block}
.ac-item{padding:.55rem .7rem;cursor:pointer;font-size:.92rem;border-bottom:1px solid #f0f2f5}
.ac-item:last-child{border-bottom:0}
.ac-item:hover,.ac-item.active{background:#ebf2fb}
.ac-item .u{color:var(--muted);font-size:.78rem;margin-left:.4rem}
.ac-empty{padding:.6rem .7rem;color:var(--muted);font-size:.85rem}

/* autocomplete dropdown floats below the input — round all corners to match */
.ac-list{border-radius:8px;margin-top:4px}

/* no faint divider directly above the Total's thick top border */
.inv-totals .tr:has(+ .grand){border-bottom:0}

/* common footer */
.appfoot{text-align:center;color:var(--muted);font-size:.8rem;padding:1.75rem 1rem;margin-top:2.5rem;border-top:1px solid var(--line)}
/* responsive top nav (was squashing on mobile) */
@media(max-width:640px){
  .topbar{flex-wrap:wrap;gap:.4rem .9rem;padding:.6rem .9rem}
  .topbar .brand{flex:1;font-size:1rem}
  .topbar .who{font-size:.75rem;order:2}
  .topbar .hide-sm{display:none}
  .topbar nav{order:5;flex-basis:100%;gap:1.1rem;overflow-x:auto;padding-top:.15rem}
}
/* new-invoice totals: one per line */
.totbox > div{padding:.12rem 0}

/* dashboard activity feed */
.activity h3{margin-bottom:.5rem}
.activity .ev{display:flex;align-items:center;gap:.7rem;padding:.55rem .15rem;border-bottom:1px solid var(--line);font-size:.9rem}
.activity .ev:last-child{border-bottom:0}
.activity .dot{width:9px;height:9px;border-radius:50%;flex:none}
.activity .dot.invoice{background:#2b6cb0}
.activity .dot.send{background:#f6ad55}
.activity .dot.stock{background:#48bb78}
.activity .when{margin-left:auto;color:var(--muted);font-size:.78rem;white-space:nowrap}

/* invoice document table — consistent ledger borders (override the rounded card-table style) */
.inv-doc-table{border:0;border-radius:0;overflow:visible}
.inv-doc-table th{background:transparent;border-bottom:2px solid #cbd5e0}
.inv-doc-table td{border-bottom:1px solid var(--line)}
.inv-doc-table tr:last-child td{border-bottom:1px solid var(--line)}
@media print{
  .inv-doc-table{border:0 !important}
  .inv-doc-table th{background:transparent !important;border-bottom:1.5px solid #333}
  .inv-doc-table td{border-bottom:1px solid #ccc}
}

/* sticky footer */
html{height:100%}
body{min-height:100vh;display:flex;flex-direction:column}
.wrap{flex:1 0 auto}
.topbar,.appfoot{flex-shrink:0}
/* textarea matches inputs */
textarea{width:100%;padding:.6rem;border:1px solid var(--line);border-radius:8px;font-size:1rem;font-family:inherit;min-height:90px;resize:vertical}
/* line-items table must let the item autocomplete dropdown overflow */
.linetable{border:0;border-radius:0;overflow:visible;background:transparent}
.linetable th{background:transparent}
.linetable td{vertical-align:top}

/* brand logo + invoice logo */
.brandlogo{height:34px;width:auto;display:block;max-width:200px;object-fit:contain}
.inv-logo{max-height:70px;max-width:260px;margin-bottom:.85rem;display:block;object-fit:contain}
.logo-preview{max-height:70px;max-width:240px;border:1px solid var(--line);border-radius:8px;padding:.4rem;background:#fff;margin:.5rem 0}

/* fix: flex-column body made .wrap collapse to content width — keep it full width up to its max-width */
.wrap{width:100%}

/* clickable logo upload */
.logo-drop{display:inline-block;cursor:pointer;border:1.5px dashed var(--line);border-radius:10px;padding:.6rem;background:#fff;min-width:220px;text-align:center}
.logo-drop:hover{border-color:var(--brand)}
.logo-ph{color:var(--muted);font-size:.9rem;padding:1.6rem 1.2rem;line-height:1.5}
.logo-preview{border:0;padding:0;margin:0}

/* ================= theme refresh: Inter font + neutral buttons ================= */
body{font-family:'Inter',system-ui,-apple-system,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility}
:root{--btn:#1f2933;--btn-hover:#0b1117}
/* primary buttons: near-black */
button,.btn{background:var(--btn);font-weight:500;letter-spacing:.005em}
button:hover,.btn:hover{background:var(--btn-hover)}
/* secondary / ghost: white + grey */
.btn-ghost{background:#fff;color:var(--ink);border:1px solid var(--line);font-weight:500}
.btn-ghost:hover{background:#f3f4f6;border-color:#cbd5e0;color:var(--ink)}
/* neutral brand text (when no logo) */
.brand span{color:var(--ink)}
/* headings a touch tighter */
h1{letter-spacing:-.01em}

/* ===== responsive nav: inline on desktop, hamburger dropdown on mobile ===== */
.navtoggle{display:none;margin-left:auto;background:transparent;border:0;color:var(--ink);padding:.25rem;cursor:pointer;align-items:center}
.topbar .navmenu{display:flex;align-items:center;gap:1.1rem;flex:1}
.topbar .navmenu > a{color:var(--ink);font-size:.95rem}
.topbar .navmenu > a:hover{color:var(--brand)}
.topbar .navmenu .navwho{margin-left:auto;color:var(--muted);font-size:.8rem;white-space:nowrap}
.topbar .navmenu .navsignout{color:var(--ink);white-space:nowrap}
@media(max-width:760px){
  .navtoggle{display:inline-flex}
  .topbar .navmenu{display:none;position:absolute;top:100%;left:0;right:0;flex-direction:column;align-items:stretch;gap:0;background:#fff;border-bottom:1px solid var(--line);box-shadow:0 12px 26px rgba(0,0,0,.12);padding:.4rem .8rem .85rem;z-index:50}
  .topbar .navmenu.open{display:flex}
  .topbar .navmenu > a{padding:.7rem .25rem;border-bottom:1px solid #f0f2f5}
  .topbar .navmenu .navwho{order:-1;margin:.5rem .25rem;border-bottom:1px solid var(--line);padding-bottom:.55rem;white-space:normal}
  .topbar .navmenu .navsignout{margin-top:.65rem;border-bottom:0;text-align:center}
}

/* line-item cells centered vertically (price/amount align with the inputs) */
.linetable td{vertical-align:middle}

/* hamburger: clean transparent icon (beats the dark button theme) */
.topbar .navtoggle{background:transparent;border:0;border-radius:0;margin:0 0 0 auto;padding:.3rem;color:var(--ink);box-shadow:none}
.topbar .navtoggle:hover{background:transparent;color:var(--brand)}

/* anchor the mobile dropdown to the topbar (was dropping to viewport bottom) */
.topbar{position:relative;z-index:40}

/* clean nav: kill blue/underline link defaults; sign-out = neutral button */
.topbar .navmenu > a{color:var(--ink);text-decoration:none;font-weight:500}
.topbar .navmenu > a:hover{color:#52606d;text-decoration:none}
.topbar .navmenu .navsignout,
.topbar .navmenu .navsignout:hover{color:var(--ink);text-decoration:none;background:#fff;border:1px solid var(--line);border-radius:8px}
.topbar .navmenu .navsignout:hover{background:#f3f4f6;border-color:#cbd5e0}
@media(max-width:760px){ .topbar .navmenu > a:hover{background:#f7f8fa} }

/* keep flash + app footer out of printed invoices */
@media print { .flash,.appfoot{display:none !important} }

/* pagination + filter bar */
.pager{display:flex;align-items:center;gap:.35rem;margin-top:1.1rem;flex-wrap:wrap}
.pager .pg{display:inline-block;padding:.4rem .7rem;border:1px solid var(--line);border-radius:8px;font-size:.85rem;color:var(--ink);text-decoration:none;background:#fff}
.pager a.pg:hover{background:#f3f4f6}
.pager .pg.current{background:var(--ink);color:#fff;border-color:var(--ink)}
.pager .pg.disabled{color:#c0c7d0;background:#fafbfc}
.pager .pg-gap{padding:0 .25rem;color:var(--muted)}
.pager .pg-info{margin-left:auto;color:var(--muted);font-size:.8rem}
.filterbar{display:flex;gap:.5rem;margin-bottom:1rem;flex-wrap:wrap;align-items:center}
.filterbar input[type=text]{width:auto;flex:1;min-width:220px}
.filterbar select{width:auto}
.filterbar .btn-sm{margin:0}

/* confirm modal */
.nsmodal{position:fixed;inset:0;background:rgba(15,23,32,.45);display:none;align-items:center;justify-content:center;z-index:200}
.nsmodal.open{display:flex}
.nsmodal-box{background:#fff;border-radius:14px;padding:1.5rem;max-width:380px;width:90%;box-shadow:0 24px 60px rgba(0,0,0,.28)}
.nsmodal-msg{font-size:.98rem;color:var(--ink);margin-bottom:1.25rem;line-height:1.5}
.nsmodal-actions{display:flex;justify-content:flex-end;gap:.6rem}
.nsmodal-actions button{margin:0}
/* paid/owed toggle pill */
.paidtoggle{margin:0;padding:.22rem .65rem;border-radius:999px;font-size:.72rem;font-weight:700;border:0;cursor:pointer;color:#fff;letter-spacing:.03em}
.paidtoggle.is-owed{background:#e53e3e}
.paidtoggle.is-owed:hover{background:#c53030}
.paidtoggle.is-paid{background:#2f855a}
.paidtoggle.is-paid:hover{background:#276749}
.totalrow td{background:#f8fafc;border-top:2px solid var(--line)}
.filterbar .fl{display:flex;flex-direction:column;font-size:.72rem;color:var(--muted);margin:0;gap:.15rem}
.filterbar .fl input{width:auto}

/* level filter controls: bottom-align (date fields have labels above) */
.filterbar{align-items:flex-end}

/* consistent buttons whether <button> or <a> (border-radius lived only on button/.btn) */
.btn-sm{display:inline-block;border-radius:8px;text-decoration:none;line-height:1.3;vertical-align:middle}
a.btn,a.btn-sm{text-decoration:none}
a.btn:hover,a.btn-sm:hover{text-decoration:none}
.fl select{width:auto}

/* filter bar: buttons match the text-box height */
.filterbar input,.filterbar select,.filterbar .btn-sm{height:42px;box-sizing:border-box}
.filterbar .btn-sm{display:inline-flex;align-items:center;justify-content:center;padding:0 1.1rem;font-size:.92rem}

/* report sub-nav (tabs) */
.subnav{display:flex;gap:1.25rem;margin-bottom:1rem;border-bottom:1px solid var(--line);padding-bottom:.5rem}
.subnav a{color:var(--muted);font-size:.92rem;text-decoration:none}
.subnav a:hover{color:var(--ink)}
.subnav a.cur{color:var(--ink);font-weight:600}

/* dashboard chart head + range tabs */
.charthead{display:flex;align-items:center;justify-content:space-between;gap:.5rem;flex-wrap:wrap;margin-bottom:.6rem}
.charthead h3{margin:0}
.rangetabs{display:flex;gap:.15rem;flex-wrap:wrap}
.rangetabs a{font-size:.74rem;color:var(--muted);text-decoration:none;padding:.2rem .5rem;border-radius:6px}
.rangetabs a:hover{background:#f3f4f6;color:var(--ink)}
.rangetabs a.cur{background:var(--ink);color:#fff}
.activity .dot.credit{background:#805ad5}

/* account link in the nav "who" area */
.topbar .navmenu .navwho a{color:var(--ink);text-decoration:underline;text-underline-offset:2px}
.topbar .navmenu .navwho a:hover{color:var(--brand)}

/* nicer checkboxes (custom, theme-coloured) */
input[type=checkbox]{
  -webkit-appearance:none;appearance:none;
  width:20px !important;height:20px;min-width:20px;
  border:1.5px solid var(--line);border-radius:6px;background:#fff;
  cursor:pointer;position:relative;vertical-align:-4px;flex:none;transition:background .12s,border-color .12s;
}
input[type=checkbox]:hover{border-color:#aab2bd}
input[type=checkbox]:checked{background:var(--ink);border-color:var(--ink)}
input[type=checkbox]:checked::after{
  content:'';position:absolute;left:6px;top:2px;width:5px;height:10px;
  border:solid #fff;border-width:0 2px 2px 0;transform:rotate(45deg);
}
input[type=checkbox]:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
input[type=checkbox]:disabled{opacity:.5;cursor:not-allowed}

/* account button in nav (ghost, like Sign out) */
.topbar .navmenu .navacct{color:var(--ink);text-decoration:none}
.topbar .navmenu .navacct:hover{color:var(--ink);background:#f3f4f6;border-color:#cbd5e0}
@media(max-width:760px){ .topbar .navmenu .navacct{margin-top:.4rem;border-bottom:0;text-align:center} }

/* ===== login page ===== */
.authbody{background:linear-gradient(165deg,#f7f9fc 0%,#eceff4 100%)}
.authwrap{box-shadow:0 20px 55px rgba(15,23,32,.12);text-align:center;padding:2.25rem 2rem 2rem}
.auth-logo{max-width:180px;height:auto;display:block;margin:0 auto 1.4rem}
.authwrap h1{font-size:1.35rem;margin:0 0 .2rem;letter-spacing:-.01em}
.authwrap .sub{margin-bottom:1.5rem}
.authwrap form{text-align:left;margin-top:.5rem}
.authwrap .err{text-align:left}
.authwrap button{width:100%;margin-top:1.6rem;padding:.7rem}
.authfoot{text-align:center;color:var(--muted);font-size:.78rem;margin:1.25rem 0}

/* restore the ghost-button bottom border in the mobile menu (it was being zeroed) */
@media(max-width:760px){
  .topbar .navmenu .navacct,.topbar .navmenu .navsignout{border-bottom:1px solid var(--line)}
}

/* login: center the card in the viewport, pin footer to bottom */
.authbody{justify-content:center;align-items:center;position:relative}
.authbody .authwrap{margin:0}
.authbody .authfoot{position:absolute;bottom:1.25rem;left:0;right:0;margin:0}

/* nudge the centered login card up a little */
.authbody .authwrap{margin-bottom:8vh}

/* hamburger: no blue focus highlight / tap flash */
.navtoggle{-webkit-tap-highlight-color:transparent}
.navtoggle:focus,.navtoggle:focus-visible{outline:none;box-shadow:none}
/* period toggle on its own row (was squashed beside the title on mobile) */
.rangetabs{margin:.25rem 0 1.25rem}
@media(max-width:640px){
  .rangetabs{width:100%;overflow-x:auto;flex-wrap:nowrap;white-space:nowrap;gap:.35rem;padding-bottom:.2rem}
  .rangetabs a{flex:none}
}

/* --- responsive tables: scroll horizontally instead of overflowing the page --- */
.tablescroll{width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
@media(max-width:640px){
  body{overflow-x:hidden}
  .tablescroll>table{min-width:560px}
}
/* --- inline-editable number cells (Items list) --- */
/* all pricing / numeric inputs render right-aligned (override the base full-width input rule) */
td.r input,th.r input,.cell-num,input.cell-num{text-align:right}
.cell-num{width:96px;max-width:100%;text-align:right;padding:.32rem .45rem;border:1px solid var(--line);border-radius:6px;font:inherit;background:#fff;display:inline-block}
.cell-num:focus{outline:none;border-color:var(--btn);box-shadow:0 0 0 2px rgba(31,41,51,.12)}
.cell-num:disabled{opacity:.55}
.cell-num.cell-ok{border-color:#48bb78;box-shadow:0 0 0 2px rgba(72,187,120,.28)}
.cell-num.cell-err{border-color:#fc8181;box-shadow:0 0 0 2px rgba(252,129,129,.28)}
input.cell-num.lowstock{color:#c0392b;font-weight:600}
