/* ---------- design tokens ---------- */
:root,
[data-theme="light"] {
  --bg:            #F6F5F9;
  --card:          #FFFFFF;
  --control:       #EFEEF3;
  --active:        #E4E0F2;
  --hairline:      #E7E5EE;
  --ink-high:      #141715;
  --ink-med:       #6E687C;
  --ink-low:       #9A93AD;
  --primary:       #7C6BC4;
  --on-primary:    #FFFFFF;
  --primary-soft:  #EDE9FA;
  --income:        #0F7B5A;
  --expense:       #C9497E;
  --track:         #E4E0EC;
  --scrim:         rgba(20,19,26,.45);
  --shadow-fab:    0 6px 16px rgba(60,45,110,.28);
}
[data-theme="dark"] {
  --bg:            #121212;
  --card:          #1E1E1E;
  --control:       #2C2C2C;
  --active:        #3D3D3D;
  --hairline:      rgba(255,255,255,.08);
  --ink-high:      #E3E3E3;
  --ink-med:       #A1A1A1;
  --ink-low:       #6B6B6B;
  --primary:       #D0BCFF;
  --on-primary:    #381E72;
  --primary-soft:  #332D41;
  --income:        #B4EBA5;
  --expense:       #F2B8B5;
  --track:         #3A3A3A;
  --scrim:         rgba(0,0,0,.6);
  --shadow-fab:    0 4px 12px rgba(0,0,0,.5);
}

/* ---------- base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink-high);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-med); }
.income { color: var(--income); }
.expense { color: var(--expense); }
::-webkit-scrollbar { display: none; }

/* ---------- app shell ---------- */
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 480px; margin: 0 auto; overflow: hidden; }
.screen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.topbar { flex-shrink: 0; padding: env(safe-area-inset-top) 16px 6px; padding-top: calc(env(safe-area-inset-top) + 18px); display: flex; align-items: center; gap: 4px; }
.topbar h1 { font-size: 16px; font-weight: 500; letter-spacing: -.01em; }
.spacer { flex: 1; }
.body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 120px; display: flex; flex-direction: column; gap: 10px; }

/* the body is a flex column — without this its children get squeezed
   and the last calendar row gets clipped */
.body > * { flex-shrink: 0; }

.card { background: var(--card); border: 1px solid var(--hairline); border-radius: 16px; }
.card-pad { padding: 12px 14px; }
.card-title { font-size: 13px; font-weight: 600; }

.iconbtn { width: 30px; height: 30px; border-radius: 999px; display: grid; place-items: center; color: var(--ink-med); background: transparent; }
.iconbtn:active { background: var(--control); }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: var(--card); border: 1px solid var(--hairline); display: grid; place-items: center; font-size: 13px; }

/* segmented control */
.seg { display: flex; background: var(--card); border: 1px solid var(--hairline); border-radius: 12px; padding: 4px; gap: 2px; }
.seg button { flex: 1; padding: 5px 0; border-radius: 9px; font-size: 12px; font-weight: 500; color: var(--ink-med); }
.seg button[aria-selected="true"] { background: var(--active); color: var(--ink-high); font-weight: 600; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 7px 14px; border-radius: 999px; font-size: 13px; border: 1px solid var(--hairline); background: var(--card); color: var(--ink-high); }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 500; }

/* totals strip */
.totals { display: flex; align-items: center; justify-content: space-between; }
.totals > div { display: flex; flex-direction: column; gap: 2px; }
.totals .lbl { font-size: 10px; color: var(--ink-med); }
.totals .val { font-size: 12px; font-weight: 600; }
.totals .val.big { font-size: 14px; font-weight: 700; }
.totals .sep { width: 1px; height: 24px; background: var(--hairline); }

/* ---------- calendar ---------- */
.cal-card { overflow: hidden; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--hairline); background: var(--control); }
.weekdays span { text-align: center; font-size: 9px; font-weight: 500; color: var(--ink-med); padding: 4px 0; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 52px;
            gap: 1px; background: var(--hairline); }
.day { background: var(--card); display: flex; flex-direction: column; align-items: center;
       justify-content: center; gap: 1px; position: relative; }
.day .d { font-size: 10px; line-height: 1.2; position: relative; z-index: 1; }
.day .amt { font-size: 8px; line-height: 1.1; position: relative; z-index: 1; }
.day.blank { background: var(--card); }
.day.today::before { content: ""; position: absolute; inset: 4px; border-radius: 8px;
                     background: var(--primary); opacity: .2; }
.day.today .d { color: var(--primary); font-weight: 700; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.row + .row { border-top: 1px solid var(--hairline); }
.tile { width: 34px; height: 34px; border-radius: 10px; background: var(--control); display: grid; place-items: center; font-size: 17px; flex-shrink: 0; }
.row .name { font-size: 13px; font-weight: 500; }
.row .meta { font-size: 11px; color: var(--ink-med); margin-top: 2px; }
.row .amt { font-size: 14px; font-weight: 600; margin-left: auto; }
.group-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-med); padding: 0 2px; }
.dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }

/* progress bars */
.bar-track { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--primary); }
.bar-fill.over { background: var(--expense); }

/* ---------- fab + nav ---------- */
.fab { position: fixed; right: calc(50% - 240px + 16px); bottom: calc(80px + env(safe-area-inset-bottom)); width: 54px; height: 54px;
       border-radius: 999px; background: var(--primary); color: var(--on-primary); font-size: 28px; display: grid; place-items: center;
       box-shadow: var(--shadow-fab); z-index: 20; }
@media (max-width: 512px) { .fab { right: 16px; } }
.nav { flex-shrink: 0; display: flex; background: var(--card); border-top: 1px solid var(--hairline);
       padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--ink-med); }
.nav button .ic { line-height: 0; }
.nav button .ic svg { width: 20px; height: 20px; stroke: currentColor; fill: none;
                      stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.nav button[aria-current="page"] { color: var(--primary); font-weight: 600; }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 30; display: none; }
.scrim.open { display: block; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto; z-index: 31;
         background: var(--card); border-radius: 24px 24px 0 0; padding: 12px 16px calc(28px + env(safe-area-inset-bottom));
         transform: translateY(100%); transition: transform .22s ease; }
.sheet.open { transform: translateY(0); }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--hairline); margin: 0 auto 12px; }
.opt-primary { background: var(--primary); color: var(--on-primary); border-radius: 16px; padding: 20px; text-align: center; width: 100%; }
.opt-primary .t { font-size: 17px; font-weight: 600; }
.opt-primary .s { font-size: 12px; opacity: .8; margin-top: 4px; }
.opt-pair { display: flex; gap: 12px; margin-top: 12px; }
.opt { flex: 1; background: var(--control); border-radius: 16px; padding: 16px 10px; text-align: center; }
.opt .t { font-size: 14px; font-weight: 500; margin-top: 4px; }
.opt .s { font-size: 11px; color: var(--ink-med); margin-top: 2px; }

/* ---------- forms ---------- */
.field { display: flex; align-items: center; padding: 13px 14px; }
.field + .field { border-top: 1px solid var(--hairline); }
.field label { font-size: 13px; color: var(--ink-med); }
.field input, .field select { margin-left: auto; text-align: right; background: none; border: 0; font-size: 14px; font-weight: 500; max-width: 60%; }
.field input:focus, .field select:focus { outline: none; color: var(--primary); }
.amount-input { width: 100%; text-align: center; background: none; border: 0; font-size: 40px; font-weight: 700; padding: 14px 0 2px; }
.amount-input:focus { outline: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); border-radius: 12px; padding: 9px 20px; font-size: 14px; font-weight: 600; }
.btn-ghost { border: 1px dashed var(--hairline); border-radius: 14px; padding: 14px; width: 100%; color: var(--primary); font-size: 14px; font-weight: 500; }
.banner { background: var(--primary-soft); color: var(--ink-high); border-radius: 10px; padding: 10px 12px; font-size: 12px; }
.switch { width: 44px; height: 26px; border-radius: 999px; background: var(--track); position: relative; margin-left: auto; transition: background .15s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 999px; background: var(--card); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(18px); background: var(--on-primary); }

/* ---------- charts ---------- */
.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut { width: 116px; height: 116px; border-radius: 999px; flex-shrink: 0; position: relative; }
.donut::after { content: ""; position: absolute; inset: 21px; border-radius: 999px; background: var(--card); }
.legend { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.legend .lg { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 132px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.bars .bar { width: 100%; border-radius: 6px 6px 0 0; background: var(--track); }
.bars .col.on .bar { background: var(--primary); }
.bars .cap { font-size: 10px; color: var(--ink-med); }
.bars .top { font-size: 9px; color: var(--ink-med); }

/* keep the clear button clear of the floating add button */
.settle { padding-right: 84px; }
.settle .btn-primary { position: relative; z-index: 21; }

.empty { text-align: center; color: var(--ink-med); font-size: 13px; padding: 32px 0; }
