/* ============ Tokens ============ */
:root {
  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f2f1ed;
  --surface-3: #e8e7e1;
  --ink: #0b0b0b;
  --ink-2: #4a4945;
  --muted: #6b6964;
  --line: #e4e3dd;
  --line-strong: #cfcec6;
  --brand: #14583a;
  --brand-hover: #0e4630;
  --on-brand: #ffffff;
  --brand-soft: #e3efe8;
  --brand-ink: #14583a;
  --danger: #b42323;
  --danger-soft: #fbeaea;
  --warn: #7a5000;
  --warn-soft: #fcf0d6;
  --good: #006300;
  --good-soft: #e4f1e4;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 6px 20px rgba(11, 11, 11, .04);
  --shadow-lg: 0 20px 60px rgba(11, 11, 11, .18);
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e0d; --surface: #181817; --surface-2: #212120; --surface-3: #2b2b29;
    --ink: #f5f5f2; --ink-2: #c3c2b7; --muted: #9a988f; --line: #2a2a28; --line-strong: #3a3a37;
    --brand: #4cc38a; --brand-hover: #63d49c; --on-brand: #06140d; --brand-soft: #14291d; --brand-ink: #6fd6a2;
    --danger: #f08080; --danger-soft: #361919; --warn: #f5c35c; --warn-soft: #33280f; --good: #5fd08a; --good-soft: #14291d;
    --series-1: #3987e5; --series-2: #d95926; --grid: #2c2c2a; --axis: #3a3a37;
    --shadow: none; --shadow-lg: 0 20px 60px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e0d; --surface: #181817; --surface-2: #212120; --surface-3: #2b2b29;
  --ink: #f5f5f2; --ink-2: #c3c2b7; --muted: #9a988f; --line: #2a2a28; --line-strong: #3a3a37;
  --brand: #4cc38a; --brand-hover: #63d49c; --on-brand: #06140d; --brand-soft: #14291d; --brand-ink: #6fd6a2;
  --danger: #f08080; --danger-soft: #361919; --warn: #f5c35c; --warn-soft: #33280f; --good: #5fd08a; --good-soft: #14291d;
  --series-1: #3987e5; --series-2: #d95926; --grid: #2c2c2a; --axis: #3a3a37;
  --shadow: none; --shadow-lg: 0 20px 60px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.015em; }
h1 { font-size: 26px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; }
p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ============ Buttons & inputs ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); font-weight: 500; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn.danger { color: #1a0707; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  border: 0; background: transparent; cursor: pointer; color: var(--ink-2); transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.sm { width: 34px; height: 34px; }

.input, select.input {
  width: 100%; min-height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input.sm { min-height: 36px; padding: 0 10px; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.field { display: grid; gap: 6px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field-hint { font-size: 12.5px; color: var(--muted); }
.field-err { font-size: 12.5px; color: var(--danger); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 38px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--line); }
.seg button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: transparent; min-height: 34px; padding: 0 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer;
}
.seg button svg { width: 16px; height: 16px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

/* ============ Shell ============ */
.shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 20px;
  padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 14px; flex: none;
}
.brand b { display: block; font-size: 14px; font-weight: 600; line-height: 1.25; }
.brand small { color: var(--muted); font-size: 12px; }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 12px; border-radius: 10px;
  text-decoration: none; color: var(--ink-2); font-weight: 500; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-ink); }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.sidebar-row { display: flex; gap: 4px; align-items: center; }
.sidebar-row .btn { flex: 1; justify-content: flex-start; }
.install-cta { width: 100%; background: var(--brand-soft); border-color: transparent; color: var(--brand-ink); }
.install-cta:hover { background: var(--brand-soft); filter: brightness(.97); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 10px; }
.steps li { padding-left: 4px; }
.topbar, .bottomnav { display: none; }
.main { width: 100%; max-width: 1320px; margin: 0 auto; padding: 28px 32px 48px; min-width: 0; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: 0; z-index: 20;
    padding: 10px 16px; background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
  }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottomnav a {
    display: grid; justify-items: center; gap: 2px; padding: 6px 0; text-decoration: none; font-size: 11px;
    font-weight: 500; color: var(--muted); border-radius: 10px; min-height: 48px;
  }
  .bottomnav a[aria-current="page"] { color: var(--brand-ink); }
  .main { padding: 18px 16px 100px; }
}

/* ============ Page parts ============ */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: 14px; margin-bottom: 12px; min-height: 32px; }
.back:hover { color: var(--ink); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 0; flex-wrap: wrap; }
.card-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-body { padding: 16px 18px 18px; }
.stack { display: grid; gap: 16px; }
.grid { display: grid; gap: 16px; }
.grid.kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid.two { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.grid.halves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.two { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) { .grid.halves { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 480px) {
  .grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; }
  .stat .value { font-size: 21px; }
  .stat .label { font-size: 12.5px; }
  .stat .label .dot { display: none; }
}

.stat { padding: 16px 18px; display: grid; gap: 6px; align-content: start; }
.stat .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.stat .label .dot { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); }
.stat .label .dot svg { width: 16px; height: 16px; }
.stat .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat .foot { font-size: 13px; color: var(--muted); }
.stat .foot b { color: var(--ink-2); font-weight: 600; }
.meter { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin-top: 4px; }
.meter span { display: block; height: 100%; border-radius: 99px; background: var(--brand); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--ink-2);
}
.badge svg { width: 13px; height: 13px; stroke-width: 2.4; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); }

.avatar {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex: none;
  font-size: 12.5px; font-weight: 600; background: var(--surface-3); color: var(--ink-2);
}
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }
.who { display: flex; align-items: center; gap: 11px; min-width: 0; }
.who b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { display: block; color: var(--muted); font-size: 12.5px; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; position: relative; }
table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.t th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 14px;
  background: var(--surface-2); white-space: nowrap; border-bottom: 1px solid var(--line);
}
.t th:first-child { padding-left: 18px; } .t td:first-child { padding-left: 18px; }
.t th:last-child { padding-right: 18px; } .t td:last-child { padding-right: 18px; }
.t td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t .num { text-align: right; white-space: nowrap; }
.t tr.row-link { cursor: pointer; transition: background .12s; }
.t tr.row-link:hover { background: var(--surface-2); }
.t th button.sort { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.t th button.sort[aria-sort] { color: var(--ink); }
.t td .sub { display: block; color: var(--muted); font-size: 12.5px; }
.t .input.sm { width: 104px; text-align: right; }
@media (max-width: 720px) { .t .hide-sm { display: none; } }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.toolbar .search { flex: 1 1 220px; }
.toolbar select.input { width: auto; min-width: 150px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 18px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list a.who { text-decoration: none; }
.list a.who:hover b { text-decoration: underline; }
.tx-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.tx-ic svg { width: 16px; height: 16px; }
.tx-ic.advance { background: var(--warn-soft); color: var(--warn); }
.tx-ic.repay, .tx-ic.salary { background: var(--good-soft); color: var(--good); }

/* ============ Charts ============ */
.chart { width: 100%; min-height: 220px; position: relative; }
.chart svg { display: block; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .bar { transition: opacity .15s; }
.chart svg.hovering .bar:not(.on) { opacity: .4; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .endlabel { font-size: 12px; font-weight: 600; fill: var(--ink-2); }
.chart .xhair { stroke: var(--axis); stroke-width: 1; }
.chart .marker { stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.viz-tip {
  position: fixed; z-index: 100; pointer-events: none; min-width: 140px; padding: 9px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow-lg); font-size: 13px;
}
.viz-tip .tt { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.viz-tip .row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.viz-tip .row span { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.viz-tip .row i { width: 8px; height: 8px; border-radius: 2px; }
.viz-tip b { font-variant-numeric: tabular-nums; font-weight: 600; }
details.viz-table { margin-top: 10px; font-size: 13px; }
details.viz-table summary { cursor: pointer; color: var(--muted); min-height: 32px; display: flex; align-items: center; }
details.viz-table table { margin-top: 6px; }

.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.hbars li { display: grid; grid-template-columns: 108px minmax(0, 1fr) 40px; align-items: center; gap: 12px; font-size: 13.5px; }
.hbars .hb-label { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbars .hb-track { height: 14px; border-radius: 0 4px 4px 0; }
.hbars .hb-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.hbars .hb-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ============ Worker detail ============ */
.profile { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 20px 18px; }
.profile h1 { font-size: 22px; }
.profile .meta { color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.profile .actions { margin-left: auto; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.facts > div { padding: 14px 18px; border-left: 1px solid var(--line); }
.facts > div:nth-child(3n+1) { border-left: 0; }
.facts > div:nth-child(n+4) { border-top: 1px solid var(--line); }
.facts dt { font-size: 12.5px; color: var(--muted); }
.facts dd { margin: 3px 0 0; font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 6px; }
.facts dd small { font-weight: 400; color: var(--muted); font-size: 13px; }
@media (max-width: 640px) {
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .facts > div { border-left: 1px solid var(--line) !important; border-top: 1px solid var(--line) !important; }
  .facts > div:nth-child(odd) { border-left: 0 !important; }
  .facts > div:nth-child(-n+2) { border-top: 0 !important; }
}

/* ============ Payroll ============ */
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.summary > div { padding: 14px 18px; border-left: 1px solid var(--line); }
.summary > div:first-child { border-left: 0; }
.summary dt { font-size: 12.5px; color: var(--muted); }
.summary dd { margin: 2px 0 0; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary > div:nth-child(3) { border-left: 0; }
  .summary > div:nth-child(n+3) { border-top: 1px solid var(--line); }
}

/* ============ Login ============ */
.login { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.login-art {
  position: relative; overflow: hidden; padding: 40px; display: flex; flex-direction: column; justify-content: space-between;
  background: #0f3f2a; color: #eaf5ee;
}
.login-art::before {
  content: ""; position: absolute; inset: 0; opacity: .5;
  background-image: linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 36px 36px; mask-image: radial-gradient(circle at 30% 40%, #000 20%, transparent 75%);
}
.login-art > * { position: relative; }
.login-art .brand-mark { background: #eaf5ee; color: #0f3f2a; }
.login-art h1 { font-size: clamp(30px, 3.4vw, 46px); font-weight: 600; letter-spacing: -0.03em; max-width: 14ch; }
.login-art p { color: #b8d6c5; max-width: 42ch; margin-top: 14px; font-size: 16px; }
.ledger-demo { display: grid; gap: 8px; max-width: 380px; }
.ledger-demo div {
  display: flex; justify-content: space-between; padding: 10px 14px; border-radius: 10px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); font-size: 14px; font-variant-numeric: tabular-nums;
}
.ledger-demo span { color: #b8d6c5; }
.login-form { display: grid; place-items: center; padding: 32px 20px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 20px; }
.login-card h2 { font-size: 24px; }
.login-card .seg { width: 100%; }
.login-card .seg button { flex: 1; }
.hint { font-size: 13px; color: var(--muted); padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px dashed var(--line-strong); }
.hint code { font-family: inherit; font-weight: 600; color: var(--ink); }
@media (max-width: 860px) {
  .login { grid-template-columns: minmax(0, 1fr); }
  .login-art { padding: 28px 20px; gap: 28px; }
  .ledger-demo { display: none; }
}

/* ============ Employee view ============ */
.me { max-width: 760px; margin: 0 auto; padding: 20px 16px 48px; }
.me-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.me-hero { padding: 22px 20px; background: var(--brand); color: var(--on-brand); border-radius: var(--radius); display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.me-hero .avatar { background: rgba(255,255,255,.18); color: inherit; }
:root[data-theme="dark"] .me-hero .avatar { background: rgba(0,0,0,.15); }
.me-hero h1 { font-size: 24px; }
.me-hero p { opacity: .85; margin-top: 2px; }
.balance-line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ============ Modal & toast ============ */
dialog.modal { padding: 0; border: 0; background: transparent; max-width: min(560px, calc(100vw - 24px)); width: 100%; color: var(--ink); }
dialog.modal::backdrop { background: rgba(10, 10, 10, .45); backdrop-filter: blur(2px); }
.modal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0 20px; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 16px 20px; max-height: 70dvh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); animation: pop .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@media (max-width: 900px) { .toasts { bottom: 92px; } }

/* ============ Tables → cards on phones ============ */
@media (max-width: 720px) {
  .table-wrap:has(> .t.cards) { overflow: visible; }
  .t.cards, .t.cards tbody { display: block; }
  .t.cards thead { display: none; }
  .t.cards tr {
    position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px;
    padding: 14px 16px; border-bottom: 1px solid var(--line);
  }
  .t.cards tr:last-child { border-bottom: 0; }
  .t.cards td { display: block; padding: 0 !important; border: 0; text-align: left; min-width: 0; width: auto !important; font-size: 14px; }
  .t.cards td.lead { grid-column: 1 / -1; order: -1; }
  .t.cards td.hide-sm { display: none; }
  .t.cards td[data-label]::before {
    content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .t.cards td.act { grid-column: 1 / -1; display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
  .t.cards td.act .btn { flex: 1; min-height: 42px; }
  .t.cards td.corner { position: absolute; top: 10px; right: 10px; }
  .t.cards td.corner .btn { flex: none; min-height: 36px; }
  .t.cards tr:has(td.corner) td.lead { padding-right: 44px !important; }
  .t.cards tr:has(td.corner .btn) td.lead { padding-right: 100px !important; }
  .t.cards .input.sm { width: 100%; text-align: left; min-height: 42px; }
}

/* ============ Logo ============ */
/* The logo artwork sits on its own light background (#f7f7f7), so it always gets a light tile — in dark mode too. */
.brand-mark.logo {
  width: 46px; height: 46px; border-radius: 50%; background: #fff; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .12);
}
.brand-mark.logo img { width: 100%; height: 100%; display: block; object-fit: contain; transform: scale(1.12); }
.brand-mark.lg { width: 52px; height: 52px; }
.brand-mark.xl { width: 96px; height: 96px; }
.login-art { justify-content: center; gap: 36px; }
.login-logo {
  width: 240px; height: 240px; border-radius: 50%; background: #fff; overflow: hidden;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, .12), 0 30px 60px rgba(0, 0, 0, .35);
}
.login-logo img { width: 100%; height: 100%; display: block; }
.eyebrow { font-size: 13px !important; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #8fd0ad !important; margin: 0 0 10px !important; }
.login-mobile-logo { display: none; align-items: center; gap: 12px; }
.login-mobile-logo b { display: block; font-size: 16px; }
.login-mobile-logo small { color: var(--muted); font-size: 13px; }
@media (max-width: 860px) {
  .login-art { display: none; }
  .login-mobile-logo { display: flex; }
  .login-form { align-items: start; padding-top: 40px; }
}
.biz-logo { display: flex; align-items: center; gap: 14px; }
.boot { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 14px; }

/* ============ Sync status ============ */
.sync { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; color: var(--muted); padding: 4px 8px; white-space: nowrap; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync[data-state="saved"] i { background: var(--good); }
.sync[data-state="saving"] i { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
.sync[data-state="offline"] i, .sync[data-state="error"] i { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
@media (max-width: 900px) { .topbar .sync { font-size: 0; gap: 0; padding: 4px; } }

/* ============ Import ============ */
.import-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 560px) { .import-tiles { grid-template-columns: minmax(0, 1fr); } }
.import-tile {
  display: grid; gap: 6px; text-align: left; padding: 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); transition: border-color .15s, background .15s;
}
.import-tile:hover { border-color: var(--brand); background: var(--brand-soft); }
.import-tile svg { width: 22px; height: 22px; color: var(--brand-ink); }
.import-tile b { font-size: 15px; }
.import-tile span { font-size: 13px; color: var(--muted); line-height: 1.45; }
.dropzone {
  display: grid; justify-items: center; gap: 6px; text-align: center; padding: 28px 16px; cursor: pointer;
  border: 2px dashed var(--line-strong); border-radius: 14px; background: var(--surface-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over, .dropzone:focus-within { border-color: var(--brand); background: var(--brand-soft); }
.dropzone svg { width: 28px; height: 28px; color: var(--brand-ink); }
.dropzone span { font-size: 13px; color: var(--muted); }
.pv-title { font-weight: 600; margin: 16px 0 8px; }
.pv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pv { display: flex; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.pv.bad { border-color: var(--danger); background: var(--danger-soft); }
.pv-ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); flex: none; }
.pv-body { min-width: 0; display: grid; gap: 3px; font-size: 14px; }
.pv-body p { color: var(--ink-2); }
.pv-body .src { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.warns summary { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--warn); min-height: 28px; }
.warns summary svg { width: 14px; height: 14px; }
.warns ul { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); display: grid; gap: 3px; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.t .input.xs { width: 72px; }

/* ============ Bills ============ */
.tx-ic.bill { background: var(--brand-soft); color: var(--brand-ink); }
.empty-hero { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 48px 20px; }
.empty-hero p { max-width: 46ch; }
.empty-ic { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-ink); margin-bottom: 4px; }
.empty-ic svg { width: 26px; height: 26px; }
.page-head .sub .badge { vertical-align: middle; }

.invoice { padding: 28px; display: grid; gap: 22px; max-width: 920px; }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; padding-bottom: 18px; border-bottom: 2px solid var(--ink); }
.inv-head h2 { font-size: 20px; letter-spacing: .12em; }
.inv-brand { display: flex; gap: 14px; align-items: center; }
.inv-brand img { width: 72px; height: 72px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .1); }
.inv-brand b { display: block; font-size: 20px; letter-spacing: -0.01em; }
.inv-brand span, .inv-meta span { display: block; font-size: 13px; color: var(--ink-2); }
.inv-meta { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; }
.inv-meta b { display: block; margin: 2px 0; }
.lbl { display: block; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.inv-meta dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.inv-meta dt, .inv-totals dt { font-size: 12.5px; color: var(--muted); }
.inv-meta dd { margin: 1px 0 0; font-weight: 600; }
.inv-items { border: 1px solid var(--line); }
.inv-items td, .inv-items th { padding: 9px 12px !important; }
.inv-heading td { background: var(--surface-2); }
.inv-foot { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 320px); gap: 24px; align-items: start; }
.inv-words b { display: block; margin-top: 4px; font-weight: 500; }
.inv-totals { margin: 0; display: grid; gap: 6px; font-variant-numeric: tabular-nums; }
.inv-totals div { display: flex; justify-content: space-between; gap: 16px; }
.inv-totals dd { margin: 0; }
.inv-totals .grand { border-top: 2px solid var(--ink); padding-top: 8px; margin-top: 4px; font-size: 18px; font-weight: 700; }
.inv-totals .grand dt { color: var(--ink); font-size: 16px; }
.inv-sign { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; font-size: 13px; color: var(--ink-2); padding-top: 10px; }
.inv-sign div { display: grid; gap: 40px; text-align: right; font-weight: 600; }
.inv-sign .sig { font-weight: 400; }
@media (max-width: 720px) {
  .invoice { padding: 18px; }
  .inv-meta, .inv-foot { grid-template-columns: minmax(0, 1fr); }
  .inv-items { min-width: 620px; }
  .table-wrap:has(> .inv-items) { overflow-x: auto; }
}

/* ============ Print (bills) ============ */
@media print {
  :root { color-scheme: light; --ink: #000; --ink-2: #222; --muted: #555; --line: #bbb; --surface: #fff; --surface-2: #f2f2f2; }
  body { background: #fff; }
  .sidebar, .topbar, .bottomnav, .no-print, .toasts, .viz-tip { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; max-width: none; }
  .invoice { border: 0; box-shadow: none; padding: 0; max-width: none; }
  .inv-items { min-width: 0; }
  @page { margin: 14mm; }
}
.pv-body .badge { justify-self: start; }

/* ============ Documents & KYC ============ */
.avatar.has-photo { overflow: hidden; background: var(--surface-3); }
.avatar.has-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-head + .facts { margin-top: 14px; }
.facts.info dd { display: block; font-size: 14.5px; line-height: 1.45; overflow-wrap: anywhere; }
.facts.info dd a { color: inherit; }
.kyc-meter { padding: 12px 18px 0; display: grid; gap: 6px; max-width: 520px; }
.doc-tip { margin: 14px 18px 0; display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--ink-2); font-size: 13.5px; line-height: 1.5; }
.doc-tip svg { flex: none; width: 18px; height: 18px; color: var(--brand-ink); margin-top: 1px; }
.doc-tip a { color: var(--brand-ink); font-weight: 600; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; padding: 16px 18px 18px; }
.doc-slot { position: relative; display: grid; grid-template-columns: 76px 1fr; grid-template-areas: "thumb info" "act act"; gap: 10px 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); transition: border-color .15s; }
.doc-slot[data-state="missing"] { border-style: dashed; border-color: var(--line-strong); }
.doc-slot[data-state="pending"] { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.doc-slot[data-state="rejected"] { border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); background: color-mix(in srgb, var(--danger-soft) 45%, var(--surface)); }
.doc-slot.busy { pointer-events: none; opacity: .6; }
.doc-slot.busy::after { content: "Uploading…"; position: absolute; inset: auto 12px 12px auto; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.doc-thumb { grid-area: thumb; width: 76px; height: 76px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); display: grid; place-items: center; overflow: hidden; color: var(--muted); padding: 0; cursor: pointer; }
.doc-thumb:disabled { cursor: default; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.doc-thumb svg { width: 26px; height: 26px; }
.doc-thumb span { display: grid; place-items: center; gap: 2px; }
.doc-thumb small { font-size: 11px; font-weight: 700; }
.doc-thumb:not(:disabled):hover { border-color: var(--line-strong); }
.doc-info { grid-area: info; display: grid; gap: 5px; align-content: start; min-width: 0; }
.doc-info b { font-weight: 600; font-size: 14px; line-height: 1.3; }
.doc-info b small { font-weight: 400; }
.doc-info .badge { justify-self: start; }
.doc-info small { font-size: 12.5px; line-height: 1.4; }
.doc-reason { color: var(--danger); font-weight: 500; }
.doc-actions { grid-area: act; display: flex; flex-wrap: wrap; gap: 6px; }
.doc-actions:empty { display: none; }
.doc-actions .btn { flex: 1 1 auto; justify-content: center; min-height: 40px; }
.doc-actions label.btn { cursor: pointer; }
.doc-actions label.btn:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
.review-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; padding: 16px 18px 18px; }
.review { display: grid; grid-template-columns: 76px 1fr; grid-template-areas: "thumb info" "act act"; gap: 10px 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.form-sec { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.form-sec:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; min-height: 32px; cursor: pointer; line-height: 1.45; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.reasons { display: grid; gap: 4px; }
dialog.modal.wide { max-width: min(860px, calc(100vw - 24px)); }
.doc-view { display: grid; place-items: center; min-height: 200px; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; }
.doc-view img { max-width: 100%; max-height: 60dvh; display: block; object-fit: contain; }
.doc-view iframe { width: 100%; height: 60dvh; border: 0; background: #fff; }
.doc-view-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.danger-text { color: var(--danger) !important; }
.banner { display: flex; align-items: center; gap: 14px; padding: 14px 18px; text-decoration: none; color: inherit; border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); background: color-mix(in srgb, var(--warn-soft) 60%, var(--surface)); }
.banner > svg:first-child { width: 22px; height: 22px; color: var(--warn); flex: none; }
.banner span { display: grid; gap: 2px; flex: 1; min-width: 0; }
.banner small { color: var(--ink-2); font-size: 13px; }
.banner > svg:last-child { color: var(--muted); flex: none; }
.banner:hover { border-color: var(--warn); }
@media (max-width: 480px) {
  .doc-grid, .review-grid { grid-template-columns: 1fr; padding: 14px; }
  .doc-tip { margin: 12px 14px 0; }
  .kyc-meter { padding: 12px 14px 0; }
}
a.btn { text-decoration: none; }

/* collapsible card (owner: Documents & KYC) */
details.fold > summary { list-style: none; cursor: pointer; padding-bottom: 16px; border-radius: var(--radius); }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary:hover h2 { color: var(--brand-ink); }
details.fold > summary:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
details.fold[open] > summary { padding-bottom: 0; }
.fold-end { display: inline-flex; align-items: center; gap: 10px; }
.fold-chev { width: 18px; height: 18px; color: var(--muted); transition: transform .2s ease; }
details.fold[open] .fold-chev { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { .fold-chev { transition: none; } }
.me .back { margin-bottom: -4px; }
