:root {
  --ink: #1c2b29;
  --muted: #62716e;
  --line: #e2ddd0;
  --paper: #f6f3ec;
  --card: #fffdf8;
  --brand: #14463f;
  --brand-soft: #dcebe6;
  --income: #17744f;
  --expense: #b2402f;
  --transfer: #2a5f96;
  --gold: #d9952b;
  --warn-bg: #fdf1d8;
  --warn-ink: #7c5206;
  --radius: 16px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Myanmar", "Pyidaungsu", "Myanmar Text", sans-serif;
}

html[lang="my"] body { line-height: 1.75; }

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

h1, h2, h3 { margin: 0; line-height: 1.3; }

.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { max-width: 640px; margin: 0 auto; padding: 0 16px calc(104px + env(safe-area-inset-bottom)); }

.topbar {
  background: var(--brand);
  color: #f6f3ec;
  padding: 16px 16px 44px;
  padding-top: calc(16px + env(safe-area-inset-top));
}

.topbar-inner { max-width: 608px; margin: 0 auto; }

.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.topbar h1 { font-size: 1.05rem; font-weight: 600; overflow-wrap: anywhere; }

.lang-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,.4);
  color: inherit;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: .85rem;
  flex: none;
}

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }

.month-nav strong { font-size: 1.25rem; font-weight: 600; text-align: center; }

.month-range { display: block; font-size: .78rem; font-weight: 400; opacity: .8; }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(255,255,255,.14);
  color: inherit;
  font-size: 1.2rem;
  flex: none;
}

.overlap { margin-top: -32px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}

.tabbar-inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 72px 1fr 1fr; align-items: center; }

.tab {
  background: none; border: 0;
  padding: 10px 2px 8px;
  min-height: 58px;
  color: var(--muted);
  font-size: .75rem;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}

.tab svg { width: 22px; height: 22px; }

.tab[aria-current="page"] { color: var(--brand); font-weight: 700; }

.add-btn {
  width: 58px; height: 58px;
  margin: -22px auto 0;
  border-radius: 50%;
  border: 4px solid var(--paper);
  background: var(--gold);
  color: #1c2b29;
  font-size: 1.9rem;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(28,43,41,.25);
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card > h2, .section-title { font-size: 1rem; font-weight: 700; margin-bottom: 10px; }

.page-title { font-size: 1.4rem; font-weight: 700; margin: 20px 0 14px; }

.balance-grid { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 14px; }

@media (min-width: 560px) { .balance-grid { grid-template-columns: 1fr 1fr; } }

.balance { margin-bottom: 0; box-shadow: 0 4px 14px rgba(28,43,41,.07); }

.balance-head { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; color: var(--muted); }

.cur-tag { font-weight: 700; letter-spacing: .04em; color: var(--brand); background: var(--brand-soft); border-radius: 6px; padding: 1px 8px; }

.balance-left { font-size: 1.85rem; font-weight: 700; margin: 2px 0 8px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.25; }

.balance-left.neg { color: var(--expense); }

.kv { display: flex; justify-content: space-between; gap: 12px; font-size: .9rem; padding: 2px 0; font-variant-numeric: tabular-nums; }

.kv > span:first-child { color: var(--muted); }

.kv > span:last-child { text-align: right; overflow-wrap: anywhere; }

.t-income { color: var(--income); }
.t-expense { color: var(--expense); }
.t-transfer { color: var(--transfer); }

.combined { font-size: .9rem; }

.combined strong { font-size: 1.1rem; display: block; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }

.small { font-size: .85rem; }

/* ---------- category bars ---------- */
.bar-row { margin-bottom: 10px; }

.bar-label { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; font-variant-numeric: tabular-nums; }

.bar-track { height: 8px; background: #eee9dc; border-radius: 4px; overflow: hidden; margin-top: 3px; }

.bar-fill { height: 100%; background: var(--brand); border-radius: 4px; }

.w-0 { width: 0; } .w-5 { width: 5%; } .w-10 { width: 10%; } .w-15 { width: 15%; } .w-20 { width: 20%; }
.w-25 { width: 25%; } .w-30 { width: 30%; } .w-35 { width: 35%; } .w-40 { width: 40%; } .w-45 { width: 45%; }
.w-50 { width: 50%; } .w-55 { width: 55%; } .w-60 { width: 60%; } .w-65 { width: 65%; } .w-70 { width: 70%; }
.w-75 { width: 75%; } .w-80 { width: 80%; } .w-85 { width: 85%; } .w-90 { width: 90%; } .w-95 { width: 95%; } .w-100 { width: 100%; }

.sub-head { font-size: .78rem; font-weight: 700; letter-spacing: .05em; color: var(--muted); margin: 12px 0 6px; }

.sub-head:first-of-type { margin-top: 0; }

/* ---------- transaction list ---------- */
.tx {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  width: 100%;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
  min-height: 62px;
  text-align: left;
  align-items: center;
}

.tx:last-child { border-bottom: 0; }

.tx-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700;
}

.tx-icon.income { background: #dff1e8; color: var(--income); }
.tx-icon.expense { background: #f8e3df; color: var(--expense); }
.tx-icon.transfer { background: #e0ebf6; color: var(--transfer); }

.tx-main { min-width: 0; }

.tx-title { font-weight: 600; overflow-wrap: anywhere; }

.tx-sub { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }

.tx-amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: .95rem; }

.tx-amount small { display: block; font-weight: 500; font-size: .8rem; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 12px; font-size: .88rem; font-weight: 600; }

label.field > input, label.field > select, label.field > textarea { margin-top: 4px; }

input, select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #cfc9b9;
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
  font-weight: 400;
}

input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--brand); }

.amount-input { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.row { display: flex; gap: 10px; }

.row > * { flex: 1; min-width: 0; }

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  min-height: 46px;
  padding: 10px 18px;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn.block { width: 100%; }

.btn.ghost { background: transparent; border-color: #cfc9b9; color: var(--ink); }

.btn.danger { background: transparent; border-color: var(--expense); color: var(--expense); }

.btn.small-btn { min-height: 38px; padding: 6px 12px; font-size: .85rem; font-weight: 600; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: #eee9dc; padding: 4px; border-radius: 12px; margin-bottom: 14px; }

.seg button { border: 0; background: transparent; border-radius: 9px; min-height: 40px; font-weight: 600; font-size: .92rem; padding: 4px; }

.seg button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 3px rgba(28,43,41,.18); color: var(--brand); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 14px; }

.chip { border: 1px solid #cfc9b9; background: #fff; border-radius: 999px; padding: 7px 12px; min-height: 38px; font-size: .86rem; }

.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.error { background: #f8e3df; color: #7e2719; border-radius: 10px; padding: 10px 12px; font-size: .9rem; margin-bottom: 12px; }

.notice { background: var(--brand-soft); color: var(--brand); border-radius: 10px; padding: 10px 12px; font-size: .9rem; margin-bottom: 12px; overflow-wrap: anywhere; }

.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 6px 10px; font-size: .82rem; margin-top: 4px; }

.field-label { font-size: .88rem; font-weight: 600; }

.transfer-side { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }

.transfer-side legend { font-weight: 700; font-size: .85rem; padding: 0 6px; }

.rate-hint { text-align: center; font-size: .85rem; color: var(--transfer); margin: -2px 0 12px; }

/* ---------- dialog ---------- */
dialog {
  border: 0;
  padding: 0;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  max-height: 92vh;
  background: var(--card);
  color: var(--ink);
}

@media (min-width: 640px) { dialog { border-radius: 20px; margin: auto; } }

dialog::backdrop { background: rgba(20,35,32,.55); }

.sheet { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }

.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }

.sheet-head h2 { font-size: 1.15rem; }

.close-btn { background: #eee9dc; border: 0; border-radius: 50%; width: 40px; height: 40px; font-size: 1.1rem; flex: none; }

/* ---------- auth pages ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: 40px 18px; }

.auth-logo { width: 64px; height: 64px; display: block; margin: 0 auto 12px; }

.auth h1 { text-align: center; font-size: 1.6rem; }

.auth > p { text-align: center; color: var(--muted); margin: 6px 0 20px; }

.auth .lang-btn { color: var(--ink); border-color: #cfc9b9; display: block; margin: 16px auto 0; }

/* ---------- lists in family page ---------- */
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }

.list-row:last-child { border-bottom: 0; }

.list-row > div:first-child { min-width: 0; overflow-wrap: anywhere; }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); }

.badge.off { background: #eee9dc; color: var(--muted); }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.copy-box { word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: .8rem; background: #fff; border: 1px dashed #cfc9b9; border-radius: 8px; padding: 8px; margin: 8px 0; }

.gap-top { margin-top: 10px; }

.link-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; text-align: center; }

/* ---------- filters ---------- */
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }

.filter-grid .wide { grid-column: 1 / -1; }

/* ---------- import ---------- */
.import-row { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff; }

.import-row.off { opacity: .55; background: transparent; }

.import-row.has-warning { border-color: #e4b65e; }

.import-row.has-error { border-color: var(--expense); }

.import-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; font-size: .9rem; font-weight: 600; }

.import-head span { overflow-wrap: anywhere; }

.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.import-grid label { font-size: .75rem; font-weight: 600; color: var(--muted); }

.import-grid .wide { grid-column: 1 / -1; }

.sticky-action {
  position: sticky;
  bottom: calc(66px + env(safe-area-inset-bottom));
  background: var(--paper);
  padding: 10px 0;
  z-index: 2;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 20;
  font-size: .9rem;
  max-width: 90vw;
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip, .seg button { transition: background-color .12s, color .12s; }
}
