*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Tufte: low-contrast chrome lets data dominate. Card surfaces near the
     background; borders whispered; accent reserved for data, not decoration. */
  --bg:        #0a0d14;
  --surface:   #0f1421;
  --card:      #111724;
  --border:    rgba(148,163,184,0.10);
  --muted:     #3d5170;
  --subtle:    #64748b;
  --text:      #e2e8f0;
  --heading:   #f8fafc;
  --blue:      #38bdf8;
  --purple:    #a78bfa;
  --green:     #34d399;
  --orange:    #fb923c;
  --pink:      #f472b6;
  --yellow:    #facc15;
  --red:       #f87171;
  --status-green:  #22c55e;
  --status-amber:  #f59e0b;
  --status-red:    #ef4444;
  --radius:    6px;
  --radius-sm: 4px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ── */
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 28px;
}
header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--heading);
  letter-spacing: -0.02em;
}
#last-updated {
  font-size: 0.75rem;
  color: var(--subtle);
}

/* ── Insights bar ── */
#insights-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}
.insight-pill {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.insight-pill .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
}
.insight-pill .value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
}
.insight-pill .sub {
  font-size: 0.75rem;
  color: var(--subtle);
  display: flex;
  align-items: center;
  gap: 4px;
}
.insight-pill.status-green { border-color: var(--status-green); }
.insight-pill.status-amber { border-color: var(--status-amber); }
.insight-pill.status-red   { border-color: var(--status-red);   }
.insight-pill.status-green .value { color: var(--status-green); }
.insight-pill.status-amber .value { color: var(--status-amber); }
.insight-pill.status-red   .value { color: var(--status-red);   }
.arrow-up   { color: var(--status-green); }
.arrow-down { color: var(--status-red);   }

/* ── Sections ── */
.page-section { margin-bottom: 32px; }
.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--subtle);
  margin-bottom: 14px;
}

/* ── Stat row ── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.stat .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
  margin-bottom: 6px;
}
.stat .value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--heading);   /* data is the primary signal, not the accent */
  font-variant-numeric: tabular-nums;
}
.stat .delta {
  font-size: 0.72rem;
  color: var(--subtle);
  margin-top: 2px;
}

/* ── Cards & grid ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
  margin-bottom: 16px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 8px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--subtle);
  border-bottom: 1px solid var(--border);
}
td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(148,163,184,0.06);
  font-size: 0.85rem;
  color: var(--text);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.025); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.green { color: var(--status-green); }
.amber { color: var(--status-amber); }
.red   { color: var(--status-red);   }
.muted { color: var(--subtle); }

/* ── Filters ── */
.filter-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
select, input {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.83rem;
  cursor: pointer;
  outline: none;
}
select:hover, input:hover { border-color: var(--muted); }

/* ── Trend badges ── */
.trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: 100px;
  font-weight: 600;
}
.trend.up   { background: rgba(34,197,94,0.12);  color: var(--status-green); }
.trend.down { background: rgba(239,68,68,0.12);  color: var(--status-red);   }
.trend.flat { background: rgba(100,116,139,0.12); color: var(--subtle); }
.trend.new  { background: rgba(56,189,248,0.12); color: var(--blue); }

/* ── Progress bar ── */
.progress-wrap { background: var(--border); border-radius: 100px; height: 5px; overflow: hidden; margin-top: 4px; }
.progress-fill { height: 100%; border-radius: 100px; background: var(--blue); transition: width 0.6s ease; }

/* ── Loading / empty ── */
.loading { color: var(--subtle); font-size: 0.85rem; padding: 20px 0; text-align: center; }

/* ── Collapsible section toggle ── */
.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-bottom: 14px;
  text-align: left;
}
.section-toggle:hover .section-title { color: var(--text); }
.toggle-chevron {
  font-size: 0.9rem;
  color: var(--subtle);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  line-height: 1;
}
.section-toggle[aria-expanded="false"] .toggle-chevron { transform: rotate(-90deg); }

/* ── Callouts ── */
.callouts-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0 24px;
  align-items: start;
}
.callout-divider {
  width: 1px;
  background: var(--border);
  align-self: stretch;
}
.callout-col-head {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.callout-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(148,163,184,0.05);
}
.callout-item:last-child { border-bottom: none; }
.callout-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.callout-dot.ok    { background: var(--status-green); }
.callout-dot.warn  { background: var(--status-amber); }
.callout-dot.alert { background: var(--status-red); }
.callout-body { min-width: 0; }
.callout-label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.callout-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 1px;
  flex-wrap: wrap;
}
.callout-value {
  font-size: 0.75rem;
  color: var(--subtle);
  font-variant-numeric: tabular-nums;
}
.callout-delta {
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.callout-delta.ok    { color: var(--status-green); }
.callout-delta.warn  { color: var(--status-amber); }
.callout-delta.alert { color: var(--status-red);   }

/* ── Investment ledger ── */
.instrument-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

/* ── Global tooltip ── */
#global-tip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--muted);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.78rem;
  color: var(--text);
  max-width: 260px;
  line-height: 1.4;
  pointer-events: none;
  z-index: 300;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* ── Category hover tip (spend-dna) ── */
#cat-tip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-width: 200px;
  font-size: 0.82rem;
  pointer-events: none;
  z-index: 200;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* ── Preset row (expenditure) ── */
.preset-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 10px;
}
.preset-select-wrap { flex: 0 0 auto; }
.preset-preview-wrap {
  flex: 1;
  min-width: 0;
}
.preset-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--subtle);
  margin-bottom: 5px;
}
.preset-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  min-height: 30px;
}

/* ── Category chips (expenditure filter) ── */
.cat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.cat-chip {
  background: var(--surface);
  color: var(--subtle);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.cat-chip:hover { border-color: var(--muted); color: var(--text); }
.cat-chip.active { background: rgba(56,189,248,0.15); border-color: var(--blue); color: var(--blue); font-weight: 600; }

/* ── Sortable table headers ── */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }

/* ── Heatmap ── */
.heatmap-scroll { overflow-x: auto; }
.heatmap-grid {
  display: grid;
  gap: 2px;
  min-width: max-content;
}
.heatmap-header { font-size: 0.65rem; color: var(--subtle); text-align: center; padding: 2px 4px; }
.heatmap-label { font-size: 0.75rem; color: var(--text); padding: 4px 8px; display: flex; align-items: center; white-space: nowrap; }
.heatmap-cell {
  border-radius: 3px;
  min-width: 48px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.8);
  cursor: default;
  transition: opacity 0.15s;
}
.heatmap-cell:hover { outline: 1px solid rgba(255,255,255,0.3); }
.heatmap-cell.empty { background: rgba(255,255,255,0.03); }

/* ── Insight pill cursor ── */
.insight-pill[data-tip] { cursor: help; }

/* ── 2×2 chart grid ── */
.chart-grid-2x2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-card {
  position: relative;
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.chart-card-header h2 { margin-bottom: 0; }

.chart-card canvas {
  height: 240px !important;
  width: 100% !important;
}

.fs-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--subtle);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
  padding: 0;
}
.fs-btn:hover { border-color: var(--muted); color: var(--text); }

.chart-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 1000;
  border-radius: 0 !important;
  display: flex !important;
  flex-direction: column;
  overflow: hidden;
}
.chart-fullscreen .chart-card-header { padding: 20px 24px 0; }
.chart-fullscreen canvas {
  flex: 1 1 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  width: 100% !important;
  padding: 0 24px 24px !important;
}

@media (max-width: 1100px) {
  #insights-bar { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  #insights-bar, .stat-row, .grid-2 { grid-template-columns: 1fr 1fr; }
  .chart-grid-2x2 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  #insights-bar, .stat-row, .grid-2 { grid-template-columns: 1fr; }
  body { padding: 16px; }
}
