@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg: #121212;
  --card: #1F1F1F;
  --border: #2C2C2C;
  --primary: #E60012;
  --text: #FFFFFF;
  --secondary: #AAAAAA;
  --green: #2ECC71;
  --amber: #F5A623;
  --card-radius: 10px;

  /* v4: glass surface tokens, built on top of the same palette */
  --glass-bg: rgba(31, 31, 31, 0.55);
  --glass-bg-soft: rgba(24, 24, 24, 0.5);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: 16px;
  --ease: cubic-bezier(.4, 0, .2, 1);
}

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

body {
  background:
    radial-gradient(circle at 15% 0%, rgba(230, 0, 18, 0.08), transparent 40%),
    radial-gradient(circle at 85% 15%, rgba(46, 204, 113, 0.05), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: 'Oswald', sans-serif;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

::selection { background: var(--primary); color: #fff; }

.mono { font-family: 'JetBrains Mono', monospace; }

/* subtle ambient scan-line texture, industrial HUD feel */
.scan-line {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.012) 0px,
    rgba(255,255,255,0.012) 1px,
    transparent 1px,
    transparent 3px
  );
}

/* ============ ENTRANCE ANIMATION ============ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.health-block,
.budget-card,
.funnel-card,
.top-row > *,
.triple-row > *,
.charts-row > *,
.table-card {
  animation: fadeInUp 0.5s var(--ease) both;
}
.top-row > *:nth-child(1) { animation-delay: 0.02s; }
.top-row > *:nth-child(2) { animation-delay: 0.06s; }
.top-row > *:nth-child(3) { animation-delay: 0.1s; }
.top-row > *:nth-child(4) { animation-delay: 0.14s; }
.triple-row > *:nth-child(1) { animation-delay: 0.02s; }
.triple-row > *:nth-child(2) { animation-delay: 0.06s; }
.triple-row > *:nth-child(3) { animation-delay: 0.1s; }
.charts-row > *:nth-child(1) { animation-delay: 0.02s; }
.charts-row > *:nth-child(2) { animation-delay: 0.06s; }

/* ============ TOPBAR ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 40px;
  border-bottom: 1px solid var(--glass-border);
  background: linear-gradient(180deg, rgba(22,22,22,0.85) 0%, rgba(18,18,18,0.6) 100%);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 16px; }

.tri-logo { width: 42px; height: 42px; }
.tri {
  fill: none;
  stroke: var(--primary);
  stroke-width: 6;
  stroke-linejoin: round;
}
.tri-1 { transform: translate(-14px, 0); opacity: 0.55; }
.tri-2 { transform: translate(0, 0); opacity: 0.78; }
.tri-3 { transform: translate(14px, 0); opacity: 1; }

.brand-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1.5px;
}
.brand-text h1 span { color: var(--primary); }

.subtitle {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--secondary);
  margin-top: 3px;
  text-transform: uppercase;
}
.version-tag {
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 2px;
  margin-left: 4px;
}

.agent-tag {
  display: inline-block;
  margin-top: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 0.6px;
  color: var(--secondary);
  text-decoration: none;
  border-bottom: 1px dotted var(--border);
  transition: color .2s, border-color .2s;
}
.agent-tag:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.topbar-right { display: flex; align-items: center; gap: 28px; }

.report-date { display: flex; flex-direction: column; align-items: flex-end; }
.report-date .label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--secondary);
  letter-spacing: 1.5px;
}
.report-date .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  margin-top: 2px;
}

.range-switch {
  display: flex;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255,255,255,0.02);
}
.range-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  background: transparent;
  color: var(--secondary);
  border: none;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.range-btn:hover:not(:disabled) { color: var(--text); }
.range-btn.active {
  background: var(--primary);
  color: #fff;
}
.range-btn:disabled,
.range-btn.range-btn--disabled {
  color: #555;
  cursor: not-allowed;
  opacity: 0.5;
}

.export-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.5px;
  background: rgba(255,255,255,0.02);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color .2s var(--ease), color .2s var(--ease), transform .15s var(--ease);
}
.export-btn:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }
.export-btn:active { transform: translateY(0); }

/* v8 ADD (Phase 3): small export variant for in-card buttons + the
   header row that holds a card-eyebrow next to one of these */
.export-btn--small { font-size: 9.5px; padding: 5px 10px; letter-spacing: 1px; }

/* v6 ADD: month dropdown that sits next to the Monthly Report export
   button, letting the user pick any archived month (not just the
   previous one) to view in the weekly breakdown table. */
.month-report-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.month-select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  background: rgba(255,255,255,0.02);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
  transition: border-color .2s var(--ease), color .2s var(--ease);
}
.month-select:hover { border-color: var(--primary); }
.month-select:disabled { color: #555; cursor: not-allowed; opacity: 0.5; }
.month-select option { background: #0d0d0d; color: var(--text); }

/* v6 ADD: manual "Log a Receipt" form (Historical Intelligence tab) */
.receipt-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.receipt-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}
.receipt-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10.5px;
  letter-spacing: .5px;
  color: var(--text-dim, #999);
  flex: 1 1 160px;
}
.receipt-form input,
.receipt-form select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: rgba(255,255,255,0.02);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 8px 10px;
}
.receipt-form input:focus,
.receipt-form select:focus { outline: none; border-color: var(--primary); }
.receipt-form-note { display: flex; flex-direction: column; gap: 4px; font-size: 10.5px; color: var(--text-dim, #999); }
.receipt-form-actions { align-items: center; }
.receipt-form-status { font-size: 11px; color: var(--text-dim, #999); }
.receipt-form-status.is-success { color: #3ecf6a; }
.receipt-form-status.is-error { color: #ff5c5c; }
.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.card-header-row .card-eyebrow { margin-bottom: 0; }

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--green);
  border: 1px solid rgba(46, 204, 113, 0.35);
  padding: 5px 12px;
  border-radius: 20px;
  background: rgba(46, 204, 113, 0.05);
}
.status-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse 1.6s infinite ease-in-out;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ============ LAYOUT ============ */
.dashboard {
  max-width: 1360px;
  margin: 0 auto;
  padding: 32px 40px 60px;
  position: relative;
  z-index: 1;
}

.card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--card-radius);
  padding: 20px 22px;
  position: relative;
  backdrop-filter: blur(var(--glass-blur)) saturate(150%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(150%);
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  transition: border-color .25s var(--ease), transform .25s var(--ease), box-shadow .25s var(--ease);
}
.card:hover {
  border-color: rgba(255,255,255,0.14);
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(0,0,0,0.35);
}

.card-eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.8px;
  color: var(--secondary);
  display: block;
  margin-bottom: 12px;
}

/* ============ HEALTH BLOCK ============ */
.health-block {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
  margin-bottom: 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--card-radius);
  padding: 24px;
  backdrop-filter: blur(var(--glass-blur)) saturate(150%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(150%);
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
}

.health-gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--glass-border);
  padding-right: 24px;
  position: relative;
}

.gauge-svg { width: 200px; height: 120px; }
.gauge-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 12;
  stroke-linecap: round;
}
.gauge-fill {
  fill: none;
  stroke: var(--primary);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 251;
  stroke-dashoffset: 251;
  filter: drop-shadow(0 0 6px rgba(230,0,18,0.45));
  transition: stroke-dashoffset 1.2s var(--ease), stroke .4s var(--ease);
}
.gauge-readout {
  position: relative;
  margin-top: -56px;
  display: flex;
  align-items: baseline;
  gap: 2px;
}
.gauge-number {
  font-family: 'JetBrains Mono', monospace;
  font-size: 38px;
  font-weight: 700;
}
.gauge-max {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: var(--secondary);
}
.gauge-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.8px;
  color: var(--secondary);
  margin-top: 10px;
}
.gauge-basis {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.6px;
  color: var(--secondary);
  opacity: 0.65;
  margin-top: 4px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.card-eyebrow-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-eyebrow-row .card-eyebrow {
  margin-bottom: 0;
}

.week-kpi-grid {
  margin-bottom: 24px;
}

.monthly-report-total-row {
  font-weight: 700;
  border-top: 1px solid var(--glass-border);
}

.monthly-report-total-row td {
  color: var(--text-primary, #fff);
}

.boost-plan-card {
  border-left: 3px solid var(--primary);
}

.kpi-card {
  background: var(--glass-bg-soft);
  border: 1px solid var(--glass-border);
  border-radius: var(--card-radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.kpi-card:hover { border-color: var(--primary); transform: translateY(-2px); }

.kpi-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 1.2px;
  color: var(--secondary);
  text-transform: uppercase;
}
.kpi-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kpi-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.kpi-unit {
  font-size: 10.5px;
  color: var(--secondary);
}

.delta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  transition: color .2s var(--ease), background .2s var(--ease);
}
.delta.up { color: var(--green); background: rgba(46,204,113,0.12); }
.delta.down { color: var(--primary); background: rgba(230,0,18,0.12); }
.delta.flat { color: var(--secondary); background: rgba(170,170,170,0.1); }
.delta:empty { display: none; }

/* ---- Phase 1: KPI sparklines + hover tooltips (additive, v8) ---- */
.kpi-spark {
  height: 22px;
  margin-top: 2px;
}
.kpi-spark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.kpi-spark:empty { display: none; }

.kpi-card[data-tooltip] { position: relative; cursor: default; }
.kpi-card[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: 220px;
  background: #101010;
  border: 1px solid var(--glass-border);
  color: var(--text-primary, #fff);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity .15s var(--ease), transform .15s var(--ease);
  z-index: 20;
}
.kpi-card[data-tooltip]:hover::after,
.kpi-card[data-tooltip]:focus-within::after {
  opacity: 1;
  transform: translateY(0);
}

/* ============ BUDGET PACING ============ */
.budget-card { margin-bottom: 16px; }
.budget-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.budget-bar-track {
  flex: 1;
  height: 14px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--glass-border);
  border-radius: 7px;
  overflow: hidden;
}
.budget-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #ff4b57);
  border-radius: 7px 0 0 7px;
  transition: width 1s var(--ease);
}
.budget-readout {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--secondary);
  white-space: nowrap;
}

/* ============ FUNNEL ============ */
.funnel-card { margin-bottom: 16px; }
.funnel-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
}
.funnel-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--glass-bg-soft);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  position: relative;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.funnel-stage:hover { border-color: rgba(255,255,255,0.16); transform: translateY(-1px); }
.funnel-stage-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.funnel-stage-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--secondary);
  text-transform: uppercase;
}
.funnel-stage-pct {
  font-size: 10.5px;
  color: var(--green);
}
.funnel-stage-drop {
  font-size: 9.5px;
  color: var(--secondary);
  opacity: .8;
}
.funnel-arrow {
  align-self: center;
  color: var(--border);
  font-size: 18px;
}

/* v8 ADD (Phase 2) */
.funnel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.funnel-overall {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--green);
}

/* ============ TOP ROW ============ */
.top-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.top-card { min-height: 118px; display: flex; flex-direction: column; justify-content: space-between; }
.top-card h2 {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.25;
}

.rec-badge {
  align-self: flex-start;
  background: rgba(230, 0, 18, 0.12);
  color: var(--primary);
  border: 1px solid rgba(230, 0, 18, 0.4);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 1.5px;
  padding: 3px 9px;
  border-radius: 3px;
  margin-top: 8px;
}

.top-metric {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 8px;
}
.top-metric span:first-child {
  font-family: 'JetBrains Mono', monospace;
  font-size: 20px;
  font-weight: 700;
  color: var(--green);
}
.top-metric small {
  color: var(--secondary);
  font-size: 11px;
  letter-spacing: 1px;
}

.audience-range {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--secondary);
  margin-top: 8px;
}

/* ============ TRIPLE ROW ============ */
.triple-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.rec-list, .alert-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.rec-list li, .alert-list li {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 14.5px;
  padding: 9px 10px;
  background: var(--glass-bg-soft);
  border: 1px solid var(--glass-border);
  border-radius: 5px;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.rec-list li:hover, .alert-list li:hover { transform: translateX(2px); }
.rec-list li { border-left: 3px solid var(--green); }
.alert-list li { border-left: 3px solid var(--primary); }

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.item-title { display: flex; align-items: center; gap: 8px; }
.rec-list .item-title::before { content: '✔'; color: var(--green); font-size: 11px; }
.alert-list .item-title::before { content: '⚠'; color: var(--primary); font-size: 11px; }

.item-reason {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--secondary);
  padding-left: 19px;
}

.priority-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 1px;
  padding: 2px 7px;
  border-radius: 3px;
  white-space: nowrap;
}
.priority-High { background: rgba(230,0,18,0.15); color: var(--primary); }
.priority-Medium { background: rgba(245,166,35,0.15); color: var(--amber); }
.priority-Low { background: rgba(170,170,170,0.12); color: var(--secondary); }
.priority-Video { background: rgba(138,110,255,0.16); color: #a48bff; }
.priority-Image { background: rgba(0,180,190,0.16); color: #3fd1c9; }

.targeting-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 720px) {
  .targeting-grid { grid-template-columns: 1fr; }
}
.targeting-col-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 1.4px;
  color: var(--secondary);
  opacity: 0.75;
}
.rec-list.plain-list li {
  padding: 6px 0;
}

.prediction-card { display: flex; flex-direction: column; }
.prediction-body {
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex: 1;
}
.prediction-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.prediction-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 30px;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.prediction-label {
  font-size: 11px;
  color: var(--secondary);
  letter-spacing: 1px;
  text-align: center;
}
.prediction-divider {
  width: 1px;
  height: 50px;
  background: var(--glass-border);
}

/* ============ CHARTS ============ */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.chart-card { min-height: 260px; }
.chart-card canvas { max-height: 210px; }

/* ============ CAMPAIGNS TABLE ============ */
.table-card { margin-bottom: 16px; }
.table-wrap {
  overflow: auto;
  max-height: 480px;
  border-radius: 6px;
}
.campaigns-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
}
.campaigns-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(24,24,24,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.campaigns-table th {
  text-align: left;
  color: var(--secondary);
  font-weight: 500;
  letter-spacing: 1px;
  font-size: 10.5px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color .15s var(--ease);
}
.campaigns-table th:hover { color: var(--text); }
.campaigns-table th.sorted::after { content: ' ▾'; color: var(--primary); }
.campaigns-table th.sorted.asc::after { content: ' ▴'; color: var(--primary); }
.campaigns-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.campaigns-table tbody tr { transition: background .15s var(--ease); }
.campaigns-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.campaigns-table tbody tr:last-child td { border-bottom: none; }

.status-chip {
  font-size: 10px;
  letter-spacing: 0.8px;
  padding: 2px 8px;
  border-radius: 10px;
}
.status-Active { background: rgba(46,204,113,0.15); color: var(--green); }
.status-Learning { background: rgba(245,166,35,0.15); color: var(--amber); }
.status-Paused { background: rgba(170,170,170,0.12); color: var(--secondary); }

/* ============ FOOTER ============ */
.footer {
  display: flex;
  justify-content: space-between;
  padding: 18px 40px 30px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--secondary);
  letter-spacing: 1px;
  max-width: 1360px;
  margin: 0 auto;
}

.footer-link {
  color: var(--secondary);
  text-decoration: none;
  transition: color .2s;
}
.footer-link:hover { color: var(--primary); }

/* ============ RESPONSIVE ============ */
@media (max-width: 980px) {
  .health-block { grid-template-columns: 1fr; }
  .health-gauge { border-right: none; border-bottom: 1px solid var(--glass-border); padding-right: 0; padding-bottom: 20px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .top-row { grid-template-columns: repeat(2, 1fr); }
  .triple-row { grid-template-columns: 1fr; }
  .charts-row { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 14px; position: static; }
  .topbar-right { width: 100%; justify-content: space-between; flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .dashboard { padding: 20px 16px 40px; }
  .top-row { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 18px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .gauge-fill { transition: none; }
  .status-pill .dot { animation: none; }
  .health-block, .budget-card, .funnel-card, .top-row > *, .triple-row > *, .charts-row > *, .table-card {
    animation: none;
  }
  .card, .kpi-card, .funnel-stage, .rec-list li, .alert-list li {
    transition: none;
  }
}

/* ============ PRINT / EXPORT ============ */
@media print {
  body { background: #fff; color: #000; }
  .scan-line { display: none; }
  .no-print { display: none !important; }
  .card, .health-block, .kpi-card {
    background: #fff;
    border: 1px solid #ccc;
    backdrop-filter: none;
    box-shadow: none;
    break-inside: avoid;
  }
  .charts-row, .top-row, .triple-row { break-inside: avoid; }
  .footer { color: #666; }
  .table-wrap { max-height: none; overflow: visible; }
  .campaigns-table thead th { position: static; background: #fff; }
}

/* ============================================================
   V5 ADDITIONS — Historical Intelligence Platform
   Fully additive: reuses existing tokens (--bg, --card, --border,
   --primary, --text, --secondary, --green, --amber, --glass-*,
   --ease) and existing component classes (.card, .kpi-card,
   .top-card, .rec-list, .campaigns-table). Nothing above this
   point is modified.
   ============================================================ */

/* ---- Tab navigation ---- */
.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1360px;
  margin: 20px auto 0;
  padding: 0 40px;
}
.tab-nav-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.2px;
  background: var(--glass-bg-soft);
  color: var(--secondary);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.tab-nav-btn:hover { color: var(--text); border-color: rgba(255,255,255,0.18); }
.tab-nav-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---- Tab panel visibility ---- */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Shared historical toolbar (year switch / timeline switches) ---- */
.history-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.year-switch, .timeline-switch {
  display: flex;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255,255,255,0.02);
}
.year-btn, .timeline-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  background: transparent;
  color: var(--secondary);
  border: none;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.year-btn:hover, .timeline-btn:hover { color: var(--text); }
.year-btn.active, .timeline-btn.active { background: var(--primary); color: #fff; }

/* ---- Empty / unavailable state ---- */
.history-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 60px 24px;
  background: var(--glass-bg-soft);
  border: 1px dashed var(--glass-border);
  border-radius: var(--card-radius);
  color: var(--secondary);
}
/* BUGFIX: the rule above sets its own `display`, which silently beats
   the browser's built-in [hidden] { display: none } rule (author CSS
   always outranks the UA stylesheet, regardless of source order). That
   meant script.js setting el.hidden = true never actually hid this
   banner once AI/history data loaded successfully — it stayed visible
   at the same time as the real content underneath it. This rule wins
   over the one above (same selector specificity, defined later) and
   restores the intended hide-when-hidden behavior. */
.history-empty-state[hidden] {
  display: none;
}
.history-empty-state .empty-icon { font-size: 26px; color: var(--amber); }
.history-empty-state p { font-size: 16px; color: var(--text); font-weight: 600; }
.history-empty-state .empty-sub { font-family: 'JetBrains Mono', monospace; font-size: 11px; max-width: 420px; }

/* ---- Historical Intelligence: KPI + highlight rows ---- */
.history-kpi-grid { grid-template-columns: repeat(6, 1fr); margin-bottom: 16px; }
.history-highlight-row { margin-bottom: 16px; }
.highlight-card { border-left: 3px solid var(--border); }
.highlight-best { border-left-color: var(--green); }
.highlight-cost { border-left-color: var(--amber); }
.highlight-ctr { border-left-color: var(--primary); }

/* ---- Model Performance grid ---- */
.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.model-card {
  background: var(--glass-bg-soft);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.model-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.model-card-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.4px;
}
.model-card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--secondary);
}
.model-card-metrics b { color: var(--text); font-size: 13px; display: block; }
.model-card-empty { grid-column: 1 / -1; opacity: 0.5; padding: 24px; text-align: center; }

/* ---- Objective comparison ---- */
.objective-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.objective-card {
  background: var(--glass-bg-soft);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 16px;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.objective-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.objective-card-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 1.2px;
  color: var(--secondary);
  text-transform: uppercase;
  margin-bottom: 8px;
  display: block;
}
.objective-card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--secondary);
}
.objective-card-metrics b { color: var(--text); font-size: 15px; display: block; }
.objective-chart-card { min-height: 280px; }
.objective-chart-card canvas { max-height: 230px; }
.objective-card-empty { grid-column: 1 / -1; opacity: 0.5; padding: 24px; text-align: center; }

/* ---- Timeline ---- */
.timeline-trend-card { min-height: 260px; margin-bottom: 16px; }
.timeline-trend-card canvas { max-height: 210px; }
.timeline-launches {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 520px;
  overflow-y: auto;
}
.timeline-year-group {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--primary);
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--glass-border);
}
.timeline-year-group:first-child { margin-top: 0; border-top: none; padding-top: 0; }
.timeline-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--glass-bg-soft);
  border: 1px solid var(--glass-border);
  border-left: 3px solid var(--primary);
  border-radius: 5px;
  transition: transform .2s var(--ease);
}
.timeline-item:hover { transform: translateX(2px); }
.timeline-item-main { display: flex; flex-direction: column; gap: 2px; }
.timeline-item-name { font-weight: 600; font-size: 14px; }
.timeline-item-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  color: var(--secondary);
}
.timeline-item-stats {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--secondary);
  text-align: right;
  white-space: nowrap;
}
.timeline-item-stats b { color: var(--text); }
.timeline-empty { opacity: 0.5; text-align: center; padding: 24px; }

/* ---- Responsive ---- */
@media (max-width: 980px) {
  .history-kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .tab-nav { padding: 0 20px; }
}
@media (max-width: 560px) {
  .history-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .timeline-item { flex-direction: column; align-items: flex-start; }
  .timeline-item-stats { text-align: left; }
}

@media print {
  .tab-nav { display: none !important; }
  .tab-panel { display: block !important; }
}

/* ---- AI Analysis (reports/ai-analysis.json) additions ---- */
.exec-summary-card p {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
}

/* ============================================================
   AI CHAT ASSISTANT — isolated, additive feature.
   Everything above this block is untouched. Uses only existing
   CSS variables from :root so it automatically matches the v5
   theme (dark mode, glass surfaces, JetBrains Mono, Oswald).
   ============================================================ */

.ai-chat-root { position: fixed; right: 24px; bottom: 24px; z-index: 999; }

.ai-chat-toggle {
  position: relative;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(230, 0, 18, 0.35), 0 2px 8px rgba(0,0,0,0.4);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.ai-chat-toggle:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 28px rgba(230, 0, 18, 0.45); }
.ai-chat-toggle-icon { width: 26px; height: 26px; }
.ai-chat-toggle-dot {
  position: absolute; top: 4px; right: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--bg);
}

.ai-chat-panel {
  position: fixed;
  right: 24px; bottom: 96px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--card-radius);
  box-shadow: 0 24px 60px rgba(0,0,0,0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(.97);
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.ai-chat-panel.ai-chat-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.ai-chat-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--glass-bg-soft);
}
.ai-chat-header-title { display: flex; gap: 10px; align-items: flex-start; min-width: 0; }
.ai-chat-header-badge {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.ai-chat-header-title h2 {
  font-family: 'Oswald', sans-serif;
  font-size: 15px; font-weight: 600; letter-spacing: .3px;
  color: var(--text); margin: 0;
}
.ai-chat-header-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px; color: var(--secondary);
  margin: 2px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 220px;
}
.ai-chat-header-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.ai-chat-icon-btn {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid transparent;
  background: transparent; color: var(--secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s var(--ease), color .15s var(--ease);
}
.ai-chat-icon-btn svg { width: 15px; height: 15px; }
.ai-chat-icon-btn:hover { background: var(--card); color: var(--text); border-color: var(--border); }

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.ai-chat-messages::-webkit-scrollbar { width: 6px; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.ai-chat-msg { display: flex; gap: 8px; max-width: 92%; }
.ai-chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.ai-chat-msg-avatar {
  flex: 0 0 auto;
  width: 24px; height: 24px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 700;
  background: var(--card); color: var(--secondary); border: 1px solid var(--border);
}
.ai-chat-msg.assistant .ai-chat-msg-avatar { background: var(--primary); color: #fff; border-color: transparent; }
.ai-chat-bubble {
  font-family: 'Oswald', sans-serif;
  font-size: 13px; line-height: 1.5;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ai-chat-msg.user .ai-chat-bubble { background: var(--primary); border-color: transparent; color: #fff; border-bottom-right-radius: 3px; }
.ai-chat-msg.assistant .ai-chat-bubble { border-bottom-left-radius: 3px; }
.ai-chat-bubble p { margin: 0 0 6px; }
.ai-chat-bubble p:last-child { margin-bottom: 0; }
.ai-chat-bubble ul, .ai-chat-bubble ol { margin: 4px 0 6px 18px; padding: 0; }
.ai-chat-bubble strong { color: var(--text); }
.ai-chat-msg.user .ai-chat-bubble strong { color: #fff; }
.ai-chat-bubble code {
  font-family: 'JetBrains Mono', monospace; font-size: 11.5px;
  background: rgba(255,255,255,0.08); padding: 1px 4px; border-radius: 4px;
}

.ai-chat-copy-btn {
  margin-top: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px; letter-spacing: .4px;
  color: var(--secondary);
  background: transparent; border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 7px;
  cursor: pointer;
  transition: color .15s var(--ease), border-color .15s var(--ease);
}
.ai-chat-copy-btn:hover { color: var(--text); border-color: var(--secondary); }

.ai-chat-typing { display: flex; gap: 4px; padding: 4px 2px; }
.ai-chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--secondary);
  animation: aiChatTypingBounce 1.1s infinite ease-in-out;
}
.ai-chat-typing span:nth-child(2) { animation-delay: .15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aiChatTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.ai-chat-empty {
  margin: auto; text-align: center; padding: 20px 10px;
  color: var(--secondary); font-family: 'JetBrains Mono', monospace; font-size: 11.5px;
}
.ai-chat-empty strong { display: block; color: var(--text); font-family: 'Oswald', sans-serif; font-size: 15px; margin-bottom: 4px; }

.ai-chat-suggestions {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 14px 10px;
}
.ai-chat-suggestion-chip {
  font-family: 'JetBrains Mono', monospace; font-size: 10.5px;
  padding: 6px 10px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--border); color: var(--secondary);
  cursor: pointer; transition: color .15s var(--ease), border-color .15s var(--ease);
}
.ai-chat-suggestion-chip:hover { color: var(--text); border-color: var(--primary); }

.ai-chat-input-row {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--glass-bg-soft);
}
.ai-chat-input {
  flex: 1;
  resize: none;
  max-height: 96px;
  font-family: 'Oswald', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
}
.ai-chat-input:focus { border-color: var(--primary); }
.ai-chat-input::placeholder { color: var(--secondary); }
.ai-chat-send-btn {
  flex: 0 0 auto;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.ai-chat-send-btn svg { width: 16px; height: 16px; }
.ai-chat-send-btn:disabled { opacity: .5; cursor: not-allowed; }

.ai-chat-error-bubble { border-color: var(--primary) !important; }

@media (max-width: 480px) {
  .ai-chat-root { right: 14px; bottom: 14px; }
  .ai-chat-panel { right: 14px; bottom: 84px; width: calc(100vw - 28px); height: calc(100vh - 120px); }
}

/* ============================================================
   AI CHAT — VOICE COMMAND (mic input + speak-aloud toggle).
   Additive only, appended after the AI Chat Assistant block above.
   ============================================================ */

.ai-chat-icon-btn[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: transparent; }

.ai-chat-voice-status {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px; color: var(--primary);
  border-top: 1px solid var(--border);
}
.ai-chat-voice-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary);
  animation: aiChatVoicePulse 1.1s infinite ease-in-out;
}
@keyframes aiChatVoicePulse {
  0%, 100% { opacity: .35; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

.ai-chat-mic-btn {
  flex: 0 0 auto;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--card); color: var(--secondary);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: color .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.ai-chat-mic-btn svg { width: 16px; height: 16px; }
.ai-chat-mic-btn:hover { color: var(--text); border-color: var(--secondary); }
.ai-chat-mic-btn.ai-chat-mic-listening {
  background: var(--primary); color: #fff; border-color: transparent;
  box-shadow: 0 0 0 0 rgba(230, 0, 18, 0.55);
  animation: aiChatMicListening 1.3s infinite;
}
@keyframes aiChatMicListening {
  0% { box-shadow: 0 0 0 0 rgba(230, 0, 18, 0.55); }
  70% { box-shadow: 0 0 0 9px rgba(230, 0, 18, 0); }
  100% { box-shadow: 0 0 0 0 rgba(230, 0, 18, 0); }
}
.ai-chat-mic-btn.ai-chat-mic-unsupported { display: none; }

/* ============================================================
   AI CHAT — WAKE WORD ("Hey Assistant") mode. Additive, appended
   after the voice-command block above.
   ============================================================ */

.ai-chat-wake-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--green);
  pointer-events: none;
  animation: aiChatWakeIdlePulse 2.4s infinite ease-in-out;
}
.ai-chat-toggle.ai-chat-wake-capturing .ai-chat-wake-ring {
  border-color: var(--primary);
  animation: aiChatWakeCapturePulse 1s infinite ease-in-out;
}
@keyframes aiChatWakeIdlePulse {
  0%, 100% { opacity: .25; transform: scale(1); }
  50% { opacity: .7; transform: scale(1.08); }
}
@keyframes aiChatWakeCapturePulse {
  0%, 100% { opacity: .4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.14); }
}

.ai-chat-voice-status.ai-chat-voice-status--wake { color: var(--green); }
.ai-chat-voice-status.ai-chat-voice-status--wake .ai-chat-voice-dot { background: var(--green); }
