:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1d2733;
  --muted: #5d6b7a;
  --line: #dfe4ea;
  --line-soft: #edf0f3;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --side: #102a35;
  --side-ink: #c9d6dd;
  --side-active: #1d4452;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff6dd;
  --ok: #18794e;
  --ok-soft: #e7f6ee;
  --info-soft: #e8f1fb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 16px 0 8px; font-weight: 650; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* layout */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 17px; padding: 4px 8px 14px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; font-size: 14px; }
.company-switch { display: block; background: var(--side-active); color: #fff; border-radius: 6px; padding: 8px 10px; margin: 0 0 14px; font-weight: 600; }
.company-switch small { display: block; color: var(--side-ink); font-weight: 400; }
.company-switch:hover { text-decoration: none; filter: brightness(1.1); }
.nav-group { margin-bottom: 12px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7f98a5; padding: 4px 10px; }
.nav a { display: flex; justify-content: space-between; color: var(--side-ink); padding: 6px 10px; border-radius: 6px; }
.nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; font-weight: 600; }
.main { min-width: 0; }
.topbar { display: flex; justify-content: flex-end; align-items: center; gap: 14px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar form { margin: 0; }
.content { padding: 22px 24px 60px; max-width: 1280px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:hover { background: #fafcfd; }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }
tfoot td { font-weight: 650; border-top: 1px solid var(--line); }
td.tight, th.tight { width: 1%; white-space: nowrap; }

/* report tables */
.report th { position: sticky; top: 0; }
.report td { padding: 5px 12px; border-bottom: none; }
.report tr.header td { font-weight: 650; padding-top: 12px; }
.report tr.subtotal td { font-weight: 600; border-top: 1px solid var(--line); }
.report tr.total td { font-weight: 650; border-top: 1px solid var(--line); background: #fafbfc; }
.report tr.grand td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); }
.report td.label { white-space: nowrap; }
.report td.label.d1 { padding-left: 28px; }
.report td.label.d2 { padding-left: 44px; }
.report td.label.d3 { padding-left: 60px; }
.report a { color: inherit; }
.report a:hover { color: var(--accent); }

/* forms */
label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 4px; color: #344150; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local],
input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #c8d0d9; border-radius: 6px; background: #fff; font: inherit; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 118, 110, .25); border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > * { width: auto; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 14px; }
legend { font-weight: 650; padding: 0 6px; }

/* buttons */
.btn, button {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 6px; border: 1px solid #c8d0d9;
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover, button:hover { background: #f3f5f7; text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover, button.primary:hover { filter: brightness(1.07); }
.btn.danger, button.danger { color: var(--danger); border-color: #f1c4bf; }
.btn.danger:hover, button.danger:hover { background: var(--danger-soft); }
.btn.small, button.small { padding: 4px 9px; font-size: 12.5px; }
.btn.link, button.link { border: none; background: none; color: var(--accent); padding: 0; font-weight: 500; }
button[disabled] { opacity: .5; cursor: not-allowed; }

/* badges & flashes */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--line-soft); color: var(--muted); white-space: nowrap; }
.badge.ok, .badge.paid, .badge.categorized, .badge.matched, .badge.completed { background: var(--ok-soft); color: var(--ok); }
.badge.warn, .badge.overdue, .badge.unreviewed, .badge.in_progress { background: var(--warn-soft); color: var(--warn); }
.badge.danger, .badge.void, .badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.info, .badge.approved, .badge.awaiting, .badge.logged { background: var(--info-soft); color: #175cd3; }
.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #b7e2c8; color: #0f5132; }
.flash.error { background: var(--danger-soft); border-color: #f1c4bf; color: #8a1c13; }
.flash.warn { background: var(--warn-soft); border-color: #f2dc9b; color: #6b4a00; }
.flash.info { background: var(--info-soft); border-color: #c4d9f5; color: #1849a9; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs .count { background: var(--line-soft); border-radius: 999px; padding: 0 7px; font-size: 11px; margin-left: 4px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth .card { width: 100%; max-width: 420px; padding: 28px; }
.auth .brand { color: var(--ink); justify-content: center; padding-bottom: 18px; }
.qr { display: flex; justify-content: center; margin: 10px 0; }
.qr svg { width: 240px; height: 240px; background: #fff; image-rendering: pixelated; shape-rendering: crispEdges; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; background: #fafbfc; padding: 14px; border-radius: 6px; border: 1px dashed var(--line); }
.secret { word-break: break-all; }

/* line items */
.lines td { padding: 4px 6px; }
.lines input, .lines select { padding: 5px 7px; }
.lines .del { color: var(--muted); border: none; background: none; font-size: 18px; padding: 0 6px; }
.totals { margin-left: auto; width: 320px; }
.totals td { border: none; padding: 4px 8px; }
.totals tr.grand td { font-size: 16px; font-weight: 700; border-top: 2px solid var(--ink); }

/* bank feed */
.feed td { vertical-align: top; }
.feed .desc { max-width: 340px; }
.feed .desc .memo { color: var(--muted); font-size: 12px; }
.feed form.quick { display: flex; gap: 6px; align-items: center; margin: 0; }
.feed form.quick select { min-width: 150px; max-width: 220px; }
.suggest { font-size: 11.5px; color: var(--accent); }
.bulkbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: #fafbfc; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bulkbar select { width: auto; min-width: 180px; }

/* reconcile */
.recon-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 6px 0 12px; }
.recon-summary .stat.diff-zero { border-color: #9ad3b5; background: var(--ok-soft); }
.recon-summary .stat.diff-off { border-color: #f2dc9b; background: var(--warn-soft); }
tr.cleared { background: #f4fbf7; }

/* chart */
.chart svg { width: 100%; height: 220px; }
.chart .legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.chart .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* invoice document */
.doc-sheet { background: #fff; max-width: 820px; margin: 0 auto; padding: 44px; border: 1px solid var(--line); border-radius: var(--radius); }
.doc-sheet .doc-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.doc-sheet .doc-title { font-size: 28px; font-weight: 300; letter-spacing: .04em; text-transform: uppercase; }
.doc-sheet table th { background: none; }
.doc-sheet .paid-stamp { color: var(--ok); border: 2px solid var(--ok); display: inline-block; padding: 4px 12px; border-radius: 6px; font-weight: 700; transform: rotate(-4deg); }
.public-bar { max-width: 820px; margin: 20px auto 12px; display: flex; justify-content: space-between; align-items: center; }

details > summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .grid.two, .grid.three, .grid.four, .recon-summary { grid-template-columns: 1fr 1fr; }
  .content { padding: 16px; }
}
@media print {
  .side, .topbar, .no-print, .public-bar, .flashes { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .card, .doc-sheet { border: none; box-shadow: none; padding: 0; }
  .content { padding: 0; max-width: none; }
}
.nowrap { white-space: nowrap; }

/* invoice templates */
.doc-sheet { --accent: #0f766e; }
.doc-sheet .doc-logo { max-height: 72px; max-width: 240px; object-fit: contain; display: inline-block; }
.doc-sheet .doc-company { font-size: 20px; font-weight: 700; }
.doc-sheet .doc-title { color: var(--accent); }
.doc-sheet .doc-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin-bottom: 4px; }
.doc-sheet .doc-lines thead th { border-bottom: 2px solid var(--accent); color: var(--ink); }
.doc-sheet .totals .grand td { border-top: 2px solid var(--accent); }
.doc-sheet.font-serif { font-family: Georgia, "Times New Roman", serif; }
.doc-sheet.layout-modern { padding-top: 0; overflow: hidden; }
.doc-sheet .doc-band { background: var(--accent); color: #fff; margin: 0 -44px 28px; padding: 26px 44px; display: flex; align-items: center; gap: 18px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.doc-sheet .doc-band .band-name { font-size: 20px; font-weight: 700; flex: 1; }
.doc-sheet .doc-band .band-title { text-align: right; font-size: 26px; font-weight: 300; letter-spacing: .04em; text-transform: uppercase; }
.doc-sheet .doc-band .band-number { font-size: 14px; font-weight: 600; letter-spacing: 0; }
.doc-sheet .doc-band .doc-logo { background: #fff; border-radius: 6px; padding: 6px; max-height: 64px; }
.doc-sheet .doc-band.logo-right .doc-logo { order: 3; }
.doc-sheet .doc-band.logo-center { flex-wrap: wrap; justify-content: center; text-align: center; }
.doc-sheet .doc-band.logo-center .doc-logo { flex-basis: 100%; max-width: 240px; object-position: center; }
.doc-sheet.layout-compact { padding: 28px; font-size: 13px; }
.doc-sheet.layout-compact .doc-head { margin-bottom: 16px; }
.doc-sheet.layout-compact .doc-title { font-size: 20px; }
.doc-sheet.layout-compact .doc-company { font-size: 16px; }
.doc-sheet.layout-compact td, .doc-sheet.layout-compact th { padding-top: 4px; padding-bottom: 4px; }
.report-logo { max-height: 56px; max-width: 220px; object-fit: contain; display: block; margin-bottom: 8px; }
@media print { .doc-sheet .doc-band { margin: 0 0 24px; } }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; }
table.consolidated td.cons, table.consolidated th.cons { background: var(--ok-soft); font-weight: 600; }
table.consolidated td.elim, table.consolidated th.elim { color: var(--muted); }
