/* UK Local Elections 2026 forecast comparator. */

:root {
  --ink: #14213D;
  --paper: #FFFFFF;
  --sand: #F4F1EC;
  --line: #D8D4CC;
  --muted: #5A5A5A;
  --accent: #E4003B;
  --link: #0B4F9C;
  --hi-tint: #DFF3E4;
  --lo-tint: #F8DDDD;
  --hi-edge: #02A95B;
  --lo-edge: #C04040;
  --shadow: 0 1px 3px rgba(0,0,0,0.05), 0 4px 14px rgba(0,0,0,0.04);
  --radius: 6px;
  --max-width: 1200px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--sand);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: var(--max-width); margin: 0 auto; padding: 0 1.25rem; }

header {
  background: linear-gradient(135deg, #1A2B4F 0%, #14213D 55%, #0E1A33 100%);
  color: var(--paper);
  padding: 1.1rem 0 1rem;
  border-bottom: 3px solid var(--accent);
}
header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}
header .countdown {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--paper);
  background: var(--accent);
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
}
header .subtitle {
  margin: 0 0 0.35rem;
  font-size: 0.88rem;
  color: #CBD5E1;
}
header .subtitle strong { color: var(--paper); }
header .meta { margin: 0; font-size: 0.78rem; color: #94A3B8; }

main { padding: 1rem 0 1.5rem; }

section {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem 1rem;
  margin: 0 0 0.85rem;
  box-shadow: var(--shadow);
}

h2 { font-size: 1rem; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }
.panel-title { font-size: 1rem; margin: 0 0 0.4rem; font-weight: 600; }
.caveat { background: #FBF7E8; border-left: 3px solid #C97800; padding: 0.5rem 0.7rem; border-radius: 4px; }
.muted-small { font-size: 0.82rem; color: var(--muted); margin: 0 0 0.6rem; }

#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  padding: 0.7rem 1rem 0.8rem;
}
.control-row { display: flex; flex-direction: column; gap: 0.25rem; }
.control-row.toggle { flex-direction: row; align-items: center; }
.control-row label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.control-row.toggle label { text-transform: none; letter-spacing: 0; gap: 0.4rem; }
.control-row .glyph {
  width: 14px;
  height: 14px;
  color: var(--ink);
  flex-shrink: 0;
}
.control-row select {
  font-size: 0.95rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  min-width: 200px;
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.control-row select:hover { border-color: var(--ink); }
.control-row select:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 2px rgba(11, 79, 156, 0.18);
}
.control-row.toggle .glyph { color: var(--muted); }

#chart {
  width: 100%;
  min-height: 460px;
  margin-bottom: 0.6rem;
}
.caption { font-size: 0.8rem; color: var(--muted); margin: 0.4rem 0 0; }

/* Chips */
.chips-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin: 0 0 0.7rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.6rem;
  font-size: 0.78rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.12s ease, background-color 0.12s ease;
}
.chip:hover { background: var(--sand); }

/* Preset chips — clearly distinct from the round, dot-bearing method chips */
.chips-group {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.45rem 0.18rem 0.55rem;
  background: var(--sand);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.chips-group-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-right: 0.15rem;
}
.chips-group-label .glyph { width: 13px; height: 13px; color: var(--muted); }
.chip.preset {
  font-weight: 600;
  border-radius: 4px;
  background: var(--paper);
  border-color: var(--line);
  padding: 0.2rem 0.55rem;
}
.chip.preset:hover { background: var(--sand); border-color: var(--ink); }
.chip.preset.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.chip.preset.active:hover { background: var(--ink); }
.chip.preset.active::before {
  content: "✓";
  font-weight: 700;
  margin-right: 0.25rem;
  font-size: 0.78rem;
  line-height: 1;
}
.chip.method-chip {
  border-style: solid;
  transition: opacity 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
}
.chip.method-chip .swatch {
  display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%;
  border: 1.5px solid transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.chip.method-chip.off {
  opacity: 0.5;
  border-style: dashed;
  background: transparent;
  color: var(--muted);
}
.chip.method-chip.off::before {
  content: "+";
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--muted);
  margin-right: 0.05rem;
}
.chip.method-chip.off:hover { opacity: 0.95; background: var(--sand); }
.chip.method-chip:not(.off):hover { background: var(--sand); }
.chip.method-chip .mae { font-size: 0.66rem; color: var(--muted); font-weight: 500; }
.chips-divider { width: 1px; height: 1.1rem; background: var(--line); margin: 0 0.2rem; }

/* Summary stats */
.summary {
  margin-top: 0.7rem;
  padding: 0.6rem 0.8rem;
  background: var(--sand);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.82rem;
  line-height: 1.5;
}
.summary .summary-head { font-weight: 600; margin-bottom: 0.2rem; }
.summary .summary-row { display: block; }
.summary .party-name { font-weight: 600; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td {
  text-align: left;
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { font-weight: 600; background: var(--sand); }
tbody tr:hover { background: rgba(11, 79, 156, 0.04); }
td.score-cell { font-variant-numeric: tabular-nums; font-weight: 600; }

/* Predictions table view (inside chart section) */
#chart-section table.predictions {
  font-size: 0.85rem;
  margin-top: 0.4rem;
}
#chart-section table.predictions th { white-space: nowrap; }
#chart-section table.predictions td.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
#chart-section table.predictions td.num .central { font-weight: 600; }
#chart-section table.predictions td.num .range {
  display: block; font-size: 0.72rem; color: var(--muted); font-weight: 400;
}
#chart-section table.predictions td.row-label { font-weight: 600; }
#chart-section table.predictions td.row-label small { display: block; color: var(--muted); font-weight: 400; font-size: 0.74rem; }
#chart-section table.predictions tr.summary-row td { background: #FAF8F4; }
#chart-section table.predictions tr.summary-row td.row-label { font-style: italic; }
#chart-section table.predictions tr.consensus-row td {
  background: #EEF2FA; border-top: 1px solid var(--line);
}
#chart-section table.predictions tr.defending-row td { background: #FBF7E8; }
#chart-section table.predictions td.cell-hi { box-shadow: inset 3px 0 0 var(--hi-edge); background: var(--hi-tint); }
#chart-section table.predictions td.cell-lo { box-shadow: inset 3px 0 0 var(--lo-edge); background: var(--lo-tint); }

/* Method cards (compact) */
#methods-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.7rem;
}
.method-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  background: var(--sand);
}
.method-card h4 { font-size: 0.92rem; margin: 0 0 0.15rem; }
.method-card .author { font-size: 0.74rem; color: var(--muted); margin-bottom: 0.35rem; }
.method-card p { margin: 0 0 0.3rem; font-size: 0.83rem; }
.method-card a { font-size: 0.78rem; }
.method-card.outlier { border-left: 3px solid #C97800; }

#glossary dl, dl#glossary {
  display: grid;
  grid-template-columns: minmax(140px, max-content) 1fr;
  gap: 0.35rem 1rem;
  margin: 0;
}
#glossary dt { font-weight: 600; font-size: 0.85rem; }
#glossary dd { margin: 0; color: var(--muted); font-size: 0.83rem; }

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

.info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.6rem;
  font-weight: 700;
  cursor: help;
  font-style: normal;
  vertical-align: middle;
}

#tooltip {
  position: fixed; z-index: 1000;
  background: #14213D; color: #FFFFFF;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.82rem; max-width: 320px;
  pointer-events: none; opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.12s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
#tooltip.visible { opacity: 1; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--line);
  margin: 0 0 0;
  padding: 0 0.25rem;
}
.tab {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  padding: 0.5rem 0.85rem;
  font: inherit;
  font-size: 0.86rem;
  color: var(--muted);
  cursor: pointer;
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 600;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--sand);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  font-size: 0.85em;
}

@media (max-width: 720px) {
  header h1 { font-size: 1.2rem; }
  #chart { height: 460px; }
  table, #chart-section table.predictions { font-size: 0.78rem; }
  th, td { padding: 0.32rem 0.35rem; }
  .control-row select { min-width: 140px; }
}
