:root {
  color-scheme: light;
  --bg: var(--tg-theme-bg-color, #fcfcfb);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #f1f0ec));
  --text: var(--tg-theme-text-color, #0b0b0b);
  --hint: var(--tg-theme-hint-color, #6b6a66);
  --accent: var(--tg-theme-button-color, #2a78d6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --track: color-mix(in srgb, var(--hint) 16%, transparent);
  /* seri data (divalidasi: buta warna & kontras) */
  --s-in: #2a78d6;   /* pendapatan */
  --s-out: #eb6834;  /* pengeluaran */
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #1a1a19);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #242422));
  --text: var(--tg-theme-text-color, #f0efec);
  --hint: var(--tg-theme-hint-color, #a8a79f);
  --s-in: #3987e5;
  --s-out: #d95926;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: var(--tg-theme-bg-color, #1a1a19);
    --section: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #242422));
    --text: var(--tg-theme-text-color, #f0efec);
    --hint: var(--tg-theme-hint-color, #a8a79f);
    --s-in: #3987e5;
    --s-out: #d95926;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: 0 16px calc(88px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
     color: var(--hint); margin: 22px 0 8px; }
.hint { color: var(--hint); font-size: 13px; margin: 2px 0 0; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; }
.icon-btn { border: 0; background: var(--section); color: var(--text); width: 38px; height: 38px;
            border-radius: 50%; font-size: 20px; cursor: pointer; }
.icon-btn.spin { animation: spin 0.8s linear infinite; }
.tabs { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
        padding: 4px; margin: 0 0 4px; background: var(--section); border-radius: 12px; }
.tabs button { border: 0; background: transparent; color: var(--hint); padding: 8px 0; border-radius: 9px;
               font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.card { background: var(--section); border-radius: 14px; padding: 14px; margin: 0 0 10px; }
.hero .label { color: var(--hint); font-size: 13px; }
.hero .value { font-size: 30px; font-weight: 700; letter-spacing: -.01em; margin: 2px 0 6px; overflow-wrap: anywhere; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
         background: var(--bg); font-size: 13px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 10px; }
.stat { background: var(--section); border-radius: 14px; padding: 12px; min-width: 0; }
.stat .label { color: var(--hint); font-size: 12px; }
.stat .value { font-size: 16px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.note { font-size: 13px; color: var(--hint); margin: 8px 0 0; }
.note strong { color: var(--text); }
/* skor */
.score { display: flex; align-items: center; gap: 14px; }
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; flex: none;
        background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--track) 0);
        display: grid; place-items: center; }
.ring span { width: 50px; height: 50px; border-radius: 50%; background: var(--section);
             display: grid; place-items: center; font-weight: 700; }
/* baris & bar */
.rows { display: flex; flex-direction: column; gap: 12px; }
.row-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.row-head .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-head .amt { font-weight: 600; white-space: nowrap; }
.row-sub { font-size: 12px; color: var(--hint); margin-top: 2px; display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 8px; border-radius: 4px; background: var(--track); margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--s-in); min-width: 3px; }
.bar.out > i { background: var(--s-out); }
.status { font-size: 12px; font-weight: 600; white-space: nowrap; }
.list { display: flex; flex-direction: column; }
.list .item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list .item:last-child { border-bottom: 0; }
.list .item .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item .amt { font-weight: 600; white-space: nowrap; }
.empty { color: var(--hint); font-size: 14px; padding: 6px 0; }
/* grafik tren */
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--hint); }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; padding: 4px 0; }
svg.trend { width: 100%; height: auto; display: block; margin-top: 8px; overflow: visible; }
svg.trend text { fill: var(--hint); font-size: 10px; }
svg.trend .grid { stroke: var(--line); stroke-width: 1; }
svg.trend .base { stroke: var(--hint); stroke-width: 1; opacity: .5; }
svg.trend .hit { fill: transparent; cursor: pointer; }
svg.trend .col.active .hit { fill: var(--track); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
table.data th, table.data td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--hint); font-weight: 600; }
/* transaksi */
.search { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--section);
          color: var(--text); font: inherit; margin: 6px 0 4px; }
.day { font-size: 12px; font-weight: 600; color: var(--hint); margin: 16px 0 2px; display: flex; justify-content: space-between; }
.tx { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.tx .l { min-width: 0; }
.tx .t1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .t2 { font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .r { font-weight: 600; white-space: nowrap; }
.tx .sign { display: inline-block; width: 1.1em; }
/* status & tooltip */
.state { text-align: center; color: var(--hint); padding: 48px 16px; }
.state .big { font-size: 40px; }
.spinner { width: 28px; height: 28px; margin: 0 auto 12px; border-radius: 50%; border: 3px solid var(--track);
           border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--text); color: var(--bg);
           padding: 8px 10px; border-radius: 10px; font-size: 13px; line-height: 1.5; box-shadow: 0 4px 14px rgba(0,0,0,.2);
           max-width: 220px; }
.tooltip .row { display: flex; justify-content: space-between; gap: 12px; }
@media (max-width: 360px) { .grid3 { grid-template-columns: 1fr 1fr; } .hero .value { font-size: 26px; } }
/* ---------- form catat ---------- */
.fab { position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 8; width: 56px; height: 56px;
       border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); font-size: 28px; line-height: 1;
       box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer; }
.form-head { display: flex; align-items: center; gap: 10px; margin: 6px 0 12px; }
.form-head h2 { margin: 0; }
.back { border: 0; background: none; color: var(--accent); font: inherit; font-size: 15px; cursor: pointer; padding: 6px 0; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--section); border-radius: 12px; }
.seg button { border: 0; background: transparent; color: var(--hint); padding: 9px 0; border-radius: 9px; font: inherit;
              font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.field { margin: 16px 0 0; }
.field > label, .field > .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--hint); margin: 0 0 6px; }
.amount-wrap { display: flex; align-items: baseline; gap: 6px; background: var(--section); border-radius: 14px; padding: 10px 14px; }
.amount-wrap span { font-size: 22px; font-weight: 700; color: var(--hint); }
input.amount { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 30px;
               font-weight: 700; outline: none; padding: 0; }
input.text, input.date { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--section);
                         color: var(--text); font: inherit; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--section); color: var(--text); border-radius: 999px; padding: 7px 12px;
        font: inherit; font-size: 14px; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip.ghost { color: var(--hint); }
.guess { font-size: 12px; color: var(--hint); margin: 6px 0 0; min-height: 1em; }
.err { color: var(--critical); font-size: 14px; font-weight: 600; margin: 14px 0 0; }
.btn-primary { width: 100%; margin: 20px 0 0; padding: 14px; border: 0; border-radius: 12px; background: var(--accent);
               color: var(--accent-text); font: inherit; font-weight: 700; font-size: 16px; cursor: pointer; }
.btn-primary[disabled] { opacity: .6; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 9; background: var(--text);
         color: var(--bg); border-radius: 14px; padding: 12px 14px; font-size: 14px; display: flex; gap: 12px; align-items: center;
         box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.toast .msg { flex: 1; min-width: 0; white-space: pre-line; }
.toast button { border: 0; background: none; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }

/* ---------- Beranda ---------- */
.hero .value.small { font-size: 22px; }
.status-badge { margin-top: 2px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin-top: 12px; padding-top: 12px;
      border-top: 1px solid var(--line); font-size: 14px; }
.kv span { color: var(--hint); }
.kv strong { text-align: right; }
.streak { margin: 12px 0 0; font-size: 13px; font-weight: 600; }
.swatch.line { height: 3px; width: 14px; border-radius: 2px; vertical-align: 3px; }
.swatch.dash { height: 0; width: 14px; border-radius: 0; border-top: 2px dashed var(--hint); background: none; vertical-align: 3px; }
svg.trend .ideal { stroke: var(--hint); stroke-width: 1.5; stroke-dasharray: 4 4; }
svg.trend .direct { fill: var(--text); font-size: 11px; font-weight: 700; }
svg.trend .cross line { stroke: var(--hint); stroke-width: 1; }
svg.pace .hit { touch-action: pan-y; }
.delta { color: var(--hint); font-size: 12px; font-weight: 600; margin-left: 4px; }
.tappable { cursor: pointer; }
.tap-row.tappable:active { opacity: .6; }
.big-num { font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }

/* ---------- Tren: kalender & rasio ---------- */
svg.trend .ref { fill: var(--hint); font-size: 10px; }
.cal { display: grid; grid-template-rows: 16px; grid-auto-rows: auto; gap: 3px; align-items: center; }
.cal-lbl, .cal-mon { font-size: 10px; color: var(--hint); white-space: nowrap; line-height: 1; }
.cal-cell { aspect-ratio: 1; border: 0; padding: 0; border-radius: 4px; background: var(--track); cursor: pointer; min-width: 0; }
.cal-cell.none { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.cal-cell.l1 { background: color-mix(in srgb, var(--s-out) 28%, var(--section)); }
.cal-cell.l2 { background: color-mix(in srgb, var(--s-out) 50%, var(--section)); }
.cal-cell.l3 { background: color-mix(in srgb, var(--s-out) 75%, var(--section)); }
.cal-cell.l4 { background: var(--s-out); }
.cal-cell.sel { outline: 2px solid var(--text); outline-offset: 1px; }
.cal-cell.key { display: inline-block; width: 12px; height: 12px; aspect-ratio: auto; cursor: default; vertical-align: -2px; }
.cal-legend { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--hint); margin-top: 10px; flex-wrap: wrap; }
.cal-info { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; margin-top: 10px;
            min-height: 28px; }
h3.sub { font-size: 12px; font-weight: 600; color: var(--hint); margin: 16px 0 6px; }
.wd { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 74px; }
.wd-col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.wd-bar { flex: 1; width: 100%; max-width: 26px; display: flex; align-items: flex-end; }
.wd-bar i { display: block; width: 100%; background: var(--s-out); border-radius: 4px 4px 0 0; }
.wd-lbl { font-size: 11px; color: var(--hint); }

/* ---------- kebiasaan & kepercayaan ---------- */
.tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; background: var(--bg);
       font-size: 11px; font-weight: 600; color: var(--hint); vertical-align: 1px; }
.welcome { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--bg); font-size: 13px; line-height: 1.5; }
.welcome code { font-size: 12px; }
