:root {
  --bg: #f4f1ea;
  --surface: #fffdf9;
  --surface-2: #efe9de;
  --line: #e2dbcd;
  --ink: #1d2a26;
  --ink-2: #5b6661;
  --ink-3: #8b938f;
  --brand: #1f4d42;
  --brand-2: #2f6f5e;
  --brand-ink: #ffffff;
  --in: #217a52;
  --in-soft: #dcefe3;
  --out: #b4532f;
  --out-soft: #f6e1d6;
  --focus: #e0a43a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(29, 42, 38, .06), 0 6px 18px rgba(29, 42, 38, .06);
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715;
    --surface: #18201d;
    --surface-2: #212b27;
    --line: #2c3833;
    --ink: #edf1ee;
    --ink-2: #a9b4ae;
    --ink-3: #78847e;
    --brand: #7cc4ad;
    --brand-2: #5fae95;
    --brand-ink: #0e1a16;
    --in: #6fd19e;
    --in-soft: #183a2a;
    --out: #f0997a;
    --out-soft: #43261b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------ layout */
.shell { min-height: 100%; display: flex; }
.sidebar { display: none; }
.main {
  flex: 1;
  min-width: 0;
  padding: calc(14px + var(--safe-t)) 16px calc(var(--nav-h) + 28px + var(--safe-b));
  max-width: 1100px;
  margin: 0 auto;
}
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 4px 0 14px;
}
.page-head h1 { font-size: 24px; letter-spacing: -.02em; margin: 0; font-weight: 750; }
.page-head .sub { color: var(--ink-2); font-size: 13px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr 96px 1fr; align-items: center;
}
.page-head .icon-btn { color: var(--ink-2); flex-shrink: 0; }
.page-head > div { flex: 1; min-width: 0; }
.page-head .btn.ghost { padding: 8px 10px; text-decoration: none; }
@media (min-width: 900px) { .mobile-only { display: none !important; } }
.tab {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; color: var(--ink-3); padding: 6px 0; text-decoration: none;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--brand); font-weight: 650; }
.fab {
  justify-self: center; width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--brand); color: var(--brand-ink);
  box-shadow: 0 6px 16px rgba(31, 77, 66, .35);
  display: grid; place-items: center; transform: translateY(-14px);
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: translateY(-14px) scale(.95); }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 6px;
    position: sticky; top: 0; height: 100vh; width: 240px; flex-shrink: 0;
    padding: 22px 16px; border-right: 1px solid var(--line); background: var(--surface);
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 18px; margin: 0 6px 22px; }
  .brand img { width: 34px; height: 34px; border-radius: 9px; }
  .side-link {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: var(--ink-2); text-decoration: none; font-weight: 550; border: 0; background: none; text-align: left;
  }
  .side-link svg { width: 20px; height: 20px; }
  .side-link:hover { background: var(--surface-2); }
  .side-link.active { background: var(--surface-2); color: var(--brand); }
  .side-add {
    margin-top: 12px; display: flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 12px; padding: 12px; font-weight: 650;
  }
  .side-add svg { width: 18px; height: 18px; }
  .main { padding: 28px 36px 48px; }
  .page-head h1 { font-size: 28px; }
}

/* ------------------------------------------------------------ cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card, .section + .section { margin-top: 14px; }
.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-2); margin: 22px 4px 10px;
}
.section-title small { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--ink-3); }

/* ------------------------------------------------------------ filters */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.period {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 5px;
}
.period .step {
  width: 38px; height: 38px; border: 0; border-radius: 10px; background: none; color: var(--ink-2);
  display: grid; place-items: center;
}
.period .step:hover { background: var(--surface-2); }
.period .step:disabled { opacity: .25; cursor: default; background: none; }
.period .step svg { width: 20px; height: 20px; }
.period .label { flex: 1; text-align: center; font-weight: 650; text-transform: capitalize; }
.period select {
  border: 0; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 600;
}
.range-inputs { display: flex; gap: 8px; }
.range-inputs input { flex: 1; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 550; display: inline-flex; align-items: center; gap: 7px;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.on-in { background: var(--in-soft); color: var(--in); border-color: var(--in); }
.chip.on-out { background: var(--out-soft); color: var(--out); border-color: var(--out); }

/* ------------------------------------------------------------ KPIs */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { padding: 14px 16px; }
.kpi .k { font-size: 12px; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.kpi .v { font-size: 22px; font-weight: 760; margin-top: 4px; white-space: nowrap; }
.kpi.in .v { color: var(--in); }
.kpi.out .v { color: var(--out); }
.kpi.total { grid-column: 1 / -1; background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.kpi.total .k { color: inherit; opacity: .8; }
.kpi.total .v { font-size: 32px; }
.kpi.total .meta { font-size: 13px; opacity: .85; margin-top: 2px; }
@media (min-width: 900px) {
  .kpis { grid-template-columns: 1.4fr 1fr 1fr; }
  .kpi.total { grid-column: auto; }
}

/* ------------------------------------------------------------ bars */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; }
.bar-row .name { font-weight: 600; display: flex; gap: 8px; align-items: center; min-width: 0; }
.bar-row .name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .amt { font-weight: 650; }
.bar-row .pct { color: var(--ink-3); font-size: 12px; font-weight: 500; margin-left: 6px; }
.bar-row .track { grid-column: 1 / -1; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-row .fill { height: 100%; border-radius: 99px; }
.fill.in { background: var(--in); }
.fill.out { background: var(--out); }
.split { display: grid; gap: 14px; }
.split > .card { margin-top: 0; }
@media (min-width: 900px) { .split { grid-template-columns: 1fr 1fr; } .split .section-title { margin-top: 0; } }
.col-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 14px; }
.col-head .in { color: var(--in); } .col-head .out { color: var(--out); }

/* ------------------------------------------------------------ dept table */
.dept-list { display: flex; flex-direction: column; }
.dept-row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 2px;
  border-bottom: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left;
}
.dept-row:last-child { border-bottom: 0; }
.dept-row .name { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.dept-row .res { font-weight: 750; text-align: right; }
.dept-row .detail { grid-column: 1 / -1; display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); }
.pos { color: var(--in); } .neg { color: var(--out); }

/* month chart */
.months { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 6px; overflow-x: auto; }
.month { flex: 1 0 34px; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.month .cols { flex: 1; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.month .c { width: 12px; border-radius: 4px 4px 2px 2px; min-height: 2px; }
.month .c.in { background: var(--in); } .month .c.out { background: var(--out); }
.month .m { font-size: 11px; color: var(--ink-3); text-transform: capitalize; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ------------------------------------------------------------ movements */
.day { margin-top: 16px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); font-weight: 650; margin: 0 4px 6px; }
.day-head > span:first-child::first-letter { text-transform: uppercase; }
.mov-list { padding: 4px 0; }
.mov {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center;
  width: 100%; padding: 11px 14px; background: none; border: 0; text-align: left;
  border-bottom: 1px solid var(--line);
}
.mov:last-child { border-bottom: 0; }
.mov:hover { background: var(--surface-2); }
.mov .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; }
.mov.in .ic { background: var(--in-soft); } .mov.out .ic { background: var(--out-soft); }
.mov .t { font-weight: 620; }
.mov .s { font-size: 13px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; min-width: 0; }
.mov .s span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov .a { font-weight: 720; white-space: nowrap; }
.mov.in .a { color: var(--in); } .mov.out .a { color: var(--out); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.list-total { display: flex; justify-content: space-between; padding: 12px 16px; font-weight: 650; }

.empty { text-align: center; padding: 40px 20px; color: var(--ink-2); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.empty button { margin-top: 14px; }

/* ------------------------------------------------------------ forms */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 650; background: var(--surface-2); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { background: none; color: var(--out); }
.btn.ghost { background: none; color: var(--ink-2); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn svg { width: 18px; height: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .field > .lbl { font-size: 12px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; font-size: 16px;
}
textarea.input { resize: vertical; min-height: 64px; }
.input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 20%, transparent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 16px; }
.seg button { border: 0; background: none; border-radius: 10px; padding: 10px; font-weight: 700; color: var(--ink-2); }
.seg button.on.in { background: var(--in); color: #fff; }
.seg button.on.out { background: var(--out); color: #fff; }

.amount {
  display: flex; align-items: baseline; justify-content: center; gap: 4px; margin: 4px 0 18px;
  border-bottom: 2px solid var(--line); padding-bottom: 6px;
}
.amount:focus-within { border-color: var(--brand-2); }
.amount .cur { font-size: 28px; font-weight: 600; color: var(--ink-3); }
.amount input {
  border: 0; background: none; font-size: 40px; font-weight: 760; width: 100%; max-width: 320px; text-align: center; outline: none;
  font-variant-numeric: tabular-nums;
}
.amount.in input { color: var(--in); } .amount.out input { color: var(--out); }

.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick .chip { flex-shrink: 1; }

/* ------------------------------------------------------------ sheet */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 22, 20, .45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 94vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 10px 18px calc(18px + var(--safe-b));
  animation: up .22s cubic-bezier(.2,.8,.2,1);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.icon-btn { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; }
@media (min-width: 640px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 22px; max-height: 88vh; }
  .sheet .grab { display: none; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }

/* ------------------------------------------------------------ settings */
.set-list .set-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 4px; border: 0; background: none;
  border-bottom: 1px solid var(--line); text-align: left;
}
.set-list .set-item:last-child { border-bottom: 0; }
.set-item .grow { flex: 1; min-width: 0; }
.set-item .muted { color: var(--ink-3); font-size: 13px; }
.set-item.off { opacity: .5; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--ink); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0 14px; }

/* ------------------------------------------------------------ auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card img { width: 76px; height: 76px; border-radius: 20px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 16px 0 4px; font-size: 26px; }
.auth-card p { color: var(--ink-2); margin: 0 0 22px; }
.auth-card .field { text-align: left; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 26px + var(--safe-b)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; z-index: 80;
  animation: up .2s ease; max-width: calc(100% - 32px);
}
@media (min-width: 900px) { .toast { bottom: 28px; } }
.err { color: var(--out); font-size: 14px; margin: -4px 0 12px; min-height: 1em; }
.hint { color: var(--ink-3); font-size: 13px; }
.loading { padding: 40px; text-align: center; color: var(--ink-3); }

a.set-item { color: var(--ink); }
a.set-item svg { color: var(--brand-2); flex-shrink: 0; }
.kpis > .card { margin-top: 0; }
