:root {
  --bg: #222328; --surface: #2b2d33; --deep: #1b1c20; --line: #3a3c44;
  --text: #fff; --muted: rgba(255,255,255,.6);
  --accent: #2b7de9; --income: #2e9bff; --expense: #f5334b;
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f4f5f8; --surface: #fff; --deep: #e8eaf0; --line: #d9dce4; --text: #15171c; --muted: rgba(0,0,0,.55); --expense: #d91f38; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Thai', sans-serif; font-size: 16px; }
#app { height: 100dvh; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.inc { color: var(--income); } .exp { color: var(--expense); } .xfer { color: #9aa3b2; }

/* ---------- shell: bottom bar on portrait phones, side rail on landscape / wide ---------- */
.shell { height: 100%; display: flex; flex-direction: column; padding-left: var(--sal); padding-right: var(--sar); }
.main { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding-top: var(--sat); }
.page { max-width: 900px; margin: 0 auto; padding-bottom: 24px; }
.nav { display: flex; background: var(--deep); padding-bottom: var(--sab); border-top: 1px solid var(--line); }
.nav a, .nav .plus-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; font-size: 11px; color: var(--muted); }
.nav a .ic { font-size: 22px; line-height: 1; }
.nav a.on { color: var(--text); }
.nav .plus { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; border: 0; font-size: 28px; line-height: 1; }
@media (min-width: 700px), (orientation: landscape) and (max-height: 600px) {
  .shell { flex-direction: row-reverse; }
  .nav { flex-direction: column; justify-content: flex-start; width: 84px; border-top: 0; border-right: 1px solid var(--line);
    padding: calc(var(--sat) + 8px) 0 var(--sab); }
  .nav .plus-wrap { order: -1; flex: none; padding: 6px 0 14px; }
  .nav a { flex: none; padding: 10px 0; }
  .main { padding-top: var(--sat); }
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 4px; padding: 12px 16px 4px; }
.top .grow { flex: 1; min-width: 0; }
.top .name { background: none; border: 0; padding: 0; color: var(--muted); font-size: 15px; }
.top .bal { font-size: 28px; font-weight: 500; }
.ib { background: none; border: 0; font-size: 22px; width: 44px; height: 44px; border-radius: 50%; }
.ib:active { background: var(--surface); }
.pbar { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 8px; border-bottom: 1px solid var(--line); }
.plabel { font-size: 20px; font-weight: 600; }
.card { background: var(--surface); margin: 0; padding: 4px 0; }
.gap { height: 10px; background: var(--deep); }
h2.sec { margin: 0; padding: 14px 16px 6px; font-size: 22px; }
.kv { display: flex; justify-content: space-between; padding: 8px 16px; }

/* ---------- rows ---------- */
.dayhead { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.dayhead .num { font-size: 40px; font-weight: 700; line-height: 1; }
.dayhead small { display: block; color: var(--muted); }
.dayhead .tot { margin-left: auto; }
.row { display: flex; gap: 12px; padding: 10px 16px; background: var(--surface); align-items: flex-start; }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { color: var(--muted); font-size: 14px; }
.row .amt { text-align: right; white-space: nowrap; }
.row .amt .a { font-weight: 600; }
.badge { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; flex: none; }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; margin-top: 6px; display: block; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 56px; }

/* ---------- calendar ---------- */
.calwrap { display: block; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border-top: 1px solid var(--line); }
.cal .dow { text-align: center; padding: 8px 0; font-size: 14px; background: var(--deep); }
.cal .dow:first-child { color: var(--expense); }
.cal .cell { min-height: 68px; padding: 3px 4px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: 11px; text-align: right; background: none; border-top: 0; border-left: 0; color: inherit; display: flex; flex-direction: column; gap: 1px; }
.cal .cell .d { text-align: left; font-size: 13px; color: var(--muted); }
.cal .cell.sel { background: #25395c; }
.cal .cell.today .d { color: var(--accent); font-weight: 700; }
.cal .cell.sun .d { color: var(--expense); }
.daylist .head { display: flex; justify-content: space-between; padding: 12px 16px; font-weight: 600; background: var(--surface); border-bottom: 1px solid var(--line); }
@media (orientation: landscape) and (min-width: 700px) {
  .calwrap { display: grid; grid-template-columns: 1.4fr 1fr; align-items: start; }
  .cal .cell { min-height: 58px; }
}

/* ---------- stats ---------- */
.seg { display: flex; margin: 8px 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; background: none; border: 0; padding: 10px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--accent); color: #fff; }
.seg button.on.e { background: var(--expense); } .seg button.on.i { background: var(--income); } .seg button.on.t { background: #6b7385; }
.donutwrap { display: flex; gap: 16px; align-items: center; padding: 8px 16px; flex-wrap: wrap; justify-content: center; }
.donut { position: relative; width: 200px; height: 200px; flex: none; }
.donut svg { width: 100%; height: 100%; }
.donut .mid { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; font-size: 14px; }
.legend { flex: 1; min-width: 180px; }
.legend div { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.bars { display: flex; gap: 8px; padding: 8px 16px 16px; align-items: flex-end; }
.bars .col { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
.bars .pair { height: 120px; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.bars .b { width: 40%; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 2px; }
.progress { height: 8px; border-radius: 4px; background: var(--deep); overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--accent); }
.progress.over i { background: var(--expense); }

/* ---------- wallet ---------- */
.stats4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); }
.stats4 div { background: var(--surface); padding: 12px 16px; }
.stats4 small { display: block; color: var(--muted); }
.stats4 b { font-size: 20px; }
.wallets { display: flex; gap: 12px; overflow-x: auto; padding: 4px 16px 16px; scroll-snap-type: x proximity; }
.wcard { flex: none; width: 170px; border-radius: 14px; padding: 14px; color: #fff; background: #0099e5; border: 0; text-align: left; scroll-snap-align: start; }
.wcard small { opacity: .85; display: block; }
.wcard b { font-size: 18px; display: block; margin-top: 8px; }
.wcard.add { background: none; border: 2px dashed var(--line); color: var(--muted); display: grid; place-items: center; font-size: 32px; }
.link-row { display: flex; justify-content: space-between; padding: 14px 16px; background: var(--surface); border: 0; width: 100%; text-align: left; border-top: 1px solid var(--line); }

/* ---------- forms ---------- */
.form { padding: 8px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld > span { font-weight: 600; font-size: 14px; }
.fld.chk { flex-direction: row; align-items: center; gap: 10px; }
.fld.chk > span { font-weight: 400; font-size: 16px; }
input[type=text], input[type=number], input[type=search], input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; background: var(--deep); color: var(--text); border: 1px solid transparent; border-radius: 12px; padding: 14px; font: inherit; min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); }
input[type=color] { width: 56px; height: 44px; border: 0; background: none; padding: 0; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 4px; }
.chip { flex: none; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 8px 14px; font-size: 14px; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 12px; padding: 14px 18px; font-weight: 700; flex: 1; }
.btn.ghost { background: var(--deep); color: var(--text); }
.btn.danger { background: var(--expense); }
.btns { display: flex; gap: 10px; margin-top: 8px; }
.detail { padding: 8px 16px; }
.detail .title { display: flex; align-items: center; gap: 12px; font-size: 26px; font-weight: 600; padding: 12px 0; }
.detail .badge { width: 56px; height: 56px; font-size: 28px; }
.detail .kv { padding: 10px 0; } .detail .kv span:first-child { color: var(--muted); }
.detail img { width: 100%; border-radius: 12px; margin-top: 12px; }
.subtop { display: flex; align-items: center; gap: 4px; padding: 8px 8px 4px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.subtop h1 { flex: 1; margin: 0; font-size: 22px; }
.searchbox { padding: 8px 16px; display: flex; flex-direction: column; gap: 10px; }
.filters { display: flex; gap: 8px; }
.filters select { min-height: 42px; padding: 8px 10px; }

/* ---------- hub ---------- */
.hub { padding: 24px 16px; }
.hub h1 { font-size: 32px; margin: 8px 0 20px; }
.hubgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 700px), (orientation: landscape) { .hubgrid { grid-template-columns: repeat(3, 1fr); } }
.mod { background: var(--surface); border: 0; border-radius: 16px; padding: 18px; text-align: left; }
.mod .e { font-size: 38px; } .mod b { display: block; margin-top: 8px; font-size: 18px; } .mod small { color: var(--muted); }
.mod .soon { color: #ffc800; font-size: 12px; display: block; margin-top: 4px; }

/* ---------- sheets / toast ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + var(--sab)); }
@media (orientation: landscape) and (max-height: 600px) { .backdrop { align-items: center; } .sheet { border-radius: 20px; max-height: 96dvh; } }
.sheet h3 { margin: 4px 0 12px; font-size: 18px; }
.sheet form { display: flex; flex-direction: column; gap: 12px; }
.menu-item { display: flex; justify-content: space-between; align-items: center; width: 100%; background: none; border: 0; padding: 14px 4px; font-size: 17px; text-align: left; }
.radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); }
.radio.on { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--surface); }
#toast { position: fixed; left: 50%; bottom: calc(90px + var(--sab)); transform: translateX(-50%) translateY(20px); background: #000c; color: #fff;
  padding: 10px 18px; border-radius: 20px; opacity: 0; transition: .25s; z-index: 99; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
