/* =============================================================================
   STATISTICS PAGE
   Uses the shared tokens from variables.css (--panel, --border, --text...)
============================================================================= */

.statistics-page {
    position: relative;
    z-index: 1;            /* above the header picture */
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 100px 1.25rem 2rem;
    flex: 1;               /* fill the space under the header */
    min-height: 0;
    overflow-y: auto;      /* and scroll inside it */
}

/* ---------- Toolbar ---------- */

.st-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.st-year {
    display: flex;
    align-items: center;
    gap: 8px;
}

.st-year-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    transition: border-color .2s, background .2s;
}

.st-year-btn:hover:not(:disabled) {
    border-color: rgba(62, 166, 255, .5);
    background: rgba(33, 150, 243, .12);
}

.st-year-btn:disabled {
    opacity: .35;
    cursor: default;
}

.st-year-select {
    height: 38px;
    min-width: 150px;
    padding: 0 36px 0 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%2394A3B8' d='M1.6 5.1a.5.5 0 0 1 .7 0L8 10.8l5.7-5.7a.5.5 0 0 1 .7.7l-6 6a.5.5 0 0 1-.7 0l-6-6a.5.5 0 0 1 0-.7z'/%3E%3C/svg%3E")
        right 13px center / 12px no-repeat,
        var(--panel);
    color: var(--text);
    font: 600 1.05rem 'IBM Plex Sans', sans-serif;
    appearance: none;
    cursor: pointer;
}

.st-year-select option {
    background: #0d1218;
}

.st-type {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
}

.st-type button {
    padding: 7px 16px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font: 500 .875rem 'IBM Plex Sans', sans-serif;
    cursor: pointer;
    transition: color .2s, background .2s;
}

.st-type button:hover {
    color: var(--text);
}

.st-type button.is-active {
    background: rgba(33, 150, 243, .18);
    box-shadow: inset 0 0 0 1px rgba(62, 166, 255, .45);
    color: #E8F2FF;
}

.st-year-btn:focus-visible,
.st-year-select:focus-visible,
.st-type button:focus-visible,
.st-more:focus-visible {
    outline: 2px solid #3EA6FF;
    outline-offset: 2px;
}

/* ---------- Grid + cards ---------- */

.st-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 18px;
    align-items: start;    /* each card keeps its own height */
    transition: opacity .2s;
}

.st-grid.is-loading {
    opacity: .45;
    pointer-events: none;
}

.st-span-12 { grid-column: span 12; }
.st-span-7  { grid-column: span 7; }
.st-span-6  { grid-column: span 6; }
.st-span-5  { grid-column: span 5; }
.st-span-4  { grid-column: span 4; }

.st-card {
    min-width: 0;
    padding: 22px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(17, 22, 29, .6);    /* --panel at 80% */
    backdrop-filter: blur(6px);
}

.st-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.st-card-head .st-card-title {
    margin-bottom: 0;
}

.st-card-title {
    margin: 0 0 14px;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.st-card-note {
    margin: 4px 0 0;
    font-size: .8125rem;
    color: var(--text-muted);
}

.st-card-count {
    flex-shrink: 0;
    font-size: .8125rem;
    color: var(--text-muted);
}

.st-subtitle {
    margin: 20px 0 10px;
    font-size: .875rem;
    font-weight: 600;
    color: rgba(200, 220, 245, .85);
}

.st-muted {
    color: var(--text-muted);
}

.st-ellipsis {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}

.st-loading,
.st-message {
    grid-column: span 12;
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
}

/* ---------- Flags ---------- */

.st-flag {
    flex-shrink: 0;
    width: 22px;
    height: 16px;
    border-radius: 2px;
    object-fit: cover;
    box-shadow: 0 0 4px rgba(0, 0, 0, .35);
}

.st-flag--empty {
    display: inline-block;
    background: rgba(255, 255, 255, .06);
    box-shadow: none;
}

/* ---------- KPIs ---------- */

.st-kpis {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    padding: 18px 0;
}

.st-kpi {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 2px 24px;
    border-left: 1px solid var(--border);
}

.st-kpi:first-child {
    border-left: 0;
}

.st-kpi-value {
    font-size: 1.875rem;
    font-weight: 600;
    line-height: 1.15;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.st-kpi-label {
    font-size: .875rem;
    color: var(--text-muted);
}

.st-kpi-note {
    font-size: .75rem;
    color: rgba(148, 163, 184, .8);
}

.st-delta {
    display: inline-flex;
    align-items: center;
    font-size: .75rem;
    font-weight: 500;
}

.st-delta i {
    font-size: 1.1rem;
    line-height: 1;
}

.st-delta--up   { color: #4ADE80; }
.st-delta--down { color: #F87171; }
.st-delta--flat { color: var(--text-muted); }

/* ---------- Hero chart ---------- */

.st-hero {
    padding: 24px 26px 18px;
    border-color: rgba(62, 166, 255, .22);
    background:
        radial-gradient(ellipse at 50% 0%, rgba(33, 150, 243, .08), transparent 60%),
        rgba(17, 22, 29, .8);
}

.st-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px 16px;
    max-width: 60%;
}

.st-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: .8125rem;
    color: rgba(200, 215, 235, .85);
}

.st-legend-item i {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.st-chart {
    position: relative;
}

.st-chart--hero  { height: 360px; }
.st-chart--small { height: 190px; }

/* ---------- Outcomes ---------- */

.st-outcome-bar {
    display: flex;
    height: 14px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, .06);
}

.st-seg--success { background: #22C55E; }
.st-seg--failure { background: #E5484D; }
.st-seg--partial { background: #F4B400; }

.st-outcome-legend {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.st-outcome-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: .875rem;
    color: rgba(200, 215, 235, .85);
}

.st-outcome-row strong {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.st-dot {
    flex-shrink: 0;
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.st-dot--success { background: #22C55E; }
.st-dot--failure { background: #E5484D; }
.st-dot--partial { background: #F4B400; }

.st-fail-list {
    max-height: 260px;
    overflow-y: auto;
}

.st-fail-row {
    display: grid;
    grid-template-columns: 90px minmax(0, 1.4fr) minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(120, 170, 230, .08);
    font-size: .8125rem;
}

.st-fail-mission {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.st-fail-mission strong {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: 500;
    color: var(--text);
}

.st-pill {
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}

.st-pill--failure { background: rgba(229, 72, 77, .15); color: #F87171; }
.st-pill--partial { background: rgba(244, 180, 0, .15); color: #FBBF24; }

/* ---------- Records ---------- */

.st-records {
    display: flex;
    flex-direction: column;
}

.st-record {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(120, 170, 230, .08);
}

.st-record:last-child {
    border-bottom: 0;
}

.st-record-label {
    grid-row: span 2;
    font-size: .8125rem;
    color: var(--text-muted);
}

.st-record-value {
    font-size: .9375rem;
    font-weight: 600;
    color: var(--text);
}

.st-record-detail {
    font-size: .8125rem;
    color: rgba(148, 163, 184, .85);
}

/* ---------- Ranked lists ---------- */

.st-rank-row {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr) 26% 48px 46px;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    font-size: .875rem;
}

.st-rank-pos {
    font-size: .75rem;
    color: rgba(148, 163, 184, .7);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.st-rank-name {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    color: var(--text);
}

.st-rank-bar {
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .06);
    overflow: hidden;
}

.st-rank-bar i {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #1E6FD9, #3EA6FF);
}

.st-rank-count {
    text-align: right;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.st-rank-pct {
    text-align: right;
    font-size: .75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.st-rank-list.is-open {
    max-height: 470px;
    overflow-y: auto;
    padding-right: 6px;
}

.st-more {
    margin-top: 10px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: transparent;
    color: #3EA6FF;
    font: 500 .8125rem 'IBM Plex Sans', sans-serif;
    cursor: pointer;
    transition: border-color .2s, background .2s;
}

.st-more:hover {
    border-color: rgba(62, 166, 255, .5);
    background: rgba(33, 150, 243, .1);
}

/* ---------- Space nations ---------- */

.st-nations {
    max-height: 470px;
    overflow-y: auto;
    padding-right: 6px;
}

.st-nation {
    display: grid;
    grid-template-columns: 46px 22px 120px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(120, 170, 230, .08);
    font-size: .875rem;
}

.st-nation-year {
    font-weight: 600;
    color: #3EA6FF;
    font-variant-numeric: tabular-nums;
}

.st-nation-name {
    font-weight: 500;
    color: var(--text);
}

/* ---------- New and retired rockets ---------- */

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

.st-inout .st-subtitle {
    margin-top: 0;
}

.st-inout-row {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid rgba(120, 170, 230, .08);
    font-size: .875rem;
}

.st-inout-row strong {
    font-weight: 500;
    color: var(--text);
}

/* ---------- Booster landings ---------- */

.st-reuse {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 28px;
    align-items: center;
}

.st-reuse-stats {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.st-reuse-stat strong {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    color: #2DD4BF;
    font-variant-numeric: tabular-nums;
}

.st-reuse-stat span {
    font-size: .8125rem;
    color: var(--text-muted);
}

/* One year: no chart, so the numbers sit side by side */
.st-reuse--year {
    grid-template-columns: 1fr;
}

.st-reuse--year .st-reuse-stats {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px 48px;
}

/* Vehicle type tabs */
.st-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.st-tab {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font: 500 .8125rem 'IBM Plex Sans', sans-serif;
    cursor: pointer;
    transition: color .2s, border-color .2s, background .2s;
}

.st-tab span {
    margin-left: 6px;
    color: rgba(148, 163, 184, .7);
    font-variant-numeric: tabular-nums;
}

.st-tab:hover {
    color: var(--text);
}

.st-tab.is-active {
    border-color: rgba(45, 212, 191, .55);
    background: rgba(20, 184, 166, .14);
    color: #E6FBFF;
}

.st-tab.is-active span {
    color: #5EEAD4;
}

.st-tab:focus-visible {
    outline: 2px solid #2DD4BF;
    outline-offset: 2px;
}

/* ---------- Smaller screens ---------- */

@media (max-width: 1400px) {
    .st-span-4 { grid-column: span 6; }
    .st-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 18px; }
    .st-kpi:nth-child(4) { border-left: 0; }
}

@media (max-width: 1000px) {
    .st-span-7,
    .st-span-6,
    .st-span-5,
    .st-span-4 { grid-column: span 12; }

    .st-legend { max-width: none; justify-content: flex-start; }
    .st-card-head { flex-direction: column; }
    .st-reuse { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .st-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .st-kpi:nth-child(odd) { border-left: 0; }
    .st-kpi:nth-child(4) { border-left: 1px solid var(--border); }
    .st-chart--hero { height: 280px; }
    .st-outcome-legend { grid-template-columns: 1fr; }
    .st-fail-row { grid-template-columns: 80px minmax(0, 1fr) auto; }
    .st-fail-row > :nth-child(3) { display: none; }
    .st-record { grid-template-columns: 1fr; }
    .st-record-label { grid-row: auto; }
    .st-inout { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .st-grid { transition: none; }
}

/* Launches that open in the archive */
.st-link-row {
    margin: 0 -8px;
    padding-left: 8px;
    padding-right: 8px;
    border-radius: 6px;
    color: inherit;
    text-decoration: none;
    transition: background .15s;
}

.st-link-row:hover {
    background: rgba(33, 150, 243, .07);
}

.st-link-row:focus-visible,
.st-record-link:focus-visible {
    outline: 2px solid #3EA6FF;
    outline-offset: 2px;
}

.st-record-link {
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px dashed rgba(62, 166, 255, .5);
}

.st-record-link:hover {
    color: #3EA6FF;
}