/* ── TOKENS ────────────────────────────────────────────────── */
:root {
  --bg:       #0c0c10;
  --surface:  #16161e;
  --surface2: #1e1e28;
  --surface3: #262632;
  --border:   #2a2a38;
  --accent:   #6c63ff;
  --accent-glow: rgba(108,99,255,0.25);
  --green:  #51cf66;
  --red:    #ff6b6b;
  --yellow: #ffd43b;
  --orange: #ff922b;
  --text:  #e8e8f2;
  --text2: #a0a0c0;
  --muted: #606080;
  --radius:    18px;
  --radius-sm: 14px;
  --radius-xs: 10px;
  --nav-h: 70px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --c-bills:         #a78bfa;
  --c-groceries:     #f9a8d4;
  --c-subscriptions: #6ee7b7;
  --c-savings:       #fde68a;
  --c-adhoc:         #7dd3fc;
  --c-misc:          #c4b5fd;
  --starling-bg1: #160d2a;
  --starling-bg2: #1f1240;
  --starling-border: rgba(105,53,211,0.55);
  --monzo-bg1: #1c0a08;
  --monzo-bg2: #2a100e;
  --monzo-border: rgba(255,80,64,0.45);
}

/* ── RESET ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

html { font-size: 18px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  padding-top: 32px;
}

/* ── GITHUB BANNER ─────────────────────────────────────────── */
.github-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 500;
  background: linear-gradient(90deg, #24292e 0%, #2d333b 100%);
  border-bottom: 1px solid #444c56;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 7px 16px; font-size: 12px; font-weight: 600;
  color: #e6edf3; letter-spacing: 0.3px;
}
.github-banner svg { width: 16px; height: 16px; fill: #e6edf3; flex-shrink: 0; }
.github-banner span { opacity: 0.55; font-weight: 400; margin-left: 4px; }

/* ── LOGIN ─────────────────────────────────────────────────── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 32px); padding: 24px;
}
.login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px 24px; width: 100%; max-width: 360px;
}
.login-box h1 { font-size: 26px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.5px; }
.login-box p { color: var(--text2); font-size: 14px; margin-bottom: 24px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ── APP SHELL ─────────────────────────────────────────────── */
#app { display: none; }

/* ── PAGES ─────────────────────────────────────────────────── */
.page {
  display: none; width: 100%;
  padding: 20px 16px calc(var(--nav-h) + 24px);
  animation: fadeUp 0.2s ease;
}
.page.active { display: block; }
@keyframes fadeUp { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }

/* ── NAV ───────────────────────────────────────────────────── */
nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(12,12,16,0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; padding: 10px 4px 8px;
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-family: var(--font);
  font-size: 12px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: color 0.15s; position: relative;
}
.nav-btn.active { color: var(--accent); }
.nav-btn.active::before {
  content: ''; position: absolute; top: 0; left: 20%; right: 20%;
  height: 2px; background: var(--accent); border-radius: 0 0 3px 3px;
}
.nav-btn svg { width: 28px; height: 28px; stroke-width: 1.7; }

/* ── TYPOGRAPHY ────────────────────────────────────────────── */
.page-header { margin-bottom: 20px; padding-top: 6px; }
.page-header h1 { font-size: 32px; font-weight: 700; line-height: 1.1; letter-spacing: -0.5px; margin-bottom: 3px; }
.page-header p { color: var(--text2); font-size: 16px; }
.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--muted); margin: 22px 0 10px;
}
.bills-subheading {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted);
  padding: 14px 0 10px; border-top: 1px solid var(--border); margin-top: 2px;
}
.bills-subheading:first-child { border-top: none; margin-top: 0; padding-top: 0; }

/* ── CARDS ─────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 16px; margin-bottom: 12px; }

/* ── BUDGET HEADER ─────────────────────────────────────────── */
.budget-header-row {
  display: flex; align-items: flex-start;
  justify-content: space-between; margin-bottom: 18px; padding-top: 6px; gap: 10px;
}
.budget-header-row .header-text h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.1; }
.budget-header-row .header-text p { color: var(--text2); font-size: 15px; margin-top: 2px; }
.btn-save-new {
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius-sm); padding: 12px 16px;
  font-family: var(--font); font-size: 15px; font-weight: 700;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  box-shadow: 0 4px 16px var(--accent-glow);
  display: flex; align-items: center; gap: 7px;
}
.btn-save-new:active { transform: scale(0.97); }

/* ── DATE BAR ──────────────────────────────────────────────── */
.date-bar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.date-bar .dates { font-size: 19px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.date-bar .arrow { color: var(--muted); font-size: 13px; }

/* ── INCOME CARD ───────────────────────────────────────────── */
.income-card {
  background: linear-gradient(135deg, #1a1838 0%, #0f1020 100%);
  border: 1px solid rgba(108,99,255,0.28);
  border-radius: var(--radius); padding: 20px 18px; margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.income-card .ic-left .label { font-size: 11px; font-weight: 700; color: var(--text2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.8px; }
.income-card .ic-left .value { font-size: 46px; font-weight: 700; letter-spacing: -1.5px; line-height: 1; }
.income-card .ic-left .value span { font-size: 55%; opacity: 0.45; margin-right: 2px; font-weight: 400; }

/* ── BUTTONS ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 15px 20px; border: none;
  border-radius: var(--radius-sm); font-family: var(--font);
  font-weight: 700; font-size: 17px; cursor: pointer; transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: white; box-shadow: 0 4px 20px var(--accent-glow); }
.btn-primary:active { transform: scale(0.97); opacity: 0.9; }
.btn-danger { background: rgba(255,107,107,0.1); color: var(--red); border: 1px solid rgba(255,107,107,0.3); }
.btn-success { background: rgba(81,207,102,0.1); color: var(--green); border: 1px solid rgba(81,207,102,0.3); }
.btn-sm { padding: 10px 16px; font-size: 14px; border-radius: var(--radius-xs); }
.btn-ghost {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text2); border-radius: var(--radius-xs);
  padding: 10px 16px; font-family: var(--font);
  font-size: 14px; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: all 0.15s;
}
.btn-ghost:active { border-color: var(--accent); color: var(--accent); }
.btn-row { display: flex; gap: 8px; margin-bottom: 10px; }
.btn-row .btn { flex: 1; }

/* ── BILL ROWS ─────────────────────────────────────────────── */
.bill-row { display: flex; align-items: center; gap: 12px; padding: 15px 0; border-bottom: 1px solid var(--border); }
.bill-row:last-child { border-bottom: none; }
.space-pip { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.bill-info { flex: 1; min-width: 0; }
.bill-name { font-weight: 600; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bill-meta { font-size: 14px; color: var(--muted); margin-top: 3px; }
.bill-amounts { text-align: right; flex-shrink: 0; }
.bill-amounts .amt { font-weight: 700; font-size: 19px; }
.bill-amounts .var { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bill-edit-btn {
  background: var(--surface3); border: 1px solid var(--border);
  color: var(--text2); border-radius: var(--radius-xs);
  padding: 9px 14px; font-size: 13px; font-family: var(--font);
  font-weight: 600; cursor: pointer; flex-shrink: 0; white-space: nowrap;
}
.bill-edit-btn:active { border-color: var(--accent); color: var(--accent); }

/* ── MANAGE ROWS ───────────────────────────────────────────── */
.manage-row { display: flex; align-items: center; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.manage-row:last-child { border-bottom: none; }
.manage-info { flex: 1; }
.manage-name { font-weight: 600; font-size: 18px; }
.manage-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.manage-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.manage-amount { font-weight: 800; font-size: 21px; letter-spacing: -0.5px; }
.manage-amount-var { font-size: 12px; color: var(--muted); }

/* ── ACCOUNT CARDS ─────────────────────────────────────────── */
.acc-card { border-radius: var(--radius); padding: 20px 18px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.acc-card.starling { background: linear-gradient(135deg, #0d1a24 0%, #0f2535 60%, #0a1e30 100%); border: 1px solid rgba(0,180,160,0.3); }
.acc-card.monzo    { background: linear-gradient(135deg, #0d1a24 0%, #0f2535 60%, #0a1e30 100%); border: 1px solid rgba(0,180,160,0.3); }
.acc-card.default  { background: var(--surface2); border: 1px solid var(--border); }
.acc-left { display: flex; align-items: center; gap: 16px; }
.acc-logo { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden; background: transparent; }
.acc-card.starling .acc-logo { background: #6935d3; padding: 6px; }
.acc-card.monzo    .acc-logo { background: transparent; padding: 4px; }
.acc-card.default  .acc-logo { background: rgba(255,255,255,0.06); }
.acc-logo svg, .acc-logo img { width: 100%; height: 100%; display: block; }
.acc-name { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 3px; }
.acc-card.starling .acc-name, .acc-card.monzo .acc-name { color: #ffffff; }
.acc-card.default  .acc-name { color: var(--text); }
.acc-right { text-align: right; }
.acc-main { font-size: 24px; font-weight: 700; }
.acc-var { font-size: 12px; opacity: 0.55; margin-top: 4px; }

/* ── POTS ──────────────────────────────────────────────────── */
.pot-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.pot-row:last-child { border-bottom: none; }
.pot-bar { width: 4px; height: 36px; border-radius: 4px; flex-shrink: 0; }
.pot-info { flex: 1; }
.pot-name { font-weight: 600; font-size: 16px; }
.pot-bank { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pot-amounts { text-align: right; }
.pot-main { font-weight: 700; font-size: 17px; }
.pot-var { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── TOTALS ────────────────────────────────────────────────── */
.totals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.total-cell { background: var(--surface2); border-radius: var(--radius-xs); padding: 12px 14px; }
.tc-label { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px; }
.tc-val { font-size: 22px; font-weight: 700; }
.tc-val.pos { color: var(--green); }
.tc-val.neg { color: var(--red); }
.month-type-row { display: flex; gap: 8px; }
.mt-badge { flex: 1; text-align: center; padding: 10px; border-radius: var(--radius-xs); font-size: 12px; font-weight: 700; letter-spacing: 0.5px; }
.mt-badge.HIGH     { background: rgba(81,207,102,0.12);  color: var(--green);  border: 1px solid rgba(81,207,102,0.25); }
.mt-badge.AVERAGE  { background: rgba(255,212,59,0.12);  color: var(--yellow); border: 1px solid rgba(255,212,59,0.25); }
.mt-badge.LOW      { background: rgba(255,146,43,0.12);  color: var(--orange); border: 1px solid rgba(255,146,43,0.25); }
.mt-badge.NEGATIVE { background: rgba(255,107,107,0.12); color: var(--red);    border: 1px solid rgba(255,107,107,0.25); }

/* ── BADGE ─────────────────────────────────────────────────── */
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.badge.Active    { background: rgba(81,207,102,0.12); color: var(--green); }
.badge.Inactive  { background: rgba(255,146,43,0.12); color: var(--orange); }
.badge.Cancelled { background: rgba(255,107,107,0.12); color: var(--red); }
.badge.oneoff    { background: rgba(108,99,255,0.12); color: var(--accent); }

/* ── FAB ───────────────────────────────────────────────────── */
.fab {
  position: fixed; bottom: calc(var(--nav-h) + 14px); right: 16px;
  width: 58px; height: 58px; background: var(--accent); color: white;
  border: none; border-radius: 50%; font-size: 26px; cursor: pointer;
  box-shadow: 0 4px 24px var(--accent-glow);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s; z-index: 99;
}
.fab:active { transform: scale(0.92); }

/* ── MODAL ─────────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 200; align-items: flex-end; justify-content: center; }
.modal-overlay.open { display: flex; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.modal {
  background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 24px 18px 20px;
  padding-bottom: max(28px, calc(env(safe-area-inset-bottom) + 20px));
  width: 100%; max-height: 92vh; overflow-y: auto;
  animation: slideUp 0.26s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-handle { width: 38px; height: 4px; background: var(--border); border-radius: 4px; margin: 0 auto 20px; }
.modal h2 { font-size: 22px; font-weight: 700; margin-bottom: 18px; letter-spacing: -0.3px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* ── FORMS ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.8px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  padding: 15px 16px; font-family: var(--font); font-size: 17px;
  transition: border-color 0.15s; -webkit-appearance: none; font-weight: 500;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr; gap: 0; }

/* ── LOADING / EMPTY / TOAST ───────────────────────────────── */
.loading { display: flex; align-items: center; justify-content: center; padding: 60px 20px; color: var(--muted); gap: 12px; font-size: 15px; font-weight: 500; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); font-size: 15px; line-height: 1.6; }
.toast { position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%) translateY(8px); background: var(--surface2); border: 1px solid var(--border); border-radius: 24px; padding: 11px 20px; font-size: 14px; font-weight: 600; opacity: 0; transition: all 0.22s; z-index: 400; white-space: nowrap; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red);   color: var(--red); }

/* ── HISTORY ───────────────────────────────────────────────── */
.history-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.history-header { padding: 16px 14px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.history-header:active { background: var(--surface2); }
.history-dates { font-size: 18px; font-weight: 700; letter-spacing: -0.2px; }
.history-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.history-chevron { color: var(--muted); font-size: 12px; transition: transform 0.2s; }
.history-chevron.open { transform: rotate(180deg); }
.history-body { display: none; border-top: 1px solid var(--border); }
.history-body.open { display: block; }
.history-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); }
.hs-cell { background: var(--surface2); border-radius: var(--radius-xs); padding: 11px 12px; }
.hs-label { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.hs-val { font-size: 18px; font-weight: 700; }
.hs-val.neg { color: var(--red); }
.hs-val.pos { color: var(--green); }
.history-bills { padding: 0 14px 14px; }
.history-action-btn { background: none; border: none; cursor: pointer; padding: 8px; border-radius: var(--radius-xs); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.history-action-btn.delete { color: var(--red); }
.history-action-btn.edit   { color: var(--muted); }
.history-action-btn:active { background: var(--surface3); }

/* ── SETTINGS ──────────────────────────────────────────────── */
.settings-item { display: flex; align-items: center; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.settings-item:last-child { border-bottom: none; }
.settings-icon { width: 42px; height: 42px; border-radius: 12px; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.settings-info { flex: 1; }
.settings-title { font-weight: 600; font-size: 18px; }
.settings-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.settings-chevron { color: var(--muted); font-size: 18px; }

/* ── MISC ──────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.pill-tabs { display: flex; gap: 4px; background: var(--surface2); padding: 4px; border-radius: var(--radius-sm); margin-bottom: 14px; }
.pill-tab { flex: 1; padding: 13px 4px; text-align: center; font-size: 16px; font-weight: 600; color: var(--muted); border-radius: var(--radius-xs); cursor: pointer; transition: all 0.15s; }
.pill-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.4); }

/* ── CONFIRM DIALOG ────────────────────────────────────────── */
.confirm-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 300; align-items: center; justify-content: center; padding: 20px; }
.confirm-overlay.open { display: flex; }
.confirm-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 22px; max-width: 320px; width: 100%; text-align: center; }
.confirm-box h3 { font-size: 20px; font-weight: 700; margin-bottom: 10px; }
.confirm-box p { font-size: 14px; color: var(--text2); margin-bottom: 24px; line-height: 1.5; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }

/* ── DESKTOP ───────────────────────────────────────────────── */
@media (min-width: 700px) {
  html { font-size: 17px; }
  .page { max-width: 680px; margin: 0 auto; padding: 28px 24px calc(var(--nav-h) + 32px); }
  .page-header h1 { font-size: 32px; }
  .page-header p  { font-size: 15px; }
  .budget-header-row .header-text h1 { font-size: 30px; }
  .budget-header-row .header-text p  { font-size: 14px; }
  .btn-save-new { font-size: 14px; padding: 13px 18px; }
  .income-card .ic-left .value { font-size: 44px; }
  .date-bar .dates { font-size: 18px; }
  .bill-name { font-size: 15px; }
  .bill-amounts .amt { font-size: 16px; }
  .form-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .acc-name { font-size: 20px; }
  .acc-main { font-size: 20px; }
  .total-cell .tc-val { font-size: 20px; }
  .history-dates { font-size: 15px; }
  .hs-val { font-size: 15px; }
  .modal { max-width: 620px; }
  .modal h2 { font-size: 22px; }
  .login-box { padding: 40px 32px; }
}
