:root {
  color-scheme: light dark;
  --ink: #122033;
  --ink-soft: #405168;
  --ink-faint: #66758a;
  --canvas: #f4f7fb;
  --paper: #ffffff;
  --paper-soft: #f8fafc;
  --line: #dce3ec;
  --line-strong: #c6d0dd;
  --primary: #173f70;
  --primary-hover: #0f315a;
  --focus: #2563eb;
  --success: #137a55;
  --success-bg: #e8f7f0;
  --info: #2563a9;
  --info-bg: #eaf3ff;
  --warning: #9a5a0a;
  --warning-bg: #fff4dc;
  --danger: #b4232d;
  --danger-bg: #fff0f1;
  --shadow-sm: 0 1px 2px rgba(18, 32, 51, 0.04), 0 8px 24px rgba(18, 32, 51, 0.05);
  --shadow-md: 0 18px 50px rgba(18, 32, 51, 0.09);
  --surface-hover: #f3f7fc;
  --surface-disabled: #eef2f7;
  --table-hover: #f8fbff;
  --progress-track: #e5ebf2;
  --shot-bg: #e9eef5;
  --badge-bg: #edf1f5;
  --card-tint: rgba(255, 255, 255, 0.94);
  --hero-glow: rgba(37, 99, 235, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--canvas);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, var(--hero-glow), transparent 28rem),
    var(--canvas);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: contain;
}

button, textarea, select { font: inherit; }
button, a { touch-action: manipulation; }
a { color: inherit; }

svg {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: 9px;
  color: white;
  background: var(--primary);
  font-weight: 800;
  text-decoration: none;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  margin-bottom: 40px;
}

.brand {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  color: white;
  background: var(--primary);
  box-shadow: 0 6px 16px rgba(23, 63, 112, 0.2);
}

.brand-mark svg { width: 20px; height: 20px; }

.edition-pill,
.field-note,
.report-age {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.75);
  font-size: 0.78rem;
  font-weight: 750;
}

.workspace {
  display: grid;
  gap: 28px;
  align-items: center;
}

.intro-block { max-width: 680px; }

.eyebrow,
.section-kicker {
  margin: 0 0 7px;
  color: var(--info);
  font-size: 0.73rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, h3, p { overflow-wrap: break-word; }

h1 {
  margin: 0;
  font-size: clamp(2.35rem, 7vw, 4.4rem);
  line-height: 1.02;
  letter-spacing: -0.055em;
}

h1 span { color: var(--primary); }

.intro {
  max-width: 650px;
  margin: 20px 0 0;
  color: var(--ink-soft);
  font-size: 1.03rem;
}

.trust-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 18px;
  margin: 22px 0 0;
  padding: 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 750;
  list-style: none;
}

.trust-list li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.trust-list svg {
  width: 17px;
  height: 17px;
  color: var(--success);
  stroke-width: 2.2;
}

.control-card,
.monitor-card,
.metric-card,
.table-wrap,
.evidence-group {
  border: 1px solid var(--line);
  background: var(--card-tint);
  box-shadow: var(--shadow-sm);
}

.control-card {
  padding: 20px;
  border-radius: 20px;
}

.control-heading,
.section-heading,
.seat-heading,
.evidence-head,
.source-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.control-heading { margin-bottom: 14px; }
.control-heading h2,
.section-heading h2,
.monitor-card h2,
.seat-heading h2 {
  margin: 0;
  letter-spacing: -0.03em;
}

.control-heading h2 { font-size: 1.25rem; }

label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 800;
}

.field-group { margin-bottom: 15px; }

textarea,
select {
  display: block;
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--ink);
  background: var(--paper-soft);
  line-height: 1.45;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

textarea {
  min-height: 144px;
  resize: vertical;
}

select {
  min-height: 48px;
  cursor: pointer;
}

textarea:hover, select:hover { border-color: #9eacbd; }
textarea[readonly] { color: var(--ink-soft); background: var(--surface-disabled); }
select:disabled { cursor: not-allowed; color: var(--ink-faint); background: var(--surface-disabled); }

.help {
  margin: 8px 1px 16px;
  color: var(--ink-faint);
  font-size: 0.84rem;
}

.field-error {
  margin: -8px 1px 14px;
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 750;
}

textarea[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }

.form-actions { display: grid; grid-template-columns: 1fr 0.68fr; gap: 10px; }

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, background 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: 0.52; }
.button.is-busy { cursor: wait; }

.button-primary {
  color: white;
  background: var(--primary);
  box-shadow: 0 8px 20px rgba(23, 63, 112, 0.18);
}
.button-primary:hover:not(:disabled) { background: var(--primary-hover); }

.button-secondary {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--paper);
}
.button-secondary:hover:not(:disabled) { background: var(--surface-disabled); }
.button-icon { display: grid; font-size: 1.05rem; }

textarea:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible,
.table-wrap:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.monitor-card {
  display: grid;
  gap: 20px;
  margin-top: 32px;
  padding: 20px;
  border-radius: 20px;
}

.monitor-state {
  display: flex;
  align-items: flex-start;
  gap: 13px;
}

.monitor-card h2 { font-size: 1.15rem; }

.status-dot {
  flex: none;
  width: 12px;
  height: 12px;
  margin-top: 9px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  background: var(--ink-faint);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.status-dot.active { background: var(--info); box-shadow: 0 0 0 4px var(--info-bg); animation: pulse 1.8s ease-in-out infinite; }
.status-dot.waiting { background: var(--success); box-shadow: 0 0 0 4px var(--success-bg); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-bg); }

.status-message { margin: 4px 0 0; color: var(--ink-soft); font-size: 0.91rem; }
.status-message.error { color: var(--danger); font-weight: 700; }

.monitor-times {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.monitor-times div {
  padding: 11px 13px;
  border-radius: 11px;
  background: var(--paper-soft);
}

.monitor-times span,
.monitor-times strong { display: block; }
.monitor-times span { color: var(--ink-faint); font-size: 0.73rem; font-weight: 750; text-transform: uppercase; letter-spacing: 0.06em; }
.monitor-times strong { margin-top: 3px; font-size: 0.88rem; }

.progress-wrap { min-width: 0; }
.progress-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 7px; color: var(--ink-soft); font-size: 0.82rem; font-weight: 700; }
.progress-track { height: 7px; overflow: hidden; border-radius: 999px; background: var(--progress-track); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), #3b82f6); transition: width 240ms ease; }

.summary-section { margin-top: 52px; }
.section-heading { align-items: end; margin-bottom: 16px; }
.section-heading h2 { font-size: clamp(1.55rem, 4vw, 2rem); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: 16px;
  border-radius: 15px;
}
.metric-card::before { position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--primary); content: ""; }
.metric-card-success::before { background: var(--success); }
.metric-card-warning::before { background: var(--warning); }
.metric-card-danger::before { background: var(--danger); }
.metric-card > span { display: block; color: var(--ink-soft); font-size: 0.8rem; font-weight: 750; }
.metric-card strong { display: block; margin: 7px 0 2px; font-size: clamp(1.65rem, 6vw, 2.25rem); line-height: 1; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.metric-card small { display: block; color: var(--ink-faint); font-size: 0.72rem; line-height: 1.35; }

.seat-nav {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding: 4px 0 8px;
  overflow-x: auto;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}
.seat-nav a {
  flex: none;
  min-height: 44px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--paper);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease;
}
.seat-nav a:hover { color: var(--primary); border-color: #9db2cb; background: var(--surface-hover); }
.seat-nav a.has-conflict::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 7px; border-radius: 50%; background: var(--warning); vertical-align: 1px; }

.results { min-height: 220px; }
.empty-state {
  display: grid;
  justify-items: center;
  margin-top: 30px;
  padding: 54px 24px;
  border: 1px dashed var(--line-strong);
  border-radius: 20px;
  color: var(--ink-soft);
  text-align: center;
  background: rgba(255, 255, 255, 0.45);
}
.empty-state h2 { margin: 14px 0 5px; color: var(--ink); font-size: 1.15rem; }
.empty-state p { max-width: 460px; margin: 0; font-size: 0.9rem; }
.empty-icon { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 14px; color: var(--info); background: var(--info-bg); font-size: 1.4rem; }

.seat-group {
  scroll-margin-top: 18px;
  margin-top: 54px;
}
.seat-heading { align-items: end; margin-bottom: 14px; }
.seat-heading h2 { font-size: clamp(1.65rem, 5vw, 2.25rem); }
.seat-name { display: block; margin-top: 2px; color: var(--ink-faint); font-size: 0.87rem; font-weight: 650; letter-spacing: 0; }
.seat-summary { margin: 0; color: var(--ink-soft); font-size: 0.83rem; font-weight: 700; text-align: right; }

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border-radius: 16px;
  scrollbar-gutter: stable;
  scrollbar-color: var(--line-strong) transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
}
table { width: 100%; min-width: 650px; border-collapse: separate; border-spacing: 0; }
caption { padding: 15px 17px; color: var(--ink-soft); font-size: 0.83rem; font-weight: 750; text-align: left; }
.table-scroll-hint { display: none; margin-top: 3px; color: var(--ink-faint); font-size: 0.72rem; font-weight: 650; }
th, td { padding: 13px 16px; border-top: 1px solid var(--line); text-align: left; white-space: nowrap; }
thead th { color: var(--ink-faint); background: var(--paper-soft); font-size: 0.76rem; letter-spacing: 0.015em; }
tbody th { min-width: 170px; background: var(--paper); }
thead th:first-child,
tbody th {
  position: sticky;
  left: 0;
  z-index: 2;
  box-shadow: 1px 0 0 var(--line);
}
thead th:first-child { z-index: 3; }
tbody tr:hover td, tbody tr:hover th { background-color: var(--table-hover); }
.source-link { display: inline-flex; min-height: 44px; align-items: center; color: var(--primary); font-weight: 800; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.source-substatus { display: block; margin-top: 3px; color: var(--ink-faint); font-size: 0.69rem; font-weight: 650; }
.vote-cell { color: var(--ink); font-size: 0.98rem; font-weight: 850; font-variant-numeric: tabular-nums; }
.vote-cell.muted { color: var(--ink-faint); font-size: 0.78rem; font-weight: 700; }
.vote-cell.conflict { color: #7a4406; background: var(--warning-bg); }
.vote-cell.conflict::after { content: "Differs"; display: block; margin-top: 2px; color: var(--warning); font-size: 0.64rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }

.evidence-group {
  margin-top: 16px;
  border-radius: 16px;
}
.evidence-group > summary {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 16px;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}
.evidence-group > summary::-webkit-details-marker { display: none; }
.evidence-group > summary::after { content: "+"; color: var(--ink-faint); font-size: 1.25rem; font-weight: 500; }
.evidence-group[open] > summary { border-bottom: 1px solid var(--line); border-radius: 16px 16px 0 0; }
.evidence-group[open] > summary::after { content: "−"; }
.evidence-count { color: var(--ink-faint); font-size: 0.75rem; }

.evidence-grid { display: grid; gap: 12px; padding: 12px; }
.evidence-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); }
.shot { display: grid; aspect-ratio: 16 / 9; place-items: center; border-bottom: 1px solid var(--line); color: var(--ink-faint); background: var(--shot-bg); text-decoration: none; }
.shot img { display: block; width: 100%; height: 100%; object-fit: contain; }
.empty-shot { padding: 20px; font-size: 0.8rem; font-weight: 700; }
.evidence-body { padding: 14px; }
.source-heading { align-items: center; }
.source-heading h3 { min-width: 0; margin: 0; font-size: 0.96rem; }
.evidence-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.evidence-meta div { min-width: 0; padding: 8px 9px; border-radius: 9px; background: var(--paper-soft); }
.evidence-meta span, .evidence-meta strong { display: block; }
.evidence-meta span { color: var(--ink-faint); font-size: 0.65rem; font-weight: 750; text-transform: uppercase; }
.evidence-meta strong { margin-top: 2px; overflow: hidden; font-size: 0.73rem; text-overflow: ellipsis; white-space: nowrap; }
.evidence-link { display: inline-flex; min-height: 44px; align-items: center; color: var(--primary); font-size: 0.8rem; font-weight: 800; text-underline-offset: 3px; }
.error-details { margin-top: 11px; color: var(--danger); font-size: 0.76rem; }
.error-details summary { display: inline-flex; min-height: 44px; align-items: center; cursor: pointer; font-weight: 800; }
.error-details p { margin: 6px 0 0; overflow-wrap: anywhere; }

.badge {
  display: inline-flex;
  flex: none;
  min-height: 24px;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--badge-bg);
  font-size: 0.67rem;
  font-weight: 850;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.success { color: var(--success); background: var(--success-bg); }
.badge.info { color: var(--info); background: var(--info-bg); }
.badge.warning { color: var(--warning); background: var(--warning-bg); }
.badge.danger { color: var(--danger); background: var(--danger-bg); }

footer {
  padding: 28px 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 0.76rem;
  text-align: center;
}

.noscript-message {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 20;
  max-width: 680px;
  margin: auto;
  padding: 14px 16px;
  border: 1px solid var(--danger);
  border-radius: 12px;
  color: var(--danger);
  background: var(--paper);
  box-shadow: var(--shadow-md);
  font-weight: 750;
  text-align: center;
}

@media (hover: hover) {
  .evidence-card { transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease; }
  .evidence-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); transform: translateY(-2px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.78); opacity: 0.65; }
}

@media (min-width: 720px) {
  .app-shell { width: min(1180px, calc(100% - 56px)); padding-top: 26px; }
  .topbar { margin-bottom: 56px; }
  .workspace { grid-template-columns: minmax(0, 1.2fr) minmax(330px, 0.8fr); gap: 54px; }
  .control-card { padding: 23px; }
  .monitor-card { grid-template-columns: minmax(250px, 1fr) minmax(220px, 0.9fr) minmax(260px, 0.8fr); align-items: center; padding: 18px 20px; }
  .monitor-times { min-width: 0; }
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .metric-card { padding: 18px; }
  .evidence-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1040px) {
  .evidence-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 460px) {
  .app-shell { width: min(100% - 22px, 1180px); padding-top: 12px; }
  .topbar { margin-bottom: 28px; }
  .edition-pill { font-size: 0.7rem; }
  h1 { font-size: 2.35rem; }
  .form-actions { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { padding: 14px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  .seat-heading { align-items: flex-start; flex-direction: column; gap: 7px; }
  .seat-summary { text-align: left; }
  .monitor-times { grid-template-columns: 1fr; }
  .trust-list { display: grid; gap: 8px; }
}

@media (max-width: 700px) {
  .table-scroll-hint { display: block; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f1f5f9;
    --ink-soft: #c7d2e0;
    --ink-faint: #94a3b8;
    --canvas: #0b1220;
    --paper: #111c2e;
    --paper-soft: #162338;
    --line: #29384f;
    --line-strong: #3b4d67;
    --primary: #7db7ff;
    --primary-hover: #a8ccff;
    --focus: #93c5fd;
    --success: #59d7a5;
    --success-bg: #12372e;
    --info: #82bfff;
    --info-bg: #152f4d;
    --warning: #f5bd63;
    --warning-bg: #3b2a12;
    --danger: #ff8f98;
    --danger-bg: #421d25;
    --surface-hover: #1a2b44;
    --surface-disabled: #1c293b;
    --table-hover: #15243a;
    --progress-track: #2a3a51;
    --shot-bg: #0d1727;
    --badge-bg: #26364c;
    --card-tint: rgba(17, 28, 46, 0.94);
    --hero-glow: rgba(77, 143, 230, 0.15);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 28px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 20px 54px rgba(0, 0, 0, 0.34);
  }

  .edition-pill,
  .field-note,
  .report-age,
  .empty-state { background: rgba(17, 28, 46, 0.76); }
  .button-primary { color: #07111f; box-shadow: 0 8px 24px rgba(70, 143, 232, 0.16); }
  .brand-mark { color: #07111f; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); }
  textarea:hover,
  select:hover,
  .seat-nav a:hover { border-color: #5b7190; }
  .vote-cell.conflict { color: #ffd58f; }
}

@media (forced-colors: active) {
  .status-dot,
  .badge::before,
  .metric-card::before { forced-color-adjust: none; }
  .button,
  .badge,
  .edition-pill,
  .field-note,
  .report-age { border: 1px solid ButtonText; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
