/* Ledger — one stylesheet, light + dark, phone → desktop. */

:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --surface-3: #e9e8e4;
  --line: #e4e3df;
  --line-strong: #d3d2cc;
  --ink: #151514;
  --ink-2: #52514e;
  --ink-3: #85847e;
  --accent: #1d5fc4;
  --accent-soft: #e5eefb;
  --accent-ink: #ffffff;
  --pos: #11734f;
  --neg: #b42318;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --danger-soft: #fdecea;
  --star: #c98500;
  /* chart palette (validated categorical order) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --s-other: #b9b8b2;
  --grid: #ecebe7;
  --shadow: 0 1px 2px rgba(20, 20, 18, .04), 0 4px 16px rgba(20, 20, 18, .05);
  --shadow-lg: 0 12px 48px rgba(20, 20, 18, .18);
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sidebar: 248px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #222221; --surface-3: #2b2b29;
    --line: #2c2c2a; --line-strong: #3a3a37;
    --ink: #f4f4f1; --ink-2: #c3c2b7; --ink-3: #8f8e86;
    --accent: #5b9bf0; --accent-soft: #1d2a3d; --accent-ink: #0d1117;
    --pos: #4cc38a; --neg: #f07167; --warn: #e3b341; --warn-soft: #2e2615; --danger-soft: #331b1a;
    --star: #e3b341;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --s-other: #5c5b56; --grid: #262624;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #222221; --surface-3: #2b2b29;
  --line: #2c2c2a; --line-strong: #3a3a37;
  --ink: #f4f4f1; --ink-2: #c3c2b7; --ink-3: #8f8e86;
  --accent: #5b9bf0; --accent-soft: #1d2a3d; --accent-ink: #0d1117;
  --pos: #4cc38a; --neg: #f07167; --warn: #e3b341; --warn-soft: #2e2615; --danger-soft: #331b1a;
  --star: #e3b341;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --s-other: #5c5b56; --grid: #262624;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.num, .money { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.hidden, [hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* boot */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--ink); opacity: .08; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .2; } }

/* ---------------------------------------------------------------- shell */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); padding: 22px 14px;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-logo { width: 32px; height: 32px; border-radius: 9px; background: var(--ink); color: var(--bg); display: grid; place-items: center; flex: none; }
.brand-logo svg { width: 18px; height: 18px; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-case { font-size: 12px; color: var(--ink-3); max-width: 160px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
  color: var(--ink-2); font-weight: 500; text-decoration: none !important;
}
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 12px; background: var(--warn-soft); color: var(--warn); border-radius: 99px; padding: 1px 8px; font-weight: 600; }
.nav-sep { height: 1px; background: var(--line); margin: 10px 8px; }
.sidebar-foot { margin-top: auto; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.role-pill { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.sidebar .capture-btn { margin: 6px 4px 14px; }

.main { margin-left: var(--sidebar); padding: 28px 36px 60px; max-width: calc(1240px + var(--sidebar)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-3); font-size: 14px; margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.topbar, .tabbar { display: none; }

/* ---------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; font-weight: 550; cursor: pointer; white-space: nowrap;
  min-height: 38px; text-decoration: none !important; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(.5px); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: .9; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--neg); }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn.icon { padding: 7px; min-width: 38px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--ink-3); border-top-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); font-weight: 550; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 10px;
  padding: 9px 12px; min-height: 40px; font-size: 15px; color: var(--ink); font-weight: 400;
  outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea.input { min-height: 84px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.input.big { font-size: 30px; font-weight: 650; min-height: 58px; letter-spacing: -.01em; }
.hint { font-size: 12px; color: var(--ink-3); font-weight: 400; }
.error-text { color: var(--neg); font-size: 13px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  color: var(--ink-2); font-weight: 550; font-size: 13.5px; white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.big button { padding: 9px 18px; font-size: 15px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong);
  background: var(--surface); padding: 4px 10px; border-radius: 99px; font-size: 13px; color: var(--ink-2);
  cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .x { opacity: .6; font-size: 15px; line-height: 1; }
.tag { display: inline-block; background: var(--surface-2); color: var(--ink-2); font-size: 12px; padding: 2px 8px; border-radius: 99px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.income { background: color-mix(in srgb, var(--pos) 14%, transparent); color: var(--pos); }
.badge.star { background: color-mix(in srgb, var(--star) 16%, transparent); color: var(--star); }
.badge.danger { background: var(--danger-soft); color: var(--neg); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 25px; border-radius: 99px; background: var(--surface-3); position: relative; cursor: pointer; transition: background .15s; flex: none; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(17px); }

/* ---------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px 0; }
.card-head h2 { font-size: 15px; }
.card-head .sub { font-size: 12.5px; color: var(--ink-3); font-weight: 400; margin-top: 2px; }
.card-body { padding: 14px 20px 18px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 650; margin: 26px 0 10px; }

.grid { display: grid; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 13px; color: var(--ink-2); font-weight: 550; display: flex; align-items: center; gap: 8px; }
.kpi .label .dot { width: 8px; height: 8px; border-radius: 2px; }
.kpi .value { font-size: 27px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .value.hero { font-size: 30px; }
.kpi .foot { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.dash-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }

.attention { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.attention a { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); font-size: 13.5px; text-decoration: none; }
.attention a:hover { border-color: var(--line-strong); color: var(--ink); }
.attention a b { color: var(--ink); font-variant-numeric: tabular-nums; }
.attention svg { width: 16px; height: 16px; }
.attention .warn svg { color: var(--warn); }

.period { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: 100%; min-width: 0; }
.page-head > * { max-width: 100%; min-width: 0; }
.period .custom { display: flex; gap: 6px; align-items: center; }
.period .custom .input { min-height: 34px; padding: 5px 8px; font-size: 13.5px; width: auto; }

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; overflow: visible; }
.chart .axis text, .chart text.axis { fill: var(--ink-3); font-size: 11.5px; font-family: var(--font); }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .zero-line { stroke: var(--line-strong); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hover-band { fill: var(--ink); opacity: .04; }
.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 10px; font-size: 12.5px;
  box-shadow: var(--shadow-lg); min-width: 140px; opacity: 0; transition: opacity .1s; white-space: nowrap;
}
.tooltip.show { opacity: 1; }
.tooltip .t-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .t-row span:first-child { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .sw { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.card-body:has(.donut-wrap) { container-type: inline-size; }
.donut-wrap { display: grid; grid-template-columns: minmax(150px, 190px) 1fr; gap: 20px; align-items: center; }
@container (max-width: 470px) {
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .donut-wrap .donut-legend { width: 100%; }
}
.donut-legend { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.donut-legend .li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 44px; gap: 8px; align-items: center; font-size: 13px; padding: 4px 6px; border-radius: 8px; cursor: default; }
.donut-legend .li:hover, .donut-legend .li.hl { background: var(--surface-2); }
.donut-legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend .pct { color: var(--ink-3); text-align: right; font-variant-numeric: tabular-nums; }
.donut-legend .amt { font-variant-numeric: tabular-nums; font-weight: 550; }
.donut-center-value { fill: var(--ink); font-size: 17px; font-weight: 700; }
.donut-center-label { fill: var(--ink-3); font-size: 11px; }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 12px; align-items: center; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hbar .track { height: 10px; border-radius: 0 4px 4px 0; position: relative; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { font-variant-numeric: tabular-nums; font-weight: 550; text-align: right; }
.chart-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.chart-table th, .chart-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.chart-table td.n, .chart-table th.n { text-align: right; font-variant-numeric: tabular-nums; }
.empty-chart { color: var(--ink-3); font-size: 13.5px; padding: 30px 0; text-align: center; }

/* ---------------------------------------------------------------- lists */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 280px; min-width: 200px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--ink-3); pointer-events: none; }
.search .input { padding-left: 38px; }
.search kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font: 11px var(--mono); color: var(--ink-3); border: 1px solid var(--line-strong); border-radius: 5px; padding: 1px 5px; }
.active-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.result-line { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; font-size: 13.5px; color: var(--ink-2); margin: 4px 0 12px; }
.result-line b { color: var(--ink); font-variant-numeric: tabular-nums; }

.tx-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.tx-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 1; cursor: default; }
.tx-table th.sortable { cursor: pointer; }
.tx-table th.sortable:hover { color: var(--ink); }
.tx-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
.tx-table tr:last-child td { border-bottom: 0; }
.tx-table tbody tr { cursor: pointer; }
.tx-table tbody tr:hover td { background: var(--surface-2); }
.tx-table tbody tr.sel td { background: var(--accent-soft); }
.tx-table .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-table .party { font-weight: 550; }
.tx-table .desc { color: var(--ink-3); font-size: 13px; max-width: 360px; }
.tx-table .date { white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tx-table .ref { font: 12px var(--mono); color: var(--ink-3); white-space: nowrap; }
.tx-table input[type=checkbox], .tx-list input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
.thumb { width: 38px; height: 38px; border-radius: 8px; background: var(--surface-2); object-fit: cover; flex: none; display: grid; place-items: center; color: var(--ink-3); overflow: hidden; }
.thumb svg { width: 18px; height: 18px; }
.thumb.missing { border: 1px dashed var(--line-strong); background: transparent; }
.amount-income { color: var(--pos); }
.star-on { color: var(--star); }

.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-group { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 14px 4px 6px; display: flex; justify-content: space-between; }
.tx-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; background: var(--surface); border-bottom: 1px solid var(--line); cursor: pointer; }
.tx-item:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.tx-item:last-child { border-bottom: 0; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.tx-item .main-col { flex: 1 1 auto; min-width: 0; }
.tx-item .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-item .t2 { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-item .amt { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.tx-item.sel { background: var(--accent-soft); }
.list-card { border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }

.bulkbar {
  position: sticky; bottom: 16px; z-index: 15; margin-top: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--ink); color: var(--bg); padding: 10px 12px; border-radius: 14px; box-shadow: var(--shadow-lg);
}
.bulkbar .btn { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 30%, transparent); }
.bulkbar .btn:hover { background: color-mix(in srgb, var(--bg) 12%, transparent); }

.empty { text-align: center; padding: 56px 20px; color: var(--ink-2); }
.empty svg { width: 42px; height: 42px; color: var(--ink-3); margin-bottom: 12px; }
.empty h3 { margin-bottom: 6px; color: var(--ink); }

/* ---------------------------------------------------------------- receipts */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.rcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; position: relative; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s; }
.rcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.rcard .img { aspect-ratio: 3 / 4; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.rcard .img img { width: 100%; height: 100%; object-fit: cover; }
.rcard .img svg { width: 36px; height: 36px; color: var(--ink-3); }
.rcard .cap { padding: 9px 11px; font-size: 13px; }
.rcard .cap .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rcard .cap .t2 { color: var(--ink-3); font-size: 12px; display: flex; justify-content: space-between; gap: 6px; }
.rcard .pick { position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,.9); border: 1.5px solid rgba(0,0,0,.25); display: grid; place-items: center; }
.rcard.sel { outline: 3px solid var(--accent); outline-offset: -1px; }
.rcard.sel .pick { background: var(--accent); border-color: var(--accent); color: #fff; }
.rcard .pick svg { width: 14px; height: 14px; }
.rcard .flag { position: absolute; top: 8px; right: 8px; }

.receipt-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.receipt-tile { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface-2); position: relative; cursor: pointer; }
.receipt-tile .img { aspect-ratio: 3 / 4; display: grid; place-items: center; }
.receipt-tile img { width: 100%; height: 100%; object-fit: cover; }
.receipt-tile .img svg { width: 30px; height: 30px; color: var(--ink-3); }
.receipt-tile .meta { font-size: 11.5px; padding: 6px 8px; color: var(--ink-3); background: var(--surface); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.receipt-tile .rm { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; cursor: pointer; }
.receipt-tile .rm svg { width: 14px; height: 14px; }
.receipt-tile.add { display: grid; place-items: center; aspect-ratio: auto; border-style: dashed; color: var(--ink-2); background: transparent; min-height: 150px; font-size: 13px; text-align: center; gap: 6px; padding: 10px; }
.receipt-tile.add svg { width: 26px; height: 26px; margin: 0 auto 4px; }
.upload-progress { height: 4px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.upload-progress div { height: 100%; background: var(--accent); width: 0; transition: width .15s; }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(8, 8, 8, .97); display: flex; flex-direction: column; color: #fff; }
.lightbox .lb-bar { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 14px 10px; }
.lightbox .lb-bar .title { flex: 1; min-width: 0; font-size: 14px; }
.lightbox .lb-bar .title .t2 { color: rgba(255,255,255,.6); font-size: 12px; }
.lightbox .btn { background: rgba(255,255,255,.1); border-color: transparent; color: #fff; }
.lightbox .btn:hover { background: rgba(255,255,255,.2); }
.lightbox .lb-stage { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 8px; touch-action: pinch-zoom pan-x pan-y; }
.lightbox .lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; cursor: zoom-in; }
.lightbox .lb-stage.zoom { align-items: flex-start; justify-content: flex-start; }
.lightbox .lb-stage.zoom img { max-width: none; max-height: none; width: 180%; cursor: zoom-out; }
.lightbox .lb-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 6px; }
.lightbox .lb-foot { padding: 8px 16px calc(12px + var(--safe-b)); font-size: 12px; color: rgba(255,255,255,.65); display: flex; gap: 16px; flex-wrap: wrap; }
.lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.12); border: 0; color: #fff; display: grid; place-items: center; cursor: pointer; }
.lightbox .lb-nav.prev { left: 14px; } .lightbox .lb-nav.next { right: 14px; }
.lightbox .lb-nav svg { width: 22px; height: 22px; }

/* ---------------------------------------------------------------- detail */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.detail-hero { padding: 22px 22px 18px; }
.detail-hero .amount { font-size: 38px; font-weight: 700; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.detail-hero .party { font-size: 18px; font-weight: 600; margin-top: 2px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 0; }
.kv > div { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }
.kv .k { color: var(--ink-3); }
.notes-box { white-space: pre-wrap; font-size: 14px; }
.comment { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.comment:last-child { border-bottom: 0; }
.comment .body { white-space: pre-wrap; font-size: 14px; margin-top: 2px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.timeline li::after { content: ""; position: absolute; left: 7px; top: 16px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--ink-3); font-size: 12px; }
.timeline .diff { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; }
.timeline .diff s { color: var(--ink-3); }
.legal-box { background: var(--surface-2); border-radius: 12px; padding: 14px; }

/* ---------------------------------------------------------------- forms */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-page { max-width: 860px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.ai-note { display: flex; gap: 10px; align-items: center; background: var(--accent-soft); color: var(--ink); padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.ai-note svg { width: 18px; height: 18px; color: var(--accent); flex: none; }
.dup-note { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.suggest { position: relative; }
.suggest-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 10; max-height: 240px; overflow: auto; }
.suggest-list button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; cursor: pointer; font-size: 14px; }
.suggest-list button:hover, .suggest-list button.hl { background: var(--surface-2); }

/* ---------------------------------------------------------------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 30px 28px; }
.auth-card .brand { padding: 0 0 22px; }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card .lead { color: var(--ink-2); font-size: 14px; margin-bottom: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-foot { text-align: center; font-size: 12.5px; color: var(--ink-3); margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.auth-foot svg { width: 14px; height: 14px; }

/* ---------------------------------------------------------------- overlays */
.modal-back { position: fixed; inset: 0; background: rgba(10, 10, 10, .42); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: calc(100vh - 40px); overflow: auto; animation: rise .18s ease-out; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; gap: 10px; }
.modal-body { padding: 10px 20px 20px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 0 20px 20px; flex-wrap: wrap; }
.sheet-list { display: flex; flex-direction: column; gap: 4px; }
.sheet-list button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 14px; border: 0; background: transparent; border-radius: 12px; text-align: left; cursor: pointer; font-size: 15px; }
.sheet-list button:hover { background: var(--surface-2); }
.sheet-list button svg { width: 22px; height: 22px; color: var(--ink-2); flex: none; }
.sheet-list .t2 { font-size: 12.5px; color: var(--ink-3); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

#toasts { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg); animation: rise .18s ease-out; pointer-events: auto; max-width: 90vw; display: flex; gap: 12px; align-items: center; }
.toast.err { background: var(--neg); color: #fff; }
.toast button { background: transparent; border: 0; color: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }

.filters-panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.cat-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.table-simple { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-simple th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table-simple td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-simple tr:last-child td { border-bottom: 0; }
.link-box { display: flex; gap: 8px; align-items: center; background: var(--surface-2); padding: 8px 8px 8px 12px; border-radius: 10px; }
.link-box code { flex: 1; min-width: 0; font: 12px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.export-card { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.export-card .ic { width: 40px; height: 40px; border-radius: 11px; background: var(--surface-2); display: grid; place-items: center; }
.export-card .ic svg { width: 21px; height: 21px; }
.export-card.recommended { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.export-card ul { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 13.5px; }
.export-card .btn { margin-top: auto; align-self: flex-start; }
.more-list a { display: flex; align-items: center; gap: 14px; padding: 15px 16px; color: var(--ink); border-bottom: 1px solid var(--line); text-decoration: none; }
.more-list a:last-child { border-bottom: 0; }
.more-list svg { width: 21px; height: 21px; color: var(--ink-2); }
.more-list .chev { margin-left: auto; color: var(--ink-3); width: 16px; height: 16px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-8, .span-7, .span-5, .span-4 { grid-column: span 6; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: calc(64px + var(--safe-t)) 16px calc(var(--tabbar) + 28px + var(--safe-b)); }
  .topbar {
    display: flex; position: fixed; top: 0; left: 0; right: 0; z-index: 30; align-items: center; gap: 10px;
    padding: calc(8px + var(--safe-t)) 12px 8px; background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
    border-bottom: 1px solid var(--line); min-height: calc(52px + var(--safe-t));
  }
  .topbar .title { flex: 1; font-weight: 650; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .btn { min-height: 36px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
    border-top: 1px solid var(--line);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; color: var(--ink-3); text-decoration: none; font-weight: 550; }
  .tabbar a svg { width: 23px; height: 23px; }
  .tabbar a.active { color: var(--ink); }
  .tabbar .fab-slot { display: grid; place-items: center; }
  .fab { width: 54px; height: 54px; border-radius: 18px; background: var(--ink); color: var(--bg); border: 0; display: grid; place-items: center; box-shadow: var(--shadow-lg); transform: translateY(-10px); cursor: pointer; }
  .fab svg { width: 26px; height: 26px; }
  .page-head { margin-bottom: 14px; }
  .page-head h1 { display: none; }
  .page-head .sub { margin-top: 0; }
  .page-head.keep h1 { display: block; font-size: 22px; }
  .kpis { gap: 10px; }
  .kpi { padding: 13px 14px; }
  .kpi .value, .kpi .value.hero { font-size: 21px; }
  .dash-grid { gap: 12px; }
  .span-12, .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
  .card-head { padding: 14px 16px 0; }
  .card-body { padding: 12px 16px 16px; }
  .card-pad { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .export-grid { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .kv { grid-template-columns: 110px 1fr; }
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { border-radius: 20px 20px 0 0; max-height: 92vh; padding-bottom: var(--safe-b); animation: sheet .22s ease-out; }
  .bulkbar { bottom: calc(var(--tabbar) + 12px + var(--safe-b)); }
  #toasts { bottom: calc(var(--tabbar) + 16px + var(--safe-b)); }
  .search kbd { display: none; }
  .hide-mobile { display: none !important; }
  .members thead { display: none; }
  .members tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; border-bottom: 1px solid var(--line); padding: 10px 0; }
  .members tr:last-child { border-bottom: 0; }
  .members td { border: 0 !important; padding: 4px 0 !important; }
  .members td:last-child { grid-column: 1 / -1; text-align: left !important; }
  .detail-hero .amount { font-size: 32px; }
  .form-actions .btn { flex: 1; }
}
@media (min-width: 961px) { .show-mobile { display: none !important; } }
@keyframes sheet { from { transform: translateY(40px); opacity: .4; } }

/* ---------------------------------------------------------------- print */
@media print {
  .sidebar, .topbar, .tabbar, .page-actions, .bulkbar, .no-print, #toasts { display: none !important; }
  .main { margin: 0; padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
