/* Wallet UI kit. iPhone-first, light/dark via prefers-color-scheme.
   Palette: warm rice-paper neutrals with a single jade accent.
   Status colours (warn/over) are always paired with an icon or text label. */

:root {
  color-scheme: light dark;
  --bg: #f6f4ef;
  --bg-glow: rgba(14, 124, 102, 0.11);
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1b1d1c;
  --ink-2: #5a605c;
  --ink-3: #8a8f8b;
  --hairline: rgba(27, 29, 28, 0.09);
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --accent-soft: rgba(14, 124, 102, 0.12);
  --positive: #0b7a3c;
  --warn: #fab219;
  --warn-soft: rgba(250, 178, 25, 0.2);
  --warn-ink: #7a5200;
  --danger: #d03b3b;
  --danger-soft: rgba(208, 59, 59, 0.12);
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.04), 0 10px 28px rgba(20, 40, 30, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --tabbar-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Sukhumvit Set",
    "Noto Sans Thai", system-ui, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1211;
    --bg-glow: rgba(60, 196, 160, 0.10);
    --surface: #181c1b;
    --surface-2: #222826;
    --ink: #f1f4f2;
    --ink-2: #a8b0ac;
    --ink-3: #7b837f;
    --hairline: rgba(255, 255, 255, 0.08);
    --accent: #3cc4a0;
    --accent-ink: #06201a;
    --accent-soft: rgba(60, 196, 160, 0.16);
    --positive: #4ad98a;
    --warn-ink: #fab219;
    --danger: #f06a6a;
    --danger-soft: rgba(240, 106, 106, 0.16);
    --shadow: none;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(120% 55% at 50% -12%, var(--bg-glow), transparent 62%);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 14px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
}
.no-tabbar .page { padding-bottom: calc(var(--safe-bottom) + 28px); }
.page.has-sticky { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 108px); }

.page > * { animation: rise 0.32s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.page > *:nth-child(2) { animation-delay: 0.03s; }
.page > *:nth-child(3) { animation-delay: 0.06s; }
.page > *:nth-child(4) { animation-delay: 0.09s; }
.page > *:nth-child(n + 5) { animation-delay: 0.12s; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .page > * { animation: none; } }

/* ---------- typography ---------- */
.large-title { font-size: 34px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.1; margin: 6px 0 16px; }
.title { font-size: 22px; font-weight: 700; letter-spacing: -0.015em; margin: 4px 0 12px; }
.section-label {
  font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-3); margin: 26px 4px 8px;
}
.day-header { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 20px 4px 6px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- navigation ---------- */
.nav-bar { display: flex; align-items: center; min-height: 44px; margin-bottom: 2px; }
.nav-back { display: inline-flex; align-items: center; min-height: 44px; font-size: 17px; }

.month-switcher {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 999px;
  padding: 4px; margin: 0 0 16px;
}
.month-nav {
  width: 44px; height: 36px; display: grid; place-items: center;
  border-radius: 999px; color: var(--ink); font-size: 22px; line-height: 1;
}
.month-nav:active { background: var(--surface-2); }
.month-label { font-weight: 600; font-size: 16px; }

/* ---------- cards & lists ---------- */
.card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card + .card { margin-top: 12px; }
.card-pad { padding: 16px; }

.list { list-style: none; margin: 0; padding: 0; }
.list > * + * { border-top: 1px solid var(--hairline); }
.list-row {
  display: flex; align-items: center; gap: 12px; min-height: 60px;
  padding: 10px 16px; color: inherit;
}
a.list-row:active, a.bar-row:active { background: var(--surface-2); }
.row-icon {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  border-radius: 11px; background: var(--surface-2); font-size: 20px;
}
.row-main { flex: 1; min-width: 0; }
.row-title, .row-sub { display: block; }
.row-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub.is-wrap { white-space: normal; }
.row-amount { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-amount.is-income { color: var(--positive); }
.row-chevron { color: var(--ink-3); font-size: 20px; }

/* ---------- hero summary ---------- */
.hero { padding: 20px 18px 16px; }
.hero-label { font-size: 15px; color: var(--ink-2); }
.hero-value {
  font-family: var(--font-rounded); font-size: 48px; font-weight: 700;
  letter-spacing: -0.03em; line-height: 1.05; margin-top: 4px; overflow-wrap: anywhere;
}
.stat-row { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--hairline); }
.stat { padding: 12px 18px 14px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--hairline); }
.stat-label { font-size: 13px; color: var(--ink-2); }
.stat-value { font-size: 18px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.is-positive { color: var(--positive); }
.is-negative { color: var(--danger); }

/* ---------- category bars (ranked, single hue) ---------- */
.bar-list > * + * { border-top: 1px solid var(--hairline); }
.bar-row { display: block; padding: 12px 16px; color: inherit; }
.bar-head { display: flex; align-items: center; gap: 10px; }
.bar-icon { width: 28px; text-align: center; font-size: 18px; flex: none; }
.bar-name { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-share { width: 3.2em; text-align: right; font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bar-track { height: 6px; margin: 8px 0 0 38px; border-radius: 3px; background: var(--accent-soft); overflow: hidden; }
.bar-fill { height: 100%; min-width: 4px; border-radius: 3px; background: var(--accent); }

/* ---------- budget meter ---------- */
.meter { height: 8px; margin-top: 10px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; }
.meter-fill { height: 100%; max-width: 100%; min-width: 4px; border-radius: 4px; background: var(--accent); }
.meter.is-warn { background: var(--warn-soft); }
.meter.is-warn .meter-fill { background: var(--warn); }
.meter.is-over { background: var(--danger-soft); }
.meter.is-over .meter-fill { background: var(--danger); }
.meter-caption { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 13px; color: var(--ink-2); }
.status-warn { color: var(--warn-ink); font-weight: 600; }
.status-over { color: var(--danger); font-weight: 600; }
.meter-caption .caption-amount { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Budget limit editing: native <details>, no JS. */
.limit-edit > summary, .limit-row > summary, .edit-row > summary { list-style: none; cursor: pointer; }
.limit-edit > summary::-webkit-details-marker, .limit-row > summary::-webkit-details-marker,
.edit-row > summary::-webkit-details-marker { display: none; }
.limit-edit { margin-top: 8px; }
.limit-edit > summary { display: inline-flex; align-items: center; min-height: 36px; font-size: 14px; font-weight: 600; color: var(--accent); }
.limit-edit[open] > summary { color: var(--ink-2); }
.limit-row > summary, .edit-row > summary { display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 8px 16px; }
.limit-add, .row-action { flex: none; font-size: 14px; font-weight: 600; color: var(--accent); }
.limit-row[open] .limit-add, .edit-row[open] .row-action { color: var(--ink-2); }
.edit-body { display: grid; gap: 10px; padding: 0 16px 14px; }
.edit-body > form:not(.inline-form) { justify-self: start; }
.input-icon, .inline-form .input.input-icon { flex: none; width: 60px; text-align: center; }
.page-end { margin-top: 28px; }
.limit-row > .inline-form { padding: 0 16px 14px 54px; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  -webkit-appearance: none; appearance: none;
}
.input:focus, .select:focus, .textarea:focus, .chip-select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}
.select, .chip-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238a8f8b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
.input-amount {
  font-family: var(--font-rounded); font-size: 30px; font-weight: 700;
  text-align: center; min-height: 68px; letter-spacing: -0.02em;
}
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field-row > *, .draft-grid > * { min-width: 0; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form .input { flex: 1; min-width: 0; min-height: 40px; padding: 8px 12px; }
.inline-form .btn { flex: none; }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 3px; border-radius: 12px; background: var(--surface-2);
}
.segment { padding: 9px 0; border-radius: 9px; text-align: center; font-size: 15px; font-weight: 600; color: var(--ink-2); }
.segment.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border: 0; border-radius: 14px;
  font: inherit; font-size: 17px; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--ink); text-align: center;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-block { width: 100%; }
.btn-small { min-height: 38px; padding: 0 14px; font-size: 15px; border-radius: 11px; white-space: nowrap; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.btn-row > form > .btn { width: 100%; }

/* ---------- banners, tags, empty ---------- */
.banner {
  display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap;
  padding: 12px 14px; margin: 0 0 12px; border-radius: 14px;
  font-size: 15px; background: var(--surface-2);
}
.banner-info, .banner-success { background: var(--accent-soft); }
.banner-warn { background: var(--warn-soft); }
.banner-error { background: var(--danger-soft); color: var(--danger); }
.banner a { font-weight: 600; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px;
  border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2);
}
.tag-warn { background: var(--warn-soft); color: var(--warn-ink); }
.tag-dup { background: var(--danger-soft); color: var(--danger); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-2); }
.empty-icon { font-size: 40px; }
.empty-title { margin: 8px 0 4px; font-size: 17px; font-weight: 600; color: var(--ink); }

/* ---------- add page actions ---------- */
.action-list { display: grid; gap: 12px; }
.action {
  display: flex; align-items: center; gap: 14px; padding: 18px 16px; color: inherit;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.action:active { transform: scale(0.99); }
.action-icon {
  width: 50px; height: 50px; flex: none; display: grid; place-items: center;
  border-radius: 15px; background: var(--accent-soft); color: var(--accent); font-size: 24px;
}
.action-title { font-size: 17px; font-weight: 600; }
.action-sub { font-size: 14px; color: var(--ink-2); }

/* ---------- import review ---------- */
.draft-card {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 14px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
  transition: opacity 0.15s ease;
}
.draft-card + .draft-card { margin-top: 10px; }
.draft-card.is-low { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.draft-card.is-excluded { opacity: 0.5; }
.draft-top { display: flex; align-items: center; gap: 10px; }
.draft-check { width: 26px; height: 26px; flex: none; accent-color: var(--accent); }
.draft-meta { flex: 1; min-width: 0; font-size: 13px; color: var(--ink-2); }
.draft-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.draft-grid .input { min-height: 44px; padding: 10px 12px; }
.draft-grid .chip-select { grid-column: 1 / -1; }
.chip-select {
  width: auto; max-width: 100%; min-height: 36px; padding: 6px 34px 6px 12px;
  font: inherit; font-size: 15px; font-weight: 600; color: var(--accent);
  background-color: var(--accent-soft); border: 0; border-radius: 999px;
  -webkit-appearance: none; appearance: none;
}
.sticky-actions {
  position: fixed; left: 0; right: 0; z-index: 5;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  display: flex; gap: 10px; max-width: 560px; margin: 0 auto; padding: 14px 16px 12px;
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.sticky-actions .btn-primary { flex: 1; }

.spinner {
  width: 38px; height: 38px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-box { padding: 36px 20px; text-align: center; }

.load-more { display: flex; margin: 16px auto 0; }

/* ---------- auth ---------- */
.auth { min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 56px); display: grid; align-content: center; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; font-size: 30px; font-weight: 800; letter-spacing: -0.035em; }
.brand-mark {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 13px; background: var(--accent); color: var(--accent-ink);
  font-family: var(--font-rounded); font-size: 24px; font-weight: 800;
}
.link-box {
  padding: 12px; border-radius: 10px; background: var(--surface-2);
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; word-break: break-all;
}

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: start;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: rgba(246, 244, 239, 0.82);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--hairline);
}
@media (prefers-color-scheme: dark) { .tabbar { background: rgba(15, 18, 17, 0.82); } }
.tab {
  height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--ink-3); font-size: 10.5px; font-weight: 600;
}
.tab svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--accent); }
.tab-add-circle {
  width: 54px; height: 54px; display: grid; place-items: center; transform: translateY(-12px);
  border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 8px 18px rgba(14, 124, 102, 0.32);
}
.tab-add-circle svg { width: 27px; height: 27px; stroke-width: 2.4; }

.file-pick {
  position: relative; display: grid; justify-items: center; gap: 6px;
  padding: 32px 20px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--accent); border-radius: var(--radius); background: var(--accent-soft);
}
.file-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.file-pick-icon { font-size: 34px; line-height: 1; }
.file-pick-title { font-size: 17px; font-weight: 700; color: var(--accent); }
.file-pick-sub { font-size: 13px; color: var(--ink-2); }
.file-pick.is-filled { border-style: solid; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
