@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

:root {
  --ink: #1d3a5f;        /* ledger navy: sidebar, primary actions */
  --ink-2: #2a4f7c;
  --gold: #f2b544;       /* brand mark, current-company accent */
  --paper: #ffffff;
  --desk: #eef1f4;       /* page background */
  --line: #d9dfe6;
  --line-2: #e8ecf0;
  --text: #1c2430;
  --muted: #667283;
  --pos: #2f7d4f;
  --neg: #b23b3b;
  --warn: #9a6a12;
  --r: 6px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif; color: var(--text); background: var(--desk); }
a { color: var(--ink-2); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .6em; font-weight: 600; }
h3 { font-size: 16px; } h4 { font-size: 14px; margin-top: 1.2em; }
.muted, small { color: var(--muted); }
small { font-size: 12px; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--neg); } .pos { color: var(--pos); }
code { background: var(--line-2); padding: 1px 5px; border-radius: 3px; font-size: 13px; }

/* ---------- Shell ---------- */
.side { position: fixed; inset: 0 auto 0 0; width: 236px; background: var(--ink); color: #c9d6e6; display: flex; flex-direction: column; z-index: 20; }
.side nav { flex: 1; overflow-y: auto; padding: 6px 10px 16px; }
.side nav a { display: flex; align-items: center; gap: 10px; color: #c9d6e6; padding: 5px 10px; border-radius: 5px; font-size: 13.5px; }
.side nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.side nav a.on { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.navh { font-size: 11.5px; color: #8ea3bd; padding: 10px 10px 3px; font-weight: 500; }
.ic { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.who { padding: 12px 18px; font-size: 12.5px; border-top: 1px solid rgba(255,255,255,.1); }
.who a { color: #fff; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; font-size: 14px; color: #fff; line-height: 1.25; }
.brand small { color: #8ea3bd; }
.mark { width: 34px; height: 34px; border-radius: 7px; background: var(--gold); color: var(--ink); display: grid; place-items: center; font: 700 17px Georgia, serif; flex: none; }
.mark.sm { width: 30px; height: 30px; font-size: 15px; }
.switcher { padding: 14px 14px 10px; border-bottom: 1px solid rgba(255,255,255,.1); display: block; }
.switcher summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; padding: 6px; border-radius: 6px; }
.switcher summary::-webkit-details-marker { display: none; }
.switcher summary:hover { background: rgba(255,255,255,.07); }
.switch-menu { margin-top: 6px; background: #fff; border-radius: 6px; padding: 4px; box-shadow: 0 8px 24px rgba(10,25,45,.35); }
.switch-menu a { display: block; padding: 7px 10px; border-radius: 4px; color: var(--text); font-size: 13px; }
.switch-menu a:hover { background: var(--desk); text-decoration: none; }
.switch-menu a.all { border-top: 1px solid var(--line-2); margin-top: 2px; color: var(--ink-2); }

main { margin-left: 236px; min-height: 100vh; }
.top { display: flex; align-items: center; gap: 14px; padding: 18px 28px 14px; background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top h1 { font-size: 20px; margin: 0; flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.burger { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--ink); }
.content { padding: 22px 28px 60px; max-width: 1280px; }
.shade { display: none; }

@media (max-width: 900px) {
  .side { transform: translateX(-100%); transition: transform .2s; }
  body.navopen .side { transform: none; }
  body.navopen .shade { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; }
  main { margin-left: 0; }
  .burger { display: block; }
  .top { padding: 12px 16px; flex-wrap: wrap; }
  .content { padding: 16px; }
}

/* ---------- Components ---------- */
.flash { margin: 14px 28px 0; padding: 10px 14px; border-radius: var(--r); background: #e8f4ec; border: 1px solid #bcdcc7; color: #1f5435; }
.flash.err { background: #fbeeee; border-color: #ecc4c4; color: #7d2323; }
.flash.warn { background: #fdf5e4; border-color: #ecd7a6; color: #6e4c0c; }
.content .flash { margin: 0 0 14px; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; margin-bottom: 18px; }
.card > h3:first-child { margin-top: 0; }
details.card > summary { cursor: pointer; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-bottom: 18px; }
.cards .card { margin: 0; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--line); background: var(--paper); color: var(--text); border-radius: 5px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { border-color: #b7c2cf; text-decoration: none; background: #f8fafb; }
.btn.pri { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.pri:hover { background: var(--ink-2); }
.btn.danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn.danger-ghost { color: var(--neg); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--ink-2); font: inherit; cursor: pointer; }
.linkbtn.danger { color: var(--neg); }

label { display: block; font-size: 13px; font-weight: 500; color: #3a4554; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 5px; font: inherit; font-weight: 400; color: var(--text); background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink-2); box-shadow: 0 0 0 3px rgba(42,79,124,.15); }
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0 6px 0 0; vertical-align: -2px; }
label.check { display: flex; align-items: center; font-weight: 400; padding-top: 22px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-bottom: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; margin-bottom: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; margin-bottom: 14px; }
.span2 { grid-column: span 2; }
@media (max-width: 700px) { .grid2, .grid3, .grid4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } label.check { padding-top: 4px; } }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters label { min-width: 140px; }
.filters input, .filters select { margin-top: 2px; }

table.t { width: 100%; border-collapse: collapse; background: var(--paper); }
.tablewrap { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); overflow-x: auto; margin-bottom: 18px; }
table.t th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); background: #f7f9fb; white-space: nowrap; }
table.t td { padding: 8px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: #fafbfc; }
table.t tfoot td { font-weight: 600; border-top: 1px solid var(--line); background: #f7f9fb; }
table.t tr.sub td { font-weight: 600; background: #f7f9fb; }
table.t tr.grand td { font-weight: 700; border-top: 2px solid var(--text); }
table.t td.empty { text-align: center; color: var(--muted); padding: 34px 12px; }
table.t .ind { padding-left: 28px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; background: #edf0f3; color: #4b5767; white-space: nowrap; }
.badge.g { background: #e3f2e8; color: #22603b; }
.badge.r { background: #f8e3e3; color: #8a2727; }
.badge.a { background: #fbf0d8; color: #7a560e; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs a.on { color: var(--ink); border-color: var(--ink); }
.tabs a:hover { text-decoration: none; color: var(--text); }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.inline-del { position: relative; }
.inline-del summary { list-style: none; }
.inline-del summary::-webkit-details-marker { display: none; }
.del-box { position: absolute; z-index: 5; right: 0; top: 34px; width: 280px; background: #fff; border: 1px solid #ecc4c4; border-radius: var(--r); padding: 12px; box-shadow: 0 8px 24px rgba(10,25,45,.15); }
.del-box p { margin: 0 0 8px; font-size: 13px; }
.del-box input { margin-bottom: 8px; }

.co-head { display: flex; gap: 10px; align-items: center; }
.co-head b { display: block; }
.card.co.current { border-color: var(--ink-2); box-shadow: inset 4px 0 0 var(--gold); }
.copyopts { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 16px; margin-bottom: 16px; }
.copyopts label.check { padding-top: 0; }
.copyopts p { grid-column: 1 / -1; margin: 4px 0 0; font-size: 13px; }

/* Dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.kpi .lbl { font-size: 13px; color: var(--muted); }
.kpi .val { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi a { font-size: 12.5px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-top: 10px; }
.bars .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .pair { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bars .b { width: 42%; max-width: 16px; border-radius: 3px 3px 0 0; min-height: 1px; }
.bars .b.inc { background: var(--ink-2); } .bars .b.exp { background: var(--gold); }
.bars small { font-size: 11px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.split { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

/* Document lines editor */
table.lines input, table.lines select { margin: 0; padding: 5px 7px; }
table.lines td { padding: 5px 6px; vertical-align: middle; }
table.lines .del { color: var(--neg); cursor: pointer; background: none; border: 0; font-size: 18px; line-height: 1; }
.totals { margin-left: auto; width: 300px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 2px solid var(--text); padding-top: 6px; margin-top: 4px; }

/* Bank processing */
table.bank td { vertical-align: middle; }
table.bank select, table.bank input { margin: 0; padding: 5px 6px; font-size: 13px; }
table.bank .desc { max-width: 260px; }
table.bank tr.suggested td { background: #fcf0cf; }
table.bank select.tax { min-width: 76px; }
.diff-ok { color: var(--pos); font-weight: 700; } .diff-bad { color: var(--neg); font-weight: 700; }
.stickybar { position: sticky; bottom: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; box-shadow: 0 -4px 16px rgba(10,25,45,.06); }

/* Auth / bare */
body.bare { display: block; }
.auth { max-width: 400px; margin: 8vh auto; padding: 0 16px; }
.auth.wide { max-width: 720px; margin-top: 5vh; }
.brand.big { margin-bottom: 18px; }
.brand.big b { color: var(--text); font-size: 18px; }
.brand.big small { color: var(--muted); }
.auth .card { padding: 22px; }
.auth label { margin-bottom: 12px; }
.auth h3 { margin-top: 6px; }
body.bare > .flash { max-width: 680px; margin: 14px auto; }

/* ---------- Printed documents ---------- */
.print-wrap { max-width: 820px; margin: 24px auto; background: #fff; padding: 44px 48px; border: 1px solid var(--line); }
.print-bar { max-width: 820px; margin: 18px auto 0; display: flex; gap: 8px; justify-content: flex-end; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.doc-head img { max-height: 80px; max-width: 240px; margin-bottom: 8px; }
.doc-title { font-size: 26px; font-weight: 600; color: var(--ink); text-align: right; margin: 0 0 6px; }
.doc-meta { text-align: right; font-size: 13px; }
.doc-meta td { padding: 1px 0 1px 14px; }
.doc-parties { display: flex; gap: 40px; margin-bottom: 24px; font-size: 13px; }
.doc-parties h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.doc-lines { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 14px; }
.doc-lines th { text-align: left; border-bottom: 2px solid var(--ink); padding: 6px 6px; font-weight: 600; }
.doc-lines td { border-bottom: 1px solid var(--line-2); padding: 6px; vertical-align: top; }
.doc-foot { margin-top: 28px; font-size: 12.5px; color: #3a4554; white-space: pre-line; }
.pre { white-space: pre-line; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 12px; }
  .side, .top, .print-bar, .noprint, .flash { display: none !important; }
  main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .print-wrap { border: 0; margin: 0; padding: 0; max-width: none; }
  .tablewrap, .card { border: 0; }
  a { color: inherit; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
table.t th.n, .doc-lines th.num { text-align: right; }
