/* arthik — nss look: teal #3a807a, square-grid background, quiet cards.
   Mobile first; the sidebar layout starts at 900px. Colours are tokens on :root,
   re-stepped for dark mode (auto, or forced by settings via data-theme). */

:root {
  color-scheme: light;
  --teal: #3a807a;
  --teal-strong: #2e6863;
  --teal-soft: #e3f0ee;
  --bg: #f6f8f7;
  --grid: rgba(58, 128, 122, 0.07);
  --surface: #ffffff;
  --surface-2: #f0f4f3;
  --line: #dbe3e1;
  --text: #13201e;
  --muted: #5a6866;
  --faint: #8a9896;
  --income: #13895f;
  --expense: #c2462b;
  --warn: #b77700;
  --income-mark: #1baf7a;
  --expense-mark: #eb6834;
  --shadow: 0 1px 2px rgba(15, 30, 28, 0.06), 0 4px 16px rgba(15, 30, 28, 0.05);
  --radius: 12px;
  --nav-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --teal: #5fb3aa;
    --teal-strong: #7cc6be;
    --teal-soft: #1d3330;
    --bg: #0f1413;
    --grid: rgba(95, 179, 170, 0.06);
    --surface: #171d1c;
    --surface-2: #1e2625;
    --line: #2b3533;
    --text: #e8efed;
    --muted: #a3b1ae;
    --faint: #73817e;
    --income: #4cc792;
    --expense: #f0805f;
    --warn: #e0a640;
    --income-mark: #199e70;
    --expense-mark: #d95926;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --teal: #5fb3aa;
  --teal-strong: #7cc6be;
  --teal-soft: #1d3330;
  --bg: #0f1413;
  --grid: rgba(95, 179, 170, 0.06);
  --surface: #171d1c;
  --surface-2: #1e2625;
  --line: #2b3533;
  --text: #e8efed;
  --muted: #a3b1ae;
  --faint: #73817e;
  --income: #4cc792;
  --expense: #f0805f;
  --warn: #e0a640;
  --income-mark: #199e70;
  --expense-mark: #d95926;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 var(--font);
  color: var(--text);
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; }
h3 { font-size: 0.9rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
small, .muted { color: var(--muted); }
.faint { color: var(--faint); }
.num, .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.hide-amounts .amt { filter: blur(6px); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---- shell ---------------------------------------------------------- */
.app { display: flex; min-height: 100vh; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; min-height: 56px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 16px; max-width: 1180px; margin: 0 auto; }
.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px; font-size: 0.9rem; border: 1px solid var(--line); background: var(--surface); }
.banner.warn { border-color: var(--warn); }
.banner.demo { border-color: var(--teal); background: var(--teal-soft); }

.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.bottom a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 0.72rem; text-decoration: none;
}
.bottom a .ic { font-size: 1.25rem; line-height: 1; }
.bottom a.on { color: var(--teal); font-weight: 600; }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 31;
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--teal); color: #fff; font-size: 1.8rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(58, 128, 122, 0.35); cursor: pointer;
}
.fab:active { transform: scale(0.96); }

@media (min-width: 900px) {
  .side {
    display: flex; flex-direction: column; gap: 2px;
    position: sticky; top: 0; height: 100vh; width: 232px; flex: 0 0 232px;
    padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto;
  }
  .side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 1.15rem; color: var(--text); }
  .side .brand img { width: 30px; height: 30px; }
  .side a.nav { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--text); }
  .side a.nav:hover { background: var(--surface-2); text-decoration: none; }
  .side a.nav.on { background: var(--teal-soft); color: var(--teal-strong); font-weight: 600; }
  .side .add { margin: 12px 0 8px; }
  .side .foot { margin-top: auto; padding: 10px; font-size: 0.8rem; color: var(--faint); }
  .bottom, .fab { display: none; }
  .main { padding-bottom: 32px; }
  .top { padding: 14px 24px; }
  .content { padding: 20px 24px; }
}

/* ---- building blocks ------------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; min-width: 0;
}
.card > header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card > header h2, .card > header h3 { flex: 1; }
.grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 699px) {
  .grid.four .stat .value { font-size: 1.1rem; }
  .grid.four .card { padding: 12px; }
  .grid.three .card.stat { padding: 12px 14px; }
}
.grid > .card { margin-bottom: 0; }
@media (min-width: 700px) { .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stack > * + * { margin-top: 14px; }

.stat .label { font-size: 0.8rem; color: var(--muted); }
.stat .value { font-size: 1.45rem; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.hero { font-size: 2rem; font-weight: 750; letter-spacing: -0.01em; }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button, .btn {
  font: inherit; font-size: 0.92rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; min-height: 38px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
}
button:hover, .btn:hover { border-color: var(--teal); text-decoration: none; }
button.primary, .btn.primary { background: var(--teal); color: #fff; border-color: var(--teal); }
button.primary:hover { background: var(--teal-strong); }
button.danger { color: var(--expense); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.icon { padding: 6px 10px; min-width: 38px; }
button:disabled { opacity: 0.5; cursor: default; }
button.block { width: 100%; }

input, select, textarea {
  font: inherit; width: 100%; padding: 9px 11px; min-height: 40px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--teal); }
textarea { min-height: 64px; resize: vertical; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.fields { display: grid; gap: 0 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .fields.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0 12px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; min-height: 32px; padding: 5px 12px; border-radius: 8px; }
.seg button.on { background: var(--surface); color: var(--teal-strong); font-weight: 600; box-shadow: var(--shadow); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 0.78rem; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.chip.on { background: var(--teal-soft); color: var(--teal-strong); border-color: var(--teal); }
button.chip { min-height: 28px; }
.badge { font-size: 0.72rem; padding: 1px 7px; border-radius: 999px; background: var(--teal-soft); color: var(--teal-strong); font-weight: 600; white-space: nowrap; }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.neg { background: color-mix(in srgb, var(--expense) 15%, transparent); color: var(--expense); }

/* period switcher */
.period { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.period .label { font-weight: 600; min-width: 120px; text-align: center; }
.period select { width: auto; min-height: 36px; padding: 6px 10px; }
.period input[type="date"] { width: auto; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 2px; color: var(--text); cursor: pointer; width: 100%; text-align: left; background: none; border: 0; border-radius: 0; min-height: 0; }
.item:hover { background: var(--surface-2); text-decoration: none; }
.item .ic { flex: 0 0 36px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); font-size: 1.1rem; }
.item .main-t { flex: 1; min-width: 0; display: block; }
.item .main-t > span, .item .end > span { display: block; }
.item .end { flex: 0 0 auto; max-width: 48%; }
.item .main-t .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .main-t .s { font-size: 0.8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .end { text-align: right; }
.item .end .s { font-size: 0.75rem; color: var(--faint); }
.day { display: flex; justify-content: space-between; padding: 12px 2px 4px; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.group-h { display: flex; justify-content: space-between; align-items: center; padding: 14px 2px 6px; font-size: 0.82rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.empty { padding: 26px 8px; text-align: center; color: var(--muted); }
.child { padding-left: 24px; }

/* progress */
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--teal); }
.bar.over > i { background: var(--expense); }
.bar.near > i { background: var(--warn); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th, .tbl td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.tbl td.r, .tbl th.r { text-align: right; }
.scroll-x { overflow-x: auto; }

/* sheets (dialogs) */
dialog.sheet {
  border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%; max-height: 92vh;
  position: fixed; inset: auto 0 0 0; border-radius: 18px 18px 0 0;
  background: var(--surface); color: var(--text); box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.25);
}
dialog.sheet::backdrop { background: rgba(10, 20, 18, 0.45); }
.sheet-in { display: flex; flex-direction: column; max-height: 92vh; }
.sheet-h { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-h h2 { flex: 1; font-size: 1.05rem; }
.sheet-b { padding: 16px; overflow-y: auto; }
.sheet-f { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-f .grow { flex: 1; }
@media (min-width: 700px) {
  dialog.sheet { inset: 0; margin: auto; width: 560px; max-width: calc(100% - 32px); border-radius: 16px; max-height: 88vh; }
  .sheet-in { max-height: 88vh; }
}

.amount-in { font-size: 1.7rem; font-weight: 700; text-align: right; padding: 10px 12px; }
.calc-hint { font-size: 0.75rem; color: var(--faint); text-align: right; margin-top: -8px; margin-bottom: 10px; min-height: 1em; }
.split-line { display: grid; grid-template-columns: minmax(0, 1fr) 120px 38px; gap: 8px; margin-bottom: 8px; }

/* toast */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 86px); z-index: 100; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 0.9rem; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.toast.err { background: var(--expense); color: #fff; }

/* charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line); }
.chart .zero { stroke: var(--faint); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--teal); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--teal); opacity: 0.1; }
.chart .dot { fill: var(--teal); stroke: var(--surface); stroke-width: 2; }
.chart .inc { fill: var(--income-mark); }
.chart .exp { fill: var(--expense-mark); }
.chart .one { fill: var(--teal); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .hl, .chart .hl { pointer-events: none; }
.chart .cross { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .inc { background: var(--income-mark); }
.legend .exp { background: var(--expense-mark); }
.legend .one { background: var(--teal); }
.tip {
  position: fixed; z-index: 200; pointer-events: none; padding: 7px 10px; border-radius: 8px; font-size: 0.8rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); max-width: 240px;
}
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; margin: 8px 0; cursor: pointer; }
.hbar .bar { grid-column: 1 / -1; height: 10px; }
.hbar .bar > i { border-radius: 2px 4px 4px 2px; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { font-size: 0.72rem; text-align: center; color: var(--muted); padding: 4px 0; }
.cal button { flex-direction: column; align-items: stretch; justify-content: flex-start; min-height: 64px; padding: 4px 5px; border-radius: 8px; background: var(--surface); font-size: 0.7rem; gap: 0; text-align: right; }
.cal button .d { font-weight: 700; font-size: 0.8rem; text-align: left; color: var(--text); }
.cal button.today { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.cal button.sel { background: var(--teal-soft); }
.cal button.out { visibility: hidden; }
.cal .up { color: var(--warn); }
@media (max-width: 480px) { .cal button { min-height: 52px; font-size: 0.62rem; padding: 3px; } }

/* login + about */
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; }
.login .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login .brand img { width: 44px; height: 44px; }
.demo-box { margin-top: 14px; padding: 12px; border-radius: 10px; background: var(--teal-soft); font-size: 0.9rem; }
.demo-box code { font-family: var(--mono); background: var(--surface); padding: 1px 6px; border-radius: 6px; }

.about { max-width: 980px; margin: 0 auto; padding: 20px 16px 60px; }
.about nav { display: flex; align-items: center; gap: 12px; padding: 6px 0 30px; }
.about nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.2rem; color: var(--text); flex: 1; }
.about nav img { width: 34px; height: 34px; }
.about .lead { font-size: clamp(1.8rem, 6vw, 3rem); font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; margin: 10px 0 14px; }
.about .lead em { font-style: normal; color: var(--teal); }
.about p.intro { font-size: 1.1rem; color: var(--muted); max-width: 640px; }
.about .cta { display: flex; gap: 10px; flex-wrap: wrap; margin: 22px 0 36px; }
.about .feat { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .about .feat { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 900px) { .about .feat { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.about .feat .card h2 { margin-bottom: 6px; }
.about .feat .card p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.about .ledger { font-family: var(--mono); font-size: 0.82rem; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow-x: auto; white-space: pre; }
.about footer { margin-top: 40px; color: var(--faint); font-size: 0.85rem; }

@media (prefers-reduced-motion: no-preference) {
  .fab, button { transition: background-color 0.15s, border-color 0.15s, transform 0.1s; }
}
.hide-amounts .amt.peek { filter: none; }
.chartbox { width: 100%; min-height: 40px; }
