/* ธีม Friendly Budget: ครีม-เหลือง ขอบหมึกหนา เงาแข็ง */
:root {
  color-scheme: light;
  --bg: #fff8ef;
  --surface: #ffffff;
  --text: #2b2118;
  --ink: #2b2118;
  --muted: #8a6f55;
  --border: #eee2d0;
  --brand: #ffcc4d;
  --brand-ink: #2b2118;
  --brand-soft: #fff0c2;
  --accent: #ff7a59;
  --income: #2b8a3e;
  --expense: #e8590c;
  --danger: #d6336c;
  --ok-soft: #c9f2d5;
  --warn-soft: #ffe0b8;
  --bad-soft: #ffc9d6;
  --radius: 18px;
  --line: 2px solid var(--ink);
  --shadow: 3px 3px 0 var(--ink);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: 'Prompt', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

body.loading main { opacity: 0.5; pointer-events: none; transition: opacity 0.2s; }

button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: 0.02em; }
.brand span { color: var(--brand); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: transparent; font-size: 1.4rem; line-height: 1;
}
.icon-btn:hover { background: var(--brand-soft); }

.banner {
  margin: 12px 16px 0; padding: 10px 14px;
  border-radius: 10px; background: var(--brand-soft); font-size: 0.9rem;
}
.banner a { color: var(--brand); font-weight: 600; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

h2 { font-size: 1rem; font-weight: 600; margin: 24px 0 10px; color: var(--muted); }

/* ---------- scope ---------- */

.scope-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.scope-bar[hidden] { display: none; }
.user-chip { font-size: 0.9rem; color: var(--muted); }
.user-chip b { color: var(--text); }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.segmented button { border: none; background: none; padding: 5px 14px; border-radius: 999px; font-size: 0.9rem; color: var(--muted); }
.segmented button.active { background: var(--brand); color: #fff; font-weight: 600; }

.person-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.person-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; font-size: 0.85rem; }
.person-card .name { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.person-card .line { display: flex; justify-content: space-between; color: var(--muted); font-variant-numeric: tabular-nums; }
.person-card .line.total { color: var(--text); font-weight: 600; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.owner-tag { display: inline-block; font-size: 0.72rem; padding: 0 6px; margin-right: 4px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); }
.tx-item.others { opacity: 0.85; }

/* ---------- summary ---------- */

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.card.balance { grid-column: 1 / -1; background: var(--brand); color: #fff; border: none; }
.card .label { font-size: 0.85rem; opacity: 0.8; }
.card .value { font-size: 1.3rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.card.balance .value { font-size: 1.9rem; }
.card.income .value { color: var(--income); }
.card.expense .value { color: var(--expense); }

/* ---------- breakdown ---------- */

.breakdown {
  background: var(--surface); border-radius: var(--radius);
  padding: 6px 16px; border: 1px solid var(--border);
}
.bd-group { padding: 12px 0; }
.bd-group + .bd-group { border-top: 1px solid var(--border); }
.bd-group-head { font-weight: 600; }
.bd-group .bd-bar { margin-bottom: 8px; }
.bd-sub { font-size: 0.88rem; color: var(--muted); margin: 0; padding: 3px 0 3px 4px; }
.bd-head { display: flex; justify-content: space-between; font-size: 0.95rem; margin-bottom: 6px; }
.bd-amt { font-variant-numeric: tabular-nums; }
.bd-amt small { color: var(--muted); margin-left: 4px; }
.bd-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.bd-bar div { height: 100%; background: var(--expense); border-radius: 3px; }

/* ---------- transaction list ---------- */

.tx-list { display: flex; flex-direction: column; gap: 6px; }
.tx-group { margin-bottom: 10px; }
.tx-date {
  display: flex; justify-content: space-between;
  font-size: 0.85rem; color: var(--muted); padding: 4px 4px 6px;
}
.tx-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; margin-bottom: 6px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.tx-item:hover { border-color: var(--brand); }
.tx-icon {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  font-size: 1.3rem; background: var(--bg); border-radius: 12px;
}
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-cat { font-weight: 500; }
.tx-note { font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt.income { color: var(--income); }
.tx-amt.expense { color: var(--expense); }

.empty { color: var(--muted); text-align: center; padding: 20px 0; margin: 0; }

.filter-row { display: flex; gap: 8px; margin-bottom: 14px; }
.chip {
  padding: 6px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- FAB & tab bar ---------- */

.fab {
  position: fixed; right: 20px; bottom: calc(84px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--brand); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 20px rgb(15 118 110 / 0.35);
}
.fab[hidden] { display: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: none; background: none; padding: 8px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.75rem; color: var(--muted);
}
.tabbar button span { font-size: 1.2rem; }
.tabbar button.active { color: var(--brand); font-weight: 600; }

/* ---------- forms ---------- */

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.form input[type='text'], .form input[type='url'], .form input[type='number'], .form input[type='date'] {
  padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.form input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.amount-input { font-size: 1.6rem !important; font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 0.9rem; line-height: 1.6; }
.status { font-size: 0.9rem; min-height: 1.2em; }

.btn { padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; font-weight: 500; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: 0.5; }

.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; }
.type-toggle label { position: relative; }
.type-toggle input { position: absolute; opacity: 0; }
.type-toggle span {
  display: block; text-align: center; padding: 8px; border-radius: 9px;
  color: var(--muted); font-weight: 500; cursor: pointer;
}
.type-toggle input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.type-toggle input[value='expense']:checked + span { color: var(--expense); }
.type-toggle input[value='income']:checked + span { color: var(--income); }

.category-picker { margin-top: -8px; }
.cat-group-title { font-size: 0.8rem; font-weight: 600; color: var(--muted); margin: 10px 2px 6px; }
.cat-group-title:first-child { margin-top: 0; }
.cat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.cat-opt {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 10px; font-size: 0.8rem; line-height: 1.25;
  text-align: center; overflow-wrap: anywhere;
  border: 1px solid var(--border); background: var(--bg);
}
.cat-opt span { font-size: 1.3rem; }
.cat-opt.selected { border-color: var(--brand); background: var(--brand-soft); font-weight: 600; }

/* ---------- dialog ---------- */

dialog {
  width: min(520px, 100vw - 24px); max-height: 92vh;
  border: none; border-radius: 18px; padding: 20px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h3 { margin: 0; }

/* หน้าเพิ่ม/แก้รายการ — แบบกะทัดรัด */
#txDialog { width: min(420px, 100vw - 24px); padding: 16px; }
#txDialog .form { gap: 10px; }
#txDialog h3 { font-size: 1.05rem; }
#txDialog .form label { gap: 4px; font-size: 0.8rem; }
#txDialog .form input[type='number'], #txDialog .form input[type='date'], #txDialog .form input[type='text'] { padding: 8px 10px; }
#txDialog .amount-input { font-size: 1.3rem !important; }
#txDialog .type-toggle span { padding: 6px; }
#txDialog .category-picker { margin-top: -6px; }
#txDialog .cat-group-title { font-size: 0.72rem; margin: 8px 2px 4px; }
#txDialog .cat-group-title:first-child { margin-top: 0; }
#txDialog .cat-grid { gap: 4px; }
#txDialog .cat-opt {
  flex-direction: row; justify-content: flex-start; gap: 5px;
  padding: 5px 6px; font-size: 0.72rem; text-align: left; border-radius: 8px;
  overflow-wrap: break-word;
}
#txDialog .cat-opt span { font-size: 1rem; flex: none; }
#txDialog .btn { padding: 8px 14px; }
.form-2col { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }
.form-2col input { min-width: 0; width: 100%; }

@media (max-width: 560px) {
  dialog {
    margin: auto 0 0; width: 100vw; max-width: 100vw;
    border-radius: 18px 18px 0 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 10px; font-size: 0.9rem; z-index: 100;
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }
.toast[hidden] { display: none; }

/* ---------- login ---------- */

.login-screen {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 16px;
  background: var(--bg);
}
.login-screen[hidden] { display: none; }
.login-card {
  width: min(360px, 100%); text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 36px 24px; box-shadow: var(--shadow);
}
.login-card p { color: var(--muted); margin: 6px 0 24px; }
.brand.big { font-size: 2rem; }
.google-btn { display: flex; justify-content: center; min-height: 44px; }
.login-error { color: var(--danger) !important; font-size: 0.9rem; margin: 16px 0 0 !important; }
.login-error[hidden] { display: none; }

/* ---------- account ---------- */

.account-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
}
.account-card img { width: 44px; height: 44px; border-radius: 50%; background: var(--bg); flex: none; }
.account-info { flex: 1; min-width: 0; }
.account-info div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); font-size: 0.85rem; }
[hidden] { display: none !important; }

/* แท็บช่วงเวลา: รายเดือน / ทั้งปี / เทียบรายปี */
.period-tabs { display: flex; width: 100%; margin-bottom: 12px; }
.period-tabs button { flex: 1; }
.period-tabs[hidden], .period-nav[hidden] { display: none; }

/* เลื่อนเดือน/ปี: ปุ่มใหญ่ กดง่ายด้วยนิ้วโป้ง */
.period-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px; margin-bottom: 14px;
}
.period-nav #monthLabel { flex: 1; text-align: center; font-weight: 600; font-size: 1.05rem; }
.nav-btn {
  width: 48px; height: 40px; border: none; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand); font-size: 1.5rem; line-height: 1; font-weight: 600;
}
.nav-btn:hover { filter: brightness(1.1); }
.nav-btn:active { transform: scale(0.95); }

/* กราฟรายจ่าย 12 เดือน */
.mchart {
  display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 8px 8px;
}
.mbar { display: flex; flex-direction: column; align-items: center; gap: 4px; border: none; background: none; padding: 0; min-width: 0; color: var(--muted); }
.mbar small { font-size: 0.6rem; height: 1em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mbar-track { width: 100%; max-width: 22px; height: 100px; display: flex; align-items: flex-end; }
.mbar-track div { width: 100%; background: var(--expense); border-radius: 4px 4px 0 0; min-height: 2px; }
.mbar span { font-size: 0.65rem; }
.mbar.future { opacity: 0.4; }
.mbar:hover span { color: var(--text); font-weight: 600; }

/* เทียบรายปี */
.yc-tag { font-size: 0.7rem; font-weight: 500; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; margin-left: 4px; }
.yc-meta { font-size: 0.8rem; color: var(--muted); }
.delta.up { color: var(--expense); font-weight: 600; }
.delta.down { color: var(--income); font-weight: 600; }
.table-wrap { overflow-x: auto;  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ytable { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.ytable th, .ytable td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ytable td, .ytable thead th { text-align: right; }
.ytable tbody th { text-align: left; font-weight: 500; position: sticky; left: 0; background: var(--surface); }
.ytable thead th { color: var(--muted); font-weight: 600; }
.ytable tr:last-child th, .ytable tr:last-child td { border-bottom: none; }
.ytable .total { font-weight: 700; }
.ytable .total th { font-weight: 700; }
.ytable .avg { color: var(--muted); }

/* เป้ารายจ่าย */
.bg-bar { position: relative; display: flex; height: 8px; background: var(--border); border-radius: 4px; margin-bottom: 6px; }
.bg-bar > div { height: 100%; }
.bg-used { background: var(--income); border-radius: 4px 0 0 4px; }
.bg-later { background: var(--income); opacity: 0.35; }
.bg-bar.ahead .bg-used, .bg-bar.ahead .bg-later { background: var(--expense); }
.bg-bar.over .bg-used, .bg-bar.over .bg-later { background: var(--danger); }
.bg-pace { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 1px; opacity: 0.7; }
.bg-over { color: var(--danger); font-weight: 600; }
.bg-total .bd-group-head { font-size: 1.05rem; }
.bg-total .bg-bar { height: 12px; border-radius: 6px; }
.bg-cat { padding-left: 4px; margin-top: 8px; }
.bg-cat .bg-bar { height: 5px; }
.muted { color: var(--muted); }

/* หัวข้อ + ปุ่มด้านขวา */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.btn.small { padding: 4px 12px; font-size: 0.82rem; margin: 14px 0 0; }

/* ฟอร์มตั้งเป้า */
#budgetDialog { width: min(480px, 100vw - 24px); padding: 16px; }
#budgetDialog .form { gap: 10px; }
#budgetDialog h3 { font-size: 1.05rem; }
.budget-help { font-size: 0.78rem; margin: -4px 0 0; }
.budget-fields { display: flex; flex-direction: column; gap: 6px; max-height: 58vh; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.bf-group { border: 1px solid var(--border); border-radius: 10px; padding: 6px 8px; }
.form .bf-head, .form .bf-cat {
  display: grid; grid-template-columns: 1fr auto 110px; align-items: center; gap: 8px;
}
.bf-toggle {
  border: none; background: none; padding: 4px 0; text-align: left; color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer;
}
.bf-toggle small { font-weight: 400; color: var(--brand); font-size: 0.72rem; }
.bf-toggle::before { content: '▸ '; color: var(--muted); }
.bf-group.open .bf-toggle::before { content: '▾ '; }
.bf-cats { display: none; padding-bottom: 2px; }
.bf-group.open .bf-cats { display: block; }
.form .bf-cat { flex-direction: row; font-size: 0.82rem; color: var(--muted); padding: 2px 0 2px 16px; }
.bf-prev { font-size: 0.72rem; color: var(--muted); opacity: 0.8; font-variant-numeric: tabular-nums; font-weight: 400; }
.form .budget-fields input {
  width: 100%; padding: 6px 8px; text-align: right; font-variant-numeric: tabular-nums;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit;
}
.bf-head input { font-weight: 600; }
.bf-warn { font-size: 0.75rem; color: var(--danger); padding: 2px 0 2px 16px; }
.bf-warn[hidden] { display: none; }
.budget-total { display: flex; justify-content: space-between; align-items: baseline; font-size: 1rem; padding: 4px 2px; border-top: 1px solid var(--border); }
.budget-total b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
#budgetDialog .btn { padding: 8px 12px; }


/* =====================================================================
   ธีม C · Friendly Budget (แนว YNAB / Dime!) — ทับสไตล์พื้นฐานด้านบน
   ===================================================================== */

h2 { color: var(--text); font-size: 1.05rem; }

/* แถบบน */
.topbar { background: var(--bg); border-bottom: var(--line); }
.brand { font-size: 1.3rem; letter-spacing: 0; }
.brand span { color: var(--accent); }
.banner { background: var(--brand-soft); border: var(--line); }
.banner a { color: var(--text); }

/* ปุ่มสลับแบบแคปซูล */
.segmented { background: var(--surface); border: var(--line); }
.segmented button { color: var(--text); }
.segmented button.active { background: var(--brand); color: var(--brand-ink); }
.user-chip { color: var(--text); }
.period-tabs { padding: 4px; gap: 4px; border-radius: 14px; }
.period-tabs button { border-radius: 10px; font-weight: 500; }
.period-tabs button.active { background: var(--ink); color: var(--bg); }

.period-nav { border: var(--line); box-shadow: var(--shadow); }
.nav-btn { background: var(--brand); color: var(--ink); border: var(--line); height: 38px; border-radius: 12px; }

/* การ์ดสรุป */
.card, .breakdown, .mchart, .table-wrap, .person-card, .account-card, .tx-item, .login-card {
  border: var(--line); box-shadow: var(--shadow); border-radius: var(--radius);
}
.card.balance { background: var(--brand); color: var(--ink); border: var(--line); }
.card.balance .label { opacity: 1; }
.card .label { font-size: 0.82rem; }
.card .value { font-weight: 700; }
.card.balance .value { font-size: 2.1rem; }
.summary { gap: 12px; }

/* รายจ่ายตามหมวด */
.bd-group + .bd-group { border-top: 2px dashed var(--border); }
.bd-bar { height: 10px; border-radius: 6px; border: var(--line); background: #f5ecdf; }
.bd-bar div { background: var(--fill, var(--accent)); border-radius: 0; }
.bd-sub { padding-left: 42px; }
.grp-name { display: inline-flex; align-items: center; gap: 10px; }
.grp-emo, .env-emo {
  width: 32px; height: 32px; flex: none; display: grid; place-items: center;
  font-style: normal; font-size: 1.05rem; border-radius: 10px;
  background: var(--tile, var(--brand-soft)); border: var(--line);
}

/* เป้ารายจ่าย = ซองเงิน */
.env-list { display: flex; flex-direction: column; gap: 12px; }
.env {
  background: var(--surface); border: var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
}
.env.bg-total { background: var(--brand-soft); }
.env-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.env-emo { width: 42px; height: 42px; font-size: 1.35rem; border-radius: 12px; }
.env-main { flex: 1; min-width: 0; }
.env-name { font-weight: 600; }
.env-side { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; font-size: 0.8rem; }
.env-side b { font-size: 0.9rem; white-space: nowrap; }
.tag { display: inline-block; font-size: 0.68rem; font-weight: 600; padding: 1px 9px; border-radius: 999px; border: 1.5px solid var(--ink); white-space: nowrap; vertical-align: middle; }
.tag-ok { background: var(--ok-soft); }
.tag-ahead { background: var(--warn-soft); }
.tag-over { background: var(--bad-soft); }

.bg-bar { height: 12px; border-radius: 7px; border: var(--line); background: #f5ecdf; margin-bottom: 6px; }
.bg-bar > div:first-child { border-radius: 5px 0 0 5px; }
.bg-used, .bg-later { background: var(--fill, var(--income)); }
.bg-later { opacity: 0.4; }
.bg-bar.ahead .bg-used, .bg-bar.ahead .bg-later { background: #ffa94d; }
.bg-bar.over .bg-used, .bg-bar.over .bg-later { background: var(--accent); }
.bg-total .bg-bar { height: 16px; border-radius: 9px; }
.bg-total .bg-used { background: var(--ink); }
.bg-total .bg-later { background: var(--ink); opacity: 0.3; }
.bg-total .bg-bar.over .bg-used { background: var(--accent); }
.bg-pace { background: var(--ink); width: 3px; top: -5px; bottom: -5px; opacity: 1; }
.bg-cat { padding: 8px 0 0 54px; margin-top: 4px; }
.bg-cat .bg-bar { height: 8px; }
.bg-over { color: var(--danger); }

/* กราฟรายเดือน / ตารางเทียบปี */
.mbar-track div { background: var(--accent); border: 1.5px solid var(--ink); border-bottom: none; border-radius: 5px 5px 0 0; }
.mbar { color: var(--muted); }
.ytable th, .ytable td { border-bottom: 1px dashed var(--border); }
.yc-tag { border: 1.5px solid var(--ink); color: var(--text); }

/* รายการ */
.tx-item { margin-bottom: 10px; box-shadow: 2px 2px 0 var(--ink); }
.tx-item:hover { border-color: var(--ink); transform: translate(-1px, -1px); box-shadow: var(--shadow); }
.tx-icon { background: var(--brand-soft); border: var(--line); }
.tx-date { color: var(--text); font-weight: 600; }
.chip { border: var(--line); background: var(--surface); font-weight: 500; }
.chip.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.owner-tag { background: var(--brand-soft); color: var(--text); border: 1px solid var(--ink); }

/* ปุ่ม */
.btn { border: var(--line); font-weight: 600; border-radius: 12px; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 2px 2px 0 var(--ink); }
.btn.primary:active, .btn:active { transform: translate(1px, 1px); box-shadow: none; }
.btn.ghost { background: var(--surface); border-color: var(--ink); }
.btn.danger { border-color: var(--danger); }
.btn.small { box-shadow: 2px 2px 0 var(--ink); background: var(--brand); }

.fab {
  border-radius: 18px; background: var(--accent); color: #fff;
  border: var(--line); box-shadow: var(--shadow);
}
.fab:active { transform: translate(2px, 2px); box-shadow: none; }

.tabbar { background: var(--surface); border-top: var(--line); }
.tabbar button { color: var(--muted); }
.tabbar button.active { color: var(--text); }
.tabbar button.active span { background: var(--brand); border: var(--line); border-radius: 10px; padding: 0 12px; }

/* ฟอร์ม & dialog */
dialog { border: var(--line); box-shadow: 5px 5px 0 var(--ink); background: var(--bg); }
dialog::backdrop { background: rgb(43 33 24 / 0.45); }
.form label { color: var(--text); font-weight: 500; }
.form input[type='text'], .form input[type='url'], .form input[type='number'], .form input[type='date'],
.form .budget-fields input { border: var(--line); background: var(--surface); }
.form input:focus { outline: 3px solid var(--brand); outline-offset: 0; }
.type-toggle { background: var(--surface); border: var(--line); }
.type-toggle input:checked + span { box-shadow: none; border: var(--line); }
.type-toggle input[value='expense']:checked + span { background: #ffe3d6; color: var(--text); }
.type-toggle input[value='income']:checked + span { background: var(--ok-soft); color: var(--text); }
.cat-opt { background: var(--surface); border: 1.5px solid var(--border); }
.cat-opt.selected { border: var(--line); background: var(--brand); box-shadow: 2px 2px 0 var(--ink); }
.bf-group { background: var(--surface); border: var(--line); }
.bf-toggle small { color: var(--accent); }
.budget-total { border-top: var(--line); }

.toast { background: var(--ink); color: var(--bg); border-radius: 12px; }
.login-screen { background: var(--bg); }
.fab { font-family: system-ui, sans-serif; font-size: 2.1rem; font-weight: 500; }

/* ช่องจำนวนเงินแบบคิดเลขได้ */
.calc-wrap { position: relative; display: block; }
.calc-wrap .amount-input { width: 100%; padding-right: 130px !important; }
.calc-result {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: 0.95rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none;
}
.calc-keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: -4px; }
.calc-keys button {
  padding: 5px 0; font-size: 1.05rem; font-weight: 600; line-height: 1.2;
  background: var(--surface); border: var(--line); border-radius: 10px; box-shadow: 2px 2px 0 var(--ink);
}
.calc-keys button:active { transform: translate(1px, 1px); box-shadow: none; }
.calc-keys .eq { background: var(--brand); }
.calc-keys button { font-family: system-ui, sans-serif; font-size: 1.25rem; }
