/* Finance Lab - one stylesheet, colours as CSS variables (light + dark). */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --border: #e3e8ef;
  --border-strong: #cdd5e0;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-600: #0d5f59;
  --primary-soft: #e6f4f2;
  --accent: #6366f1;
  --accent-soft: #eef0ff;
  --pos: #059669;
  --pos-soft: #e7f7f0;
  --neg: #dc2626;
  --neg-soft: #fdeeee;
  --warn: #b45309;
  --warn-soft: #fff6e5;
  --side-bg: #0b1f2a;
  --side-text: #c4d3dc;
  --side-muted: #6f8796;
  --side-hover: #12303e;
  --side-active: #134e4a;
  --chart-1: #0f9488;
  --chart-2: #a5b4fc;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 6px 20px rgba(15, 23, 42, .07);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0a1118;
  --surface: #111b24;
  --surface-2: #14202b;
  --surface-3: #1a2935;
  --border: #22323f;
  --border-strong: #31475a;
  --text: #e6edf3;
  --text-2: #b2c0cc;
  --muted: #8396a6;
  --primary: #2dd4bf;
  --primary-600: #14b8a6;
  --primary-soft: #0f2e2c;
  --accent: #a5b4fc;
  --accent-soft: #1e2246;
  --pos: #34d399;
  --pos-soft: #0f2a22;
  --neg: #f87171;
  --neg-soft: #34171a;
  --warn: #fbbf24;
  --warn-soft: #2f2410;
  --side-bg: #070d13;
  --side-text: #b5c4cf;
  --side-hover: #0f1d27;
  --side-active: #12403c;
  --chart-1: #2dd4bf;
  --chart-2: #6366f1;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 6px 20px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 24px; letter-spacing: -.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
code, pre { font-family: var(--mono); }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 6px; font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 18px; }
.mb0 { margin-bottom: 0; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar { background: var(--side-bg); color: var(--side-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 16px 12px 24px; scrollbar-width: thin; }
.brand { display: flex; gap: 10px; align-items: center; padding: 6px 8px 16px; color: #fff; text-decoration: none !important; }
.brand strong { display: block; font-size: 16px; }
.brand small { display: block; color: var(--side-muted); font-size: 11.5px; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; font-weight: 700; color: #04201d;
  background: linear-gradient(135deg, #5eead4, #14b8a6); box-shadow: 0 4px 14px rgba(20, 184, 166, .35); }
.nav-group { margin-top: 10px; }
.nav-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--side-muted); padding: 6px 10px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--side-text); font-size: 13.5px; text-decoration: none !important; }
.nav-link:hover { background: var(--side-hover); color: #fff; }
.nav-link.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #2dd4bf; }
.nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-no { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--side-muted); background: rgba(255, 255, 255, .06); padding: 0 6px; border-radius: 6px; }
.nav-link.active .nav-no { color: #99f6e4; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.crumb { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.chip { background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 12px; padding: 1px 8px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.today { color: var(--muted); font-size: 12.5px; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); }
.only-mobile { display: none; }
.scrim { display: none; }

.page { padding: 24px 28px 8px; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); margin: 2px 0 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.flash-zone { padding: 0 28px; max-width: 1320px; }
.flash { margin-top: 16px; padding: 10px 14px; border-radius: var(--radius-sm); font-weight: 500; }
.flash.ok { background: var(--pos-soft); color: var(--pos); border: 1px solid color-mix(in srgb, var(--pos) 30%, transparent); }
.flash.err { background: var(--neg-soft); color: var(--neg); border: 1px solid color-mix(in srgb, var(--neg) 30%, transparent); }
.foot { color: var(--muted); font-size: 12px; padding: 16px 28px 28px; }

/* ---------- cards / grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px 20px; min-width: 0; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .stack > .card + .card { margin-top: 0; }
.stack > * + * { margin-top: 16px !important; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 16px 20px 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }

.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .ico { position: absolute; right: 14px; top: 14px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi.neg .ico { background: var(--neg-soft); color: var(--neg); }
.kpi.warn .ico { background: var(--warn-soft); color: var(--warn); }
.kpi.accent .ico { background: var(--accent-soft); color: var(--accent); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero { color: var(--muted); }
td.warn { color: var(--warn); }
a.card { color: inherit; text-decoration: none !important; }
a.card:hover { border-color: var(--primary); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: 0; }
tr.sub td { background: var(--surface-2); font-weight: 600; }
tr.total td { font-weight: 700; border-top: 2px solid var(--border-strong); }
tr.grand td { font-weight: 800; font-size: 15px; background: var(--primary-soft); color: var(--primary); }
td.indent { padding-left: 28px; }
.doc-link { font-weight: 600; font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---------- pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.pill.ok, .pill.PAID { background: var(--pos-soft); color: var(--pos); }
.pill.bad, .pill.overdue { background: var(--neg-soft); color: var(--neg); }
.pill.warn, .pill.PARTIAL, .pill.soon { background: var(--warn-soft); color: var(--warn); }
.pill.info, .pill.ISSUED, .pill.upcoming { background: var(--accent-soft); color: var(--accent); }
.pill.VOID { text-decoration: line-through; }
.pill.IN { background: var(--pos-soft); color: var(--pos); }
.pill.OUT { background: var(--neg-soft); color: var(--neg); }

/* ---------- forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
:root[data-theme="dark"] .btn.primary { color: #04201d; }
.btn.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, transparent); }
.btn.danger:hover { background: var(--neg-soft); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
form.inline { display: inline; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
input[type="checkbox"], input[type="radio"] { width: auto; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.field { margin-bottom: 14px; }
.field .err { color: var(--neg); font-size: 12px; margin-top: 3px; }
.field.has-err input, .field.has-err select { border-color: var(--neg); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--text); }
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.filters .field { margin: 0; min-width: 140px; }
.filters .field.w-sm { min-width: 100px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; }
.seg a { padding: 6px 12px; color: var(--text-2); font-weight: 600; font-size: 13px; text-decoration: none !important; border-right: 1px solid var(--border); }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--primary); color: #fff; }
:root[data-theme="dark"] .seg a.on { color: #04201d; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; text-decoration: none !important; white-space: nowrap; }
.tabs a.on { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- summary boxes ---------- */
.sumbox { display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; font-variant-numeric: tabular-nums; }
.sumbox .k { color: var(--text-2); }
.sumbox .v { text-align: right; font-weight: 600; }
.sumbox .total { border-top: 1px solid var(--border-strong); padding-top: 6px; font-weight: 800; font-size: 15px; }
.callout { border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-2); border: 1px dashed var(--border-strong); color: var(--text-2); }
.callout.ok { background: var(--pos-soft); border-color: color-mix(in srgb, var(--pos) 35%, transparent); color: var(--pos); }
.callout.bad { background: var(--neg-soft); border-color: color-mix(in srgb, var(--neg) 35%, transparent); color: var(--neg); }
.big-number { font-size: 30px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* bars inside tables */
.meter { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; min-width: 80px; }
.meter > span { display: block; height: 100%; background: var(--chart-1); border-radius: 99px; }
.meter.over > span { background: var(--neg); }
.meter.alt > span { background: var(--accent); }

/* charts */
.chart { width: 100%; height: 220px; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .c1 { fill: var(--chart-1); }
.chart .c2 { fill: var(--chart-2); }
.chart .stroke { fill: none; stroke: var(--chart-1); stroke-width: 2.2; }
.chart .area { fill: color-mix(in srgb, var(--chart-1) 14%, transparent); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .l1 { background: var(--chart-1); }
.legend .l2 { background: var(--chart-2); }

/* feature map */
.features { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.feature { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); text-decoration: none !important; transition: border-color .15s, transform .15s; }
.feature:hover { border-color: var(--primary); transform: translateY(-1px); }
.feature .no { font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.feature .t { font-weight: 600; }
.feature .d { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* journal t-lines */
.dr { color: var(--text); }
.cr { padding-left: 34px !important; color: var(--text-2); }

/* invoice document */
.doc { max-width: 900px; }
.doc-top { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.doc-title { font-size: 26px; font-weight: 800; letter-spacing: .02em; color: var(--primary); }
.doc-meta { display: grid; grid-template-columns: auto auto; gap: 2px 14px; font-size: 13px; }
.doc-meta .k { color: var(--muted); }
.party-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.party-box .name { font-weight: 700; }
.stamp-void { color: var(--neg); border: 3px solid var(--neg); font-weight: 900; font-size: 22px; padding: 2px 14px; border-radius: 8px; transform: rotate(-8deg); display: inline-block; }

/* lesson panel */
.lesson-panel { padding: 8px 28px 0; max-width: 1320px; }
.lesson-panel details { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); }
.lesson-panel summary { cursor: pointer; padding: 12px 16px; display: flex; gap: 10px; align-items: center; font-weight: 700; list-style: none; flex-wrap: wrap; }
.lesson-panel summary::-webkit-details-marker { display: none; }
.lesson-panel summary .i { color: var(--accent); }
.lesson-panel summary .muted { font-weight: 400; }
.lesson-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 20px; padding: 0 18px 16px; }
.lesson-body h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 0 6px; }
.lesson-body ul { margin: 0; padding-left: 18px; }
.lesson-body li { margin: 3px 0; }
.code-list { list-style: none; padding: 0 !important; display: flex; flex-wrap: wrap; gap: 6px; }
pre.sql { margin: 0; background: #0b1622; color: #cfe3f1; padding: 14px; border-radius: 10px; overflow-x: auto; font-size: 12px; line-height: 1.55; max-height: 380px; }

/* budget grid */
.budget-grid input { min-width: 84px; padding: 5px 6px; font-size: 12.5px; }
.budget-grid td, .budget-grid th { padding: 5px 6px; }
.budget-grid .acc { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 210px; }
.budget-grid tr:hover .acc { background: var(--surface-2); }

/* lines editor */
.lines td { padding: 6px; }
.lines input, .lines select { padding: 6px 8px; }

/* print */
@media print {
  .sidebar, .topbar, .lesson-panel, .foot, .no-print, .flash-zone { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
  .page { padding: 0; }
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }
  .only-mobile { display: grid; }
  .page, .topbar, .lesson-panel, .flash-zone, .foot { padding-left: 16px; padding-right: 16px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .lesson-body { grid-template-columns: 1fr; }
  .today { display: none; }
}
@media (max-width: 560px) {
  .g4 { grid-template-columns: 1fr; }
  h1 { font-size: 20px; }
}
