/* ── DESIGN TOKENS ─────────────────────────────────────────────────────── */
:root {
  --bg:           #111110;
  --surface:      #1e1e1c;
  --surface-1:    #252523;
  --surface-2:    #2c2c2a;
  --border:       rgba(255,255,255,0.08);
  --border-strong:rgba(255,255,255,0.15);
  --text:         #f0efeb;
  --text-2:       #c3c2b7;
  --text-muted:   #898781;
  --radius:       8px;
  --radius-lg:    12px;
  --accent:       #2a78d6;
  --accent-dim:   rgba(42,120,214,0.15);
  --green:        #1baf7a;
  --green-dim:    rgba(27,175,122,0.12);
  --red:          #e34948;
  --red-dim:      rgba(227,73,72,0.10);
  --amber:        #eda100;
  --amber-dim:    rgba(237,161,0,0.12);
  --purple:       #7c6af7;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ── LIGHT THEME ────────────────────────────────────────────────────────────
   Toggled via [data-theme="light"] on <html>. Every color in the app is
   already a CSS variable (no hardcoded hex anywhere in component markup),
   so overriding this single block re-themes the entire UI automatically. */
[data-theme="light"] {
  --bg:           #f7f6f3;
  --surface:      #ffffff;
  --surface-1:    #f1f0ec;
  --surface-2:    #e8e6e0;
  --border:       rgba(20,20,18,0.08);
  --border-strong:rgba(20,20,18,0.14);
  --text:         #1a1a18;
  --text-2:       #50504a;
  --text-muted:   #87867e;
  --accent:       #2a78d6;
  --accent-dim:   rgba(42,120,214,0.10);
  --green:        #0f8f5f;
  --green-dim:    rgba(15,143,95,0.10);
  --red:          #c93a39;
  --red-dim:      rgba(201,58,57,0.08);
  --amber:        #b87800;
  --amber-dim:    rgba(184,120,0,0.10);
  --purple:       #6952d6;
}

/* ── RESET ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
  min-height: 100vh; min-height: 100dvh; /* dvh accounts for mobile address bar */
  -webkit-font-smoothing: antialiased;
}
input, button, select, textarea { font-family: var(--font); }
input[type=number], input[type=text], input[type=password], input[type=email], select {
  background: var(--surface-1); border: 0.5px solid var(--border-strong);
  border-radius: var(--radius); color: var(--text); font-size: 13px;
  padding: 6px 10px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(42,120,214,.18);
}
input[type=number] { text-align: right; }
select { cursor: pointer; appearance: none; padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23898781' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0.5px solid var(--border-strong); border-radius: var(--radius);
  padding: 7px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
  background: none; color: var(--text-2); transition: background .15s, color .15s;
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; flex-shrink: 0; }
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--red); border-color: var(--red-dim); }
.btn.danger:hover { background: var(--red-dim); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 5px 8px; font-size: 16px; border: none; background: none; color: var(--text-muted); }
.btn.icon:hover { color: var(--red); background: none; }

/* ── LAYOUT ──────────────────────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 210px; flex-shrink: 0; background: var(--surface);
  border-right: 0.5px solid var(--border-strong);
  display: flex; flex-direction: column; padding: 16px 10px;
  overflow-y: auto;
}
.main-content { flex: 1; overflow-y: auto; padding: 28px 28px; }
.page { display: none; }
.page.active { display: block; }
.page-title { font-size: 20px; font-weight: 600; margin-bottom: 22px; color: var(--text); }

/* ── SIDEBAR NAV ─────────────────────────────────────────────────────────── */
.nav-logo { font-size: 16px; font-weight: 700; color: var(--text); padding: 4px 8px 16px; }
.nav-logo span { color: var(--accent); }
.nav-section { font-size: 10px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .08em; padding: 12px 8px 4px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: var(--radius); cursor: pointer; font-size: 13px;
  color: var(--text-2); border: none; background: none; width: 100%;
  text-align: left; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-1); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 500; }
.nav-icon { width: 18px; text-align: center; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; }
.nav-spacer { flex: 1; }
.nav-divider { height: 0.5px; background: var(--border); margin: 8px 0; }

/* ── CARDS ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 14px;
}
.card-title {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 14px;
  display: flex; align-items: center; gap: 6px;
}
.card-title svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; flex-shrink: 0; }
.card-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px;
}
.card-header .card-title { margin-bottom: 0; }

/* ── GRIDS ───────────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 14px; }

/* ── KPI TILES ───────────────────────────────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 10px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1; }
.kpi-value.pos { color: var(--green); }
.kpi-value.neg { color: var(--red); }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── TABLE ROWS ──────────────────────────────────────────────────────────── */
.row { display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 0.5px solid var(--border); font-size: 13px; }
.row:last-child { border-bottom: none; }
.row-total { display: flex; justify-content: space-between; padding-top: 10px;
  font-size: 13px; font-weight: 600; border-top: 0.5px solid var(--border-strong); margin-top: 4px; }

/* ── PROGRESS BARS ───────────────────────────────────────────────────────── */
.prog-wrap { margin-bottom: 14px; }
.prog-header { display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; margin-bottom: 5px; }
.prog-name { font-weight: 500; color: var(--text); }
.prog-val { color: var(--text-muted); }
.prog-track { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.prog-fill { height: 100%; border-radius: 4px; transition: width .4s ease; }
.prog-over { background: var(--red) !important; }

/* ── HORIZON TILES ───────────────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px,1fr)); gap: 8px; }
.tile { background: var(--surface-1); border-radius: var(--radius); padding: 10px 12px; }
.tile-num { font-size: 18px; font-weight: 700; color: var(--text); line-height: 1.2; }
.tile-label { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ── STATUS BADGES ───────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.good { background: var(--green-dim); color: var(--green); }
.badge.warn { background: var(--amber-dim); color: var(--amber); }
.badge.bad  { background: var(--red-dim); color: var(--red); }
.badge.info { background: var(--accent-dim); color: var(--accent); }

/* ── INLINE EDIT INPUTS ──────────────────────────────────────────────────── */
.edit-name {
  background: transparent; border: none; color: var(--text); font-weight: 500;
  font-size: 14px; width: 180px; padding: 2px 5px; border-radius: 4px;
}
.edit-name:focus { background: var(--surface-1); border: 0.5px solid var(--border-strong); outline: none; }

/* ── MODAL ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); border: 0.5px solid var(--border-strong);
  border-radius: 14px; padding: 28px 30px; min-width: 360px; max-width: 480px;
  width: 90vw;
}
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }
.form-row input, .form-row select { width: 100%; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── CHART WRAP ──────────────────────────────────────────────────────────── */
.chart-box { position: relative; width: 100%; }

/* ── LEGEND ──────────────────────────────────────────────────────────────── */
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ── SAVE INDICATOR ──────────────────────────────────────────────────────── */
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; margin-right: 5px; }
.save-dot.pending { background: var(--amber); }

/* ── USER AVATAR ─────────────────────────────────────────────────────────── */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0; cursor: pointer;
}

/* ── TAG / PILL ──────────────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 20px; font-size: 11px; font-weight: 500;
  background: var(--surface-2); color: var(--text-2);
}

/* ── ASSET/LIABILITY TYPE ICON ──────────────────────────────────────────────
   Small inline icon shown next to asset rows (cash, property, vehicle, etc.)
   and in the asset composition breakdown. Muted color since it's a quiet
   visual indicator, not a primary action. */
.type-icon { display: inline-flex; flex-shrink: 0; color: var(--text-muted); }
.type-icon svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; }

/* ── SCROLLBAR ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ── TOPBAR ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 50px; background: var(--surface);
  border-bottom: 0.5px solid var(--border-strong);
  position: sticky; top: 0; z-index: 50;
}

/* ── MONTH SELECTOR ──────────────────────────────────────────────────────── */
.month-bar { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.month-chip {
  padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 500;
  background: var(--surface-1); color: var(--text-muted); cursor: pointer; border: none;
  transition: background .12s, color .12s;
}
.month-chip:hover { background: var(--surface-2); color: var(--text); }
.month-chip.active { background: var(--accent); color: #fff; }

/* ── UNDERLINE TAB STRIP ──────────────────────────────────────────────────
   The canonical tab pattern used throughout the app: flat text buttons in
   a row, bottom border indicates active state, no background fill. This
   was originally built for the Household sub-tabs (Members / Shared
   budget / Shared expenses / Net worth) and is now the single source of
   truth — every tab-like UI in the app should use these classes rather
   than reimplementing the same look with inline styles. */
.tab-strip {
  display: flex; gap: 0; margin-bottom: 18px; border-bottom: 0.5px solid var(--border);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tab-strip .tab {
  background: none; border: none; padding: 10px 16px; font-size: 13px;
  color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; font-family: inherit; font-weight: 400; white-space: nowrap;
  transition: color .12s, border-color .12s;
}
.tab-strip .tab:hover { color: var(--text); }
.tab-strip .tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* Mobile variant — tabs share the available width evenly so 2-3 short
   labels (Budget / Expenses / Goals) always fit on one line with no
   scrolling. flex:1 lets each tab grow/shrink to fill the row; wrap stays
   on as a fallback only for cases with more tabs than fit (e.g. Household's
   4 longer labels on a very narrow phone). */
@media(max-width:700px){
  .tab-strip{ flex-wrap: wrap; overflow-x: visible; row-gap: 2px; }
  .tab-strip .tab{
    padding:9px 6px; font-size:12px; min-height:38px;
    flex: 1 1 0; text-align:center; min-width:0;
  }
}

/* ── EXPENSE LOG TABLE ───────────────────────────────────────────────────── */
.exp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.exp-table th { text-align: left; padding: 8px 10px; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 0.5px solid var(--border-strong); }
.exp-table td { padding: 9px 10px; border-bottom: 0.5px solid var(--border); color: var(--text-2); }
.exp-table tr:last-child td { border-bottom: none; }
.exp-table tr:hover td { background: var(--surface-1); }