/* ============ Fintracker ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f4f1;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, #ffffff 0%, #f4f4f1 60%);
  --surface: #ffffff;
  --surface-2: #fbfbf9;
  --line: #e7e6e1;
  --line-strong: #d8d7d1;
  --ink: #16181d;
  --ink-2: #3f434c;
  --muted: #83868f;
  --accent: #0f7a52;
  --accent-ink: #0a5c3e;
  --accent-soft: #e5f2ec;
  --warn: #c0492f;
  --warn-soft: #f8e8e3;
  --gold: #9a7b2e;
  --shadow-sm: 0 1px 2px rgba(20,24,29,.06), 0 1px 3px rgba(20,24,29,.04);
  --shadow-md: 0 2px 6px rgba(20,24,29,.06), 0 16px 40px -20px rgba(20,24,29,.28);
  --radius: 18px;
  --radius-sm: 12px;
  --maxw: 540px;
}

:root[data-theme="dark"] {
  --bg: #0e0f12;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, #1a1c20 0%, #0e0f12 60%);
  --surface: #17191d;
  --surface-2: #1c1f24;
  --line: #2a2d33;
  --line-strong: #363a41;
  --ink: #f2f3f5;
  --ink-2: #c7cad0;
  --muted: #8b8f98;
  --accent: #2fbd86;
  --accent-ink: #7ee0b7;
  --accent-soft: #143229;
  --warn: #e2725a;
  --warn-soft: #3a221c;
  --gold: #d9b866;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 2px 6px rgba(0,0,0,.35), 0 20px 48px -22px rgba(0,0,0,.7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f12;
    --bg-grad: radial-gradient(1200px 600px at 50% -10%, #1a1c20 0%, #0e0f12 60%);
    --surface: #17191d;
    --surface-2: #1c1f24;
    --line: #2a2d33;
    --line-strong: #363a41;
    --ink: #f2f3f5;
    --ink-2: #c7cad0;
    --muted: #8b8f98;
    --accent: #2fbd86;
    --accent-ink: #7ee0b7;
    --accent-soft: #143229;
    --warn: #e2725a;
    --warn-soft: #3a221c;
    --gold: #d9b866;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 2px 6px rgba(0,0,0,.35), 0 20px 48px -22px rgba(0,0,0,.7);
  }
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink);
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}
.num { font-family: 'Space Grotesk', 'Inter', sans-serif; font-feature-settings: "tnum" 1; letter-spacing: -0.01em; }

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* ---- shell ---- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 40;
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.brand svg { width: 22px; height: 22px; display: block; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm);
  font-size: 16px; transition: transform .12s ease;
}
.icon-btn:active { transform: scale(.94); }

/* ---- generic card ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 14px;
}
.panel.flush { padding: 0; overflow: hidden; }
.section-label {
  font-size: 11px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}
.hint { font-size: 13px; color: var(--muted); }

/* ---- month strip ---- */
.monthstrip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 4px 2px 14px;
}
.monthstrip .m { font-weight: 650; font-size: 15px; }
.monthstrip .reset {
  font-size: 12px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.monthstrip .reset b { color: var(--ink-2); font-weight: 600; }
.nav-mini { display: flex; gap: 6px; }
.nav-mini button {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; color: var(--ink-2);
}
.nav-mini button:disabled { opacity: .35; }

/* ---- segmented ---- */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 4px; gap: 4px; margin-bottom: 16px;
}
.seg button {
  padding: 9px 6px; border-radius: 9px; font-size: 13px; font-weight: 550;
  color: var(--muted); transition: background .14s ease, color .14s ease;
  display: flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.2;
}
.seg button .sub { font-size: 10.5px; font-weight: 450; opacity: .75; }
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-sm); font-weight: 650;
}

/* ---- credit card visual ---- */
.cc {
  position: relative; border-radius: 16px; aspect-ratio: 1.585;
  color: #fff; padding: 16px 17px; overflow: hidden;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.45);
  display: flex; flex-direction: column; justify-content: space-between;
  isolation: isolate;
}
.cc::after {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(120% 120% at 15% 0%, rgba(255,255,255,.22), transparent 55%);
}
.cc .cc-top { display: flex; align-items: flex-start; justify-content: space-between; }
.cc .cc-issuer { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; opacity: .92; }
.cc .cc-emoji { font-size: 20px; filter: drop-shadow(0 1px 3px rgba(0,0,0,.3)); }
.cc .cc-chip {
  width: 34px; height: 25px; border-radius: 5px; margin: 2px 0 0;
  background: linear-gradient(135deg, #f7e6a8, #c9a94e);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}
.cc .cc-name { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; text-shadow: 0 1px 6px rgba(0,0,0,.28); }
.cc .cc-foot { display: flex; align-items: flex-end; justify-content: space-between; }
.cc .cc-network { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; opacity: .9; }
.cc.mini { aspect-ratio: auto; padding: 11px 12px; border-radius: 11px; gap: 8px; box-shadow: 0 6px 16px -8px rgba(0,0,0,.4); }
.cc.mini .cc-name { font-size: 12.5px; }
.cc.mini .cc-chip { width: 24px; height: 17px; }

/* ---- recommendation hero ---- */
.rec { margin-bottom: 14px; }
.rec-head {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 10px;
}
.rec-head .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.rec .cc { margin-bottom: 14px; }
.rec-stats { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.rec-rate { font-size: 26px; font-weight: 700; line-height: 1; white-space: nowrap; }
.rec-rate small { font-size: 12px; font-weight: 550; color: var(--muted); letter-spacing: 0; }
.rec-headroom { text-align: right; font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.rec-headroom b { display: block; font-weight: 650; font-size: 15px; color: var(--ink); }
.rec-line { font-size: 13px; color: var(--ink-2); }
.rec-line b { font-weight: 650; }
.rec-empty { text-align: center; padding: 22px 8px; color: var(--muted); }

.callout {
  margin-top: 12px; padding: 10px 12px; border-radius: 11px; font-size: 12.5px;
  background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 22%, transparent);
  display: flex; gap: 8px;
}
.callout.ok { background: var(--accent-soft); color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---- progress ---- */
.bar { height: 7px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .35s ease; }
.bar.warn > i { background: var(--warn); }
.bar.full > i { background: var(--warn); }
.bar.calm { background: var(--line); }
.bar.calm > i { background: var(--line-strong); }
.capline { display: flex; justify-content: space-between; font-size: 12px; margin-top: 7px; color: var(--muted); }
.capline b { color: var(--ink-2); font-weight: 600; }

/* ---- fallback chain ---- */
.chain { display: flex; flex-direction: column; gap: 8px; }
.chain-row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 11px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
}
.chain-row.dim { opacity: .55; }
.chain-row.pick { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); }
.chain-ico { font-size: 17px; width: 24px; text-align: center; flex: none; }
.chain-main { flex: 1; min-width: 0; }
.chain-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chain-sub { font-size: 11.5px; color: var(--muted); }
.chain-tag { font-size: 11px; font-weight: 650; padding: 3px 8px; border-radius: 99px; flex: none; }
.chain-tag.go { background: var(--accent); color: #fff; }
.chain-tag.left { background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink-2); }
.chain-tag.max { background: var(--warn-soft); color: var(--warn); }
.chain-tag.na { background: var(--surface); border: 1px solid var(--line); color: var(--muted); }

/* ---- forms ---- */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
label.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, .select, textarea.input {
  width: 100%; padding: 11px 12px; border-radius: 11px;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink);
  outline: none; transition: border-color .14s ease, box-shadow .14s ease;
}
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea.input { resize: vertical; min-height: 66px; line-height: 1.45; }
.amount-input {
  display: flex; align-items: center; gap: 4px;
  border: 1px solid var(--line-strong); background: var(--surface-2); border-radius: 13px;
  padding: 10px 14px; transition: border-color .14s ease, box-shadow .14s ease;
}
.amount-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.amount-input .cur { font-size: 18px; font-weight: 600; color: var(--muted); }
.amount-input input {
  border: none; background: none; outline: none; width: 100%;
  font-family: 'Space Grotesk', sans-serif; font-size: 30px; font-weight: 600; letter-spacing: -0.02em;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 8px 11px; border-radius: 10px; font-size: 12.5px; font-weight: 550;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px; transition: all .12s ease;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 650; }
.chip .em { font-size: 14px; }

.btn {
  width: 100%; padding: 13px; border-radius: 13px; font-weight: 650; font-size: 14.5px;
  background: var(--accent); color: #fff; box-shadow: var(--shadow-sm);
  transition: transform .1s ease, opacity .14s ease;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line-strong); box-shadow: none; }
.btn.danger { background: var(--warn); }
.btn.sm { width: auto; padding: 9px 14px; font-size: 13px; border-radius: 10px; }

/* ---- transaction list ---- */
.daygroup { margin-bottom: 4px; }
.dayhead {
  font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 14px 4px 8px;
}
.tx {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px;
  border-top: 1px solid var(--line); width: 100%; text-align: left;
}
.tx:first-child { border-top: none; }
.tx-em {
  width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center;
  font-size: 16px; background: var(--surface-2); border: 1px solid var(--line);
}
.tx-main { flex: 1; min-width: 0; }
.tx-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 11.5px; color: var(--muted); }
.tx-amt { font-weight: 650; font-size: 14px; flex: none; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; }

/* ---- summary tiles ---- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; box-shadow: var(--shadow-sm); }
.tile .k { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 700; margin-top: 3px; }
.tile .v small { font-size: 12px; color: var(--muted); font-weight: 550; }

/* ---- card manage rows ---- */
.mcard { margin-bottom: 14px; }
.mcard-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.mcard-head .cc.mini { flex: 1; }
.mcard-body { display: none; }
.mcard.open .mcard-body { display: block; }
.disc { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.checkline { display: flex; gap: 14px; flex-wrap: wrap; }
.checkline label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.swatch-row { display: flex; gap: 8px; align-items: center; }
.swatch-row input[type=color] { width: 40px; height: 34px; border: 1px solid var(--line-strong); border-radius: 8px; background: none; padding: 2px; }
.inactive-badge { font-size: 10.5px; font-weight: 650; padding: 2px 7px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); }

/* ---- bottom nav ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; justify-content: center;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar-inner { display: flex; gap: 4px; max-width: var(--maxw); width: 100%; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 4px; border-radius: 11px; font-size: 10.5px; font-weight: 600; color: var(--muted);
}
.tab svg { width: 21px; height: 21px; }
.tab[aria-current="page"] { color: var(--accent-ink); background: var(--accent-soft); }

/* ---- modal ---- */
.scrim {
  position: fixed; inset: 0; z-index: 60; background: rgba(10,12,14,.42);
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px); animation: fade .16s ease;
}
.sheet {
  background: var(--surface); width: 100%; max-width: var(--maxw);
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-md); animation: rise .22s cubic-bezier(.2,.8,.2,1);
  max-height: 90vh; overflow-y: auto;
}
.sheet h3 { font-size: 17px; font-weight: 700; margin-bottom: 14px; letter-spacing: -0.01em; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px;
  font-size: 13px; font-weight: 550; z-index: 80; box-shadow: var(--shadow-md);
  animation: rise .2s ease;
}

@media (min-width: 480px) {
  .rec .cc { max-width: 340px; }
}
