/* ── Page header ─────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    padding-bottom: var(--sp-5);
    border-bottom: 2px solid var(--border-str);
    margin-bottom: var(--sp-8);
}

/* ── Empty state: center the verdict on the page ─────────── */
.container.is-empty {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100vh - 2 * var(--sp-8));
}

/* <main> is a flex child of .container — keep it as a transparent column
   so its children (.verdict etc.) participate in the same flex flow */
.container.is-empty main {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* In empty state the verdict halo should be invisible — no data yet */
.container.is-empty .verdict::before {
    display: none;
}

.container.is-empty .page-header {
    border-bottom: none;
    margin-bottom: var(--sp-8);
    justify-content: center;
}

.container.is-empty .logo {
    font-size: 2.5rem;
}

.container.is-empty .verdict {
    border-bottom: none;
    padding: var(--sp-6) 0 var(--sp-8);
    margin-bottom: 0;
    max-width: 960px;
    width: 100%;
    align-self: center;
}

/* ── Verdict — the hero result ───────────────────────────── */
.verdict {
    padding: var(--sp-10) 0 var(--sp-8);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--sp-8);
    position: relative;
}

/* Subtle warm halo behind the verdict — purely atmospheric */
.verdict::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 60% 80% at 50% 40%,
        oklch(95% 0.022 32 / 0.45) 0%,
        transparent 70%);
    pointer-events: none;
}

.verdict-inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: var(--sp-8);
    align-items: center;
    position: relative;
    z-index: 1;
}

.verdict-racer {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.verdict-racer--a { text-align: right; align-items: flex-end; }
.verdict-racer--b { text-align: left; align-items: flex-start; }

.verdict-racer-name {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: clamp(1.125rem, 2.5vw, 1.5rem);
    text-transform: uppercase;
    letter-spacing: -0.01em;
    line-height: 1;
    color: var(--ink-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.verdict-racer--a .verdict-racer-name { color: var(--race-a); }
.verdict-racer--b .verdict-racer-name { color: var(--race-b); }

.verdict-center {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
}

/* ── Verdict VS (shown when no data) ─────────────────────── */
.verdict-vs {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) 0;
}

.verdict-vs-text {
    font-family: var(--f-display);
    font-weight: 900;
    font-size: clamp(3rem, 7vw, 6rem);
    color: var(--border-str);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1;
    font-style: italic;
}

.verdict-vs-hint {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--ink-3);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* ── Verdict delta ───────────────────────────────────────── */
.verdict-delta {
    font-family: var(--f-display);
    font-weight: 900;
    font-size: clamp(4rem, 10vw, 10rem);
    line-height: 0.9;
    letter-spacing: -0.01em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    font-style: italic;
    animation: delta-reveal 0.95s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes delta-reveal {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.88);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.verdict-delta.is-faster {
    color: var(--faster);
    text-shadow: 0 2px 12px oklch(40% 0.155 148 / 0.12);
}
.verdict-delta.is-slower {
    color: var(--slower);
    text-shadow: 0 2px 12px oklch(46% 0.190 10 / 0.12);
}
.verdict-delta.is-tied   { color: var(--ink-3); }

.verdict-qualifier {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--ink-3);
    animation: qualifier-in 0.6s 0.35s cubic-bezier(0.25, 1, 0.5, 1) both;
}

@keyframes qualifier-in {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}

.verdict-qualifier.is-faster { color: var(--faster); }
.verdict-qualifier.is-slower { color: var(--slower); }

/* ── Table row entrance ──────────────────────────────────── */
.data-table tbody tr {
    animation: row-in 0.3s cubic-bezier(0.25, 1, 0.5, 1) both;
}

@keyframes row-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Reduced motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .verdict-delta,
    .verdict-qualifier,
    .data-table tbody tr,
    .racer-verdict-badge,
    .verdict-racer.is-winner .race-label {
        animation: none !important;
        filter: none !important;
    }
    /* Badges still need to be visible when animation is disabled */
    .racer-verdict-badge.badge-faster,
    .racer-verdict-badge.badge-slower,
    .racer-verdict-badge.badge-tied {
        opacity: 1;
    }
}

/* ── Content grid ────────────────────────────────────────── */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 460px;
    gap: var(--sp-8);
    align-items: start;
    margin-bottom: var(--sp-8);
    contain: layout style;
}

.chart-section {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Force both headings to exactly the same height so the boxes below them
   always start at the same y position. */
.chart-section .section-title,
.sidebar .section-title {
    min-height: 28px;
    margin-bottom: var(--sp-4);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1200px) {
    .content-grid {
        grid-template-columns: 1fr;
        gap: var(--sp-6);
    }

    .sidebar {
        order: -1;
    }
}

@media (max-width: 768px) {
    body {
        padding: var(--sp-5) var(--sp-4);
    }

    .container.is-empty {
        min-height: calc(100vh - 2 * var(--sp-5));
    }

    .verdict-inner {
        grid-template-columns: 1fr auto 1fr;
        gap: var(--sp-4);
    }

    .verdict-delta {
        font-size: clamp(2.5rem, 12vw, 4.5rem);
    }

    .chart-container {
        padding: var(--sp-5) var(--sp-4);
    }

    #waterfallChart {
        min-height: 400px;
    }

    .chart-legend {
        gap: var(--sp-4);
        flex-wrap: wrap;
    }

    td, th {
        padding: var(--sp-2) var(--sp-3);
    }
}

@media (max-width: 480px) {
    .verdict-inner {
        grid-template-columns: 1fr;
        gap: var(--sp-4);
        text-align: center;
    }

    .verdict-racer--a,
    .verdict-racer--b {
        text-align: center;
        align-items: center;
    }

    .verdict-racer--a .verdict-input-wrap,
    .verdict-racer--b .verdict-input-wrap {
        justify-content: center;
    }

    /* Both sides center the name block on mobile */
    .verdict-racer--a .racer-name-block,
    .verdict-racer--b .racer-name-block {
        align-items: center;
    }

    /* Badge centers under name on mobile */
    .racer-verdict-badge {
        align-self: center;
    }

    .verdict-racer--a { order: 0; }
    .verdict-center   { order: 1; }
    .verdict-racer--b { order: 2; }
}

/* ══════════════════════════════════════════════════════════════
   SPLIT ANALYSIS TABLE — BOLD REDESIGN
   Two-column layout: station-cell | delta-cell
   ══════════════════════════════════════════════════════════════ */

/* ── station-cell: standard table-cell, children stack via block ─ */
td.station-cell {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.station-name {
    display: block;
    margin-bottom: var(--sp-1);
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink);
    line-height: 1;
}

/* ── station-times row: pip · time · bar · time · pip ──────── */
.station-times {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    min-width: 0;
    overflow: hidden;
}

.time-pip {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.time-pip--a { background: var(--race-a); }
.time-pip--b { background: var(--race-b); }

td.station-cell .time-value {
    font-family: var(--f-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.6875rem;
    color: var(--ink-2);
    white-space: nowrap;
    flex-shrink: 0;
}

td.station-cell .time-a { color: var(--race-a); }
td.station-cell .time-b { color: var(--race-b); }

/* ── Performance bar ─────────────────────────────────────────── */
.perf-bar-track {
    flex: 1;
    height: 5px;
    background: var(--bg-inset);
    border-radius: 99px;
    overflow: hidden;
    min-width: 40px;
}

.perf-bar-track--total { height: 6px; }

.perf-bar {
    height: 100%;
    border-radius: 99px;
    width: var(--bar-width, 0%);
    transform-origin: left center;
    animation: bar-grow 0.55s var(--ease) both;
    will-change: transform;
}

.perf-bar.diff-negative { background: var(--faster); }
.perf-bar.diff-positive { background: var(--slower); }

@keyframes bar-grow {
    from { transform: scaleX(0); }
    to   { transform: scaleX(1); }
}

/* ── delta-cell: standard table-cell, right-aligned ─────────── */
td.delta-cell {
    text-align: right;
    vertical-align: middle;
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    /* width: 1px + nowrap = take minimum width, station-cell gets the rest */
    width: 1px;
}

.delta-number {
    display: block;
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 1.75rem;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

td.delta-cell.diff-negative .delta-number { color: var(--faster); }
td.delta-cell.diff-positive .delta-number { color: var(--slower); }

.delta-badge {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 0.5625rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    line-height: 1;
    padding: 3px 6px;
    border-radius: var(--r-sm);
}

td.delta-cell.diff-negative .delta-badge {
    color: var(--faster);
    background: var(--faster-bg);
}

td.delta-cell.diff-positive .delta-badge {
    color: var(--slower);
    background: var(--slower-bg);
}

/* ── thead: 2-col alignment ──────────────────────────────────── */
.data-table thead tr th:nth-child(1) { text-align: left; }
.data-table thead tr th:nth-child(2) { text-align: right; }

.delta-col-header { width: 108px; }

/* ── Row hover: color-aware backgrounds via tr.diff-* class ──── */
.data-table tbody tr.diff-negative:hover { background: var(--faster-bg); }
.data-table tbody tr.diff-positive:hover { background: var(--slower-bg); }
.data-table tbody tr.highlighted          { background: var(--faster-bg); }

/* Left accent on hover / chart-linked highlight */
.data-table tbody tr:hover td.station-cell,
.data-table tbody tr.highlighted td.station-cell {
    box-shadow: inset 3px 0 0 var(--ink);
}

/* ── Total row ───────────────────────────────────────────────── */
.data-table tbody tr.total-row {
    background: var(--bg-subtle);
    border-top: 2px solid var(--border-str);
}

.data-table tbody tr.total-row td {
    padding-top: var(--sp-4);
    padding-bottom: var(--sp-4);
    border-bottom: none;
}

.data-table tbody tr.total-row .station-name  { font-size: 0.9375rem; }
.data-table tbody tr.total-row .delta-number  { font-size: 2.125rem; }

/* ── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .perf-bar { animation: none !important; }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .delta-number { font-size: 1.375rem; }
    .perf-bar-track { min-width: 24px; }
}
