:root{
  --ink:#10233f;
  --ink-soft:#40536f;
  --muted:#78859b;
  --paper:#f4f6f9;
  --card:#ffffff;
  --line:#dde3ec;
  --line-soft:#eef1f6;
  --accent:#1a4fd6;
  --accent-dark:#12379a;
  --accent-wash:#e9efff;
  --amber:#f2b21c;
  --green:#0d7a55;
  --green-wash:#e3f5ed;
  --red:#c8342a;
  --red-wash:#fdeae8;
  --radius:10px;
  --shadow:0 1px 2px rgba(16,35,63,.06), 0 6px 18px rgba(16,35,63,.05);
  --sidebar:236px;
}

*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  background:var(--paper);
  color:var(--ink);
  font-size:15px;
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
a{color:var(--accent);text-decoration:none}
a:hover{text-decoration:underline}
h1,h2,h3,h4{margin:0 0 .4em;font-weight:650;letter-spacing:-.015em;line-height:1.2}
h1{font-size:26px}
h2{font-size:19px}
h3{font-size:16px}
p{margin:0 0 1em}
small{font-size:12.5px}
.num{font-variant-numeric:tabular-nums;font-feature-settings:"tnum" 1}
.muted{color:var(--muted)}
.right{text-align:right}
.center{text-align:center}
.nowrap{white-space:nowrap}
.hide{display:none !important}
:focus-visible{outline:3px solid var(--accent);outline-offset:2px;border-radius:4px}

/* ---------- shell ---------- */
.shell{display:flex;min-height:100vh}
.sidebar{
  width:var(--sidebar);flex:0 0 var(--sidebar);
  background:var(--ink);color:#c6d2e4;
  padding:20px 14px 40px;position:sticky;top:0;height:100vh;overflow-y:auto;
}
.brand{display:flex;align-items:center;gap:10px;padding:4px 8px 20px;color:#fff}
.brand-mark{
  width:30px;height:30px;border-radius:8px;background:var(--accent);
  display:grid;place-items:center;font-weight:700;color:#fff;font-size:15px;flex:0 0 auto;
}
.brand-name{font-weight:650;font-size:15.5px;letter-spacing:-.01em}
.brand-name span{display:block;font-weight:400;font-size:11.5px;color:#7f92ae}
.nav{display:flex;flex-direction:column;gap:1px}
.nav a{
  display:flex;align-items:center;gap:10px;
  padding:9px 10px;border-radius:8px;color:#c6d2e4;font-size:14.5px;
}
.nav a:hover{background:rgba(255,255,255,.07);text-decoration:none;color:#fff}
.nav a.on{background:var(--accent);color:#fff;font-weight:550}
.nav-sep{margin:14px 10px 6px;font-size:11px;color:#6d80a0;letter-spacing:.04em}
.nav svg{width:17px;height:17px;flex:0 0 auto;opacity:.9}

.main{flex:1;min-width:0;padding:26px 30px 90px}
.topbar{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin-bottom:22px;flex-wrap:wrap}
.topbar .sub{color:var(--muted);font-size:14px;margin-top:-2px}
.topbar-actions{display:flex;gap:8px;flex-wrap:wrap}

/* ---------- buttons ---------- */
.btn{
  display:inline-flex;align-items:center;gap:7px;justify-content:center;
  padding:9px 15px;border-radius:8px;border:1px solid var(--line);
  background:var(--card);color:var(--ink);font-size:14.5px;font-weight:550;
  cursor:pointer;font-family:inherit;
}
.btn:hover{background:#f7f9fc;text-decoration:none}
.btn-primary{background:var(--accent);border-color:var(--accent);color:#fff}
.btn-primary:hover{background:var(--accent-dark);border-color:var(--accent-dark)}
.btn-danger{color:var(--red);border-color:#f0c9c5}
.btn-danger:hover{background:var(--red-wash)}
.btn-sm{padding:6px 11px;font-size:13.5px}
.btn-block{width:100%}
.btn svg{width:16px;height:16px}
.btn[disabled]{opacity:.5;cursor:not-allowed}

/* ---------- cards ---------- */
.card{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow)}
.card-pad{padding:18px 20px}
.card-head{padding:14px 20px;border-bottom:1px solid var(--line-soft);display:flex;align-items:center;justify-content:space-between;gap:12px}
.card-head h2,.card-head h3{margin:0}
.stack{display:flex;flex-direction:column;gap:18px}
.grid{display:grid;gap:18px}
.grid-2{grid-template-columns:repeat(2,minmax(0,1fr))}
.grid-3{grid-template-columns:repeat(3,minmax(0,1fr))}
.grid-side{grid-template-columns:minmax(0,1fr) var(--side-w,340px);align-items:start}

/* ---------- money hero ---------- */
.hero{
  background:var(--ink);color:#fff;border-radius:14px;padding:24px 26px;
  display:flex;gap:34px;flex-wrap:wrap;align-items:flex-end;justify-content:space-between;
}
.hero-figure .label{font-size:13.5px;color:#9fb1cb;margin-bottom:2px}
.hero-figure .amount{font-size:42px;font-weight:680;letter-spacing:-.03em;line-height:1}
.hero-figure .amount.small{font-size:24px;font-weight:640}
.hero-split{display:flex;gap:30px;flex-wrap:wrap}
.hero-figure .amount.warn{color:var(--amber)}
.spark{display:flex;align-items:flex-end;gap:7px;height:70px}
.spark-col{width:26px;display:flex;flex-direction:column;justify-content:flex-end;align-items:center;gap:5px;height:100%}
.spark-bar{width:100%;background:var(--accent);border-radius:3px 3px 0 0;min-height:3px}
.spark-bar.dim{background:#33507c}
.spark-label{font-size:10.5px;color:#8ea1bd}

/* ---------- stat tiles ---------- */
.tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:14px}
.tile{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:15px 16px}
.tile .k{font-size:13px;color:var(--muted)}
.tile .v{font-size:23px;font-weight:660;letter-spacing:-.02em;margin-top:3px}
.trend{font-size:12.5px;font-weight:600;margin-left:6px}
.trend.up{color:var(--green)}
.trend.down{color:var(--red)}

/* ---------- tables ---------- */
.table-wrap{overflow-x:auto}
table.list{width:100%;border-collapse:collapse}
table.list th{
  text-align:left;font-size:12.5px;font-weight:600;color:var(--muted);
  padding:10px 14px;border-bottom:1px solid var(--line);white-space:nowrap;
}
table.list td{padding:12px 14px;border-bottom:1px solid var(--line-soft);vertical-align:middle}
table.list tr:last-child td{border-bottom:0}
table.list tbody tr:hover{background:#fafbfd}
table.list a.strong{font-weight:600;color:var(--ink)}
table.list a.strong:hover{color:var(--accent)}
.row-actions{display:flex;gap:6px;justify-content:flex-end}

/* ---------- pills ---------- */
.pill{
  display:inline-block;padding:3px 9px;border-radius:99px;font-size:12px;font-weight:600;
  background:var(--line-soft);color:var(--ink-soft);white-space:nowrap;
}
.pill-paid{background:var(--green-wash);color:var(--green)}
.pill-overdue{background:var(--red-wash);color:var(--red)}
.pill-partial{background:#fdf2d9;color:#8a6100}
.pill-unpaid,.pill-sent{background:var(--accent-wash);color:var(--accent-dark)}
.pill-draft{background:#eef1f6;color:var(--muted)}
.pill-accepted{background:var(--green-wash);color:var(--green)}
.pill-declined{background:var(--red-wash);color:var(--red)}
.pill-invoiced{background:var(--accent-wash);color:var(--accent-dark)}

/* ---------- forms ---------- */
label{display:block;font-size:13px;font-weight:600;color:var(--ink-soft);margin-bottom:5px}
input[type=text],input[type=email],input[type=password],input[type=number],
input[type=date],input[type=url],input[type=tel],select,textarea{
  width:100%;padding:9px 11px;border:1px solid var(--line);border-radius:8px;
  font-family:inherit;font-size:14.5px;color:var(--ink);background:#fff;
}
input:focus,select:focus,textarea:focus{border-color:var(--accent);outline:none;box-shadow:0 0 0 3px rgba(26,79,214,.14)}
textarea{min-height:88px;resize:vertical;line-height:1.5}
input[type=file]{font-size:13.5px}
.field{margin-bottom:15px}
.field-row{display:grid;gap:14px;grid-template-columns:repeat(auto-fit,minmax(190px,1fr))}
.check{display:flex;align-items:center;gap:8px;font-weight:500;color:var(--ink)}
.check input{width:16px;height:16px;margin:0}
.help{font-size:12.5px;color:var(--muted);margin-top:5px}
fieldset{border:0;padding:0;margin:0 0 26px}
legend{font-size:12.5px;font-weight:650;color:var(--muted);padding:0 0 10px}

/* ---------- line items editor ---------- */
.lines{width:100%;border-collapse:collapse}
.lines th{font-size:12.5px;color:var(--muted);text-align:left;font-weight:600;padding:0 8px 8px}
.lines td{padding:5px 8px 5px 0;vertical-align:top}
.lines td:last-child{padding-right:0}
.lines input{padding:8px 9px}
.lines .amt{font-weight:600;padding-top:16px;display:block;text-align:right}
.line-desc{margin-top:5px}
.drag{cursor:grab;color:var(--muted);padding:12px 2px 0;user-select:none}
.line-del{
  background:none;border:0;color:var(--muted);cursor:pointer;font-size:19px;
  line-height:1;padding:12px 4px 0;
}
.line-del:hover{color:var(--red)}
.totals{margin-left:auto;width:100%;max-width:340px}
.totals .row{display:flex;justify-content:space-between;padding:7px 0;font-size:14.5px}
.totals .row.grand{
  border-top:2px solid var(--ink);margin-top:6px;padding-top:11px;
  font-size:19px;font-weight:680;letter-spacing:-.02em;
}
.totals .row.due{color:var(--accent)}

/* ---------- flash ---------- */
.flash{padding:11px 15px;border-radius:9px;margin-bottom:16px;font-size:14.5px;border:1px solid}
.flash-ok{background:var(--green-wash);border-color:#bfe5d4;color:#0a5c40}
.flash-error{background:var(--red-wash);border-color:#f3c8c4;color:#93261e}
.flash-info{background:var(--accent-wash);border-color:#c9d8fb;color:var(--accent-dark)}

/* ---------- empty state ---------- */
.empty{padding:52px 24px;text-align:center;color:var(--muted)}
.empty h3{color:var(--ink);margin-bottom:6px}
.empty p{max-width:38ch;margin:0 auto 18px}

/* ---------- filters ---------- */
.filters{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:16px}
.filters input,.filters select{width:auto;min-width:150px}
.chips{display:flex;gap:6px;flex-wrap:wrap}
.chip{padding:6px 12px;border-radius:99px;border:1px solid var(--line);background:#fff;font-size:13.5px;color:var(--ink-soft)}
.chip:hover{text-decoration:none;background:#f7f9fc}
.chip.on{background:var(--ink);border-color:var(--ink);color:#fff;font-weight:550}

/* ---------- auth screens ---------- */
.auth{min-height:100vh;display:grid;place-items:center;padding:24px;background:var(--ink)}
.auth-box{width:100%;max-width:390px;background:#fff;border-radius:14px;padding:30px 28px;box-shadow:0 20px 50px rgba(0,0,0,.3)}
.auth-box h1{font-size:22px}
.auth-box .lead{color:var(--muted);font-size:14px;margin-bottom:22px}

/* ---------- document preview ---------- */
.doc-frame{background:#fff;border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;box-shadow:var(--shadow)}
.doc-frame iframe{width:100%;border:0;display:block;min-height:900px;background:#fff}
.side-panel{display:flex;flex-direction:column;gap:16px}
.kv{display:flex;justify-content:space-between;gap:12px;padding:6px 0;font-size:14px;border-bottom:1px solid var(--line-soft)}
.kv:last-child{border-bottom:0}
.kv .k{color:var(--muted)}
.share-url{
  display:flex;gap:6px;
}
.share-url input{font-size:12.5px;padding:7px 9px}

/* ---------- report bars ---------- */
.bars{display:flex;align-items:flex-end;gap:12px;height:200px;padding-top:10px}
.bars-col{flex:1;display:flex;flex-direction:column;justify-content:flex-end;gap:4px;height:100%;min-width:0}
.bars-pair{display:flex;gap:3px;align-items:flex-end;height:100%}
.bars-bar{flex:1;border-radius:3px 3px 0 0;min-height:2px}
.bars-in{background:var(--accent)}
.bars-out{background:#c9d3e2}
.bars-label{font-size:11.5px;color:var(--muted);text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.legend{display:flex;gap:16px;font-size:13px;color:var(--muted);margin-top:12px}
.legend i{display:inline-block;width:10px;height:10px;border-radius:2px;margin-right:6px}

/* ---------- mobile ---------- */
.mobile-bar{display:none}
.mobile-topbar{display:none}
@media (max-width:860px){
  .mobile-topbar{
    display:flex;align-items:center;justify-content:space-between;gap:10px;
    position:sticky;top:0;z-index:45;background:var(--ink);color:#fff;padding:11px 14px;
  }
  .mobile-topbar .brand{padding:0;color:#fff}
  .menu-btn{
    background:rgba(255,255,255,.14);border:0;color:#fff;width:38px;height:38px;
    border-radius:9px;display:grid;place-items:center;cursor:pointer;flex:0 0 auto;
  }
  .menu-btn svg{width:19px;height:19px}

  .sidebar{
    position:fixed;top:0;left:0;bottom:0;z-index:60;max-width:84vw;
    transform:translateX(-100%);transition:transform .22s ease;box-shadow:none;
  }
  .sidebar.open{transform:translateX(0);box-shadow:14px 0 44px rgba(0,0,0,.35)}
  .sidebar .brand{position:relative}
  .sidebar-close{
    margin-left:auto;background:transparent;border:0;color:#9fb1cb;
    font-size:26px;line-height:1;cursor:pointer;padding:2px 6px;
  }
  .sidebar-backdrop{display:none;position:fixed;inset:0;background:rgba(7,17,32,.55);z-index:55}
  .sidebar-backdrop.show{display:block}
  body.menu-open{overflow:hidden}

  .main{padding:16px 14px 96px}
  h1{font-size:21px}
  .hero{padding:18px;gap:20px}
  .hero-figure .amount{font-size:34px}
  .grid-2,.grid-3,.grid-side{grid-template-columns:1fr}
  .mobile-bar{
    display:flex;position:fixed;bottom:0;left:0;right:0;z-index:40;
    background:#fff;border-top:1px solid var(--line);padding:6px 4px 8px;
    justify-content:space-around;
  }
  .mobile-bar a,.mobile-bar button{
    flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;
    font-size:10.5px;color:var(--muted);padding:5px 2px;
    background:none;border:0;font-family:inherit;cursor:pointer;
  }
  .mobile-bar a.on{color:var(--accent);font-weight:600}
  .mobile-bar svg{width:21px;height:21px}
  .mobile-bar a:hover{text-decoration:none}
  table.list th:nth-child(n+4),table.list td:nth-child(n+4){display:none}
  .lines thead{display:none}
  .lines tr{display:block;border:1px solid var(--line);border-radius:9px;padding:10px;margin-bottom:10px;background:#fbfcfe}
  .lines td{display:block;padding:4px 0}
  .lines td[data-l]::before{content:attr(data-l);display:block;font-size:12px;color:var(--muted);font-weight:600;margin-bottom:4px}
  .lines .amt{text-align:left;padding-top:0}
  .line-del{padding:4px 0}
  .drag{display:none}
  .totals{max-width:none}
  .doc-frame iframe{min-height:640px}
}

@media print{
  .sidebar,.mobile-bar,.mobile-topbar,.sidebar-backdrop,.topbar-actions,.no-print{display:none !important}
  body{background:#fff}
  .main{padding:0}
}

.nav-count{
  display:inline-block;min-width:19px;padding:1px 6px;margin-left:auto;
  background:var(--amber);color:#3a2900;border-radius:99px;
  font-size:11.5px;font-weight:700;text-align:center;
}
