/* Tipping points page (js/views/tipping.js). Owner: the alerts module agent.
   Loaded after app.css. Every class carries the .tp- prefix; shared components (.card, .btn, .seg-toggle, .tag, .meter, .kpis,
   table.data, .m-D/.m-R) and variables come from app.css. The three sources are drawn in colours that are NOT party colours
   (violet = pre-election forecast, cyan = prediction markets, white = the live needle) so a line is never mistaken for a side. */

.tp-page {
  --tp-forecast: var(--spend);
  --tp-markets: var(--orgs);
  --tp-live: var(--text);
  display: grid;
  gap: 14px;
}
.tp-explain p {
  max-width: 112ch;
  line-height: 1.5;
}
.tp-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px 16px;
}
.tp-sort select {
  min-width: 15em;
}
.tp-warn {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--warn);
  border-radius: 8px;
  background: color-mix(in srgb, var(--warn) 7%, transparent);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}
.tp-kpis .kpi-value {
  font-size: 22px;
}
.tp-tops {
  display: grid;
  gap: 1px;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.35;
}
.tp-toprow .muted {
  display: inline-block;
  min-width: 4.6em;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---- chart ----------------------------------------------------------------------------------------------------------------------- */
.tp-chart-wrap {
  overflow: hidden;
}
.tp-chart {
  display: block;
  width: 100%;
  height: auto;
  max-height: 340px;
}
.tp-zone-r {
  fill: var(--r-fill);
  fill-opacity: 0.07;
}
.tp-zone-d {
  fill: var(--d-fill);
  fill-opacity: 0.09;
}
.tp-grid {
  stroke: var(--line-soft);
  stroke-width: 1;
}
.tp-axis {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.tp-axis-title {
  font-size: 11.5px;
}
.tp-thr {
  stroke: var(--text);
  stroke-opacity: 0.6;
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
}
.tp-zone-label {
  font-size: 11.5px;
  font-weight: 650;
}
.tp-zone-label-r {
  fill: var(--r);
}
.tp-zone-label-d {
  fill: var(--d);
}
.tp-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
}
.tp-line.tp-s-forecast {
  stroke: var(--tp-forecast);
}
.tp-line.tp-s-markets {
  stroke: var(--tp-markets);
}
.tp-line.tp-s-live {
  stroke: var(--tp-live);
  stroke-dasharray: 5 3;
  stroke-width: 2.2;
}
.tp-area.tp-s-forecast {
  fill: var(--tp-forecast);
  fill-opacity: 0.14;
}
.tp-area.tp-s-markets {
  fill: var(--tp-markets);
  fill-opacity: 0.12;
}
.tp-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}
.tp-key {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tp-sw {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 0;
  border-top: 3px solid;
}
.tp-sw.tp-s-forecast {
  border-color: var(--tp-forecast);
}
.tp-sw.tp-s-markets {
  border-color: var(--tp-markets);
}
.tp-sw.tp-s-live {
  border-top-style: dashed;
  border-color: var(--tp-live);
}

/* ---- table --------------------------------------------------------------------------------------------------------------------------- */
.tp-gaps {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.9;
}
.tp-gap-chip {
  display: inline-flex;
  gap: 6px;
  margin: 0 4px 0 2px;
  padding: 1px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}
.tp-gap-chip:hover {
  background: var(--surface-3);
  text-decoration: none;
}
.tp-table .num {
  text-align: right;
}
.tp-table td {
  vertical-align: top;
}
.tp-c-rank {
  width: 2.4em;
  color: var(--muted);
}
.tp-race {
  color: var(--text);
  font-weight: 700;
}
.tp-rname {
  font-size: 12px;
}
.tp-tags {
  display: block;
}
.tp-st {
  display: inline-block;
  margin: 2px 4px 0 0;
  font-size: 11px;
  font-weight: 600;
}
.tp-livetag {
  color: var(--tp-live);
  border-color: color-mix(in srgb, var(--text) 50%, transparent);
}
.tp-row.is-live-top > td:first-child {
  box-shadow: inset 3px 0 0 var(--tp-live);
}
.tp-rep {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 8px;
}
.tp-rep b {
  white-space: nowrap;
}
.tp-pbar {
  display: grid;
  gap: 3px;
  min-width: 64px;
  font-variant-numeric: tabular-nums;
}
.tp-pbar .meter {
  margin-top: 0;
}
.tp-p-f .meter i {
  background: var(--tp-forecast);
}
.tp-p-m .meter i {
  background: var(--tp-markets);
}
.tp-p-l .meter i {
  background: var(--tp-live);
}
.tp-more {
  display: flex;
  justify-content: center;
  padding-top: 12px;
}
.tp-note {
  max-width: 100ch;
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.45;
}

.tp-method summary {
  cursor: pointer;
}
.tp-method summary h2 {
  display: inline;
}
.tp-method-body {
  display: grid;
  gap: 8px;
  max-width: 105ch;
  margin-top: 10px;
  font-size: 13.5px;
  line-height: 1.5;
}
.tp-sens {
  width: 100%;
  max-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}
.tp-sens th {
  padding: 5px 10px 5px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
}
.tp-sens td {
  padding: 5px 10px 5px 0;
  border-bottom: 1px solid var(--line-soft);
  overflow-wrap: anywhere; /* WCAG 1.4.10: a long assumption name wraps instead of widening the table past a 320 px screen */
}
.tp-sens th {
  overflow-wrap: anywhere;
}
@media (max-width: 560px) {
  .tp-sens {
    table-layout: fixed;
  }
  .tp-sens th:first-child,
  .tp-sens td:first-child {
    width: 40%;
  }
  .tp-sens th,
  .tp-sens td {
    padding-right: 6px;
  }
}
.tp-sens .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.tp-notes {
  margin: 0;
  padding-left: 18px;
}

@media (max-width: 1180px) {
  .tp-c-vp {
    display: none;
  }
}
@media (max-width: 980px) {
  .tp-table thead {
    display: none;
  }
  .tp-table,
  .tp-table tbody,
  .tp-table tr,
  .tp-table td {
    display: block;
  }
  .tp-table tr.tp-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px 14px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
  }
  .tp-table tr.tp-row:first-child {
    border-top: 0;
  }
  .tp-row td {
    padding: 0;
    border: 0;
    text-align: left;
  }
  .tp-row td.num {
    text-align: left;
  }
  .tp-row td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }
  .tp-row td.tp-c-rank {
    display: none;
  }
  .tp-row td[data-label='Race'] {
    grid-column: 1 / -1;
  }
  .tp-row td[data-label='Race']::before {
    display: none;
  }
  .tp-row td[data-label='Reported'] {
    grid-column: 1 / -1;
  }
  .tp-c-vp {
    display: block;
  }
  .tp-row.is-live-top {
    box-shadow: inset 3px 0 0 var(--tp-live);
    padding-left: 10px;
  }
  .tp-row.is-live-top > td:first-child {
    box-shadow: none;
  }
}
@media (max-width: 560px) {
  .tp-sort,
  .tp-sort select {
    width: 100%;
  }
  .tp-chamber button {
    flex: 1 1 auto;
  }
  .tp-chamber {
    width: 100%;
  }
}

/* ---- path to control (Silver Bulletin-style ladder) ---------------------------------------------------------------------- */
.tp-path-head { display: flex; flex-wrap: wrap; gap: var(--space-3, 12px); align-items: flex-start; justify-content: space-between; }
.tp-path-head h2 { margin: 0; }
.tp-path-sub { margin: 4px 0 0; max-width: 62ch; }
.tp-path-ctl { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.tp-path-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-variant-numeric: tabular-nums; }
.tp-path-table thead th { text-align: left; font-size: var(--text-xs, 11.5px); font-weight: 600; color: var(--muted); padding: 6px 8px; border-bottom: 2px solid var(--text); }
.tp-path-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tp-path-table .num, .tp-path-table th.num { text-align: right; }
.tp-pc-party { width: 4.5rem; }
.tp-pc-seat { width: 5.5rem; font-size: 1.05rem; }
.tp-pc-bar { width: 46%; min-width: 9rem; }
.tp-pchip { display: inline-block; min-width: 2.2rem; text-align: center; padding: 3px 6px; border-radius: var(--radius-sm, 3px); font-weight: 700; color: #fff; }
.tp-pchip-D { background: var(--d-fill); }
.tp-pchip-R { background: var(--r-badge); }
.tp-pchip-I { background: var(--panel2); color: var(--text); border: 1px solid var(--control-border); }
.tp-dbar { position: relative; display: block; height: 1.55rem; }
.tp-dbar-axis { position: absolute; left: 50%; top: -6px; bottom: -6px; border-left: 1px solid var(--text); }
.tp-dbar-fill { position: absolute; top: 2px; bottom: 2px; border-radius: 2px; }
.tp-dbar-D { background: var(--d-fill); }
.tp-dbar-R { background: var(--r-fill); }
.tp-dbar-even { background: var(--control-border); }
.tp-dbar-val { position: absolute; top: 50%; transform: translateY(-50%); font-weight: 700; font-size: var(--text-sm, 12.5px); white-space: nowrap; }
.tp-dbar-val-D { color: var(--d); }
.tp-dbar-val-R { color: var(--r); }
.tp-dbar-val-even { color: var(--muted); }
.tp-path-row.is-tip td { background: color-mix(in srgb, var(--gold-fill) 28%, transparent); }
.tp-path-row.is-tip td:first-child { box-shadow: inset 4px 0 0 var(--gold); }
.tp-path-row.is-tip + tr td { border-top: 2px dashed var(--gold); }
.tp-tiptag { background: var(--gold-fill); color: var(--on-gold); border-color: transparent; font-weight: 700; }
.tp-flip { margin-left: 4px; }
.tp-path-more td { font-size: var(--text-sm, 12.5px); font-style: italic; padding: 8px; }
.tp-path-note { margin-top: 10px; font-size: var(--text-xs, 11.5px); max-width: 90ch; }
@media (max-width: 560px) {
  .tp-pc-party { width: 2.6rem; }
  .tp-pchip { min-width: 1.6rem; padding: 2px 4px; }
  .tp-pc-bar { width: 42%; min-width: 7rem; }
  .tp-pc-seat { width: 3rem; }
}
@media (forced-colors: active) {
  .tp-dbar-fill, .tp-pchip { forced-color-adjust: none; }
  .tp-path-row.is-tip td { outline: 2px solid CanvasText; }
}
.nd-ladder-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 30rem), 1fr)); gap: var(--space-5, 20px); }
.nd-ladder-sub { font-size: var(--text-xs, 11.5px); margin: 2px 0 0; }
.tp-morecols { margin-left: auto; }
.tp-onecell { white-space: nowrap; }
