/* ============================================================
 * Base — neutral placeholder theme. Swap the tokens below to rebrand.
 * Chart colors live in app/prediction_charts_render.py (keep in sync).
 * ============================================================ */
:root {
  --color-accent-primary: #2563EB;
  --color-accent-secondary: #3B82F6;
  --color-accent-muted: #64748B;
  --color-accent-tint: rgba(37, 99, 235, 0.08);
  --color-focus-ring: rgba(59, 130, 246, 0.25);
  --color-text: #0F172A;
  --color-bg: #FFFFFF;
  --color-bg-subtle: #F1F5F9;
  --color-border: #CBD5E1;
  --color-error: #B91C1C;

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius-md: 6px;
  --radius-lg: 10px;
  --touch-target: 44px;
  --content-width: 720px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg-subtle);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--color-accent-primary); }

h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 12px; }

main {
  flex: 1;
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 32px 16px 48px;
}

/* Header / footer */
.site-header {
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.site-header-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 14px 16px;
}

.site-name {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-text);
  text-decoration: none;
}

.site-footer {
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  font-size: 0.875rem;
}

.site-footer nav {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

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

/* ============================================================
 * Form building blocks
 * ============================================================ */
.question {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
}

.question.error { border-color: var(--color-error); }

.question-text { font-weight: 700; margin: 0 0 12px; }

.required-mark {
  color: var(--color-accent-primary);
  font-weight: 700;
  margin-left: 2px;
}

.optional-mark {
  color: var(--color-accent-muted);
  font-weight: 400;
  margin-left: 6px;
  font-size: 0.9em;
}

.error-message {
  color: var(--color-error);
  font-size: 0.9rem;
  margin: 8px 0 0;
}

.radio-stack { display: flex; flex-direction: column; gap: 8px; }

.radio-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: var(--touch-target);
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.radio-option input[type="radio"] {
  margin-top: 4px;
  accent-color: var(--color-accent-primary);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.radio-option:hover { border-color: var(--color-accent-secondary); }

.radio-option:has(input:checked) {
  border-color: var(--color-accent-primary);
  background: var(--color-accent-tint);
}

.radio-text { flex: 1; }

.text-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.text-field > span { font-weight: 700; }

.text-field input {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  min-height: var(--touch-target);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
}

.text-field input:focus {
  outline: none;
  border-color: var(--color-accent-secondary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.text-field input.error,
.text-field.error input { border-color: var(--color-error); }

.optin-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: -4px 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle);
  color: var(--color-accent-muted);
  font-size: 0.9rem;
  line-height: 1.4;
  cursor: pointer;
}

.optin-row[hidden] { display: none; }

.optin-row input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--color-accent-primary);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.optin-row:has(input:checked) {
  color: var(--color-text);
  border-color: var(--color-accent-primary);
}

/* Honeypot: off-screen, not display:none, so naive bots still fill it. */
.hp-field {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Legal / prose pages */
.prose h2 { font-size: 1.2rem; margin: 28px 0 8px; }
.prose p, .prose li { font-size: 1rem; }

/* ============================================================
 * Signal Exchange (v4)
 * Reuses existing color/spacing tokens.
 * ============================================================ */
.prediction-page p {
  font-size: 1rem;
  margin: 0 0 14px;
}

.prediction-lede {
  color: var(--color-accent-muted);
  margin: 0 0 24px;
}

/* Topic cards (used on landing + continue) */
.topic-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 8px 0 24px;
}

.topic-card {
  display: block;
  padding: 20px 18px;
  text-decoration: none;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
  min-height: 88px;
}

.topic-card:hover,
.topic-card:focus-visible {
  border-color: var(--color-accent-primary);
  background: var(--color-accent-tint);
  outline: none;
}

.topic-card:active {
  transform: translateY(1px);
}

.topic-card-title {
  font-weight: 700;
  font-size: 1.1rem;
  display: block;
  margin-bottom: 4px;
}

.topic-card-sub {
  color: var(--color-accent-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

/* Completed (non-clickable) variant */
.topic-card.completed {
  cursor: default;
  pointer-events: none;
  border-color: var(--color-border);
  background: var(--color-bg-subtle);
}

.topic-card.completed .topic-card-title::after {
  content: " ✓";
  color: var(--color-accent-primary);
  font-weight: 700;
}

.topic-card-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-accent-primary);
  background: var(--color-accent-tint);
  border-radius: 999px;
}

@media (min-width: 600px) {
  .topic-cards {
    flex-direction: row;
  }
  .topic-card {
    flex: 1;
  }
}

/* Demographics select styling — make native selects match .text-field inputs */
.text-field select {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  min-height: var(--touch-target);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%2364748B' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.text-field select:focus {
  outline: none;
  border-color: var(--color-accent-secondary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

/* Submit-button styling for prediction pages (matches existing patterns) */
.prediction-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.prediction-actions button,
.prediction-actions .btn-primary {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  min-height: var(--touch-target);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
}

.prediction-actions .btn-primary {
  background: var(--color-accent-primary);
  color: var(--color-bg);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.prediction-actions .btn-primary:hover {
  background: var(--color-accent-secondary);
}

.prediction-actions .btn-primary[disabled] {
  background: var(--color-accent-muted);
  cursor: not-allowed;
}

.prediction-actions .btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border);
}

.form-error {
  color: var(--color-error);
  font-size: 0.9rem;
  margin: 12px 0 0;
}

.prediction-progress {
  color: var(--color-accent-primary);
  font-weight: 700;
  font-size: 0.9rem;
  margin: 0 0 12px;
}

/* ============================================================
 * Signal Exchange charts (v4 §6)
 * ============================================================ */
.prediction-topic-heading {
  margin: 28px 0 12px;
  font-size: 1.25rem;
  color: var(--color-text);
}

.chart-block {
  margin: 0 0 32px;
  padding: 18px 18px 22px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.chart-block-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.chart-block-question {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--color-text);
}

.chart-block-pick {
  margin: 0 0 14px;
  font-size: 0.95rem;
}

.chart-block-pick-label {
  color: var(--color-accent-muted);
}

.chart-block-pick-value {
  font-weight: 700;
  color: var(--color-accent-primary);
}

.prediction-chart {
  width: 100%;
  max-width: 600px;
  height: auto;
  display: block;
  margin: 8px auto 0;
}

.prediction-chart--waffle {
  max-width: 320px;
}

.prediction-chart--gauge {
  max-width: 360px;
}

/* SVG text classes — Play font via parent context; explicit sizes here. */
.prediction-chart .chart-center-large {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 28px;
  fill: var(--color-text);
}

.prediction-chart .chart-center-small {
  font-family: var(--font-body);
  font-size: 11px;
  fill: var(--color-accent-muted);
}

.prediction-chart .chart-label-pct {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  fill: var(--color-text);
}

.prediction-chart .chart-label-pct--user {
  fill: var(--color-accent-primary);
}

.prediction-chart .chart-label-on-color {
  fill: #FFFFFF;
}

.prediction-chart .chart-axis-label {
  font-family: var(--font-body);
  font-size: 11px;
  fill: var(--color-accent-muted);
}

.prediction-chart .chart-axis-label--user {
  fill: var(--color-accent-primary);
  font-weight: 700;
}

.prediction-chart .chart-caption-svg {
  font-family: var(--font-body);
  font-size: 11px;
  fill: var(--color-accent-muted);
}

/* Legend (used under pie + stacked) */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  margin-top: 12px;
  font-size: 0.85rem;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text);
}

.chart-legend-item.is-user {
  font-weight: 700;
}

.chart-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-legend-text {
  line-height: 1.3;
}

.chart-legend-pct {
  color: var(--color-accent-muted);
}

/* Waffle subtitle (rendered as HTML below the SVG) */
.chart-caption {
  text-align: center;
  margin: 12px 0 0;
  color: var(--color-text);
  font-size: 0.95rem;
}
