
/* Layout: one calm column (max 560px), iOS-style grouped lists, big balance up top, tab bar at the bottom */
:root {
  --bg: #f2f2f6;
  --card: #ffffff;
  --fg: #16181d;
  --muted: #6d717a;
  --faint: #e4e5ea;
  --line: #e9eaee;
  --accent: #10805a;
  --accent-soft: #dff2ea;
  --bad: #d23a2c;
  --bar-bg: rgba(248,248,250,.86);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 14px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #000000; --card: #1b1c1f; --fg: #f3f4f6; --muted: #9a9ea6; --faint: #2e3034; --line: #2a2c30;
  --accent: #35c48b; --accent-soft: #11382a; --bad: #ff6a5c; --bar-bg: rgba(22,22,24,.86); color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #000000; --card: #1b1c1f; --fg: #f3f4f6; --muted: #9a9ea6; --faint: #2e3034; --line: #2a2c30;
  --accent: #35c48b; --accent-soft: #11382a; --bad: #ff6a5c; --bar-bg: rgba(22,22,24,.86); color-scheme: dark }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg); }
body { color: var(--fg); font-family: var(--font); font-size: 16px; line-height: 1.35;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 calc(84px + env(safe-area-inset-bottom, 0px)); }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bar-bg); }
.app { max-width: 560px; margin: 0 auto; }
.num { font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* top bar */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding-block: 10px; background: var(--bg); }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--accent); }
.icon-btn:active { background: var(--faint); }
.icon-btn svg { width: 22px; height: 22px; }
.month-nav { display: flex; align-items: center; gap: 2px; }
h1 { font-family: var(--font-display); font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 16px; text-wrap: balance; }
h1 small { color: var(--muted); font-weight: 600; font-size: 20px; letter-spacing: 0; margin-left: 6px; }

/* hero */
.hero { background: var(--card); border-radius: 20px; padding: 20px; display: grid; gap: 14px; }
.hero-label { color: var(--muted); font-size: 14px; font-weight: 500; }
.hero-amount { font-family: var(--font-display); font-size: 42px; font-weight: 700; letter-spacing: -.03em; line-height: 1.05; }
.hero-amount .cur { font-size: 20px; font-weight: 600; color: var(--muted); margin-right: 6px; letter-spacing: 0; }
.hero-amount.neg { color: var(--bad); }
.meter { height: 10px; border-radius: 6px; background: var(--faint); display: flex; overflow: hidden; }
.meter i { display: block; height: 100%; transition: width .4s ease; }
.meter .paid { background: var(--accent); }
.meter .due { background: color-mix(in srgb, var(--accent) 35%, var(--faint)); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { display: grid; gap: 2px; text-align: left; padding: 8px 10px; border-radius: 12px; min-width: 0; }
.stat span { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat b { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.tap { background: var(--bg); }
.stat.tap:active { opacity: .7; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* grouped list */
.sec-head { display: flex; justify-content: space-between; align-items: baseline; margin: 26px 4px 8px; }
.sec-head h2 { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.sec-head span { color: var(--muted); font-size: 15px; }
.list { background: var(--card); border-radius: var(--r); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; min-height: 60px; position: relative; width: 100%; text-align: left; }
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 58px; height: 1px; background: var(--line); }
.row.plain + .row.plain::before { left: 14px; }
.row-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.row-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amt { font-size: 16px; font-weight: 500; white-space: nowrap; }
.row-amt.empty { color: var(--accent); font-weight: 500; font-size: 14px; }
.row.is-paid .row-title { color: var(--muted); }
.row.is-paid .row-amt { color: var(--muted); }
.row-edit { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; }
.check { width: 30px; height: 30px; flex: none; border-radius: 50%; border: 2px solid var(--faint); display: grid; place-items: center; transition: background .15s, border-color .15s; }
.check svg { width: 16px; height: 16px; color: #fff; opacity: 0; transition: opacity .15s; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on svg { opacity: 1; }
.cat-ico { width: 32px; height: 32px; flex: none; border-radius: 9px; display: grid; place-items: center; color: #fff; }
.cat-ico svg { width: 18px; height: 18px; }
.empty-note { padding: 18px 16px; color: var(--muted); font-size: 15px; text-align: center; }
.foot-note { color: var(--muted); font-size: 13px; margin: 8px 4px 0; line-height: 1.45; }

/* summary */
.cat-row { display: grid; grid-template-columns: 32px 1fr auto; gap: 4px 12px; align-items: center; padding: 12px 14px; position: relative; }
.cat-row + .cat-row::before { content: ""; position: absolute; top: 0; right: 0; left: 58px; height: 1px; background: var(--line); }
.cat-row .cat-ico { grid-row: span 2; }
.cat-bar { grid-column: 2 / 4; height: 6px; border-radius: 4px; background: var(--faint); overflow: hidden; }
.cat-bar i { display: block; height: 100%; border-radius: 4px; }
.cat-pct { color: var(--muted); font-size: 13px; margin-left: 6px; }
.mon-row { display: grid; gap: 8px; padding: 13px 14px; position: relative; width: 100%; text-align: left; }
.mon-row + .mon-row::before { content: ""; position: absolute; top: 0; right: 0; left: 14px; height: 1px; background: var(--line); }
.mon-top { display: flex; justify-content: space-between; gap: 10px; }
.mon-top b { font-weight: 600; }
.mon-top span { color: var(--muted); font-size: 14px; }
.mon-top .left { color: var(--accent); }
.mon-top .left.neg { color: var(--bad); }

/* empty month */
.start { background: var(--card); border-radius: 20px; padding: 28px 22px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.start h2 { margin: 0; font-size: 22px; }
.start p { margin: 0 0 8px; color: var(--muted); max-width: 34ch; }
.btn { background: var(--accent); color: #fff; font-weight: 600; border-radius: 12px; padding: 13px 18px; width: 100%; max-width: 320px; }
.btn:active { opacity: .8; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--bad); }

/* tab bar */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--bar-bg); backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line); display: flex; justify-content: center;
  padding: 6px max(16px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.tabs-in { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; max-width: 560px; }
.tab { display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 500; color: var(--muted); padding: 4px 0; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-selected="true"] { color: var(--accent); }

/* sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s ease; }
.sheet { position: relative; width: 100%; max-width: 560px; max-height: 92%; overflow-y: auto; background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 0 max(16px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); animation: up .28s cubic-bezier(.2,.9,.3,1); }
.sheet-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 14px 0; background: var(--bg); z-index: 1; }
.sheet-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.sheet-head button { color: var(--accent); font-size: 17px; min-width: 64px; }
.sheet-head .save { font-weight: 600; text-align: right; }
.sheet-head .save:disabled { opacity: .35; }
.field { display: flex; align-items: center; gap: 12px; padding: 0 14px; min-height: 50px; position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; right: 0; left: 14px; height: 1px; background: var(--line); }
.field label { width: 92px; flex: none; font-size: 16px; }
.field input, .field select { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; color: var(--fg); padding: 13px 0; text-align: right; appearance: none; -webkit-appearance: none; }
.field select { direction: rtl; color: var(--muted); }
.field input::placeholder { color: var(--muted); opacity: .7; }
.field input:focus-visible, .field select:focus-visible, .big-amount input:focus-visible { outline: none; }
.field input, .big-amount input { caret-color: var(--accent); }
.field:focus-within { background: color-mix(in srgb, var(--accent) 9%, var(--card)); }
.field:focus-within label { color: var(--accent); }
.big-amount { display: flex; align-items: baseline; justify-content: center; gap: 8px; padding: 18px 10px 22px; }
.big-amount span { color: var(--muted); font-size: 22px; font-weight: 600; }
.big-amount input { border: 0; background: transparent; font: 700 44px/1 var(--font-display); color: var(--fg); width: 2ch; max-width: 70%; text-align: left; letter-spacing: -.02em; padding: 0; }
.big-amount input::placeholder { color: var(--muted); opacity: .5; }
.switch { position: relative; width: 51px; height: 31px; flex: none; margin-left: auto; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 20px; background: var(--faint); transition: background .2s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.gap { height: 22px; }
.sheet .btn { max-width: none; }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 22px; font-size: 14px; font-weight: 500; z-index: 30; animation: fade .2s ease; white-space: nowrap; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* sign-in */
.auth { display: grid; gap: 18px; padding-top: 12vh; }
.auth-mark { width: 64px; height: 64px; border-radius: 16px; display: block; }
.auth h1 { margin: 0; }
.auth p { margin: 0; color: var(--muted); }
.auth .btn { max-width: none; }
.auth .switch-mode { color: var(--accent); font-size: 15px; justify-self: center; padding: 6px; }
.auth .err { color: var(--bad); font-size: 14px; margin: 0; }
.auth .field label { width: 84px; }
/* sync status */
.status { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--card); border-radius: 12px; padding: 4px 10px; display: inline-flex; align-items: center; gap: 6px; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: #e39b16; }
.loading { padding: 40vh 0 0; text-align: center; color: var(--muted); }

/* brand */
.brand { display: flex; align-items: center; gap: 12px; }
.auth-mark { width: 52px; height: 52px; border-radius: 13px; }
.wordmark { font-family: var(--font-display); font-size: 30px; font-weight: 800; letter-spacing: -.035em; }
.auth { padding-top: 9vh; }
.btn:disabled { opacity: .6; }
.auth .ok { color: var(--accent); font-size: 14px; margin: 0; font-weight: 500; }
