/* ===========================================================================
   Bill Tracker v2 — Base stylesheet
   Reference: Tiller dark + Personal Finance Pro + Qlik typography
   Sidebar navigation, KPI strip, denser bill list, saturated accents.

   ARCHITECTURE:
   - All visual decisions live in CSS custom properties
   - Themes are loaded as additional stylesheets after this one
   - Each theme supplies .theme-dashboard overrides
   - See themes/README.md for theme authoring instructions
   =========================================================================== */

/* Default values (used as fallback if no theme loaded). These match the
   "default" theme (v2 dark). Theme files override them by setting the
   same variables under .theme-dashboard. */
:root {
  /* ---- Surfaces (backgrounds) ---- */
  --bg-ground:      #0a0e1a;    /* page background */
  --bg-sidebar:     #0d121f;    /* sidebar background */
  --bg-panel:       #141a2b;    /* primary card/panel background */
  --bg-panel-2:     #1a2138;    /* alt/hover panel, cluster header */
  --bg-row:         #131929;    /* bill list row */
  --bg-row-hover:   #1c2340;    /* bill list row hover */
  --bg-track:       #0a0e1a;    /* progress bar / util bar track */
  --bg-chip:        #0a0e1a;    /* count pills, badges on panels */

  /* ---- Borders ---- */
  --border:         #232a44;
  --border-strong:  #2e3757;
  --border-accent:  #3a4572;

  /* ---- Text (foreground) ---- */
  --fg-primary:     #e8ecf7;
  --fg-secondary:   #9aa4c4;
  --fg-tertiary:    #6b7699;
  --fg-muted:       #4a536e;
  --fg-on-accent:   #ffffff;

  /* ---- Accents: paid / success ---- */
  --accent-green:     #3dd68c;
  --accent-green-bg:  #0f2e21;
  --accent-green-dim: #1a4d3a;

  /* ---- Accents: amber / warning ---- */
  --accent-amber:     #f5b547;
  --accent-amber-bg:  #2e2113;
  --accent-amber-dim: #4d3a1e;

  /* ---- Accents: red / alert ---- */
  --accent-red:       #ff5e6c;
  --accent-red-bg:    #2e1219;
  --accent-red-dim:   #4d1f2a;

  /* ---- Accents: cyan / info ---- */
  --accent-cyan:      #56c8ff;
  --accent-cyan-bg:   #0e2535;
  --accent-cyan-dim:  #1a3d55;

  /* ---- Accents: secondary family (badges) ---- */
  --accent-purple:    #a78bfa;
  --accent-purple-bg: #1e1a36;
  --accent-pink:      #f472b6;
  --accent-pink-bg:   #2e1524;

  /* ---- Accents: extended palette for custom budget tiers ---- */
  --accent-teal:      #2dd4bf;
  --accent-orange:    #fb923c;
  --accent-blue:      #60a5fa;

  /* ---- Layout constants ---- */
  --sidebar-w:        240px;
  --max-content:      1240px;

  /* ---- Type ---- */
  --font-body:        "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono:        "JetBrains Mono", "SF Mono", Menlo, monospace;

  /* ---- Type scale (TV theme scales these up ~1.3x) ---- */
  --fs-base:          14px;    /* body text */
  --fs-label:         11px;    /* KPI labels, section sublabels */
  --fs-micro:         10px;    /* uppercase eyebrow, table headers */
  --fs-small:         12px;    /* secondary info, chip buttons */
  --fs-bill-name:     14px;    /* bill name, primary row text */
  --fs-amount:        15px;    /* monetary values in tables */
  --fs-kpi-value:     30px;    /* KPI big numbers */
  --fs-page-title:    34px;    /* page h1 */
  --fs-section-head:  18px;    /* section h2 */

  /* ---- Corner radius scale ---- */
  --radius-xs:        3px;
  --radius-sm:        6px;
  --radius-md:        8px;
  --radius-lg:        10px;
  --radius-pill:      12px;
  --radius-round:     50%;

  /* ---- Shadow scale ---- */
  --shadow-none:      none;
  --shadow-card:      none;
  --shadow-overlay:   0 10px 30px rgba(0,0,0,0.5);
  --shadow-progress:  0 0 12px rgba(61, 214, 140, 0.3);

  /* ---- Page background glow ---- */
  --glow-1-color:     rgba(86, 200, 255, 0.04);
  --glow-2-color:     rgba(167, 139, 250, 0.03);

  /* ---- Focus ring ---- */
  --focus-ring:       var(--accent-cyan);
}

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

html, body {
  background: var(--bg-ground);
  color: var(--fg-primary);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 800px 400px at 15% 0%, var(--glow-1-color), transparent 60%),
    radial-gradient(ellipse 600px 400px at 85% 100%, var(--glow-2-color), transparent 60%),
    var(--bg-ground);
}

/* ---------------------------------------------------------------------------
   Sidebar
   --------------------------------------------------------------------------- */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow-y: auto;
}

/* ---------------------------------------------------------------------------
   Mobile drawer chrome — hidden on desktop; activated by the <=960px media
   query below. The .sidebar becomes an off-canvas drawer on mobile; these are
   the hamburger toggle, the dimmed backdrop, and the in-drawer close button.
   Injected into every page by mobile-nav.js.
   --------------------------------------------------------------------------- */
.nav-toggle { display: none; }
.nav-close  { display: none; }
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.26s ease, visibility 0.26s ease;
  z-index: 70;
}
.nav-backdrop.is-open { opacity: 1; visibility: visible; }
.nav-toggle-bars { display: flex; flex-direction: column; gap: 4px; width: 18px; }
.nav-toggle-bars span { height: 2px; background: currentColor; border-radius: 2px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-green) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-on-accent);
  font-weight: 800;
  font-size: 16px;
}
.brand-name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--fg-tertiary);
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-tertiary);
  font-weight: 600;
  padding: 0 10px;
  margin-bottom: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.12s ease;
}
.nav-item:hover {
  background: var(--bg-panel);
  color: var(--fg-primary);
}
.nav-item.is-active {
  background: var(--bg-panel-2);
  color: var(--fg-primary);
  box-shadow: inset 2px 0 0 var(--accent-cyan);
}
.nav-item.is-disabled {
  color: var(--fg-muted);
  cursor: not-allowed;
}
.nav-item.is-disabled:hover { background: transparent; color: var(--fg-muted); }
.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-round);
  background: currentColor;
  opacity: 0.5;
}
.month-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.month-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--fg-secondary);
  text-decoration: none;
  font-size: 11px;
  transition: all 0.12s ease;
  border: 1px solid transparent;
}
.month-item:hover {
  background: var(--bg-panel-2);
  color: var(--fg-primary);
}
.month-item.is-active {
  background: var(--bg-panel-2);
  border-color: var(--accent-cyan);
  color: var(--fg-primary);
}
.month-short {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.month-year {
  font-size: 9px;
  color: var(--fg-tertiary);
  margin-top: 1px;
  font-family: var(--font-mono);
}

/* Theme picker — at bottom of sidebar */
.theme-picker .theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg-secondary);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.12s ease;
}
.theme-picker .theme-option:hover {
  background: var(--bg-panel);
  color: var(--fg-primary);
}
.theme-picker .theme-option.is-active {
  background: var(--bg-panel-2);
  color: var(--fg-primary);
  box-shadow: inset 2px 0 0 var(--accent-green);
}
.theme-swatch {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-xs);
  flex-shrink: 0;
  border: 1px solid var(--border);
}
/* Individual swatch colors — each theme can set these if desired,
   but a fallback lets the swatch show without per-theme code */
.theme-swatch-default    { background: linear-gradient(135deg, #0a0e1a 0%, #56c8ff 100%); }
.theme-swatch-slate      { background: linear-gradient(135deg, #ffffff 0%, #0284c7 100%); }
.theme-swatch-tv-mode    { background: linear-gradient(135deg, #0d1220 0%, #a78bfa 100%); }
.theme-swatch-meridian       { background: linear-gradient(135deg, #0e1014 0%, #818cf8 100%); }
.theme-swatch-meridian-light { background: linear-gradient(135deg, #f3f4f8 0%, #4f46e5 100%); }
.theme-swatch-harbor         { background: linear-gradient(135deg, #0b101c 0%, #5b9bff 100%); }
.theme-swatch-harbor-light   { background: linear-gradient(135deg, #ffffff 0%, #2563eb 100%); }
.theme-swatch-carbon         { background: linear-gradient(135deg, #0c0d0f 0%, #93a6c4 100%); }
.theme-swatch-carbon-light   { background: linear-gradient(135deg, #f4f4f2 0%, #475569 100%); }

/* ---------------------------------------------------------------------------
   Main area
   --------------------------------------------------------------------------- */

.main {
  margin-left: var(--sidebar-w);
  padding: 28px 32px 80px;
  max-width: calc(var(--max-content) + var(--sidebar-w));
}

.main-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  font-size: var(--fs-label);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-cyan);
  font-weight: 600;
  margin-bottom: 6px;
}

.page-title {
  font-size: var(--fs-page-title);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg-primary);
  line-height: 1.1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg-secondary);
  text-decoration: none;
  font-size: var(--fs-small);
  font-weight: 500;
  transition: all 0.12s ease;
}
.chip-btn:hover {
  background: var(--bg-panel-2);
  color: var(--fg-primary);
  border-color: var(--border-strong);
}

.today-chip {
  font-size: 11px;
  color: var(--fg-tertiary);
  padding: 8px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

/* ---------------------------------------------------------------------------
   KPI strip
   --------------------------------------------------------------------------- */

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease;
  box-shadow: var(--shadow-card);
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--kpi-color, var(--accent-cyan));
  opacity: 0.7;
}

.kpi-expected      { --kpi-color: var(--accent-cyan); }
.kpi-paid          { --kpi-color: var(--accent-green); }
.kpi-remaining     { --kpi-color: var(--accent-amber); }
.kpi-anomalies     { --kpi-color: var(--accent-red); }
.kpi-anomalies.is-empty { --kpi-color: var(--accent-green); }

.kpi-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.kpi-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--bg-panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--kpi-color);
  flex-shrink: 0;
}

.kpi-label {
  font-size: var(--fs-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-tertiary);
  font-weight: 600;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: var(--fs-kpi-value);
  font-weight: 600;
  color: var(--fg-primary);
  letter-spacing: -0.02em;
  font-feature-settings: "tnum" on, "lnum" on;
  line-height: 1.1;
  margin-bottom: 4px;
}

.kpi-paid .kpi-value      { color: var(--accent-green); }
.kpi-remaining .kpi-value { color: var(--accent-amber); }
.kpi-anomalies .kpi-value { color: var(--accent-red); }
.kpi-anomalies.is-empty .kpi-value { color: var(--accent-green); }

.kpi-sub {
  font-size: var(--fs-small);
  color: var(--fg-tertiary);
}
.kpi-sub span { color: var(--fg-secondary); font-weight: 600; }

/* Progress bar */
.progress-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
  padding: 12px 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.progress-track {
  flex: 1;
  height: 6px;
  background: var(--bg-track);
  border-radius: var(--radius-xs);
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-green) 0%, var(--accent-cyan) 100%);
  border-radius: var(--radius-xs);
  transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-progress);
}
.progress-label {
  font-size: 12px;
  color: var(--fg-secondary);
  font-weight: 500;
  white-space: nowrap;
  font-family: var(--font-mono);
}

/* ---------------------------------------------------------------------------
   Cluster cards
   --------------------------------------------------------------------------- */

.bills-wrapper {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.cluster-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.cluster-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel-2);
}

.cluster-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.cluster-title h2 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--fg-primary);
}
.cluster-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-round);
  background: var(--accent-cyan);
}
.cluster-count {
  font-size: 11px;
  color: var(--fg-tertiary);
  background: var(--bg-chip);
  padding: 2px 8px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-weight: 500;
}

.cluster-stats {
  display: flex;
  gap: 18px;
}
.cstat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: flex-end;
  font-family: var(--font-mono);
}
.cstat-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-tertiary);
}
.cstat-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-primary);
}
.cstat-paid { color: var(--accent-green); }
.cstat-remaining { color: var(--accent-amber); }

/* ---------------------------------------------------------------------------
   Bill table
   --------------------------------------------------------------------------- */

.bill-table {
  display: flex;
  flex-direction: column;
}

.bill-table-head,
.bill-row {
  display: grid;
  /* Toggles track holds three controls (Paid + Cleared + Hide). It must be
     wide enough for all three or the flex-end content overflows left over the
     amount column and obscures it. */
  grid-template-columns: 56px 1fr 110px 120px 270px;
  gap: 16px;
  align-items: center;
  padding: 10px 20px;
}

.bill-table-head {
  padding-top: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--fg-tertiary);
}
.bill-table-head .col-amount { text-align: right; }

.bill-row {
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
  outline: none;
  cursor: default;
}
.bill-row:last-child { border-bottom: none; }
.bill-row:hover,
.bill-row:focus {
  background: var(--bg-row-hover);
}
.bill-row.is-overdue:not(.is-paid) {
  background: linear-gradient(90deg, var(--accent-red-bg) 0%, var(--bg-panel) 40%);
  border-left: 2px solid var(--accent-red);
  padding-left: 18px;
}
.bill-row.is-due-soon:not(.is-paid) {
  background: linear-gradient(90deg, var(--accent-amber-bg) 0%, var(--bg-panel) 40%);
  border-left: 2px solid var(--accent-amber);
  padding-left: 18px;
}
.bill-row.has-anomaly:not(.is-paid) {
  box-shadow: inset 0 0 0 1px var(--accent-amber-dim);
}
.bill-row.is-paid .amount-val,
.bill-row.is-paid .bill-name {
  color: var(--fg-tertiary);
}
.bill-row.is-paid {
  opacity: 0.78;
}

/* Day pill */
.daypill {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  color: var(--fg-primary);
}
.bill-row.is-overdue:not(.is-paid) .daypill {
  background: var(--accent-red-bg);
  border-color: var(--accent-red-dim);
  color: var(--accent-red);
}
.bill-row.is-due-soon:not(.is-paid) .daypill {
  background: var(--accent-amber-bg);
  border-color: var(--accent-amber-dim);
  color: var(--accent-amber);
}
.bill-row.is-paid .daypill {
  background: var(--accent-green-bg);
  border-color: var(--accent-green-dim);
  color: var(--accent-green);
}
.daypill-empty { color: var(--fg-muted); }

/* Name column */
.bill-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.bill-name {
  font-size: var(--fs-bill-name);
  font-weight: 600;
  color: var(--fg-primary);
  letter-spacing: -0.005em;
}

.bill-notes {
  font-size: 12px;
  color: var(--fg-tertiary);
  margin-top: 4px;
  font-style: italic;
  line-height: 1.4;
}

.bill-debt-line {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.debt-balance { color: var(--fg-tertiary); }
.debt-balance strong { color: var(--fg-secondary); font-weight: 600; }

.debt-util {
  display: flex;
  align-items: center;
  gap: 6px;
}
.util-bar {
  width: 60px;
  height: 4px;
  background: var(--bg-track);
  border-radius: var(--radius-xs);
  overflow: hidden;
}
.util-fill {
  display: block;
  height: 100%;
  border-radius: var(--radius-xs);
}
.util-fill.util-low { background: var(--accent-green); }
.util-fill.util-med { background: var(--accent-amber); }
.util-fill.util-high { background: var(--accent-red); }
.util-pct { font-weight: 600; font-size: 11px; }
.util-pct.util-low { color: var(--accent-green); }
.util-pct.util-med { color: var(--accent-amber); }
.util-pct.util-high { color: var(--accent-red); }

.debt-apr { color: var(--fg-tertiary); }

.bill-anomaly {
  font-size: 11px;
  color: var(--accent-amber);
  margin-top: 6px;
  padding: 4px 10px;
  background: var(--accent-amber-bg);
  border-left: 2px solid var(--accent-amber);
  border-radius: var(--radius-xs);
  display: inline-block;
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.6;
  font-family: var(--font-mono);
}
.badge-ap {
  background: var(--bg-chip);
  color: var(--fg-tertiary);
  border: 1px solid var(--border-strong);
}
.badge-debt { background: var(--accent-cyan-bg); color: var(--accent-cyan); }
.badge-credit_card { background: var(--accent-pink-bg); color: var(--accent-pink); }
.badge-student_loan { background: var(--accent-purple-bg); color: var(--accent-purple); }
.badge-personal_loan { background: var(--accent-amber-bg); color: var(--accent-amber); }
.badge-phone_financing { background: var(--accent-cyan-bg); color: var(--accent-cyan); }
.badge-parent_car { background: var(--accent-green-bg); color: var(--accent-green); }
.badge-medical { background: var(--accent-red-bg); color: var(--accent-red); }

/* Status pills */
.status-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  text-align: center;
  min-width: 80px;
}
.status-paid {
  background: var(--accent-green-bg);
  color: var(--accent-green);
  border: 1px solid var(--accent-green-dim);
}
.status-overdue {
  background: var(--accent-red-bg);
  color: var(--accent-red);
  border: 1px solid var(--accent-red-dim);
}
.status-due-soon {
  background: var(--accent-amber-bg);
  color: var(--accent-amber);
  border: 1px solid var(--accent-amber-dim);
}
.status-upcoming {
  background: var(--bg-chip);
  color: var(--fg-tertiary);
  border: 1px solid var(--border);
}

/* Amount column */
.col-amount {
  text-align: right;
}
.amount-val {
  font-family: var(--font-mono);
  font-size: var(--fs-amount);
  font-weight: 600;
  color: var(--fg-primary);
  font-feature-settings: "tnum" on, "lnum" on;
  letter-spacing: -0.01em;
}
/* Muted "was $X" badge on a paid row whose actual differs from the plan. */
.amount-was {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-tertiary);
  font-feature-settings: "tnum" on, "lnum" on;
}
/* A paid row's amount is tappable to correct the recorded actual. */
.bill-row.is-paid .col-amount { cursor: pointer; }

/* Inline actual-amount editor (opened on mark-paid / correction). */
.amount-edit {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;              /* finger-sized touch target */
  padding: 2px 8px;
  border: 1px solid var(--accent-cyan);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}
.amount-edit-prefix {
  font-family: var(--font-mono);
  font-size: var(--fs-amount);
  color: var(--fg-secondary);
}
.amount-input {
  width: 6.5em;
  border: none;
  outline: none;
  background: transparent;
  color: var(--fg-primary);
  font-family: var(--font-mono);
  font-size: var(--fs-amount);
  font-weight: 600;
  text-align: right;
  font-feature-settings: "tnum" on, "lnum" on;
}
/* Hide the number-spinner so the field reads as a clean money input. */
.amount-input::-webkit-outer-spin-button,
.amount-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.amount-input { -moz-appearance: textfield; }

/* ---------------------------------------------------------------------------
   Toggles
   --------------------------------------------------------------------------- */

.col-toggles {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.toggle {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
  font-family: var(--font-body);
  outline: none;
}
.toggle:hover { background: var(--bg-row-hover); }
.toggle:focus-visible {
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.toggle:disabled { opacity: 0.55; cursor: default; }
.toggle:disabled:hover { background: none; }

.toggle-track {
  width: 28px;
  height: 16px;
  background: var(--border-strong);
  border-radius: 9px;
  position: relative;
  transition: background 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--fg-secondary);
  border-radius: var(--radius-round);
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
.toggle.is-on .toggle-track { background: var(--accent-green); }
.toggle.is-on .toggle-thumb {
  left: 14px;
  background: var(--fg-on-accent);
}
.toggle.toggle-reflected.is-on .toggle-track { background: var(--accent-cyan); }

.toggle-label {
  font-size: 10px;
  color: var(--fg-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  min-width: 40px;
}
.toggle.is-on .toggle-label { color: var(--fg-primary); }

/* ---------------------------------------------------------------------------
   Footer + toast
   --------------------------------------------------------------------------- */

.main-footer {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 11px;
  color: var(--fg-tertiary);
}
.main-footer kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  color: var(--fg-secondary);
  margin: 0 1px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-panel-2);
  border: 1px solid var(--border-strong);
  color: var(--fg-primary);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-overlay);
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 100;
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.is-error {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.kpi-value.is-updated {
  animation: pulse-update 0.6s ease;
}
@keyframes pulse-update {
  0%   { filter: brightness(1.5); }
  100% { filter: brightness(1); }
}

/* Responsive */
@media (max-width: 960px) {
  :root { --sidebar-w: 0px; }

  /* Sidebar becomes an off-canvas slide-out drawer */
  .sidebar {
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 80;
    will-change: transform;
    /* Anchor to top + size by the *visible* viewport, not bottom:0/100vh.
       On phones bottom:0 and 100vh extend behind the browser's bottom toolbar,
       which hid the last item ("Sign out") under it. 100dvh tracks the visible
       area above the toolbar; 100vh is the fallback for browsers without dvh. */
    bottom: auto;
    height: 100vh;
    height: 100dvh;
    /* thumb clearance below "Sign out" + home-indicator inset on notched phones
       (env resolves to 0 unless viewport-fit=cover, so 40px is the floor). */
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch; /* reliable momentum scroll on iOS */
    overscroll-behavior: contain;      /* don't chain scroll to the locked body */
  }
  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: 8px 0 48px -12px rgba(0, 0, 0, 0.55);
  }
  /* The user chip (name + Sign out) is pinned to the bottom via margin-top:auto
     on desktop. In the taller mobile drawer that auto-gap pushes "Sign out"
     past the fold; flow it directly under the theme picker instead. The
     .sidebar prefix outspecifies the partial's inline `.user-chip` rule. */
  .sidebar .user-chip { margin-top: 24px; }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 10px;
    left: 10px;
    width: 44px;
    height: 44px;
    z-index: 75;
    background: var(--bg-sidebar);
    color: var(--fg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--lift-1, 0 2px 8px rgba(0, 0, 0, 0.3));
    cursor: pointer;
  }

  .nav-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--fg-secondary);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
  }

  body.nav-open { overflow: hidden; }

  /* ----- M5: bill-tracker mobile content reflow (built around the drawer) -----
     Goals: 44pt touch targets, no horizontal page scroll, comfortable one-handed
     use. The drawer chrome above handles nav; these rules reflow page content. */

  .main { padding: 64px 16px 60px; }       /* top clearance for the fixed toggle */

  /* Header: let the month-nav + today chips wrap under the title instead of
     overflowing; the left pad clears the fixed hamburger when sticky. */
  .main-header { padding-left: 48px; flex-wrap: wrap; align-items: flex-start; }
  .header-right { flex-wrap: wrap; }
  /* Scoped to the bill tracker (.ui-modern): .today-chip is a read-only info
     span on the other 6 dashboards, where a 44px min-height would just over-
     inflate it. .chip-btn (month-nav links) is tracker-only already. */
  .ui-modern .chip-btn, .ui-modern .today-chip {
    display: inline-flex;
    align-items: center;
    min-height: 44px;            /* 44pt touch target */
    padding: 10px 14px;
  }

  .kpi-strip { grid-template-columns: repeat(2, 1fr); }

  /* Filter segmented control: contain its own horizontal scroll so a row of
     5 segments can never push the page past the viewport width. The meta text
     still wraps below via the .filter-bar flex-wrap. */
  .segmented {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;        /* hide the scrollbar; swipe to scroll */
  }
  .segmented::-webkit-scrollbar { display: none; }
  .seg {
    flex: 0 0 auto;               /* don't squash segments; scroll instead */
    min-height: 44px;             /* 44pt touch target */
  }

  /* Cluster header: stack title over the running subtotals when tight. */
  .cluster-header { flex-wrap: wrap; gap: 10px; }
  .cluster-stats { gap: 14px; flex-wrap: wrap; }

  /* Bill row: a single content column beside the day pill. */
  .bill-table-head { display: none; }
  .bill-row {
    grid-template-columns: 44px 1fr;
    row-gap: 10px;
  }
  .col-status, .col-amount, .col-toggles {
    grid-column: 2;
    justify-self: start;
  }
  .col-amount { justify-self: end; }
  .bill-debt-line { flex-wrap: wrap; }   /* balance/util/APR wrap, no overflow */

  /* Paid / Cleared / Hide controls: full 44pt touch targets, comfortably
     spaced. Allow them to wrap so the third control (Hide) drops to a second
     line rather than overflowing on the narrowest phones. */
  .col-toggles { gap: 12px; flex-wrap: wrap; }
  .toggle { min-height: 44px; padding: 8px 12px; }

  /* The tracker footer holds only keyboard hints — meaningless on touch.
     Scoped to .ui-modern so the other dashboards' footer disclaimers
     (methodology / assumptions) still show on mobile. */
  .ui-modern .main-footer { display: none; }
}

/* Narrow phones: drop the KPI tiles to one column so mono currency values
   never clip inside a half-width card. */
@media (max-width: 460px) {
  .kpi-strip { grid-template-columns: 1fr; }
}

/* ===========================================================================
   Edit buttons (Phase 7.5) — small icon-link in row tables
   =========================================================================== */
.edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-tertiary);
  text-decoration: none;
  transition: all 0.12s;
}
.edit-btn:hover {
  background: var(--bg-row-hover);
  border-color: var(--border);
  color: var(--accent-cyan);
}
.col-edit { display: flex; justify-content: center; }

.bill-name-link {
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius-xs);
  padding: 1px 4px;
  margin: -1px -4px;
  transition: background 0.12s, color 0.12s;
}
.bill-name-link:hover {
  background: var(--bg-row-hover);
  color: var(--accent-cyan);
}
.bill-name-link:hover .bill-name {
  color: var(--accent-cyan);
}

/* ===========================================================================
   UI Modern enhancements — productionized from the Claude Design proposal
   (design_handoff_themes/ui-modern.css). Gated on .ui-modern + per-feature
   .f-* classes that the bill tracker sets on <body> (tracker_v2.html), so the
   other dashboards sharing this stylesheet are unaffected. Every rule reads
   theme variables, so it tracks all themes. The card-rows layer (.f-rows) and
   the preview-only #uiPanel chrome are intentionally NOT ported.
   =========================================================================== */

.ui-modern {
  --r-card:   16px;
  --r-row:    12px;
  --r-pill:   999px;
  --lift-1:   0 1px 2px rgba(0,0,0,0.04), 0 6px 18px -10px rgba(0,0,0,0.30);
  --lift-2:   0 2px 4px rgba(0,0,0,0.05), 0 14px 30px -12px rgba(0,0,0,0.38);
}

/* f-motion — subtle, tasteful transitions (respects reduced-motion) */
.f-motion .kpi,
.f-motion .cluster-card,
.f-motion .bill-row,
.f-motion .chip-btn,
.f-motion .nav-item,
.f-motion .month-item,
.f-motion .seg,
.f-motion .toggle,
.f-motion .status-pill {
  transition: background-color .18s ease, border-color .18s ease,
              box-shadow .22s ease, transform .18s cubic-bezier(.4,0,.2,1),
              color .18s ease;
}
@media (prefers-reduced-motion: reduce) {
  .f-motion * { transition: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-backdrop { transition: none !important; }
}

/* f-header — compact, sticky header + tighter KPI tiles */
.f-header .main-header {
  position: sticky;
  top: 0;
  z-index: 30;
  margin-bottom: 22px;
  padding-top: 14px;
  padding-bottom: 14px;
  background: var(--bg-ground);
  border-bottom: 1px solid var(--border);
}
.f-header .page-title { font-size: calc(var(--fs-page-title) - 6px); }
.f-header .kpi-strip { gap: 12px; margin-bottom: 12px; }
.f-header .kpi { padding: 14px 16px; }
.f-header .kpi-value { font-size: calc(var(--fs-kpi-value) - 3px); margin-bottom: 2px; }
.f-header .kpi-top { margin-bottom: 7px; }
.f-header .progress-row { margin-bottom: 22px; }

/* f-filters — segmented control (markup in tracker_v2.html, hidden until on) */
.filter-bar { display: none; }
.f-filters .filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 20px;
  flex-wrap: wrap;
}
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
}
.seg {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--fg-secondary);
  padding: 7px 16px;
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.seg:hover { color: var(--fg-primary); }
.seg .seg-count {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  background: var(--bg-chip);
  color: var(--fg-tertiary);
}
.seg.is-active {
  background: var(--accent-cyan);
  color: var(--fg-on-accent);
}
.seg.is-active .seg-count { background: rgba(255,255,255,.22); color: var(--fg-on-accent); }
.filter-meta { font-size: var(--fs-small); color: var(--fg-tertiary); font-family: var(--font-mono); }

/* f-sticky — sticky cluster headers (running subtotals stay in view).
   position:sticky needs the overflow clip removed from the card. */
.f-sticky .cluster-card { overflow: visible; }
.f-sticky .cluster-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  backdrop-filter: saturate(1.1);
}
/* when the compact sticky header is also on, drop cluster headers to sit
   flush directly beneath it (height measured live into --stick-top) */
.f-sticky.f-header .cluster-header { top: var(--stick-top, 88px); }

/* f-nav — sidebar / navigation polish: pill active states, softer items */
.f-nav .brand-mark { border-radius: 12px; }
.f-nav .nav-item { border-radius: var(--r-pill, 999px); padding: 9px 12px; }
.f-nav .nav-item .nav-dot { transition: transform .18s ease, opacity .18s ease; }
.f-nav .nav-item:hover .nav-dot { transform: scale(1.25); opacity: .9; }
.f-nav .nav-item.is-active {
  background: var(--accent-cyan-bg);
  color: var(--accent-cyan);
  box-shadow: none;
}
.f-nav .nav-item.is-active .nav-dot { background: var(--accent-cyan); opacity: 1; }
.f-nav .month-item { border-radius: 10px; }
.f-nav .month-item.is-active {
  background: var(--accent-cyan-bg);
  border-color: var(--accent-cyan-dim);
  color: var(--accent-cyan);
}
.f-nav .theme-option.is-active { border-radius: var(--r-pill, 999px); }

/* ===========================================================================
   Hide / unhide bills (post-8.2 polish 4) — subtle ghost control on each row,
   plus a muted "Hidden bills" section shown only when ?show_hidden=1.
   =========================================================================== */
.hide-form { display: inline-flex; margin: 0; }
.hide-btn {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-tertiary);
  transition: all 0.12s;
}
.hide-btn:hover {
  background: var(--bg-row-hover);
  border-color: var(--border);
  color: var(--fg-primary);
}

.hidden-section {
  margin-top: 28px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  opacity: 0.85;
}
.hidden-section-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.hidden-section-head h2 {
  margin: 0;
  font-size: 14px;
  color: var(--fg-secondary);
}
.hidden-section-sub {
  font-size: 12px;
  color: var(--fg-tertiary);
}
.hidden-section-empty {
  padding: 16px 20px;
  color: var(--fg-tertiary);
}
.hidden-section .bill-table-head,
.hidden-section .bill-row.is-hidden {
  grid-template-columns: 56px 1fr 120px 200px;
}
.hidden-section .bill-row.is-hidden {
  color: var(--fg-secondary);
}
