/* Cashpot — mobile-first, dark by default, iOS system font. */

:root {
  color-scheme: dark;
  --bg: #000000;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f2f2f7;
  --text-2: #c7c7cc;
  --muted: #8e8e93;
  --accent: #30d158;
  --accent-ink: #00230b;
  --accent-soft: rgba(48, 209, 88, 0.16);
  --good: #30d158;
  --warn: #ffd60a;
  --bad: #ff453a;
  --info: #64d2ff;
  --track: #2c2c2e;
  --key: #2c2c2e;
  --key-active: #48484a;
  /* chart series (dark steps) — fixed order = category order */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #0ca30c;

  --radius: 18px;
  --tab-h: 58px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #e5e5ea;
  --line: rgba(0, 0, 0, 0.08);
  --text: #0b0b0b;
  --text-2: #3a3a3c;
  --muted: #6c6c70;
  --accent: #1f9d43;
  --accent-ink: #ffffff;
  --accent-soft: rgba(31, 157, 67, 0.12);
  --good: #1f8f3d;
  --warn: #b37400;
  --bad: #d70015;
  --info: #0071a4;
  --track: #e5e5ea;
  --key: #ffffff;
  --key-active: #d1d1d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
}

@media (prefers-color-scheme: light) {
  :root[data-theme='system'] {
    color-scheme: light;
    --bg: #f2f2f7;
    --card: #ffffff;
    --card-2: #e5e5ea;
    --line: rgba(0, 0, 0, 0.08);
    --text: #0b0b0b;
    --text-2: #3a3a3c;
    --muted: #6c6c70;
    --accent: #1f9d43;
    --accent-ink: #ffffff;
    --accent-soft: rgba(31, 157, 67, 0.12);
    --good: #1f8f3d;
    --warn: #b37400;
    --bad: #d70015;
    --info: #0071a4;
    --track: #e5e5ea;
    --key: #ffffff;
    --key-active: #d1d1d6;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --series-6: #008300;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  touch-action: manipulation;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: 0.3; cursor: default; }
h1, h2, h3, h4, p { margin: 0; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px)
    calc(var(--safe-b) + var(--tab-h) + 96px) calc(var(--safe-l) + 16px);
}
.view { display: flex; flex-direction: column; gap: 12px; animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0.4; } to { opacity: 1; } }

.page-head { padding: 8px 4px 4px; }
.page-head h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.center { text-align: center; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 4px; }
.hint.warn { color: var(--warn); }
.empty { color: var(--muted); text-align: center; padding: 20px 0 8px; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card h3 { font-size: 17px; font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row-card { flex-direction: row; align-items: center; justify-content: space-between; cursor: pointer; }
.row-card .big { font-size: 22px; white-space: nowrap; }

.hero { text-align: center; padding: 22px 16px 18px; gap: 6px; }
.hero .label { color: var(--text-2); font-size: 15px; }
.hero-num {
  font-size: clamp(48px, 15vw, 64px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--accent);
}
.hero.over .hero-num { color: var(--bad); }
.hero-break {
  display: flex; justify-content: center; gap: 14px; flex-wrap: wrap;
  margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.hero-break b { color: var(--text-2); font-weight: 600; }

.welcome { background: var(--accent-soft); }
.welcome p { color: var(--text-2); font-size: 15px; }

.banner {
  background: var(--card-2); border-radius: 14px; padding: 12px 14px; text-align: left; font-size: 14px;
}

/* progress bars */
.bar { height: 10px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--info); transition: width 0.3s; }
.bar.good > span { background: var(--good); }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }

.status { font-size: 14px; padding: 10px 12px; border-radius: 12px; background: var(--card-2); }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }
.status.info { color: var(--text-2); }

.bill-list, .tx-list, .pot-list, .legend { list-style: none; margin: 0; padding: 0; }
.bill-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.pot-list li { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }

.goal-num { font-size: 28px; letter-spacing: -0.02em; }
.goal-num .muted { font-size: 17px; }

/* ---------- buttons ---------- */
.btn {
  min-height: 50px; padding: 0 18px; border-radius: 14px;
  background: var(--card-2); font-weight: 600; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform 0.08s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14px; border-radius: 11px; align-self: flex-start; }
.bill-list .btn.small { align-self: center; flex-shrink: 0; }
.link { color: var(--accent); font-weight: 600; font-size: 15px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; background: var(--card-2);
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0;
}
.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.action-row .btn { min-height: 56px; background: var(--card); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn-row.stack { flex-direction: column; }
.btn-row:empty { display: none; }

.fab {
  position: fixed; z-index: 20;
  right: calc(var(--safe-r) + 20px);
  bottom: calc(var(--safe-b) + var(--tab-h) + 18px);
  width: 68px; height: 68px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-size: 40px; font-weight: 400; line-height: 1;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s;
}
.fab:active { transform: scale(0.92); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px calc(var(--safe-r) + 6px) calc(var(--safe-b) + 4px) calc(var(--safe-l) + 6px);
  background: color-mix(in srgb, var(--card) 82%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  backdrop-filter: blur(20px) saturate(1.6);
  border-top: 1px solid var(--line);
}
.tabbar button {
  height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 11px; font-weight: 500; color: var(--muted);
}
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--accent); }
.tab-add .plus {
  width: 44px; height: 32px; border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font-size: 26px; line-height: 32px; font-weight: 500;
}

/* ---------- sheets ---------- */
.sheet-root { position: fixed; inset: 0; z-index: 50; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); opacity: 0; transition: opacity 0.25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  max-height: calc(100dvh - var(--safe-t) - 12px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 24px 24px 0 0;
  padding: 6px calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  display: flex; flex-direction: column; gap: 12px;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
}
:root[data-theme='dark'] .sheet { background: #1c1c1e; }
.sheet-root.show .backdrop { opacity: 1; }
.sheet-root.show .sheet { transform: translateY(0); }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--card-2); margin: 4px auto 0; flex-shrink: 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { font-size: 20px; font-weight: 700; }
.sheet .sub { color: var(--text-2); font-size: 14px; }

.amount-display {
  text-align: center; font-size: 52px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1;
  padding: 4px 0; font-variant-numeric: tabular-nums;
}
.amount-display.empty { color: var(--muted); }
.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.meta-row { display: flex; gap: 8px; }
.chip-input {
  min-height: 42px; padding: 0 12px; border-radius: 12px; border: 0;
  background: var(--card-2); font-size: 16px; /* 16px stops iOS zooming */
}
.chip-input.grow { flex: 1; min-width: 0; }
.chip-input.full { width: 100%; }
input[type='date'].chip-input { flex-shrink: 0; min-width: 0; max-width: 46%; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  height: 54px; border-radius: 14px; background: var(--key); font-size: 26px; font-weight: 500;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
.key:active { background: var(--key-active); }

.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat {
  min-height: 66px; border-radius: 14px; background: var(--card-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; font-weight: 600; border: 2px solid transparent;
}
.cat-icon { font-size: 24px; line-height: 1; }
.cat.selected { border-color: var(--accent); background: var(--accent-soft); }
.cat:active { transform: scale(0.96); }

.split-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 14px; }
.split-preview .hint { grid-column: 1 / -1; }
.split-item { display: flex; justify-content: space-between; color: var(--text-2); }
.split-item b { color: var(--text); font-variant-numeric: tabular-nums; }

.segmented { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; }
.view > .segmented { background: var(--card); }
.segmented button { flex: 1; min-height: 38px; border-radius: 10px; font-size: 15px; font-weight: 600; color: var(--muted); }
.segmented button.on { background: var(--key-active); color: var(--text); }
:root[data-theme='light'] .segmented button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.gap-readout { text-align: center; font-weight: 600; min-height: 22px; }
.mini-list h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.mini-row { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; font-size: 14px; padding: 6px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; cursor: pointer; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 51px; height: 31px; border-radius: 99px; background: var(--card-2); position: relative; flex-shrink: 0; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,.3); }
.toggle-row input:checked + .switch { background: var(--good); }
.toggle-row input:checked + .switch::after { transform: translateX(20px); }
.toggle-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-2); }
.form input, .field-row input, .field-row select, .bill-edit input {
  min-height: 46px; padding: 0 12px; border-radius: 12px; border: 0; background: var(--card-2); font-size: 16px; width: 100%;
}
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; }
.field-row input { width: 96px; text-align: right; }
.field-row select { width: auto; max-width: 150px; }
.bill-edit, .bill-edit-head { display: grid; grid-template-columns: 1fr 84px 64px 36px; gap: 8px; align-items: center; }
.bill-edit input[name='amount'], .bill-edit input[name='dueDay'] { text-align: right; }

/* ---------- history ---------- */
.period-nav { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.period-nav .icon-btn { width: 44px; height: 44px; font-size: 24px; background: var(--card); }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.totals div { display: flex; flex-direction: column; }
.totals b { font-size: 24px; letter-spacing: -0.02em; }

.chart-wrap { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.donut-box { position: relative; width: 200px; height: 200px; }
.donut { width: 100%; height: 100%; }
.arc { transition: opacity 0.2s; cursor: pointer; }
.arc.dim { opacity: 0.25; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center b { font-size: 22px; }
.legend { width: 100%; }
.legend li {
  display: grid; grid-template-columns: 12px 1fr auto 42px; gap: 10px; align-items: center;
  padding: 10px 6px; border-top: 1px solid var(--line); cursor: pointer; border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.legend li.on { background: var(--card-2); }
.swatch { width: 12px; height: 12px; border-radius: 4px; }
.lg-pct { text-align: right; font-size: 13px; }

.day-head { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; color: var(--text-2); padding: 8px 6px 0; }
.tx-list.card { padding: 4px 16px; gap: 0; }
.tx { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.tx-list .tx:first-child { border-top: 0; }
.tx-icon { font-size: 22px; text-align: center; }
.tx-main { display: flex; flex-direction: column; min-width: 0; }
.tx-main b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 60; left: 16px; right: 16px; max-width: 520px; margin: 0 auto;
  bottom: calc(var(--safe-b) + var(--tab-h) + 22px);
  background: #f2f2f7; color: #0b0b0b; border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 15px; font-weight: 500; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0; transform: translateY(10px); transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-action { color: #1f7a38; font-weight: 700; padding: 6px 4px; }
:root[data-theme='light'] .toast { background: #1c1c1e; color: #f2f2f7; }
:root[data-theme='light'] .toast-action { color: #30d158; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
