:root {
  --navy-deep: #0B1B2B;
  --navy: #142A42;
  --navy-mid: #1F3A57;
  --gold: #C9A227;
  --gold-light: #E8C766;
  --gold-dim: #A9841F;
  --bg: #F5F3EC;
  --card: #FFFFFF;
  --ink: #16243B;
  --muted: #5C6B7A;
  --green: #3E8E6E;
  --green-bg: #E4F1EC;
  --rust: #B5495B;
  --rust-bg: #F7E7EA;
  --border: rgba(20,42,66,0.12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito Sans', sans-serif;
  line-height: 1.5;
}
h1, h2, h3 { font-family: 'Outfit', sans-serif; font-weight: 700; letter-spacing: -0.01em; }
.mono { font-family: 'Space Mono', monospace; }
button { font-family: inherit; cursor: pointer; border: none; }
input, select { font-family: inherit; }

/* ===== Auth screen ===== */
#auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 15%, #17324e 0%, var(--navy-deep) 55%);
  padding: 2rem;
}
.auth-card {
  background: white; border-radius: 18px; padding: 3rem 2.5rem;
  max-width: 400px; width: 100%; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.auth-card h1 { font-size: 1.6rem; color: var(--navy-deep); margin-bottom: 0.5rem; }
.auth-card p { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.8rem; }
.btn-auth {
  background: var(--navy-deep); color: var(--gold-light); font-weight: 700;
  padding: 0.9rem 1.8rem; border-radius: 8px; font-size: 0.95rem; width: 100%;
  margin-bottom: 0.7rem;
}
.btn-auth.secondary { background: white; color: var(--ink); border: 1.5px solid var(--border); }

/* ===== Wizard ===== */
#wizard-screen {
  min-height: 100vh; display: none;
  align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 15%, #17324e 0%, var(--navy-deep) 55%);
  padding: 2rem;
}
.wizard-card {
  background: white; border-radius: 18px; padding: 2.6rem 2.2rem;
  max-width: 440px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.progress-dots { display: flex; gap: 0.4rem; margin-bottom: 1.6rem; }
.progress-dots span { height: 4px; flex: 1; border-radius: 4px; background: var(--border); }
.progress-dots span.done { background: var(--gold); }
.step-eyebrow {
  font-family: 'Space Mono', monospace; font-size: 0.72rem; color: var(--gold-dim);
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.5rem;
}
.wizard-card h2 { font-size: 1.45rem; margin-bottom: 0.4rem; color: var(--navy-deep); }
.wizard-card p.sub { color: var(--muted); font-size: 0.93rem; margin-bottom: 1.6rem; }
.option-list { display: flex; flex-direction: column; gap: 0.7rem; margin-bottom: 1.8rem; }
.option-btn {
  display: flex; align-items: center; gap: 0.8rem; background: var(--bg);
  border: 1.5px solid var(--border); border-radius: 10px; padding: 0.9rem 1rem;
  text-align: left; font-weight: 700; font-size: 0.96rem; color: var(--ink);
}
.option-btn.selected { background: var(--navy-deep); border-color: var(--navy-deep); color: white; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.8rem; }
.chip {
  background: var(--bg); border: 1.5px solid var(--border); border-radius: 8px;
  padding: 0.55rem 1rem; font-weight: 700; font-size: 0.86rem; color: var(--ink);
}
.chip.selected { background: var(--navy-deep); border-color: var(--navy-deep); color: var(--gold-light); }
.chip.selected::before { content: "✓ "; }
.wizard-nav { display: flex; justify-content: space-between; align-items: center; }
.btn-back { background: transparent; color: var(--muted); font-weight: 700; font-size: 0.9rem; padding: 0.7rem 0.4rem; }
.btn-next { background: var(--navy-deep); color: var(--gold-light); font-weight: 700; padding: 0.85rem 1.8rem; border-radius: 8px; font-size: 0.94rem; }
.tax-choice-grid { display: flex; flex-direction: column; gap: 0.8rem; margin-bottom: 1.8rem; }
.tax-card { border: 1.5px solid var(--border); border-radius: 12px; padding: 1.1rem 1.2rem; text-align: left; background: var(--bg); }
.tax-card.selected { background: var(--navy-deep); border-color: var(--navy-deep); }
.tax-card.selected strong, .tax-card.selected span { color: white; }
.tax-card strong { display: block; font-size: 1rem; margin-bottom: 0.2rem; color: var(--navy-deep); }
.tax-card span { font-size: 0.85rem; color: var(--muted); }

/* ===== App shell ===== */
#app-screen { display: none; min-height: 100vh; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.1rem 2.5rem; background: var(--navy-deep); color: white;
}
.topbar .logo { font-family: 'Outfit', sans-serif; font-weight: 800; font-size: 1.1rem; }
.topbar .logo span { color: var(--gold-light); }
.topbar .logout { background: transparent; color: #B9C4D0; font-size: 0.85rem; font-weight: 700; }

.toast {
  background: var(--gold-light); padding: 0.85rem 2.5rem;
  display: flex; justify-content: center; align-items: center; gap: 1rem; flex-wrap: wrap;
  font-size: 0.88rem; font-weight: 700; color: var(--navy-deep);
}
.toast a { color: var(--navy-deep); }
.toast button.close-toast { background: transparent; color: var(--navy-deep); font-weight: 700; font-size: 1.1rem; }

.dash-body { padding: 2rem 2.5rem 3rem; max-width: 1100px; margin: 0 auto; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 1.6rem; flex-wrap: wrap; gap: 1rem; }
.dash-head h1 { font-size: 1.5rem; color: var(--navy-deep); }
.dash-head p { color: var(--muted); font-size: 0.9rem; }
.btn-upload { background: var(--navy-deep); color: var(--gold-light); font-weight: 700; padding: 0.7rem 1.3rem; border-radius: 8px; font-size: 0.86rem; }

.stat-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 1.1rem; margin-bottom: 1.4rem; }
.stat-hero {
  background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy-mid) 100%);
  border-radius: 16px; padding: 1.5rem 1.7rem; color: white; position: relative; overflow: hidden;
}
.stat-hero .label { font-family: 'Space Mono', monospace; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gold-light); margin-bottom: 0.6rem; }
.stat-hero .value { font-size: 2rem; font-weight: 800; }
.stat-card { background: white; border: 1px solid var(--border); border-radius: 16px; padding: 1.4rem 1.5rem; }
.stat-card .label { font-family: 'Space Mono', monospace; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.6rem; }
.stat-card .value { font-size: 1.6rem; font-weight: 800; color: var(--navy-deep); }
@media (max-width: 900px) { .stat-row { grid-template-columns: 1fr; } }

.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1.1rem; margin-bottom: 1.4rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.panel { background: white; border: 1px solid var(--border); border-radius: 16px; padding: 1.6rem 1.7rem; }
.panel h3 { font-size: 1rem; margin-bottom: 1.1rem; color: var(--navy-deep); }

.legend-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.86rem; margin-bottom: 0.7rem; }
.legend-row .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-row .name { flex: 1; }
.legend-row .amt { font-family: 'Space Mono', monospace; font-weight: 700; }

.recurring-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
.recurring-item:last-child { border-bottom: none; }
.recurring-badge { background: var(--gold-light); color: var(--gold-dim); font-size: 0.7rem; font-weight: 800; padding: 0.2rem 0.5rem; border-radius: 6px; }

/* Add transaction form */
.tx-form { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 70px auto; gap: 0.7rem; align-items: end; margin-bottom: 1.4rem; }
.tx-form .field label { display: block; font-size: 0.72rem; font-weight: 700; color: var(--muted); margin-bottom: 0.3rem; }
.tx-form input, .tx-form select {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.7rem; font-size: 0.86rem; color: var(--ink);
}
.tx-form button { background: var(--gold); color: var(--navy-deep); font-weight: 800; padding: 0.62rem 1.2rem; border-radius: 8px; font-size: 0.85rem; }
@media (max-width: 900px) { .tx-form { grid-template-columns: 1fr 1fr; } }

/* ===== Categories page ===== */
.cat-input-row { display: flex; gap: 0.6rem; align-items: center; margin-top: 0.9rem; }
.chip-add-btn {
  background: var(--navy-deep); color: var(--gold-light); font-weight: 700;
  padding: 0.55rem 1rem; border-radius: 8px; font-size: 0.85rem; white-space: nowrap;
}
.cat-input-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.8rem; font-size: 0.86rem; color: var(--ink); font-family: 'Nunito Sans', sans-serif;
}
.cat-list-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; font-weight: 600;
}
.cat-list-row:last-child { border-bottom: none; }

/* ===== Insights ===== */
.insight-card {
  display: flex; gap: 0.9rem; background: white; border: 1px solid var(--border);
  border-left: 3px solid var(--gold); border-radius: 12px; padding: 1rem 1.2rem; margin-bottom: 0.9rem;
}
.insight-card.tone-good { border-left-color: var(--green); }
.insight-card.tone-bad { border-left-color: var(--rust); }
.insight-card.tone-steady { border-left-color: var(--navy-mid); }
.insight-card .ic-icon {
  width: 32px; height: 32px; border-radius: 8px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1rem;
}
.insight-card .ic-body h4 { font-size: 0.96rem; margin-bottom: 0.35rem; color: var(--navy-deep); display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.insight-card .ic-badge {
  font-size: 0.64rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--bg); color: var(--navy-mid); padding: 0.18rem 0.5rem; border-radius: 6px;
}
.insight-card p { font-size: 0.85rem; color: var(--muted); line-height: 1.55; margin: 0; }

/* ===== Reconciliation live preview ===== */
.recon-preview {
  margin-top: 0.9rem; padding: 0.9rem 1rem; background: var(--bg); border-radius: 10px;
  border: 1px solid var(--border); font-size: 0.88rem; min-height: 0;
}
.recon-preview:empty { display: none; }
.recon-preview-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.6rem; }
.recon-status-ok {
  color: var(--green); font-weight: 800; background: var(--green-bg);
  padding: 0.3rem 0.8rem; border-radius: 6px; font-size: 0.82rem;
}
.recon-status-bad {
  color: var(--rust); font-weight: 800; background: var(--rust-bg);
  padding: 0.3rem 0.8rem; border-radius: 6px; font-size: 0.82rem;
}

/* ===== Error toast (transient, auto-dismissing) ===== */
.error-toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
  background: var(--navy-deep); color: white; font-size: 0.88rem; font-weight: 600;
  padding: 0.9rem 1.3rem; border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  max-width: 340px; border-left: 3px solid var(--rust);
}

/* ===== Load-error banner (blocks the wizard-on-failure bug) ===== */
.load-error-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1001;
  background: var(--rust); color: white; font-size: 0.9rem; font-weight: 700;
  padding: 0.8rem 1.5rem; display: flex; align-items: center; justify-content: center; gap: 1rem;
}
.load-error-banner button {
  background: white; color: var(--rust); font-weight: 800; padding: 0.4rem 1rem;
  border-radius: 6px; font-size: 0.82rem;
}

/* Desktop grid shapes for forms that used to set this inline — moved here
   so the mobile breakpoints below can actually override them. Inline
   styles always beat stylesheet rules, media query or not. */
.tx-form-sub-row { grid-template-columns: auto auto 1fr auto; }
.tx-form-recon { grid-template-columns: 1fr 1.4fr 1fr 1fr auto; }
.tx-form-taxpay { grid-template-columns: 1fr 90px 1fr 1fr auto; }

/* ===== Mobile ===== */
@media (max-width: 900px) {
  .tx-form-sub-row,
  .tx-form-recon,
  .tx-form-taxpay {
    grid-template-columns: 1fr 1fr;
  }

  /* Tables don't reflow into cards here — that's a bigger redesign than
     this pass covers — but they do scroll horizontally instead of
     squeezing every column unreadably thin or breaking the page layout. */
  .tx-table { display: block; overflow-x: auto; white-space: nowrap; }
  .tx-table th, .tx-table td { padding-right: 1rem; }
}

@media (max-width: 768px) {
  /* Sidebar switches from a fixed-width left column to a horizontal,
     wrapping bar above the content — a 230px fixed sidebar would eat most
     of a phone's width otherwise. */
  #app-screen.active { flex-direction: column; min-height: auto; }
  .sidebar {
    width: 100%; min-height: auto; flex-direction: row; flex-wrap: wrap;
    align-items: center; padding: 0.8rem 1rem; gap: 0.3rem;
  }
  .side-logo { width: 100%; margin-bottom: 0.5rem; }
  .side-link { padding: 0.45rem 0.7rem; font-size: 0.8rem; margin-bottom: 0; }
  .side-divider { display: none; }
  .side-foot { display: none; }
  .sidebar .logout { margin-left: auto; padding: 0.45rem 0.7rem; }

  .dash-body { padding: 1.2rem 1rem 2rem; }
  .topbar { padding: 0.9rem 1.2rem; }
  .dash-head { flex-direction: column; align-items: flex-start; }

  .tx-form, .tx-form-sub-row, .tx-form-recon, .tx-form-taxpay {
    grid-template-columns: 1fr !important;
  }
}

.tx-table { width: 100%; border-collapse: collapse; }
.tx-table th {
  text-align: left; font-family: 'Space Mono', monospace; font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  padding-bottom: 0.7rem; border-bottom: 1px solid var(--border);
}
.tx-table td { padding: 0.8rem 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.tx-table tr:last-child td { border-bottom: none; }
.tag-pill { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 0.25rem 0.65rem; border-radius: 6px; }
.tag-pill.income { background: var(--green-bg); color: var(--green); }
.tag-pill.expense { background: var(--rust-bg); color: var(--rust); }
.amt-cell { font-family: 'Space Mono', monospace; font-weight: 700; text-align: right; }
.amt-cell.pos { color: var(--green); }
.amt-cell.neg { color: var(--rust); }
.del-btn { background: transparent; color: var(--muted); font-size: 0.85rem; }
.receipt-btn {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.3rem 0.6rem; font-size: 0.76rem; font-weight: 700; color: var(--ink);
  cursor: pointer; white-space: nowrap; display: inline-block;
}
.receipt-btn:hover { border-color: var(--gold-dim); }
.empty-state { text-align: center; padding: 2rem; color: var(--muted); font-size: 0.9rem; }

/* ===== App shell v2: sidebar layout ===== */
#app-screen { display: none; }
#app-screen.active { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px; min-height: 100vh; background: var(--navy-deep);
  padding: 1.6rem 1.2rem; flex-shrink: 0; color: #B9C4D0;
  display: flex; flex-direction: column;
}
.side-logo { font-family: 'Outfit', sans-serif; font-weight: 800; font-size: 1.15rem; color: white; margin-bottom: 2rem; padding: 0 0.4rem; }
.side-logo span { color: var(--gold-light); }
.side-link {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem;
  border-radius: 8px; font-weight: 700; font-size: 0.88rem; margin-bottom: 0.2rem;
  color: #93A4B5; cursor: pointer;
}
.side-link .ic { font-size: 1rem; width: 20px; text-align: center; }
.side-link.current { background: var(--navy-mid); color: white; }
.side-divider { height: 1px; background: rgba(255,255,255,0.08); margin: 1.2rem 0; }
.side-foot { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.4rem; margin-top: auto; }
.side-foot .who { font-size: 0.82rem; color: #B9C4D0; font-weight: 700; }
.side-foot .sub { font-size: 0.72rem; color: #6E7E8E; }
.sidebar .logout { background: transparent; color: #6E7E8E; font-size: 0.78rem; font-weight: 700; text-align: left; padding: 0.6rem 0.4rem; margin-top: 0.4rem; }
.sidebar .logout:hover { color: #B9C4D0; }

.dash-main { flex: 1; min-width: 0; }
.page { display: none; }
.page.active { display: block; }

/* ===== Filter bar (Transactions) ===== */
.filter-bar { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.search-input {
  background: white; border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.9rem; font-size: 0.85rem; font-weight: 600; color: var(--ink);
  flex: 1; min-width: 180px; font-family: 'Nunito Sans', sans-serif;
}
.filter-chip {
  background: white; border: 1px solid var(--border); border-radius: 100px;
  padding: 0.5rem 0.9rem; font-size: 0.82rem; font-weight: 700; color: var(--muted);
}
.filter-chip.active { background: var(--navy-deep); color: var(--gold-light); border-color: var(--navy-deep); }

.cat-dropdown {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.35rem 0.55rem; font-size: 0.78rem; font-weight: 700; color: var(--ink);
  font-family: 'Nunito Sans', sans-serif;
}

/* ===== Reports ===== */
.range-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.range-tab { background: white; border: 1px solid var(--border); border-radius: 100px; padding: 0.55rem 1.1rem; font-size: 0.85rem; font-weight: 700; color: var(--muted); }
.range-tab.active { background: var(--navy-deep); color: var(--gold-light); border-color: var(--navy-deep); }
.export-btn { background: var(--gold); color: var(--navy-deep); font-weight: 800; padding: 0.75rem 1.4rem; border-radius: 8px; font-size: 0.88rem; }

.cat-bar-row { margin-bottom: 1rem; }
.cat-bar-top { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.35rem; }
.cat-bar-top .amt { font-family: 'Space Mono', monospace; font-weight: 700; }
.cat-bar-bg { background: var(--bg); border-radius: 100px; height: 8px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 100px; }

.trend-chart { display: flex; align-items: flex-end; gap: 0.8rem; height: 160px; padding-top: 1rem; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.trend-bar { width: 60%; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dim) 100%); min-height: 3px; }
.trend-label { font-size: 0.72rem; color: var(--muted); margin-top: 0.5rem; font-weight: 700; }
.trend-value { font-size: 0.68rem; color: var(--ink); font-weight: 700; margin-bottom: 0.3rem; }

/* ===== Settings ===== */
.settings-section { margin-bottom: 1.4rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 0.9rem; }
.form-field label { display: block; font-size: 0.78rem; font-weight: 700; color: var(--muted); margin-bottom: 0.4rem; }
.form-field input, .form-field select {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.65rem 0.8rem; font-size: 0.88rem; color: var(--ink); font-family: 'Nunito Sans', sans-serif;
}
.readonly-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.readonly-chip { background: var(--bg); border: 1px solid var(--border); border-radius: 100px; padding: 0.4rem 0.9rem; font-size: 0.8rem; font-weight: 700; color: var(--ink); }
.plan-card {
  background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy-mid) 100%);
  color: white; border-radius: 14px; padding: 1.4rem 1.6rem;
}
.plan-card .name { font-family: 'Outfit', sans-serif; font-weight: 800; font-size: 1.1rem; color: var(--gold-light); }
.plan-card .price { font-size: 0.85rem; color: #B9C4D0; margin-top: 0.2rem; }

/* ===== Tax Center ===== */
.stat-row-tax { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; margin-bottom: 0.6rem; }
@media (max-width: 900px) { .stat-row-tax { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .stat-row-tax { grid-template-columns: 1fr; } }
.tax-note-inline { font-size: 0.8rem; color: var(--muted); margin-top: 0.9rem; }
.current-q { background: var(--gold-light); }
.current-q td { font-weight: 700; }
