/* ----------------------------------------------------------------------
   Finance Dashboard — styles
   Mobile-first. Dark by default, follows system. No build step.
---------------------------------------------------------------------- */

:root {
  color-scheme: dark light;

  /* Palette — dark */
  --bg:           #0e1116;
  --bg-card:      #161b22;
  --bg-card-2:    #1c232c;
  --border:       #2a313c;
  --text:         #e6edf3;
  --text-dim:     #8b949e;
  --text-faint:   #6e7681;

  --accent:       #58a6ff;
  --good:         #3fb950;
  --warn:         #d29922;
  --bad:          #f85149;
  --neutral:      #8b949e;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Radius / spacing */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:         #f6f8fa;
    --bg-card:    #ffffff;
    --bg-card-2:  #f0f3f6;
    --border:     #d0d7de;
    --text:       #1f2328;
    --text-dim:   #59636e;
    --text-faint: #818b95;
    --accent:     #0969da;
    --good:       #1a7f37;
    --warn:       #9a6700;
    --bad:        #cf222e;
    --neutral:    #6e7781;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { background: var(--bg-card-2); }
button:active { transform: translateY(1px); }
button[disabled] { opacity: 0.5; cursor: default; }

/* ----------------------------------------------------------------------
   Layout
---------------------------------------------------------------------- */

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 14px 80px;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 2px 14px;
}

.app-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.app-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.asof {
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 4px;
  margin-bottom: 14px;
  position: sticky;
  top: 8px;
  z-index: 5;
  backdrop-filter: blur(6px);
}
.tab {
  flex: 1;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  border-radius: 7px;
  font-weight: 500;
  font-size: 14px;
}
.tab.is-active {
  background: var(--bg-card-2);
  color: var(--text);
}

/* ----------------------------------------------------------------------
   Card
---------------------------------------------------------------------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 10px;
  font-weight: 600;
}
.card-section + .card-section { margin-top: 14px; }

/* ----------------------------------------------------------------------
   Hero — Headroom
---------------------------------------------------------------------- */

.hero {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-card-2) 100%);
}
.hero-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.hero-amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 44px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 4px 0 6px;
  line-height: 1.1;
}
.hero-amount.is-good  { color: var(--good); }
.hero-amount.is-bad   { color: var(--bad); }
.hero-sub {
  font-size: 13px;
  color: var(--text-dim);
}
.delta {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  margin-left: 4px;
}
.delta.up   { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--neutral); }

/* ----------------------------------------------------------------------
   Mini-KPIs row
---------------------------------------------------------------------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
}
.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
}
.kpi-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 600;
  margin-top: 4px;
  letter-spacing: -0.01em;
}
.kpi-sub {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* ----------------------------------------------------------------------
   Tier bars
---------------------------------------------------------------------- */

.tier-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tier-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: center;
  gap: 10px;
}
.tier-name {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
.tier-bar {
  height: 8px;
  background: var(--bg-card-2);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.tier-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 350ms ease;
}
.tier-bar-fill.required     { background: var(--bad); }
.tier-bar-fill.lifestyle    { background: var(--warn); }
.tier-bar-fill.discretionary{ background: var(--accent); }
.tier-amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text);
}
.tier-projected {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------------
   Sparkline / chart wrapper
---------------------------------------------------------------------- */

.chart-wrap {
  position: relative;
  height: 180px;
}
.chart-legend {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.chart-legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}

/* ----------------------------------------------------------------------
   Lists (projections, recurring)
---------------------------------------------------------------------- */

.row-list {
  display: flex;
  flex-direction: column;
}
.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }

.row-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-card-2);
  color: var(--text-dim);
}
.row-icon.expected { background: rgba(88,166,255,0.15); color: var(--accent); }
.row-icon.late     { background: rgba(248,81,73,0.15); color: var(--bad); }
.row-icon.matched  { background: rgba(63,185,80,0.15); color: var(--good); }
.row-icon.skipped  { background: rgba(210,153,34,0.15); color: var(--warn); }

.row-title {
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub {
  font-size: 12px;
  color: var(--text-faint);
}
.row-amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 500;
  text-align: right;
}
.row-amount.income  { color: var(--good); }
.row-amount.expense { color: var(--text); }

/* ----------------------------------------------------------------------
   States: loading / empty / error
---------------------------------------------------------------------- */

.state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.state.is-error {
  color: var(--bad);
}
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  font-size: 13px;
  color: var(--text-faint);
  padding: 16px 0;
  text-align: center;
}

/* ----------------------------------------------------------------------
   Stale banner
---------------------------------------------------------------------- */

.stale-banner {
  background: rgba(210,153,34,0.12);
  border: 1px solid rgba(210,153,34,0.35);
  color: var(--warn);
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-size: 12px;
  margin-bottom: 10px;
}

/* ----------------------------------------------------------------------
   "Why?" expandable — explain the math behind any amount
---------------------------------------------------------------------- */

.why-toggle {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  display: inline-grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  line-height: 1;
}
.why-toggle:hover { color: var(--text); border-color: var(--text-dim); }
.why-toggle[aria-expanded="true"] {
  background: var(--bg-card-2);
  color: var(--text);
  border-color: var(--text-dim);
}

.why-panel {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-dim);
}
.why-panel.is-open { display: block; }

.why-formula {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 10px;
}
.why-formula .op   { color: var(--text-dim); padding: 0 4px; }
.why-formula .lbl  { color: var(--text-dim); }
.why-formula .val  { color: var(--text); }
.why-formula .total { color: var(--good); font-weight: 600; }
.why-formula .neg   { color: var(--bad); }

.why-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  font-variant-numeric: tabular-nums;
  margin: 6px 0;
}
.why-list .lbl  { color: var(--text-dim); }
.why-list .val  { font-family: var(--font-mono); color: var(--text); text-align: right; }
.why-list .lbl.tot, .why-list .val.tot {
  color: var(--text);
  font-weight: 600;
  border-top: 1px solid var(--border);
  padding-top: 4px;
  margin-top: 2px;
}

.why-note {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 8px;
}

/* Make the hero card title row roomy enough for the toggle */
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.card-title-row .card-title { margin: 0; }

/* Tier row gets a tiny inline toggle */
.tier-row .why-toggle {
  width: 18px;
  height: 18px;
  font-size: 11px;
  margin-left: 4px;
}
.tier-why-panel {
  grid-column: 1 / span 3;
  display: none;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  margin-top: 4px;
}
.tier-why-panel.is-open { display: block; }

/* KPI "Why?" affordance */
.kpi { position: relative; }
.kpi .why-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  font-size: 11px;
}
.kpi .why-panel {
  margin-top: 8px;
  padding-top: 8px;
  font-size: 12px;
}

/* ----------------------------------------------------------------------
   Wider screens
---------------------------------------------------------------------- */

@media (min-width: 720px) {
  .app { padding: 24px; }
  .hero-amount { font-size: 56px; }
  .kpi-row { gap: 14px; }
}


/* ============================================================================
   AI assessment, overrides, anomalies cards (Phase 4)
   ============================================================================ */

.ai-card {
  border-left: 3px solid var(--accent, #4f8cc9);
  background: rgba(79, 140, 201, 0.06);
  padding: 18px 20px;
}
.ai-card .ai-meta {
  font-size: 11px;
  color: var(--text-faint, #6b7380);
  margin-left: auto;
  white-space: nowrap;
}
.ai-card .ai-body {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text, #d6dae0);
  white-space: pre-wrap;
}

.overrides-card {
  border-left: 3px solid #c97a4f;
  background: rgba(201, 122, 79, 0.06);
}
.overrides-card .overrides-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.override-row {
  padding: 8px 10px;
  background: rgba(201, 122, 79, 0.05);
  border-radius: 6px;
}
.override-label { font-size: 12px; font-weight: 600; color: #c97a4f; letter-spacing: 0.04em; }
.override-note  { font-size: 13px; color: var(--text-dim, #8b949e); margin-top: 3px; }


.why-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint, #6b7380);
  margin: 14px 0 6px;
}
.why-panel .why-section-title:first-child { margin-top: 0; }


/* ============================================================================
   Two-column layout for Today view (Phase 4)
   ============================================================================ */
.today-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 1000px) {
  /* Open up the whole app on wider screens so two-column layout has room */
  .app { max-width: 1320px; }
  .today-grid {
    grid-template-columns: minmax(0, 1.4fr) minmax(380px, 1fr);
    align-items: start;
    gap: 24px;
  }
}
.today-main, .today-sidebar { display: flex; flex-direction: column; gap: 14px; }

/* Watch list — compact, text-only replacement for the heavy anomalies card */
.watch-card { /* no extra border/bg — uses default card styling */ }
.watch-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint, #6b7380);
  margin-bottom: 10px;
}
.watch-list { display: flex; flex-direction: column; gap: 7px; }
.watch-row {
  font-size: 13px;
  color: var(--text-dim, #8b949e);
  line-height: 1.45;
}
.watch-row strong { color: var(--text, #d6dae0); font-weight: 600; }
.watch-arrow { font-weight: 700; display: inline-block; min-width: 12px; }
.watch-above { color: #d9b34f; }
.watch-below { color: var(--text-faint, #6b7380); }
