:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2430;
  --muted: #6b7380;
  --line: #e2e5ea;
  --primary: #0f5c8c;
  --primary-ink: #ffffff;
  --primary-soft: #e6f0f7;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --ok: #18794e;
  --ok-soft: #e5f5ec;
  --info-soft: #eaf2fb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Sinhala", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
:root[data-theme="dark"] {
  --bg: #12151b; --surface: #1b2029; --text: #e6e9ee; --muted: #98a1ae; --line: #2c333f;
  --primary: #4ea3db; --primary-ink: #0b1620; --primary-soft: #16303f;
  --danger: #f2877d; --danger-soft: #3a1d1b; --warn: #f0b955; --warn-soft: #3a2e14;
  --ok: #5fd39a; --ok-soft: #15301f; --info-soft: #182736;
  color-scheme: dark;
}
:root {
  color-scheme: light;
  --surface-2: #ffffff;
  /* Chart palette (validated: colour-blind safe adjacent pairs) */
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100; --c5: #e87ba4; --c6: #008300; --c7: #6250d6; --c8: #e34948;
  --c-rec: #2a78d6; --c-exp: #eb6834; --c-net: #6250d6;
  --chart-grid: #eceef1; --chart-axis: #c3c7cf; --chart-ink: #1d2430; --chart-muted: #6b7380; --chart-hover: rgba(15, 92, 140, .06);
  --h1: #cde2fb; --h2: #9ec5f4; --h3: #6da7ec; --h4: #3987e5; --h5: #256abf; --h6: #184f95; --h7: #0d366b;
  --h-ink-dark: #0b1f36; --h-ink-light: #ffffff;
}
:root[data-theme="dark"] {
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
  --c-rec: #3987e5; --c-exp: #d95926; --c-net: #9085e9;
  --chart-grid: #262c36; --chart-axis: #3a424f; --chart-ink: #e6e9ee; --chart-muted: #98a1ae; --chart-hover: rgba(78, 163, 219, .08);
  --h1: #13263b; --h2: #163657; --h3: #184f95; --h4: #1c5cab; --h5: #2a78d6; --h6: #5598e7; --h7: #9ec5f4;
  --h-ink-dark: #e6e9ee; --h-ink-light: #0b1620;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 48px; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 20px; min-height: 56px; }
.brand { font-weight: 600; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { background: var(--primary); color: var(--primary-ink); padding: 2px 7px; border-radius: 5px; font-size: .8rem; letter-spacing: .04em; margin-right: 4px; }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 6px; }
.nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: .9rem; white-space: nowrap; }
.userbox a:first-child { color: var(--text); }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 10px; font-size: 1.1rem; }
.role { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 4px; background: var(--bg); color: var(--muted); }
.role-admin { background: var(--primary-soft); color: var(--primary); }

@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .nav-toggle { display: block; }
  .nav, .userbox { display: none; width: 100%; }
  .nav-open .nav { display: flex; flex-direction: column; }
  .nav-open .userbox { display: flex; padding: 8px 12px 4px; border-top: 1px solid var(--line); }
}

/* Page */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.narrow { max-width: 460px; }
.card.narrow-wide { max-width: 760px; }
.table-card { padding: 0; overflow: hidden; }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; color: var(--text); box-shadow: var(--shadow); }
.stat:hover { border-color: var(--primary); text-decoration: none; }
.stat-num { font-size: 1.7rem; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-warn .stat-num { color: var(--warn); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 4px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--primary); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--line); }
.btn-sm { padding: 3px 9px; font-size: .82rem; }
.btn-block { width: 100%; justify-content: center; }
form.inline { display: inline; }

/* Forms */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input.short { width: 80px; }
input.full { width: 100%; }
input.short-pass { width: 140px; padding: 3px 8px; font-size: .82rem; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; font-weight: 500; }
.form label input, .form label select, .form label textarea { font-weight: 400; width: 100%; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
label.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; }
label.check input { width: auto !important; }
label.confirm { background: var(--warn-soft); padding: 8px 10px; border-radius: 6px; }
.form-buttons { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; }

.filters, .inline-add { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters label, .inline-add label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); }
.filters label.check { align-self: center; padding-top: 18px; color: var(--text); }
.filters .grow, .inline-add .grow { flex: 1 1 220px; }
.filters .grow input, .inline-add .grow input { width: 100%; }
.filters select { max-width: 280px; }
.filter-buttons { display: flex; gap: 6px; }
.result-count { margin: -4px 0 10px; font-size: .88rem; }

/* Tables */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 40%, transparent); }
.table td.right form + form, .table td.right .btn + form, .table td.right form + .btn { margin-left: 4px; }
.card > .table { margin: 0; }
.card .table th:first-child, .card .table td:first-child { padding-left: 16px; }
.table td input { padding: 4px 8px; }
.row-inactive td { color: var(--muted); }
.row-inactive td.code { text-decoration: line-through; }
.empty { text-align: center; color: var(--muted); padding: 32px !important; }
.codes-table td.code { font-family: var(--mono); font-size: .9rem; white-space: nowrap; }
.codes-table td.notes { max-width: 280px; }
.cat-chip { display: inline-block; min-width: 30px; text-align: center; font-family: var(--mono); font-size: .8rem; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

/* Badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: var(--bg); color: var(--muted); vertical-align: middle; white-space: nowrap; }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-dup { background: var(--info-soft); color: var(--primary); margin-left: 4px; }
.badge-off, .badge-deactivate { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge-new, .badge-create { background: var(--ok-soft); color: var(--ok); }
.badge-ok, .badge-activate, .badge-reviewed { background: var(--ok-soft); color: var(--ok); }
.badge-update, .badge-password { background: var(--primary-soft); color: var(--primary); }
.badge-replace, .badge-migrate, .badge-apply { background: var(--warn-soft); color: var(--warn); }
.badge-delete { background: var(--danger-soft); color: var(--danger); }
a.badge:hover { text-decoration: none; filter: brightness(.95); }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid transparent; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.alert-success { background: var(--ok-soft); color: var(--ok); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--primary); }

/* Activity */
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.activity li:last-child { border-bottom: 0; }
.activity .muted { display: block; font-size: .8rem; }

/* Pager */
.pager { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.pager a, .pager span { padding: 5px 11px; border-radius: 6px; font-size: .88rem; }
.pager a { border: 1px solid var(--line); background: var(--surface); }
.pager .current { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.pager .gap { color: var(--muted); }

/* Login */
body.bare main.wrap { padding-top: 8vh; }
.login-box { max-width: 380px; margin: 0 auto; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 1.2rem; font-weight: 600; margin-bottom: 16px; }
.login-box h1 { font-size: 1.25rem; margin-bottom: 14px; }
body.bare .card.narrow { margin: 0 auto; }

/* Footer + update page */
.footer { color: var(--muted); font-size: .8rem; padding-bottom: 24px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.report { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.report li { padding: 4px 0; }
.report .r-ok::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.report .r-info::before { content: "• "; color: var(--muted); }
.report .r-error { color: var(--danger); }
.report .r-error::before { content: "✗ "; font-weight: 700; }
.steps { margin: 0 0 12px; padding-left: 20px; color: var(--muted); font-size: .9rem; }
.check-ok { color: var(--ok); font-weight: 600; }
.check-bad { color: var(--danger); font-weight: 600; }
input[type=file] { padding: 6px; width: 100%; }

/* Menu groups */
.nav { align-items: center; }
.nav-group { position: relative; }
.nav-group summary { list-style: none; cursor: pointer; color: var(--muted); padding: 8px 12px; border-radius: 6px; user-select: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after { content: " ▾"; font-size: .75em; }
.nav-group summary:hover { background: var(--bg); color: var(--text); }
.nav-group summary.active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.nav-menu { position: absolute; top: calc(100% + 4px); left: 0; min-width: 180px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(16,24,40,.12); padding: 4px; z-index: 20; display: flex; flex-direction: column; }
.nav-menu a { padding: 8px 12px; border-radius: 6px; color: var(--text); }
.theme-toggle { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; cursor: pointer; padding: 2px 8px; font-size: 1rem; line-height: 1.2; }
.theme-toggle:hover { color: var(--text); }
@media (max-width: 860px) {
  .nav-open .nav { align-items: stretch; }
  .nav-menu { position: static; box-shadow: none; border: 0; padding: 0 0 0 12px; }
}

/* Imports & reports */
.amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--danger); }
.row-group td { background: var(--bg); font-weight: 600; }
.row-sub td { color: var(--muted); font-size: .88rem; }
.row-total td { font-weight: 700; border-top: 2px solid var(--line); }
.row-sub td:first-child { padding-left: 32px !important; }
.row-detail td:first-child { padding-left: 48px !important; }
.file-card { border-left: 4px solid var(--primary); }
.file-card.has-error { border-left-color: var(--danger); }
.file-card.has-warn { border-left-color: var(--warn); }
.file-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.file-head h2 { margin: 0; word-break: break-all; }
.file-fields { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0; align-items: flex-end; }
.file-fields label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); }
.check-pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .8rem; font-weight: 600; }
.check-pill.ok { background: var(--ok-soft); color: var(--ok); }
.check-pill.bad { background: var(--danger-soft); color: var(--danger); }
.check-pill.warn { background: var(--warn-soft); color: var(--warn); }
.coverage { border-collapse: collapse; width: 100%; font-size: .85rem; }
.coverage th, .coverage td { border: 1px solid var(--line); padding: 6px; text-align: center; }
.coverage th:first-child, .coverage td:first-child { text-align: left; white-space: nowrap; }
.cov { display: inline-block; min-width: 18px; padding: 0 4px; border-radius: 4px; font-size: .72rem; font-weight: 700; margin: 1px; }
.cov-e { background: var(--warn-soft); color: var(--warn); }
.cov-r { background: var(--ok-soft); color: var(--ok); }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 28px; text-align: center; background: var(--bg); }
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
.drop input[type=file] { max-width: 420px; margin: 12px auto 0; display: block; }
.totals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }

/* ---------- Analysis page ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: .82rem; display: flex; align-items: center; gap: 6px; }
.kpi-label .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.kpi-num { font-size: 1.45rem; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; }
.kpis-money .kpi-num { font-size: clamp(1.05rem, 1.6vw, 1.35rem); white-space: nowrap; }
[hidden] { display: none !important; }
.kpi-delta { font-size: .8rem; color: var(--muted); }
.kpi-note { margin: 0 0 14px; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 960px) { .grid-2.even { grid-template-columns: 1fr; } }
.chart-card { min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.chart-head h2 { margin: 0; }
.chart-tools { display: flex; gap: 2px; }
.chart-sub { color: var(--muted); font-size: .84rem; margin: 4px 0 10px; }
.chart { position: relative; min-width: 0; }
.chart-box { position: relative; width: 100%; }
.chart-box svg { display: block; overflow: visible; }
.chart-empty { color: var(--muted); text-align: center; padding: 40px 0; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 8px; font-size: .82rem; color: var(--text); }
.lg-item { display: inline-flex; align-items: center; gap: 6px; }
.lg-sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tip { position: absolute; display: none; pointer-events: none; z-index: 5; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(16,24,40,.14); padding: 8px 10px; font-size: .8rem; min-width: 180px; max-width: 300px; }
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.tip-sw { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.tip-name { flex: 1; color: var(--muted); }
.tip-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip-total { border-top: 1px solid var(--line); margin-top: 3px; padding-top: 4px; font-weight: 600; }
.chart-table-holder { margin-top: 10px; overflow-x: auto; }
.chart-table { font-size: .85rem; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.chip { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: .82rem; color: var(--text); background: var(--surface); }
.chip:hover { text-decoration: none; border-color: var(--primary); }
.chip.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); font-weight: 600; }
.ex-cats { position: relative; }
.ex-cats summary { list-style: none; }
.ex-cats summary::-webkit-details-marker { display: none; }
.ex-menu { position: absolute; z-index: 15; top: calc(100% + 4px); left: 0; width: 340px; max-height: 360px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(16,24,40,.14); padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.ex-menu label.check { color: var(--text); font-size: .85rem; padding: 0 !important; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--muted); padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.seg button.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.heatmap { border-collapse: separate; border-spacing: 2px; width: 100%; font-size: .78rem; }
.heatmap th { font-weight: 600; color: var(--muted); padding: 4px 6px; text-align: center; white-space: nowrap; }
.heatmap tbody th { text-align: left; color: var(--text); }
.heatmap td { text-align: center; padding: 8px 4px; border-radius: 4px; white-space: nowrap; font-variant-numeric: tabular-nums; background: var(--bg); min-width: 54px; }
.heatmap td.heat-total { background: transparent; font-weight: 600; }
.heat.h1 { background: var(--h1); color: var(--h-ink-dark); } .heat.h2 { background: var(--h2); color: var(--h-ink-dark); }
.heat.h3 { background: var(--h3); color: var(--h-ink-dark); } .heat.h4 { background: var(--h4); color: var(--h-ink-light); }
.heat.h5 { background: var(--h5); color: var(--h-ink-light); } .heat.h6 { background: var(--h6); color: var(--h-ink-light); }
.heat.h7 { background: var(--h7); color: var(--h-ink-light); }
:root[data-theme="dark"] .heat.h4, :root[data-theme="dark"] .heat.h5, :root[data-theme="dark"] .heat.h6, :root[data-theme="dark"] .heat.h7 { color: var(--h-ink-light); }
:root[data-theme="dark"] .heat.h1, :root[data-theme="dark"] .heat.h2, :root[data-theme="dark"] .heat.h3 { color: var(--h-ink-dark); }
.heat-legend { display: flex; align-items: center; gap: 3px; margin-top: 10px; }
.heat-legend .heat { width: 22px; height: 10px; border-radius: 3px; display: inline-block; }
.share { display: inline-block; width: 120px; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.share span { display: block; height: 100%; background: var(--c-rec); border-radius: 4px; }
.share-col { white-space: nowrap; }
@media print {
  .topbar, .no-print, .chart-tools, .footer, .nav-toggle { display: none !important; }
  body { background: #fff; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  main.wrap { padding: 0; max-width: none; }
}

.heat-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.lg-item { margin-right: 6px; }

/* Code check */
.cc-table td { vertical-align: top; }
.cc-tick { width: 28px; }
.cc-sec .badge { vertical-align: middle; font-size: .75rem; }

/* Purposes & line status */
.pp, .ls { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 10px; white-space: nowrap; vertical-align: middle; border: 1px solid transparent; }
.pp-expenditure { background: color-mix(in srgb, var(--c-exp) 14%, transparent); color: color-mix(in srgb, var(--c-exp) 75%, var(--text)); }
.pp-receipt { background: color-mix(in srgb, var(--c-rec) 14%, transparent); color: color-mix(in srgb, var(--c-rec) 75%, var(--text)); }
.pp-both { background: color-mix(in srgb, var(--c-net) 14%, transparent); color: color-mix(in srgb, var(--c-net) 75%, var(--text)); }
.pp-excluded { background: var(--bg); color: var(--muted); border-color: var(--line); }
.pp-none, .ls-unclassified { background: var(--warn-soft); color: var(--warn); }
.ls-counted { background: var(--ok-soft); color: var(--ok); }
.ls-excluded { background: var(--bg); color: var(--muted); border-color: var(--line); }
.ls-mismatch { background: var(--danger-soft); color: var(--danger); }
.bulk-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 10px 16px; position: sticky; top: 64px; z-index: 6; }
.bulk-bar label { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.recon { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.recon-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.recon-box h3 { margin: 0 0 6px; font-size: .9rem; }
.recon-row { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; padding: 2px 0; }
.recon-row.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 5px; font-weight: 600; }
.recon-row span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Debtors */
.seg a { display: inline-block; padding: 6px 14px; color: var(--muted); font-size: .88rem; }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.debt-hero { display: flex; flex-direction: column; gap: 2px; color: var(--text); border-left: 4px solid var(--c-exp); }
.debt-hero:hover { text-decoration: none; border-color: var(--primary); }
.debt-hero .kpi-num { font-size: 1.8rem; }
.tx-opening { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
.tx-invoice { background: var(--warn-soft); color: var(--warn); }
.tx-collection { background: var(--ok-soft); color: var(--ok); }
.tx-adjustment { background: var(--primary-soft); color: var(--primary); }
.tx-writeoff { background: var(--danger-soft); color: var(--danger); }

/* v1.6.1: selecting rows, bulk actions, delete zone */
.check-col { width: 34px; text-align: center; }
.check-col input { width: 16px; height: 16px; margin: 0; cursor: pointer; accent-color: var(--primary); }
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); }
.bulk-bar select, .bulk-bar input[type=text] { width: auto; }
.bulk-bar.sticky { position: sticky; top: 0; z-index: 5; background: var(--surface); border-top: 0; border-bottom: 1px solid var(--line); }
tr.row-editing td, tr.row-picked td { background: var(--primary-soft); }
.card-editing { outline: 2px solid var(--primary); outline-offset: -2px; }
.danger-zone { border-color: var(--danger-soft); }
.danger-zone h2 { color: var(--danger); }
.danger-zone .inline-add + .inline-add { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { filter: brightness(1.08); }

/* v1.6.2: Debtors list */
body.page-wide .wrap { max-width: 1680px; }
.dt-card { overflow: visible; }
.dt-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.dt-bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.dt-bulk select { padding: 5px 8px; font-size: .88rem; }
.dt-ticked { font-size: .82rem; font-weight: 600; color: var(--muted); min-width: 64px; }
.dt-tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.dt-per select { padding: 4px 8px; font-size: .85rem; }
.dt-scroll { overflow: auto; max-height: calc(100vh - 150px); min-height: 240px; }
.dt { font-size: .9rem; }
.dt th { position: sticky; top: 0; z-index: 3; white-space: nowrap; }
.dt th a.sort { color: inherit; text-decoration: none; }
.dt th a.sort:hover, .dt th a.sort.on { color: var(--primary); }
.dt td { vertical-align: top; padding-top: 10px; padding-bottom: 10px; }
.dt tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface)); }
.dt tbody tr.row-picked td { background: var(--primary-soft); }
.dt .amount { font-size: .86rem; }
.dt .c-project { min-width: 260px; max-width: 420px; }
.dt .c-client { min-width: 170px; max-width: 240px; }
.dt .c-status { white-space: nowrap; }
.dt td.c-balance { font-weight: 700; font-size: .95rem; color: var(--text); background: color-mix(in srgb, var(--primary-soft) 35%, var(--surface)); }
.dt th.c-balance { background: color-mix(in srgb, var(--primary-soft) 60%, var(--surface)); }
.dt td.c-balance.neg { color: var(--danger); }
.dt td.c-balance.zero { color: var(--muted); font-weight: 500; }
.dt-title { color: var(--text); font-weight: 600; text-decoration: none; line-height: 1.35; }
.dt-title:hover { color: var(--primary); text-decoration: underline; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dt-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag { display: inline-block; font-size: .72rem; line-height: 1.5; padding: 0 7px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.tag-unit { color: var(--text); font-weight: 600; }
.tag-code { font-size: .7rem; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag-bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.c-status .tag { margin-top: 4px; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; font-weight: 600; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.st-ongoing::before { background: var(--primary); }
.pill.st-completed::before { background: var(--ok); }
.pill.st-suspended::before { background: var(--warn); }
/* hideable columns */
.dt.hide-client .c-client, .dt.hide-status .c-status, .dt.hide-opening .c-opening, .dt.hide-invoiced .c-invoiced,
.dt.hide-collected .c-collected, .dt.hide-adjusted .c-adjusted, .dt.hide-provision .c-provision, .dt.hide-last .c-last { display: none; }
.dt.compact td { padding-top: 5px; padding-bottom: 5px; }
.dt.compact .dt-title { -webkit-line-clamp: 1; }
.dt.compact .clamp-2 { -webkit-line-clamp: 1; }
/* sticky edge columns */
.dt .sticky-l { position: sticky; left: 0; z-index: 2; background: var(--surface); }
.dt .sticky-r { position: sticky; right: 0; z-index: 2; background: var(--surface); box-shadow: -1px 0 0 var(--line); }
.dt th.sticky-l, .dt th.sticky-r { z-index: 4; }
.dt tfoot td { position: sticky; bottom: 0; z-index: 2; background: var(--surface); box-shadow: 0 -1px 0 var(--line); }
.dt tfoot td.sticky-l, .dt tfoot td.sticky-r { z-index: 4; }
.dt th.c-actions { text-align: right; }
/* row actions */
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
.act { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 9px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: .8rem; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; list-style: none; }
.act::-webkit-details-marker { display: none; }
.act svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.act:hover { border-color: var(--primary); color: var(--primary); }
.act-money { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.act-money:hover { color: var(--primary-ink); filter: brightness(1.08); }
.act-more { padding: 0 6px; }
.act-more svg { fill: currentColor; stroke: none; }
/* popovers (column picker, row menu) */
details.pop { position: relative; }
details.pop > summary { list-style: none; }
details.pop > summary::-webkit-details-marker { display: none; }
.pop-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; min-width: 190px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(16, 24, 40, .16); }
.pop-menu a, .pop-menu button, .pop-menu label { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; background: none; border-radius: 6px; font: inherit; font-size: .86rem; color: var(--text); text-align: left; text-decoration: none; cursor: pointer; white-space: nowrap; }
.pop-menu a:hover, .pop-menu button:hover, .pop-menu label:hover { background: var(--bg); }
.pop-menu .danger { color: var(--danger); }
.pop-menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
.pop-menu form { margin: 0; }
.col-picker .pop-menu { min-width: 210px; }
.dt-foot { padding: 10px 14px; border-top: 1px solid var(--line); }
.dt-foot .pager { margin: 0; }
/* dialog */
.dlg { border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(16, 24, 40, .3); }
.dlg::backdrop { background: rgba(15, 23, 42, .45); }
.dlg form { padding: 18px 20px 20px; }
.dlg-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.dlg-head h2 { margin: 0 0 2px; }
.dlg-head p { margin: 0; }
.dlg-x { border: 0; background: none; font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.dlg-bal { margin: 12px 0; padding: 8px 12px; background: var(--primary-soft); border-radius: 8px; font-size: .9rem; }
@media (max-width: 720px) {
  .act span { display: none; }
  .act { padding: 0 7px; }
  .dt .c-project { min-width: 200px; }
  .dt-tools { margin-left: 0; }
}
.dt td.menu-open { z-index: 30; }
/* keep Balance visible next to Actions while scrolling sideways */
.dt .c-balance { position: sticky; right: var(--actw, 190px); z-index: 2; box-shadow: -1px 0 0 var(--line); }
.dt th.c-balance { z-index: 4; }
.dt tfoot td.c-balance { z-index: 4; }
.dt td.c-balance { background: color-mix(in srgb, var(--primary-soft) 35%, var(--surface)); }
.dt tfoot td.c-balance { background: color-mix(in srgb, var(--primary-soft) 60%, var(--surface)); }
.dt .sticky-r { box-shadow: none; }
@media (max-width: 720px) {
  .dt .c-balance { position: static; box-shadow: none; }
  .dt .sticky-l { position: static; }
}

/* =====================================================================
   v1.7.0 visual refresh. Tokens first, then components (overrides above).
   ===================================================================== */
:root {
  --bg: #eef2f4; --surface: #ffffff; --surface-2: #f6f8f9; --text: #15212b; --muted: #5b6874;
  --line: #dde4e9; --line-strong: #c3cdd5;
  --primary: #0f5c8c; --primary-ink: #ffffff; --primary-soft: #e3eef6; --primary-hover: #0b4a72;
  --navy: #0c2536; --navy-2: #133a55; --navy-ink: #e8f0f6; --navy-muted: #9db4c6;
  --ok: #17784c; --ok-soft: #e1f3e9; --warn: #975700; --warn-soft: #fcefd6;
  --danger: #b3261e; --danger-soft: #fbe8e6; --info-soft: #e6f0f8;
  --k-owed: #0f5c8c; --k-open: #5b6874; --k-inv: #b06c00; --k-col: #17784c; --k-prov: #b3261e; --k-adj: #6a4fc4;
  --radius: 10px; --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(12, 37, 54, .05), 0 1px 3px rgba(12, 37, 54, .04);
  --shadow-pop: 0 12px 32px rgba(12, 37, 54, .18);
  --ring: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Sinhala", sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0e141a; --surface: #161f28; --surface-2: #1b2631; --text: #e3e9ee; --muted: #93a2af;
  --line: #26323e; --line-strong: #34424f;
  --primary: #5aaee6; --primary-ink: #06131d; --primary-soft: #14324a; --primary-hover: #7cc0ee;
  --navy: #0a1924; --navy-2: #10293b; --navy-ink: #e3edf5; --navy-muted: #8aa4b8;
  --ok: #5ccf96; --ok-soft: #12301f; --warn: #f0b552; --warn-soft: #362812;
  --danger: #f08a80; --danger-soft: #3a1c1a; --info-soft: #152839;
  --k-owed: #5aaee6; --k-open: #93a2af; --k-inv: #f0b552; --k-col: #5ccf96; --k-prov: #f08a80; --k-adj: #a996f0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, .5);
}

body { font: 15px/1.55 var(--font); font-feature-settings: "tnum" 1; -webkit-font-smoothing: antialiased; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.015em; line-height: 1.25; }
h2 { font-size: 1.08rem; font-weight: 650; letter-spacing: -.005em; }
a { color: var(--primary); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
::selection { background: color-mix(in srgb, var(--primary) 25%, transparent); }

/* ---- Top bar: the one dark band ---- */
.topbar { background: var(--navy); border-bottom: 0; box-shadow: 0 1px 0 rgba(0, 0, 0, .2); }
.topbar-inner { min-height: 58px; gap: 18px; }
.brand { display: inline-flex; align-items: center; gap: 9px; color: #fff; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { background: #fff; color: var(--navy); padding: 3px 7px; border-radius: 6px; font-size: .74rem; font-weight: 800; letter-spacing: .06em; margin: 0; }
:root[data-theme="dark"] .brand-mark { background: var(--primary); color: var(--navy); }
.nav { gap: 2px; }
.nav a, .nav-group summary { display: inline-flex; align-items: center; gap: 7px; color: var(--navy-muted); padding: 7px 11px; border-radius: 8px; font-size: .9rem; font-weight: 500; }
.nav a:hover, .nav-group summary:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.nav a.active, .nav-group summary.active { background: rgba(255, 255, 255, .12); color: #fff; font-weight: 600; box-shadow: inset 0 -2px 0 #f2b33d; }
.nav .ic { opacity: .85; }
.nav-group summary::after { content: ""; width: 6px; height: 6px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor; transform: rotate(45deg) translateY(-2px); margin-left: 2px; opacity: .7; }
.nav-menu { padding: 6px; border-radius: 10px; box-shadow: var(--shadow-pop); min-width: 220px; }
.nav-menu a { color: var(--text); font-size: .9rem; padding: 8px 12px; border-radius: 7px; }
.nav-menu a:hover { background: var(--surface-2); color: var(--text); }
.nav-menu a.active { background: var(--primary-soft); color: var(--primary); box-shadow: none; }
.userbox { gap: 6px; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; color: #fff !important; padding: 4px 10px 4px 4px; border-radius: 999px; }
.user-chip:hover { background: rgba(255, 255, 255, .08); text-decoration: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #f2b33d; color: var(--navy); font-weight: 800; font-size: .8rem; }
.user-name { font-weight: 600; font-size: .88rem; }
.role { font-size: .7rem; text-transform: none; letter-spacing: 0; padding: 1px 8px; border-radius: 999px; background: rgba(255, 255, 255, .12); color: var(--navy-ink); font-weight: 600; }
.role-admin { background: rgba(242, 179, 61, .22); color: #ffd58a; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: var(--navy-muted); cursor: pointer; padding: 0; }
.icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }
.icon-btn .ic { width: 18px; height: 18px; vertical-align: 0; }
.theme-toggle { border: 0; font-size: inherit; }
.nav-toggle { border-color: rgba(255, 255, 255, .25); color: #fff; }
@media (max-width: 1100px) { .nav a span, .nav-group summary span { display: none; } .nav a, .nav-group summary { padding: 8px 10px; } .user-name { display: none; } }
@media (max-width: 860px) {
  .nav a span, .nav-group summary span { display: inline; }
  .nav-open .userbox { border-top-color: rgba(255, 255, 255, .12); }
  .nav-menu { background: transparent; }
  .nav-menu a { color: var(--navy-ink); }
  .nav-menu a:hover, .nav-menu a.active { background: rgba(255, 255, 255, .08); color: #fff; }
  .user-name { display: inline; }
}

/* ---- Page ---- */
main.wrap { padding-top: 26px; }
.page-head { margin-bottom: 20px; align-items: flex-end; }
.page-head p.muted { font-size: .94rem; }
.card { border-radius: var(--radius); border-color: var(--line); box-shadow: var(--shadow); padding: 20px; }
.card > h2:first-child, .card > div > h2:first-child { margin-bottom: .8rem; }
.footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 8px; }

/* ---- Buttons ---- */
.btn { border-radius: var(--radius-sm); padding: 7px 14px; font-weight: 550; gap: 6px; border-color: var(--line-strong); transition: background-color .12s, border-color .12s, color .12s; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--primary-ink); filter: none; }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger-solid:hover { color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .82rem; border-radius: 6px; }
.btn:focus-visible { box-shadow: var(--ring); }

/* ---- Forms ---- */
input, select, textarea { border-color: var(--line-strong); border-radius: var(--radius-sm); padding: 7px 10px; transition: border-color .12s, box-shadow .12s; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--line-strong)); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
select { appearance: none; -webkit-appearance: none; padding-right: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6874' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
select[multiple] { background-image: none; padding-right: 10px; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); }
.form label { font-weight: 600; font-size: .86rem; }
.filters { background: var(--surface); }
.filters.card { padding: 16px 18px; }
.filters label, .inline-add label, .file-fields label { font-weight: 600; font-size: .8rem; color: var(--muted); }

/* ---- Tables ---- */
.table th { text-transform: none; letter-spacing: 0; font-size: .8rem; font-weight: 650; color: var(--muted); background: var(--surface-2); border-bottom-color: var(--line); padding: 10px 12px; }
.table td { border-bottom-color: var(--line); }
.table tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 45%, var(--surface)); }
.row-total td { background: var(--surface-2); border-top: 1px solid var(--line-strong); }
.table-card { overflow: hidden; }
.dt-card { overflow: visible; }
.empty { padding: 40px 16px !important; font-size: .95rem; }

/* ---- Badges, chips, pills ---- */
.badge { font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 18%, transparent); letter-spacing: .005em; }
.badge-off, .badge-deactivate { box-shadow: inset 0 0 0 1px var(--line); border: 0; }
.chip { padding: 4px 12px; font-weight: 550; transition: border-color .12s, background-color .12s; }
.chip:hover { background: var(--primary-soft); color: var(--primary); }
.tag { box-shadow: none; }
.cat-chip { border-radius: 6px; font-weight: 600; }
.seg { border-radius: 9px; background: var(--surface-2); padding: 2px; border-color: var(--line); }
.seg button, .seg a { border-radius: 7px; }
.seg button.on, .seg a.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

/* ---- Alerts ---- */
.alert { display: flex; gap: 10px; align-items: flex-start; border-radius: var(--radius-sm); padding: 11px 14px; border: 1px solid color-mix(in srgb, currentColor 22%, transparent); font-weight: 500; }
.alert > .ic { margin-top: 2px; width: 18px; height: 18px; }
.alert-flash { box-shadow: var(--shadow); animation: flash-in .28s ease-out; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .alert-flash { animation: none; } * { transition: none !important; } }

/* ---- KPI cards: colour says what the number is ---- */
.kpi { position: relative; border-radius: var(--radius); padding: 15px 16px 14px; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kc, var(--line-strong)); }
.kpi-label { font-weight: 600; font-size: .8rem; }
.kpi-num { font-weight: 750; letter-spacing: -.02em; }
.k-owed { --kc: var(--k-owed); } .k-open { --kc: var(--k-open); } .k-inv { --kc: var(--k-inv); }
.k-col { --kc: var(--k-col); } .k-prov { --kc: var(--k-prov); } .k-adj { --kc: var(--k-adj); }
.kpis-money .k-owed { background: var(--navy); border-color: var(--navy); color: var(--navy-ink); }
.kpis-money .k-owed::before { background: #f2b33d; }
.kpis-money .k-owed .kpi-label, .kpis-money .k-owed .kpi-delta { color: var(--navy-muted); }
.kpis-money .k-owed .kpi-num { color: #fff; }
.k-col .kpi-num { color: var(--k-col); }

/* ---- Stat tiles (dashboard) ---- */
.stat { border-radius: var(--radius); padding: 14px 16px; gap: 2px; transition: border-color .12s, transform .12s; }
.stat:hover { border-color: var(--primary); }
.stat-num { font-weight: 750; letter-spacing: -.02em; font-size: 1.6rem; }
.stat-label { font-weight: 500; }
.stat-warn .stat-num { color: var(--warn); }

/* ---- Pager ---- */
.pager a, .pager span { border-radius: 8px; min-width: 34px; text-align: center; font-weight: 550; }
.pager a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

/* ---- Debtors list polish ---- */
.dt-toolbar { background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; }
.dt th { background: var(--surface-2); }
.dt .sticky-l, .dt .sticky-r { background: var(--surface); }
.dt th.sticky-l, .dt th.sticky-r { background: var(--surface-2); }
.dt tfoot td, .dt tfoot td.sticky-l, .dt tfoot td.sticky-r { background: var(--surface-2); }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); background: color-mix(in srgb, var(--danger-soft) 35%, var(--surface)); }

/* ---- Login ---- */
body.bare { min-height: 100vh; background-color: var(--navy);
  background-image: linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px),
                    linear-gradient(rgba(255, 255, 255, .02) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .02) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px; }
body.bare main.wrap { padding-top: 12vh; }
.login-brand { color: #fff; font-size: 1.35rem; font-weight: 700; margin-bottom: 18px; }
.login-box .card { padding: 26px; box-shadow: var(--shadow-pop); border: 0; }
.login-box h1 { font-size: 1.2rem; }

/* ---- Blueprint panel (dashboard hero) ---- */
.blueprint { position: relative; background-color: var(--navy); color: var(--navy-ink); border: 0; border-radius: 14px; padding: 24px 26px; overflow: hidden;
  background-image: linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px),
                    linear-gradient(rgba(255, 255, 255, .022) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .022) 1px, transparent 1px);
  background-size: 96px 96px, 96px 96px, 24px 24px, 24px 24px; background-position: -1px -1px; }
.blueprint a { color: #fff; }
.blueprint .muted { color: var(--navy-muted); }
.bp-grid { display: grid; grid-template-columns: minmax(280px, 1.15fr) 1fr 1fr; gap: 28px; align-items: start; }
@media (max-width: 1080px) { .bp-grid { grid-template-columns: 1fr 1fr; } .bp-main { grid-column: 1 / -1; } }
@media (max-width: 640px) { .bp-grid { grid-template-columns: 1fr; } .blueprint { padding: 20px 18px; } }
.bp-label { font-size: .86rem; color: var(--navy-muted); font-weight: 600; display: flex; align-items: center; gap: 7px; }
.bp-big { display: block; font-size: clamp(1.9rem, 3.4vw, 2.7rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.1; color: #fff; margin: 6px 0 4px; white-space: nowrap; }
.bp-big small { font-size: .5em; font-weight: 700; color: var(--navy-muted); letter-spacing: 0; margin-right: 4px; }
.bp-meter { margin: 16px 0 8px; height: 10px; border-radius: 99px; background: rgba(255, 255, 255, .12); overflow: hidden; display: flex; }
.bp-meter span { display: block; height: 100%; }
.bp-meter .m-col { background: #5ccf96; }
.bp-meter .m-adj { background: #a996f0; }
.bp-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .82rem; color: var(--navy-muted); }
.bp-legend b { color: #fff; font-weight: 650; }
.bp-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: 0; }
.bp-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.bp-fact { background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .08); border-radius: 10px; padding: 10px 12px; color: var(--navy-ink); }
a.bp-fact:hover { background: rgba(255, 255, 255, .1); text-decoration: none; }
.bp-fact strong { display: block; font-size: 1.15rem; font-weight: 750; color: #fff; }
.bp-fact span { font-size: .78rem; color: var(--navy-muted); }
.bp-fact.warn strong { color: #f7c66b; }
.bp-list h3 { margin: 0 0 10px; font-size: .9rem; font-weight: 650; color: #fff; display: flex; justify-content: space-between; align-items: baseline; }
.bp-list h3 a { font-size: .78rem; font-weight: 600; color: var(--navy-muted); }
.bp-row { display: block; padding: 6px 0; color: var(--navy-ink); }
.bp-row:hover { text-decoration: none; }
.bp-row:hover .bp-name { color: #fff; text-decoration: underline; }
.bp-row-top { display: flex; justify-content: space-between; gap: 10px; font-size: .84rem; }
.bp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bp-val { font-weight: 650; color: #fff; white-space: nowrap; }
.bp-bar { height: 5px; border-radius: 9px; background: rgba(255, 255, 255, .1); margin-top: 5px; overflow: hidden; }
.bp-bar span { display: block; height: 100%; border-radius: 9px; background: #6ab7ec; }
.bp-list.units .bp-bar span { background: #f2b33d; }

/* ---- Quick links ---- */
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 18px 0; }
.quick a { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; color: var(--text); box-shadow: var(--shadow); transition: border-color .12s; }
.quick a:hover { border-color: var(--primary); text-decoration: none; }
.quick .q-ic { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.quick .q-ic .ic { width: 20px; height: 20px; vertical-align: 0; }
.quick .q-money .q-ic { background: var(--ok-soft); color: var(--ok); }
.quick .q-imp .q-ic { background: var(--warn-soft); color: var(--warn); }
.quick strong { display: block; font-size: .92rem; }
.quick small { color: var(--muted); font-size: .8rem; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 22px 0 10px; }
.section-title h2 { margin: 0; font-size: 1.05rem; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.feed li:last-child { border-bottom: 0; }
.feed .badge { grid-row: span 2; align-self: start; margin-top: 2px; }
.feed .when { color: var(--muted); font-size: .78rem; }
.bp-bar { display: block; }
.nav a, .nav-group summary { white-space: nowrap; }
.wrap { max-width: 1360px; }
body.page-wide .wrap { max-width: 1680px; }
@media (max-width: 1400px) { .user-name { display: none; } }
@media (max-width: 1240px) and (min-width: 861px) { .nav a span, .nav-group summary span { display: none; } .nav a, .nav-group summary { padding: 8px 10px; } }
.card.table-card { padding: 0; }
.card.table-card > h2:first-child { padding: 16px 16px 0; }
.bp-grid > *, .bp-facts > *, .bp-row-top > * { min-width: 0; }
.bp-row-top .bp-val { flex: none; }
@media (max-width: 640px) { .bp-big { font-size: 1.8rem; } .bp-facts { grid-template-columns: 1fr 1fr; gap: 8px; } }
.form label > span.muted, .inline-add label > span.muted, .file-fields label > span.muted { font-weight: 400; font-size: .76rem; margin-top: -3px; }
.view-only { color: var(--muted); opacity: .6; } .view-only .ic { width: 14px; height: 14px; }

/* v1.8.0: unit access & month lock */
.units-cell { min-width: 220px; }
.unit-badges { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 2px 0; }
.ub-label { font-size: .72rem; font-weight: 700; color: var(--muted); width: 34px; }
.access-form .all-units { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; }
.access-form .all-units input { margin-top: 4px; width: 18px; height: 18px; }
.access-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 16px 0 10px; }
.access-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 0 24px; margin-bottom: 14px; }
.access-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.access-unit { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.access-seg { flex: none; }
.access-seg label { display: inline-flex; cursor: pointer; }
.access-seg input { position: absolute; opacity: 0; pointer-events: none; }
.access-seg span { padding: 4px 12px; border-radius: 7px; font-size: .82rem; color: var(--muted); font-weight: 550; }
.access-seg input:checked + span { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); font-weight: 650; }
.access-seg .a-edit input:checked + span { color: var(--ok); }
.access-seg input:focus-visible + span { box-shadow: var(--ring); }
.lock-state { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.lock-state h2 { margin: 0 0 4px; }
.lock-state p { margin: 0; }
.lock-ic { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex: none; }
.lock-ic .ic { width: 24px; height: 24px; vertical-align: 0; }
.lock-card.is-locked { border-left: 4px solid #f2b33d; }
.lock-card.is-locked .lock-ic { background: var(--warn-soft); color: var(--warn); }

/* v1.8.1: "log in as" banner */
.as-user-bar { background: #f2b33d; color: #2b1d00; position: sticky; top: 58px; z-index: 9; box-shadow: 0 1px 0 rgba(0, 0, 0, .1); }
.as-user-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; font-size: .9rem; }
.as-user-inner .ic { vertical-align: -3px; }
.as-user-bar .btn { background: #2b1d00; color: #fff; border-color: #2b1d00; }
.as-user-bar .btn:hover { background: #000; color: #fff; }
.badge-impersonate, .badge-impersonate_end { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 860px) { .as-user-bar { top: 0; position: relative; } }
.access-form .all-units .all-on { display: none; }
.access-form .all-units:has(input:checked) { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.access-form .all-units:has(input:checked) .all-on { display: inline-block; }

/* v1.9.0: Financial Unit classification */
.cls { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 6px; white-space: nowrap; letter-spacing: .01em; }
.cls-pl { background: color-mix(in srgb, #2a78d6 14%, transparent); color: color-mix(in srgb, #2a78d6 80%, var(--text)); }
.cls-bs { background: color-mix(in srgb, #6250d6 14%, transparent); color: color-mix(in srgb, #6250d6 80%, var(--text)); }
.cls-none { background: var(--warn-soft); color: var(--warn); }
.cls-cell { min-width: 170px; }
.cls-cell .small { margin-top: 2px; line-height: 1.3; }
fieldset.cls-fields { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px 14px; margin: 0; }
fieldset.cls-fields legend { font-weight: 650; font-size: .88rem; padding: 0 6px; }
.form-row.three { grid-template-columns: 1fr 1.4fr 1.4fr; }
@media (max-width: 700px) { .form-row.three { grid-template-columns: 1fr; } }
.row-cls td { background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface)); font-weight: 650; }
.row-cls-main td { background: var(--surface-2); font-weight: 600; }
.row-cls-main td:first-child { padding-left: 28px !important; }
.cls-cov { display: grid; gap: 10px; }
.cls-cov-row { display: grid; grid-template-columns: 170px 1fr 230px; gap: 12px; align-items: center; }
.cls-cov-bar { height: 9px; border-radius: 9px; background: var(--surface-2); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.cls-cov-bar span { display: block; height: 100%; border-radius: 9px; }
.cls-cov-bar .p { background: #2a78d6; } .cls-cov-bar .b { background: #6250d6; } .cls-cov-bar .u { background: #e0a020; }
.cls-cov-val { font-size: .88rem; white-space: nowrap; }
@media (max-width: 720px) { .cls-cov-row { grid-template-columns: 1fr; gap: 4px; } }
/* classification review */
.rv-card { padding: 16px 18px; border-left: 4px solid var(--line-strong); }
.rv-card.dec-approved { border-left-color: var(--ok); }
.rv-card.dec-corrected { border-left-color: var(--primary); }
.rv-card.dec-rejected { border-left-color: var(--danger); }
.rv-card:target { box-shadow: var(--ring); }
.rv-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; margin-bottom: 10px; }
.rv-code { display: inline-block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; margin-right: 8px; font-weight: 700; }
.rv-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rv-dec { display: inline-block; font-size: .74rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.rv-dec-approved { background: var(--ok-soft); color: var(--ok); }
.rv-dec-corrected { background: var(--primary-soft); color: var(--primary); }
.rv-dec-rejected { background: var(--danger-soft); color: var(--danger); }
.rv-dec-pending { background: var(--warn-soft); color: var(--warn); }
.rv-body { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(360px, 1.2fr); gap: 20px; }
@media (max-width: 980px) { .rv-body { grid-template-columns: 1fr; } }
.rv-facts { font-size: .88rem; }
.rv-form { display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.rv-decisions { display: flex; flex-wrap: wrap; gap: 6px; }
.rv-opt { cursor: pointer; }
.rv-opt input { position: absolute; opacity: 0; pointer-events: none; }
.rv-opt span { display: inline-block; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line-strong); font-size: .82rem; font-weight: 600; color: var(--muted); background: var(--surface); }
.rv-opt input:checked + span { color: #fff; border-color: transparent; }
.rv-opt-pending input:checked + span { background: var(--warn); }
.rv-opt-approved input:checked + span { background: var(--ok); }
.rv-opt-corrected input:checked + span { background: var(--primary); }
.rv-opt-rejected input:checked + span { background: var(--danger); }
.rv-opt input:disabled + span { opacity: .4; cursor: not-allowed; }
.rv-opt input:focus-visible + span { box-shadow: var(--ring); }
.rv-final { display: grid; grid-template-columns: 110px 1fr 1fr; gap: 8px; }
@media (max-width: 640px) { .rv-final { grid-template-columns: 1fr; } }
.rv-final label, .rv-note { display: flex; flex-direction: column; gap: 3px; font-size: .78rem; font-weight: 600; color: var(--muted); }
.rv-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.rv-facts { align-content: start; }
.cls-edit { display: grid; grid-template-columns: 150px repeat(3, minmax(0, 1fr)); gap: 10px; }
.cls-edit label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; font-weight: 600; color: var(--muted); }
.cls-edit select, .cls-edit input { width: 100%; }
.cls-edit input[type=text] { margin-top: 4px; }
@media (max-width: 760px) { .cls-edit { grid-template-columns: 1fr; } }
.row-cls-sub td { font-weight: 600; color: var(--text); }
.row-cls-sub td:first-child { padding-left: 44px !important; }
.row-sub.lv-sb td:first-child { padding-left: 44px !important; }
.row-sub.lv-mn td:first-child { padding-left: 28px !important; }
.row-sub.lv-st td { font-weight: 650; color: var(--text); }

/* v1.11.0: P&L and Balance Sheet analysis */
.fs-hero { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(380px, 1.5fr) minmax(220px, .8fr); gap: 22px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px 24px; box-shadow: var(--shadow); margin-bottom: 10px; }
@media (max-width: 1100px) { .fs-hero { grid-template-columns: 1fr; } }
.fs-hero-label { display: block; font-size: .86rem; font-weight: 600; color: var(--muted); }
.fs-hero-num { display: block; font-size: clamp(1.8rem, 3vw, 2.5rem); font-weight: 800; letter-spacing: -.03em; color: var(--k-col); line-height: 1.15; white-space: nowrap; }
.fs-hero-num.neg { color: var(--danger); }
.fs-hero-num small { font-size: .5em; font-weight: 700; color: var(--muted); margin-right: 4px; }
.fs-hero-sub { font-size: .84rem; color: var(--muted); }
.fs-eq { display: flex; align-items: stretch; gap: 8px; }
.fs-eq-item { flex: 1; border-radius: 10px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.fs-eq-item span:first-child { display: block; font-size: .78rem; font-weight: 650; color: var(--muted); }
.fs-eq-item strong { display: block; font-size: 1.15rem; font-weight: 750; white-space: nowrap; }
.fs-eq-item > span:last-child { font-size: .76rem; }
.fs-eq-item.inc { border-top: 3px solid var(--c-rec); }
.fs-eq-item.exp { border-top: 3px solid var(--c-exp); }
.fs-eq-item.net { border-top: 3px solid var(--c-net); background: color-mix(in srgb, var(--c-net) 8%, var(--surface)); }
.fs-eq-op { align-self: center; font-size: 1.3rem; font-weight: 700; color: var(--muted); }
@media (max-width: 640px) { .fs-eq { flex-direction: column; } .fs-eq-op { display: none; } }
.fs-side { display: grid; gap: 8px; }
.fs-side div { display: flex; justify-content: space-between; gap: 10px; font-size: .84rem; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.fs-side div:last-child { border-bottom: 0; }
.fs-side span { color: var(--muted); }
.fs-side .warn strong { color: var(--warn); }
.fs-good { color: var(--ok); font-weight: 650; white-space: nowrap; }
.fs-bad { color: var(--danger); font-weight: 650; white-space: nowrap; }
.fs-flat { color: var(--muted); white-space: nowrap; }
.fs-table-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 16px 16px 8px; }
.fs-table-head h2 { margin: 0; }
.fs-table td a { color: inherit; text-decoration: none; }
.fs-table td a:hover { color: var(--primary); text-decoration: underline; }
.fs-table tr.fs-main td { background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface)); font-weight: 750; font-size: .95rem; }
.fs-table tr.fs-sub1 td { font-weight: 600; }
.fs-table tr.fs-sub1 td:first-child { padding-left: 26px; }
.fs-table tr.fs-sub2 td { color: var(--muted); font-size: .88rem; }
.fs-table tr.fs-sub2 td:first-child { padding-left: 48px; }
.fs-table tr.fs-result td { font-weight: 800; font-size: 1rem; background: color-mix(in srgb, var(--c-net) 10%, var(--surface)); border-top: 2px solid var(--line-strong); }
.fs-table tr.fs-result.neg td { background: var(--danger-soft); }
.fs-share-col { width: 180px; white-space: nowrap; }
.fs-bar { display: inline-block; width: 100px; height: 7px; border-radius: 9px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; vertical-align: middle; }
.fs-bar span { display: block; height: 100%; }
.fs-bar.income span { background: var(--c-rec); }
.fs-bar.expense span { background: var(--c-exp); }
.fs-how summary { cursor: pointer; }
@media print { .fs-hero { box-shadow: none; } }
