/* ============ FinPal design system ============ */
:root {
  --radius: 18px;
  --radius-sm: 12px;
  --emerald: #2ec27e;
  --emerald-2: #5ad19a;
  --gold: #ffc75f;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
[data-theme='dark'] {
  --bg: #0f1a16;
  --bg-2: #142320;
  --card: #182a25;
  --card-2: #21362f;
  --line: rgba(210, 255, 235, 0.09);
  --text: #ecf7f1;
  --text-dim: #96b3a6;
  --chip-text: #10231c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --ok: #4cd7a5;
  --bad: #ff8a7a;
  --warn: #ffc75f;
}
[data-theme='light'] {
  --bg: #f2f6f1;
  --bg-2: #ffffff;
  --card: #ffffff;
  --card-2: #eaf2ea;
  --line: rgba(30, 60, 45, 0.12);
  --text: #21312a;
  --text-dim: #71887d;
  --chip-text: #ffffff;
  --shadow: 0 10px 30px rgba(50, 90, 70, 0.12);
  --ok: #14a06e;
  --bad: #e05a44;
  --warn: #c98a1b;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 1rem; color: var(--text); }
a { color: var(--emerald-2); font-weight: 700; text-decoration: none; }
.dim { color: var(--text-dim); font-weight: 500; }
.flex-spacer { flex: 1; }
[hidden] { display: none !important; }

input[type='text'], input[type='password'], input[type='date'], input[type='number'], select, textarea {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--bg-2);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--emerald); }
textarea { resize: vertical; min-height: 90px; }

.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--emerald-2), var(--emerald));
  color: #08251a;
  font-weight: 800;
  font-size: 1rem;
  box-shadow: 0 6px 18px rgba(46, 194, 126, 0.35);
  transition: transform 0.12s, filter 0.12s;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-ghost {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  color: var(--text-dim);
  font-weight: 700;
  background: transparent;
}
.btn-ghost:hover { border-color: var(--emerald); color: var(--text); }
.btn-ghost.small { padding: 8px 12px; font-size: 0.85rem; }
.btn-danger {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  color: var(--bad);
  border: 1.5px solid var(--bad);
  font-weight: 700;
}

/* ============ Login ============ */
.screen { min-height: 100dvh; }
#login-screen {
  display: grid;
  place-items: center;
  padding: 24px 16px 48px;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(46, 194, 126, 0.14), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(255, 199, 95, 0.10), transparent 60%),
    var(--bg);
}
.login-card { width: 100%; max-width: 440px; }
.logo { text-align: center; margin-bottom: 30px; }
.logo-coin { width: 74px; height: 74px; filter: drop-shadow(0 8px 16px rgba(46, 194, 126, 0.35)); }
.logo-coin.small { width: 34px; height: 34px; filter: none; }
.logo h1 {
  font-size: 2.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--emerald-2), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--text-dim); margin-top: 4px; font-weight: 600; }

.login-step { display: grid; gap: 12px; }
.field-label { font-size: 0.85rem; font-weight: 700; color: var(--text-dim); }
.field-label.centered { text-align: center; }
.login-alt { text-align: center; color: var(--text-dim); font-size: 0.92rem; }
.login-error {
  margin-top: 12px;
  text-align: center;
  color: var(--bad);
  font-weight: 700;
  font-size: 0.92rem;
}
.register-title { font-size: 1.3rem; }

.pin-greeting { text-align: center; font-size: 1.05rem; }
.pin-dots { display: flex; justify-content: center; gap: 10px; margin: 6px 0 10px; }
.pin-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--text-dim);
  transition: background 0.12s, border-color 0.12s;
}
.pin-dot.filled { background: var(--emerald); border-color: var(--emerald); }
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 280px;
  margin: 0 auto;
}
.pin-pad button {
  padding: 16px 0;
  font-size: 1.35rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 1.5px solid var(--line);
  transition: background 0.1s, transform 0.08s;
}
.pin-pad button:active { transform: scale(0.94); background: var(--card-2); }
.pin-pad .pad-aux { color: var(--text-dim); font-size: 1.1rem; }

.reg-member-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.reg-color { width: 34px; height: 34px; min-width: 34px; border-radius: 50%; border: 2px solid var(--line); }
.reg-remove { color: var(--text-dim); font-size: 1rem; padding: 6px; }

.trust-note { margin-top: 26px; text-align: center; }
.trust-headline { font-size: 0.9rem; font-weight: 700; color: var(--text-dim); }
.trust-details { margin-top: 8px; font-size: 0.85rem; color: var(--text-dim); }
.trust-details summary { cursor: pointer; font-weight: 700; }
.trust-details ul { text-align: left; margin: 10px 0 0 18px; display: grid; gap: 6px; }

/* ============ App shell ============ */
#app-screen { display: flex; min-height: 100dvh; }
.sidebar {
  width: 230px;
  min-width: 230px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 14px;
  border-right: 1.5px solid var(--line);
  background: var(--bg-2);
  position: sticky;
  top: 0;
  height: 100dvh;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.side-title { font-weight: 800; font-size: 1.15rem; }
.side-nav { display: grid; gap: 4px; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  color: var(--text-dim);
  text-align: left;
}
.nav-btn:hover { background: var(--card); color: var(--text); }
.nav-btn.active { background: var(--card-2); color: var(--text); }
.nav-ico { font-size: 1.1rem; }
.side-footer { margin-top: auto; display: grid; gap: 10px; }
.side-family { font-size: 0.85rem; color: var(--text-dim); font-weight: 700; padding: 0 8px; }

.main { flex: 1; padding: 26px clamp(16px, 4vw, 42px) 96px; max-width: 1060px; }

.tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-2);
  border-top: 1.5px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
  padding: 6px 0;
  border-radius: var(--radius-sm);
}
.tab-btn span { font-size: 1.25rem; }
.tab-btn.active { color: var(--emerald-2); }

.fab {
  position: fixed;
  right: 22px;
  bottom: 86px;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--emerald-2), var(--emerald));
  color: #08251a;
  font-size: 1.7rem;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(46, 194, 126, 0.45);
  z-index: 41;
}

@media (max-width: 760px) {
  .sidebar { display: none; }
  .tabbar { display: flex; }
  .main { padding-top: 18px; }
}
@media (min-width: 761px) {
  .fab { bottom: 32px; }
}

/* ============ Shared view pieces ============ */
.view-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.view-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.01em; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 7px;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip.active { background: var(--card-2); color: var(--text); border-color: var(--emerald); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.tile-label { font-size: 0.78rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font-size: 1.55rem; font-weight: 800; margin-top: 4px; letter-spacing: -0.01em; }
.tile-sub { font-size: 0.8rem; color: var(--text-dim); font-weight: 600; margin-top: 2px; }
.tile-value.bad { color: var(--bad); }
.tile-value.ok { color: var(--ok); }

.section-title { font-size: 1.05rem; font-weight: 800; margin: 22px 0 10px; }
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 16px;
  background: var(--card);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  font-weight: 600;
}
.empty .big { font-size: 2rem; display: block; margin-bottom: 8px; }

.month-nav { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.month-nav button { padding: 6px 12px; border-radius: var(--radius-sm); border: 1.5px solid var(--line); font-weight: 800; }
.month-nav .month-label { font-weight: 800; min-width: 120px; text-align: center; }

/* ============ Debt view ============ */
.card-list { display: grid; gap: 10px; }
.debt-card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: grid;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}
.debt-card:hover { border-color: var(--emerald); }
.debt-card:active { transform: scale(0.995); }
.debt-card-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.debt-card-name { font-weight: 800; font-size: 1.02rem; display: flex; align-items: center; gap: 8px; }
.debt-card-name .dot { width: 10px; height: 10px; border-radius: 50%; }
.debt-card-issuer { color: var(--text-dim); font-size: 0.85rem; font-weight: 600; }
.debt-card-balance { margin-left: auto; font-weight: 800; font-size: 1.25rem; }
.debt-card-balance.owed { color: var(--bad); }
.util-bar { height: 8px; border-radius: 6px; background: var(--card-2); overflow: hidden; }
.util-fill { height: 100%; border-radius: 6px; background: var(--emerald); }
.util-fill.warn { background: var(--warn); }
.util-fill.bad { background: var(--bad); }
.debt-card-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.meta-chip {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--card-2);
  padding: 4px 10px;
  border-radius: 999px;
}
.meta-chip.warn { color: var(--warn); }
.meta-chip.bad { color: var(--bad); }
.meta-chip.ok { color: var(--ok); }

.insight {
  background: linear-gradient(135deg, rgba(46, 194, 126, 0.12), rgba(255, 199, 95, 0.08));
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 20px;
}
.insight strong { color: var(--emerald-2); }

/* ============ Spending view ============ */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 130px; padding: 4px 2px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-val { font-size: 0.66rem; font-weight: 700; color: var(--text-dim); }
.bar { width: 100%; max-width: 54px; border-radius: 8px 8px 3px 3px; background: var(--card-2); min-height: 3px; }
.bar.current { background: linear-gradient(180deg, var(--emerald-2), var(--emerald)); }
.bar-label { font-size: 0.72rem; font-weight: 700; color: var(--text-dim); }

.cat-list, .merch-list { display: grid; gap: 8px; }
.cat-row { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; }
.cat-emoji { font-size: 1.1rem; }
.cat-name { font-weight: 700; font-size: 0.92rem; }
.cat-track { height: 6px; border-radius: 4px; background: var(--card-2); margin-top: 5px; overflow: hidden; }
.cat-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--emerald-2), var(--emerald)); }
.cat-amt { font-weight: 800; font-size: 0.95rem; white-space: nowrap; }
.cat-pct { font-size: 0.75rem; color: var(--text-dim); font-weight: 700; text-align: right; }

.txn-list { display: grid; gap: 6px; }
.txn-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.txn-desc { font-weight: 700; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-sub { font-size: 0.75rem; color: var(--text-dim); font-weight: 600; }
.txn-amt { font-weight: 800; white-space: nowrap; }
.txn-amt.in { color: var(--ok); }
.txn-del { color: var(--text-dim); padding: 4px 8px; font-size: 0.9rem; border-radius: 8px; }
.txn-del:hover { color: var(--bad); }
.show-more { margin: 10px auto 0; display: block; }

/* ============ Subscriptions view ============ */
.sub-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.sub-name { font-weight: 800; font-size: 0.98rem; }
.sub-meta { font-size: 0.78rem; color: var(--text-dim); font-weight: 600; margin-top: 2px; }
.sub-cost { text-align: right; }
.sub-monthly { font-weight: 800; font-size: 1.05rem; }
.sub-cadence { font-size: 0.75rem; color: var(--text-dim); font-weight: 700; }
.sub-ignore { color: var(--text-dim); font-size: 0.75rem; font-weight: 700; padding: 4px 8px; }
.sub-ignore:hover { color: var(--bad); }

/* ============ Settings ============ */
.settings-card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  display: grid;
  gap: 12px;
}
.settings-card h3 { font-size: 1.02rem; }
.settings-note { font-size: 0.85rem; color: var(--text-dim); font-weight: 600; line-height: 1.5; }
.member-row { display: flex; align-items: center; gap: 10px; }
.member-dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: var(--chip-text); font-size: 0.85rem; }
.member-name { font-weight: 700; }
.conn-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg-2); border-radius: var(--radius-sm); border: 1.5px solid var(--line); }
.conn-info { flex: 1; }
.conn-org { font-weight: 700; font-size: 0.92rem; }
.conn-meta { font-size: 0.75rem; color: var(--text-dim); font-weight: 600; }
.conn-meta.err { color: var(--bad); }
.settings-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.settings-actions .btn-ghost, .settings-actions .btn-danger { flex: 0 0 auto; }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 60;
  backdrop-filter: blur(3px);
}
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px; }
.modal-head h2 { font-size: 1.2rem; }
.modal-close { color: var(--text-dim); font-size: 1.1rem; padding: 6px 10px; }
.modal-body { padding: 10px 20px; overflow-y: auto; display: grid; gap: 12px; }
.modal-foot { display: flex; gap: 10px; padding: 14px 20px 18px; align-items: center; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-col { display: grid; gap: 6px; }
.hint { font-size: 0.8rem; color: var(--text-dim); font-weight: 600; }

.member-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.member-picker button {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.member-picker button.active { border-color: var(--emerald); color: var(--text); background: var(--card-2); }
.member-picker .dot { width: 10px; height: 10px; border-radius: 50%; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  padding: 9px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.seg button.active { border-color: var(--emerald); color: var(--text); background: var(--card-2); }

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-2);
  border: 1.5px solid var(--line);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 80;
  max-width: 90vw;
  text-align: center;
}
