/* Budget App — visual design per Document 04 + reference file. */

:root {
  --bg:         #0e1117;
  --surface:    #161b25;
  --surface2:   #1e2535;
  --border:     #2a3347;
  --border2:    #3a4a63;
  --text:       #e8edf5;
  --muted:      #6b7a96;
  --accent:     #4a9eff;
  --green:      #2ecc8a;
  --green-dim:  #1a7a52;
  --orange:     #f5a623;
  --red:        #e8455a;
  --gold:       #c9a84c;
  --teal:       #2dd4bf;
  --font-display: 'Fraunces', Georgia, serif;
  --font-mono:    'DM Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-mono); font-size: 13px;
  min-height: 100vh; overflow-x: hidden;
}

/* ── HEADER ─────────────────────────────────────────── */
header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 32px; display: flex; align-items: center; justify-content: space-between;
  height: 60px; position: sticky; top: 0; z-index: 100;
}
.logo { font-family: var(--font-display); font-size: 22px; font-weight: 300; color: var(--text); letter-spacing: -0.5px; flex-shrink: 0; }
.logo span { color: var(--gold); font-style: italic; }
.header-nav { display: flex; align-items: stretch; height: 100%; margin: 0 24px; }
.header-right { display: flex; align-items: center; gap: 12px; }
/* Buttons and the tiny currency box must never be squeezed; the month
   selector stays shrinkable (it has width:100% by default, like the
   original app) so the header-right never overflows. */
.header-right .btn, .header-right .currency-input, .header-right .mobile-menu-wrap { flex-shrink: 0; }
.month-selector { width: auto; min-width: 96px; }
.month-selector {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  font-family: var(--font-mono); font-size: 12px; padding: 6px 12px; border-radius: 4px; cursor: pointer;
}

/* ── NAV ────────────────────────────────────────────── */
.nav-tab {
  padding: 0 20px; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.15s; display: flex; align-items: center; height: 100%;
  white-space: nowrap;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* Mobile bottom nav (hidden on desktop) */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottom-nav .nav-tab { border-bottom: none; border-top: 2px solid transparent; height: auto; padding: 12px 4px; flex: 1; justify-content: center; text-align: center; }
.bottom-nav .nav-tab.active { border-top-color: var(--gold); }

/* Mobile menu (⋯) for header controls */
.mobile-menu-wrap { position: relative; }
.mobile-menu {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border2); border-radius: 8px;
  padding: 10px; min-width: 180px; flex-direction: column; gap: 6px; z-index: 200;
  box-shadow: 0 12px 32px rgba(0,0,0,0.45);
}
.mobile-menu.show { display: flex; }
.mobile-menu .btn { width: 100%; text-align: left; }

/* Currency symbol control */
.currency-input {
  width: 52px; text-align: center; background: var(--surface2);
  border: 1px solid var(--border); color: var(--text);
  font-family: var(--font-mono); font-size: 13px; padding: 4px 6px;
  border-radius: 4px; outline: none;
}
.currency-input:focus { border-color: var(--accent); }

/* ── MAIN ───────────────────────────────────────────── */
main { padding: 32px; max-width: 1100px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ── TYPOGRAPHY ─────────────────────────────────────── */
.section-title { font-family: var(--font-display); font-size: 26px; font-weight: 300; color: var(--text); margin-bottom: 6px; }
.section-sub { color: var(--muted); font-size: 11px; letter-spacing: 0.5px; margin-bottom: 4px; }
.card-title { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold); margin-bottom: 9px; }

/* ── BUTTONS ────────────────────────────────────────── */
.btn {
  font-family: var(--font-mono); font-size: 11px; padding: 6px 14px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface2); color: var(--muted);
  letter-spacing: 0.5px; transition: all 0.15s; white-space: nowrap;
}
.btn:hover { border-color: var(--border2); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #5aadff; }
.btn.teal { background: var(--teal); border-color: var(--teal); color: #0e1117; }
.btn.teal:hover { background: #5eead4; }

/* ── CARDS ──────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 12px; margin-bottom: 4px; }
.tx-entry-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 12px; margin-bottom: 28px; position: relative; }
.tx-entry-card::before { content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%; background: var(--accent); border-radius: 8px 0 0 8px; }
.transfer-entry-card { background: var(--surface); border: 1px solid var(--teal); border-radius: 8px; padding: 5px 12px; margin-bottom: 14px; position: relative; }
.transfer-entry-card::before { content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%; background: var(--teal); border-radius: 8px 0 0 8px; }

/* ── FORMS ──────────────────────────────────────────── */
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.form-row:last-child { margin-bottom: 0; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 120px; }
/* Uniform control heights in entry rows: date pickers render taller than
   plain inputs in some browsers, so every field — and the action button — in
   a row shares one height and nothing sticks out next to the date box. */
.form-row input, .form-row select, .form-row textarea,
.add-cat-row input, .add-cat-row select { height: 36px; }
.form-row > .btn, .add-cat-row > .btn { height: 36px; }
label { font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
input, select, textarea {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  font-family: var(--font-mono); font-size: 13px; padding: 1px 12px; border-radius: 4px;
  outline: none; width: 100%; transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.cat-name-input {
  background: transparent; border: none; border-bottom: 1px dashed var(--border);
  color: var(--text); font-family: var(--font-mono); font-size: 13px; padding: 2px 4px; width: 100%;
}
.cat-name-input:focus { outline: none; border-bottom-color: var(--accent); }
.amt-input {
  background: transparent; border: none; border-bottom: 1px dashed var(--border);
  color: var(--text); font-family: var(--font-mono); font-size: 13px; padding: 2px 4px;
  text-align: right; width: 90px; outline: none;
}
.amt-input:focus { border-bottom-color: var(--accent); }

/* ── BUDGET TABLE ───────────────────────────────────── */
.budget-table { width: 100%; border-collapse: collapse; }
.budget-table th { font-size: 9px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.budget-table th.right { text-align: right; }
.budget-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.budget-table tr:last-child td { border-bottom: none; }
.budget-table tr:hover td { background: var(--surface2); }
.amt-cell { text-align: right; color: var(--text); }
.amt-cell.weekly { color: var(--muted); font-size: 12px; }
.add-cat-row { display: flex; gap: 10px; margin-top: 14px; }
.add-cat-row input[type="text"] { max-width: 220px; }
.add-cat-row input[type="number"] { max-width: 140px; }

/* ── PROGRESS BARS ──────────────────────────────────── */
.tracker-grid { display: flex; flex-direction: column; gap: 8px; }
.tracker-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; width: fit-content; min-width: 100%; box-sizing: border-box; }
.tracker-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 12px; }
.tracker-cat-name { font-size: 12px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.tracker-amounts { font-size: 11px; color: var(--muted); text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.bar-outer { height: 12px; background: var(--surface2); border-radius: 4px; position: relative; overflow: visible; }
.bar-scale { height: 100%; position: relative; background: var(--border2); border-radius: 4px; transition: width 0.4s ease; }
.bar-fill { height: 100%; border-radius: 4px; position: relative; max-width: 100%; transition: width 0.4s ease, background 0.3s ease; }
.bar-fill.dark-green { background: linear-gradient(90deg, #0d5a3a, #1a7a52); }
.bar-fill.green      { background: linear-gradient(90deg, var(--green-dim), var(--green)); }
.bar-fill.orange     { background: linear-gradient(90deg, #a06010, var(--orange)); }
.bar-fill.red        { background: linear-gradient(90deg, #8a1a28, var(--red)); }
.bar-budget-label { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; color: rgba(255,255,255,0.55); pointer-events: none; }
.bar-budget-label-outside { position: absolute; left: 100%; margin-left: 6px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; pointer-events: none; }
.bar-overflow { position: absolute; right: -2px; top: 50%; transform: translateY(-50%); background: var(--red); color: #fff; font-size: 10px; padding: 2px 7px; border-radius: 3px; white-space: nowrap; pointer-events: none; }
.bar-overflow.outside { right: auto; left: 100%; margin-left: 6px; }

/* ── TRANSACTION / ACTIVITY LOG ─────────────────────── */
.tx-log { margin-top: 6px; }
.tx-log-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px; cursor: pointer; }
.tx-log-item:last-child { border-bottom: none; }
.tx-log-item:hover { background: var(--surface2); }
.tx-log-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 44px; }
.tx-log-date { color: var(--muted); font-size: 11px; width: 80px; }
.tx-log-cat { display: flex; align-items: center; gap: 6px; }
.tx-log-note { color: var(--muted); font-style: italic; font-size: 11px; }
.tx-log-amount { color: var(--red); font-weight: 500; white-space: nowrap; }
.tx-log-amount.credit { color: var(--green); }
.tx-log-amount.transfer { color: var(--teal); }
.tx-log-account { font-size: 10px; color: var(--muted); background: var(--surface2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 3px; }
.tx-delete { color: var(--muted); cursor: pointer; font-size: 14px; margin-left: 12px; }
.tx-delete:hover { color: var(--red); }

/* ── ACCOUNTS ───────────────────────────────────────── */
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 14px; }
.account-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; position: relative; cursor: pointer; }
.account-card:hover { border-color: var(--border2); }
.account-card.default-acc { border-color: var(--accent); }
.account-name { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.account-balance { font-family: var(--font-display); font-size: 22px; font-weight: 300; color: var(--green); }
.account-balance.negative { color: var(--red); }
.account-sub { font-size: 10px; color: var(--muted); margin-top: 4px; }
.account-actions { display: flex; gap: 8px; margin-top: 12px; }
.default-badge { font-size: 9px; letter-spacing: 1px; text-transform: uppercase; background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 3px; }
.acc-delete { position: absolute; top: 10px; right: 12px; color: var(--muted); cursor: pointer; font-size: 16px; }
.acc-delete:hover { color: var(--red); }

/* ── REPORT ─────────────────────────────────────────── */
.report-grid { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.report-row { display: grid; grid-template-columns: 24px 1fr 110px 110px 110px 90px; align-items: center; gap: 10px; padding: 5px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.report-row.header { background: transparent; border-color: transparent; font-size: 9px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); padding-bottom: 4px; }
.report-row.total { background: var(--surface2); border-color: var(--border2); margin-top: 8px; font-weight: 500; }
.report-cat { font-size: 12px; }
.report-budget { text-align: right; color: var(--muted); font-size: 12px; }
.report-spent { text-align: right; font-size: 12px; }
.report-diff { text-align: right; font-size: 12px; font-weight: 500; }
.report-diff.under { color: var(--green); }
.report-diff.over { color: var(--red); }
.report-pct { text-align: right; font-size: 11px; color: var(--muted); }

/* ── STATS ──────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 8px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 9px; }
.stat-label { font-size: 9px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.stat-value { font-family: var(--font-display); font-size: 22px; font-weight: 300; color: var(--text); }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-value.gold { color: var(--gold); }
.stat-sub { font-size: 10px; color: var(--muted); margin-top: 4px; }

/* ── MISC ───────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px; color: var(--muted); font-style: italic; }
.tag { font-size: 10px; padding: 2px 8px; border-radius: 3px; background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.month-badge { font-size: 10px; padding: 3px 10px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--border); color: var(--gold); letter-spacing: 1px; }
.section-divider { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--teal); margin: 20px 0 16px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.cat-color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; flex-shrink: 0; }

/* ── TOAST ──────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--surface2);
  border: 1px solid var(--green); color: var(--green); font-size: 12px; padding: 10px 18px;
  border-radius: 6px; transform: translateY(80px); opacity: 0; transition: all 0.3s; z-index: 999;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* ── CONFIRM MODAL ──────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 1000; }
.modal-overlay.show { display: flex; }
.modal-box { background: var(--surface); border: 1px solid var(--border2); border-radius: 8px; padding: 20px 22px; max-width: 380px; box-shadow: 0 12px 32px rgba(0,0,0,0.45); }
.modal-message { font-size: 13px; color: var(--text); line-height: 1.5; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ── AUTH SCREEN ────────────────────────────────────── */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 100%; max-width: 380px; }
.auth-card .logo { text-align: center; margin-bottom: 24px; }
.auth-card .card-title { text-align: center; margin-bottom: 20px; }
.auth-card .form-group { margin-bottom: 14px; }
.auth-card .btn { width: 100%; height: 38px; margin-top: 6px; }
.auth-toggle { text-align: center; margin-top: 16px; font-size: 11px; color: var(--muted); }
.auth-toggle a { color: var(--accent); cursor: pointer; text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }
.auth-error { color: var(--red); font-size: 11px; margin-top: 10px; min-height: 14px; text-align: center; }

/* ── SCROLLBAR ──────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── SVG CHARTS ─────────────────────────────────────── */
svg text { font-family: var(--font-mono); }
/* Pie: let max-width scale both dimensions (otherwise the SVG keeps its
   full height and letterboxes — a small donut with huge space above/below). */
#reportPieWrap { margin: 20px 0 4px; }
/* Pie: let max-width scale both dimensions (otherwise the SVG keeps its
   full height and letterboxes — a small donut with huge space above/below). */
#reportPieWrap svg { height: auto; }

/* ── RESPONSIVE (Document 04 §22) ───────────────────── */
.hide-desktop { display: none; }
@media (max-width: 1200px) {
  /* Compact header + bottom nav before the header runs out of room, so the
     Export/Import/Logout buttons are never squeezed or wrapped and the
     month selector never overflows. */
  header { padding: 0 16px; }
  main { padding: 20px 16px 84px; }
  .header-nav { display: none; }
  .bottom-nav { display: flex; }
  .hide-mobile { display: none !important; }
  .hide-desktop { display: block; }
  body { padding-bottom: 0; }
  .mobile-menu { position: fixed; top: 52px; right: 12px; left: auto; }
}
@media (max-width: 1400px) {
  /* Give the desktop header room between 1201-1400px so it never overflows */
  .header-nav { margin: 0 12px; }
  .nav-tab { padding: 0 10px; }
  .header-right { gap: 8px; }
  .header-right .btn { padding: 6px 10px; }
}
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  /* Phones: let the pie use the full viewport width (main padding is 16px) */
  #reportPieWrap { margin: 20px -16px 4px; }
}
@media (max-width: 768px) {
  main { padding: 20px 16px 84px; }
  .report-row { grid-template-columns: 16px 1fr 90px 90px; }
  .report-row .report-budget, .report-row .report-diff, .report-row .report-pct { font-size: 11px; }
  .report-row.header div:nth-child(3), .report-row.header div:nth-child(6) { display: none; }
}
@media (max-width: 480px) {
  /* Tiny screens: shrink the logo, tighten gaps, and move the currency
     control into the ⋯ menu (it is also there) so the header fits. */
  .logo { font-size: 17px; }
  .header-right { gap: 8px; }
  header .currency-input { display: none; }
}
@media (max-width: 360px) {
  .logo { font-size: 15px; }
}
@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
  .tracker-header { flex-direction: column; align-items: flex-start; gap: 6px; }
}
