/* ============================================================
   Finance Portal — Core Styles
   Design system: dark navy theme, CSS custom properties
   ============================================================ */

:root {
  /* Colours */
  --bg-base:       #0f1523;
  --bg-surface:    #141b2d;
  --bg-card:       #1a2236;
  --bg-elevated:   #1f2b40;
  --bg-hover:      #243047;

  --accent:        #3b82f6;
  --accent-dark:   #2563eb;
  --accent-light:  #60a5fa;
  --success:       #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --info:          #06b6d4;

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --text-inverse:  #0f172a;

  --border:        #2d3a52;
  --border-light:  #334155;

  /* Category colours */
  --cat-banking:    #3b82f6;
  --cat-savings:    #10b981;
  --cat-investment: #8b5cf6;
  --cat-pension:    #f59e0b;
  --cat-property:   #ef4444;
  --cat-commodity:  #f97316;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'SF Mono', 'Consolas', monospace;
  --text-xs:  11px;
  --text-sm:  13px;
  --text-base:15px;
  --text-lg:  17px;
  --text-xl:  20px;
  --text-2xl: 24px;
  --text-3xl: 30px;
  --text-4xl: 36px;

  /* Radii */
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;
  --radius-xl:  20px;
  --radius-full:9999px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
  --shadow:     0 4px 12px rgba(0,0,0,.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.6);

  /* Layout */
  --sidebar-width: 220px;
  --sidebar-collapsed: 60px;
  --header-height: 60px;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; scroll-behavior: smooth; }
body {
  height: 100%;
  font-family: var(--font);
  font-size: var(--text-base);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-light); text-decoration: none; }
a:hover { color: var(--accent); }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Layout ─────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .25s ease;
  overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .brand-name,
.sidebar.collapsed .brand-user,
.sidebar.collapsed .sidebar-footer { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border);
  min-height: var(--header-height);
}

.sidebar-logo {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

.sidebar-brand { flex: 1; min-width: 0; }
.brand-name { display: block; font-weight: 600; font-size: var(--text-sm); white-space: nowrap; }
.brand-user { display: block; font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  padding: var(--space-1);
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

.nav-list {
  list-style: none;
  padding: var(--space-3) 0;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--text-secondary);
  border-radius: 0;
  transition: background .15s, color .15s;
  white-space: nowrap;
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: rgba(59,130,246,.15); color: var(--accent-light); }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-icon { font-size: 17px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-label { font-size: var(--text-sm); font-weight: 500; }
.nav-separator { height: 1px; background: var(--border); margin: var(--space-2) var(--space-4); }

.nav-section-label {
  padding: var(--space-3) var(--space-4) var(--space-1);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-muted);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--border);
}

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-base);
}

.page-container {
  padding: var(--space-8);
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .page-container { padding: var(--space-4); }
  .sidebar { position: fixed; z-index: 100; height: 100vh; }
  .sidebar:not(.open) { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
}

/* ── Page Header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.page-title { font-size: var(--text-2xl); font-weight: 700; color: var(--text-primary); }
.page-subtitle { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card-sm { padding: var(--space-4); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-5); }
.card-title { font-size: var(--text-base); font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; font-size: var(--text-xs); }

/* ── KPI Metrics ─────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
}

.metric-label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin-bottom: var(--space-2); }
.metric-value { font-size: var(--text-3xl); font-weight: 700; color: var(--text-primary); line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric-change { font-size: var(--text-sm); margin-top: var(--space-1); }
.metric-change.up   { color: var(--success); }
.metric-change.down { color: var(--danger); }
.metric-change.flat { color: var(--text-muted); }

/* ── Levers (FIRE planner interactive controls) ──────────── */
.lever-section { border-bottom: 1px solid var(--border); }
.lever-section:last-child { border-bottom: none; }
.lever-header {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: none; border: none; color: var(--text);
  font-size: var(--text-sm); font-weight: 600; cursor: pointer; text-align: left;
  transition: background .15s;
}
.lever-header:hover { background: var(--bg-elevated); }
.lever-header span:first-child { font-size: 10px; color: var(--text-muted); width: 12px; }

/* ── Charts ─────────────────────────────────────────────── */
.chart-container { position: relative; height: 280px; }
.chart-container-lg { height: 360px; }
.chart-container-sm { height: 180px; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg-elevated); }
th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-light); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: var(--space-2); border-radius: var(--radius-sm); min-width: 32px; justify-content: center; }

/* ── Forms ─────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
label { font-size: var(--text-sm); font-weight: 500; color: var(--text-secondary); }

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="email"],
select,
textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}
select option { background: var(--bg-surface); }
.form-hint { font-size: var(--text-xs); color: var(--text-muted); }
.form-error { font-size: var(--text-sm); color: var(--danger); margin-top: var(--space-2); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.form-section-heading {
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
  margin: var(--space-4) 0 var(--space-3);
}

/* ── Login Screen ─────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-10);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo { text-align: center; margin-bottom: var(--space-8); }
.login-logo .logo-icon {
  display: inline-block;
  font-size: 48px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: var(--space-3);
  font-style: normal;
}
.login-logo h1 { font-size: var(--text-2xl); font-weight: 700; }
.login-logo p { color: var(--text-muted); font-size: var(--text-sm); margin-top: 4px; }

/* ── Tabs ─────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; background: var(--bg-elevated); border-radius: var(--radius); padding: 3px; margin-bottom: var(--space-6); }
.tab {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.tab.active { background: var(--bg-card); color: var(--text-primary); }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-banking    { background: rgba(59,130,246,.15);  color: #93c5fd; }
.badge-savings    { background: rgba(16,185,129,.15);  color: #6ee7b7; }
.badge-investment { background: rgba(139,92,246,.15);  color: #c4b5fd; }
.badge-pension    { background: rgba(245,158,11,.15);  color: #fcd34d; }
.badge-property   { background: rgba(239,68,68,.15);   color: #fca5a5; }
.badge-commodity  { background: rgba(249,115,22,.15);  color: #fdba74; }
.badge-success    { background: rgba(16,185,129,.15);  color: #6ee7b7; }
.badge-warning    { background: rgba(245,158,11,.15);  color: #fcd34d; }
.badge-danger     { background: rgba(239,68,68,.15);   color: #fca5a5; }
.badge-info       { background: rgba(6,182,212,.15);   color: #67e8f9; }
.badge-company    { background: rgba(139,92,246,.15);  color: #c4b5fd; }

/* ── Grid layouts ─────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-6); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-6); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px)  { .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ── Allowance progress bars ─────────────────────────────── */
.allowance-bar { margin-bottom: var(--space-4); }
.allowance-label { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--text-muted); margin-bottom: var(--space-1); }
.allowance-label strong { color: var(--text-primary); }
.progress-track { height: 6px; background: var(--bg-elevated); border-radius: var(--radius-full); overflow: hidden; }
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width .4s ease;
}
.progress-fill.near   { background: var(--warning); }
.progress-fill.full   { background: var(--danger); }

/* ── FIRE score ─────────────────────────────────────────── */
.fire-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-6);
}
.fire-gauge {
  position: relative;
  width: 180px;
  height: 90px;
  overflow: hidden;
}
.fire-percent {
  font-size: var(--text-4xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.fire-label { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-2); }

/* ── Utility ─────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.loading-spinner { display: flex; justify-content: center; padding: var(--space-12); color: var(--text-muted); }
.empty-state { text-align: center; padding: var(--space-12); color: var(--text-muted); }
.empty-state h3 { font-size: var(--text-lg); color: var(--text-secondary); margin-bottom: var(--space-2); }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mono { font-family: var(--font-mono); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: var(--text-sm); }
.text-xs      { font-size: var(--text-xs); }
.font-bold    { font-weight: 700; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mt-4 { margin-top: var(--space-4); }

/* ── Member colour dots ─────────────────────────────────── */
.member-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ── Account card in list ─────────────────────────────────── */
.account-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  transition: border-color .15s;
  cursor: pointer;
}
.account-card:hover { border-color: var(--border-light); background: var(--bg-hover); }

/* Dashboard expandable wrapper — replaces the plain .account-card for the accounts list */
.account-card-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color .15s;
}
.account-card-wrap:hover { border-color: var(--border-light); }
.account-card-wrap .account-card {
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  margin: 0 !important;
}
.account-card .account-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.account-card .account-details { flex: 1; min-width: 0; }
.account-card .account-name { font-weight: 600; font-size: var(--text-base); }
.account-card .account-meta { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.account-card .account-value { text-align: right; flex-shrink: 0; }
.account-card .value-amount { font-size: var(--text-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.account-card .value-date { font-size: var(--text-xs); color: var(--text-muted); }

/* ── Privacy toggle switch (shared by sidebar + dashboard header) ── */
.priv-toggle-wrap {
  display: flex; align-items: center; gap: 7px;
  font-size: .78rem; color: var(--text-muted); cursor: pointer; user-select: none;
}
.priv-switch { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.priv-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.priv-slider {
  position: absolute; inset: 0; background: #334155; border-radius: 10px; transition: .2s;
}
.priv-slider::before {
  content: ''; position: absolute; left: 3px; top: 3px; width: 14px; height: 14px;
  background: #64748b; border-radius: 50%; transition: .2s;
}
.priv-switch input:checked + .priv-slider { background: #3b82f6; }
.priv-switch input:checked + .priv-slider::before { transform: translateX(16px); background: #fff; }

/* ── Privacy mode ─────────────────────────────────────────── */
/*
 * When body.privacy-on is active, blur all .pv spans (explicit wrapper),
 * plus the common value display classes used across pages so they are
 * covered without needing per-page code changes.
 */
body.privacy-on .pv,
body.privacy-on .value-amount,
body.privacy-on .metric-value {
  filter: blur(7px);
  user-select: none;
  border-radius: 3px;
  display: inline-block;
  transition: filter .2s;
}

/* Sidebar privacy toggle */
.sidebar-privacy {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius);
  transition: background .15s;
  width: 100%;
  background: none;
  border: none;
}
.sidebar-privacy:hover { background: var(--bg-hover); color: var(--text-base); }
/* Sidebar uses slightly smaller toggle — override just the dimensions */
.sidebar-privacy .priv-switch { width: 32px; height: 18px; }
/* When collapsed, hide the label but keep the icon */
.sidebar.collapsed .sidebar-privacy .priv-label { display: none; }

/* ── Dashboard account expand ─────────────────────────────── */
.acc-expand-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: .65rem; padding: 6px 8px; cursor: pointer;
  flex-shrink: 0; transition: transform .18s, color .15s; line-height: 1;
  border-radius: 4px;
}
.acc-expand-btn:hover { color: var(--text-base); background: rgba(255,255,255,.05); }
.acc-expand-btn.open  { transform: rotate(180deg); color: var(--accent, #3b82f6); }
.acc-expand-body {
  display: none;
  padding: 10px 16px 14px 76px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.02);
  font-size: .8rem;
  animation: expandIn .15s ease;
}
.acc-expand-body.open { display: block; }
@keyframes expandIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.acc-expand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px 20px;
  margin-top: 4px;
}
.acc-expand-item .ei-label { color: var(--text-muted); font-size: .7rem; margin-bottom: 1px; }
.acc-expand-item .ei-val   { font-weight: 600; }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
