/* Rankings use the existing dashboard palette and compact mobile row styles. */
.rankings-page {
    color: var(--color-text);
}

.rankings-page .rankings-title {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: normal;
    text-transform: none;
}

.rankings-intro,
.rankings-method,
.rankings-help {
    color: var(--color-text-muted);
    line-height: 1.5;
}

.rankings-page .query-input-container.rankings-control {
    min-width: 0;
    padding: 0 calc(var(--bs-gutter-x) / 2);
}

.rankings-control .form-label {
    margin-bottom: 6px;
}

.rankings-page .rankings-control .form-control {
    width: 100%;
    min-height: var(--control-height);
}

.rankings-page input[type="date"]::-webkit-calendar-picker-indicator {
    filter: none;
}

.rankings-page .rankings-select {
    color: var(--color-text);
    min-width: 0;
}

.rankings-page .dash-dropdown.rankings-select {
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-control);
    min-height: var(--control-height);
}

.rankings-market-controls {
    margin-top: 16px;
}

/* Geography ranking: level slider and the area trail (pages/rankings.py). */
.rankings-geo-controls {
    margin-top: 16px;
    max-width: 640px;
}

/* Room for the end marks' labels ("Nation", "Postcode district"). */
.rankings-geo-slider {
    padding: 4px 56px 0 24px;
}

.rankings-area-trail {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 8px;
    margin-top: 14px;
    font-size: 0.95rem;
}

.rankings-area-trail__lead,
.rankings-area-trail__sep {
    color: var(--color-text-muted);
}

.rankings-area-trail__step {
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-text);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

.rankings-area-trail__step:hover {
    text-decoration-thickness: 2px;
}

.rankings-area-trail__step:focus-visible {
    outline: 2px solid var(--color-text);
    outline-offset: 2px;
    border-radius: 2px;
}

/* An area's name drills like its bar (rankings_view.js). */
#cross-chart .js-plotly-plot.hc-drill .yaxislayer-above .ytick text {
    pointer-events: all;
    cursor: pointer;
}

#cross-chart .js-plotly-plot.hc-drill .yaxislayer-above .ytick text:hover {
    text-decoration: underline;
}

.rankings-area-trail__current {
    font-weight: 600;
}

.rankings-details {
    border-top: 1px solid var(--color-border-light);
    margin-top: 12px;
    padding-top: 10px;
}

.rankings-details > summary {
    cursor: pointer;
    font-size: 0.94rem;
    font-weight: 600;
}

.rankings-details .rankings-controls {
    margin-top: 0;
}


.rankings-help {
    font-size: 0.85rem;
    margin: 12px 0 0;
}

.rankings-page .rankings-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.rankings-page .rankings-download {
    color: var(--color-text);
    border-color: var(--color-border);
    background: transparent;
    font-size: 0.88rem;
    letter-spacing: normal;
    min-height: 36px;
}

.rankings-page .rankings-download:hover:not(:disabled) {
    color: var(--color-bg-light);
    background: var(--color-primary);
}

.rankings-status {
    line-height: 1.6;
    margin-bottom: 8px;
}

.rankings-method,
.rankings-quality {
    font-size: 0.9rem;
}

.rankings-quality {
    padding-top: 12px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.rankings-quality li {
    margin-bottom: 6px;
}

.rankings-table-frame {
    margin-top: 20px;
    min-width: 0;
}

.rankings-date-actions,
.rankings-selection {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 14px;
}

.rankings-date-actions [role="status"] {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.rankings-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 16px 0;
}

.rankings-stat {
    display: flex;
    flex-direction: column;
    padding: 10px 18px;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-tile);
    background: var(--color-bg-light);
    min-width: 140px;
}

.rankings-stat strong {
    font-size: 1.5rem;
    line-height: 1.3;
}

.rankings-stat span {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.rankings-chart-scroll {
    max-height: 600px;
    overflow: auto;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-control);
    margin-top: 14px;
}

.rankings-page .dash-table-container .previous-next-container {
    background: var(--color-bg-card);
    padding: 8px;
}

/* The pager's page box is DataTable's grey with black text: 1.9:1 on the dark
   theme. It takes the page's own surface and text. */
.rankings-page .previous-next-container input.current-page,
.rankings-page .previous-next-container input.current-page::placeholder {
    color: var(--color-text) !important;
    opacity: 1;
}

.rankings-page .previous-next-container input.current-page {
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-control);
}

/* DataTable's own input rule (#3c3c3c) outranks a plain selector; its grey
   was 1.6:1 on the dark card. */
.rankings-page .dash-spreadsheet-container .dash-filter input:not([type="button"]) {
    color: var(--color-text) !important;
}

.rankings-page .dash-spreadsheet-container .dash-filter input::placeholder {
    color: var(--color-text-muted) !important;
    opacity: 1;
}

/* Filters always ignore case (filter_options), so the per-column case toggle,
   a faint 15 px target, has nothing to switch. */
.rankings-page .dash-filter--case {
    display: none;
}

.rankings-page .dash-table-container {
    --accent: var(--color-primary);
    --selected-background: var(--color-bg-light);
}

.rankings-table-hint {
    display: none;
}

.rankings-mobile-score {
    margin-top: 6px;
    color: var(--color-text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 600px) {
    .rankings-page {
        padding: 12px !important;
    }

    .rankings-chart-scroll {
        max-height: 440px;
    }

    .rankings-chart-frame {
        min-width: 600px;
    }

    .rankings-participation-chart .rankings-chart-frame {
        min-width: 0;
    }

    .rankings-stat {
        flex: 1;
        min-width: 90px;
        padding: 8px;
    }

    .rankings-page .rankings-results-header {
        gap: 8px;
    }

    .rankings-page .rankings-title {
        font-size: 1.4rem;
    }

    .rankings-page .button-container .btn {
        width: 100%;
    }

    .rankings-page .mobile-ranking-row__name {
        white-space: normal;
        overflow-wrap: anywhere;
    }
}

/* Phones: rank, name, score and MW lead (pages/rankings.py ranking_columns)
   and fit a 390 px screen; the secondary columns stay one swipe away in the
   table's own horizontal scroll. Inline DataTable styles need !important. */
@media (max-width: 600px) {
    .rankings-table-frame .dash-spreadsheet-container th,
    .rankings-table-frame .dash-spreadsheet-container td {
        min-width: 0 !important;
        padding: 8px 6px !important;
        font-size: 13px !important;
    }

    .rankings-table-frame .dash-spreadsheet-container [data-dash-column="rank"] {
        width: 2.75rem !important;
        min-width: 2.75rem !important;
        max-width: 2.75rem !important;
    }

    .rankings-table-frame .dash-spreadsheet-container [data-dash-column="label_link"] {
        min-width: 7.5rem !important;
        max-width: 10rem !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
    }

    .rankings-table-frame .dash-spreadsheet-container [data-dash-column="score"] {
        min-width: 5.5rem !important;
    }

    .rankings-table-frame .dash-spreadsheet-container [data-dash-column="power_mw"] {
        min-width: 3.25rem !important;
    }

    .rankings-table-frame .dash-spreadsheet-container td[data-dash-column="label_link"] p {
        margin: 0;
    }

    .rankings-table-hint {
        display: block;
        margin-top: 6px;
    }
}

/* Touch: every table, pager and form control reaches a 44 px target. */
@media (pointer: coarse), (max-width: 600px) {
    .rankings-page .rankings-control .form-control,
    .rankings-page .dash-dropdown.rankings-select,
    .rankings-page .btn {
        min-height: var(--touch-target);
    }

    /* Grow the link's hit area, not the row: padding cancelled by margin. */
    .rankings-table-frame td a {
        display: inline-block;
        padding-block: 15px;
        margin-block: -15px;
    }

    .rankings-table-frame th.dash-filter input:not([type="button"]) {
        min-height: var(--touch-target);
    }

    .rankings-page .previous-next-container {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-wrap: wrap;
        gap: 4px;
    }

    .rankings-page .previous-next-container button {
        min-width: var(--touch-target);
        min-height: var(--touch-target);
        margin: 0;
        padding: 0;
    }

    .rankings-page .previous-next-container input.current-page {
        min-width: var(--touch-target);
        min-height: var(--touch-target);
    }
}

@media (max-width: 600px) {
    /* The filter box fills its cell so the narrow rank column stays 44 px. */
    .rankings-table-frame .dash-spreadsheet-container th.dash-filter {
        padding-inline: 0 !important;
    }
}

/* Chart asset labels sit 30 px apart, too close for fingers; on touch the
   table below carries the same links at 44 px, so the labels stop taking taps. */
@media (pointer: coarse) {
    .rankings-chart-frame .ytick a {
        pointer-events: none;
    }
}

/* Two-series comparison (series_compare.py, behind BESS_FRONTEND_COMPARE).
   The heading row is drawn by the shell and the app alike, so the button
   never moves the heading; the dialog opens over the page. */
.page-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px 16px;
    margin: 0 0 0.75rem;
}

.prerender__body .page-title-row h1 {
    margin: 0;
    min-width: 0;
}

.page-title-row .compare-open {
    flex: none;
    white-space: nowrap;
}

.compare-modal {
    --bs-modal-bg: var(--color-bg-card);
    --bs-modal-color: var(--color-text);
    --bs-modal-border-color: var(--color-border-light);
    --bs-modal-header-border-color: var(--color-border-light);
    --bs-modal-footer-border-color: var(--color-border-light);
    --bs-modal-box-shadow: none;
    --bs-modal-padding: 25px;
    --bs-modal-header-padding: 20px 25px;
    color: var(--color-text);
}

.compare-modal .modal-content {
    box-shadow: none;
}

.compare-modal .modal-title {
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--color-text);
}

:root[data-theme="dark"] .compare-modal .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.compare-intro,
.compare-help {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.compare-field .form-label {
    margin-bottom: 6px;
}

/* What the chosen series is: plain text under its picker (no hover needed). */
.compare-explain {
    display: block;
    margin-top: 4px;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    line-height: 1.45;
}

/* A series row: its picker and, from three rows, a square remove control
   with a drawn cross (no text glyph); the control's name is its series. */
.compare-series-pick {
    display: flex;
    gap: 8px;
}

.compare-series-pick .form-select {
    flex: 1 1 auto;
    min-width: 0;
}

.compare-remove {
    position: relative;
    flex: none;
    width: var(--control-height);
    min-height: var(--control-height);
    padding: 0;
}

.compare-remove::before,
.compare-remove::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 2px;
    background: currentColor;
}

.compare-remove::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.compare-remove::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.compare-add-row {
    display: flex;
}

.compare-explain:empty,
.compare-mode-note:empty {
    display: none;
}

.compare-modal .form-select,
.compare-modal .form-control {
    background-color: var(--color-bg-card);
    color: var(--color-text);
    border-color: var(--color-border);
    border-radius: var(--radius-control);
    font-variant-numeric: tabular-nums;
}

:root[data-theme="dark"] .compare-modal .form-select {
    --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23e3d8c6' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

/* The dialog's controls: disabled and busy until series_compare.js is ready. */
.compare-fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.compare-fieldset[aria-busy="true"] {
    cursor: progress;
}

/* Draw while a draw reads: aria-disabled, so a keyboard press keeps focus. */
.compare-run[aria-disabled="true"] {
    opacity: 0.65;
    cursor: progress;
}

.compare-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;
    margin: 16px 0;
}

.compare-actions .toggle-group {
    margin: 0;
}

.compare-chart-area {
    position: relative;
}

/* Before the first draw: the graph is laid out but invisible under a
   hairline-framed prompt, so nothing moves when the chart arrives. */
.compare-chart-area.is-empty #compare-graph {
    visibility: hidden;
}

.compare-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 16px;
    border: 1px dashed var(--color-border-light);
    border-radius: var(--radius-tile);
    color: var(--color-text-muted);
    text-align: center;
}

.compare-chart-area:not(.is-empty) .compare-empty {
    display: none;
}

/* Shown only while the chart is zoomed: top left, in the band above the
   plot, clear of the mode bar on the right. */
.compare-reset {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    padding: 0 8px;
    font-size: 0.8rem;
    line-height: 1.6;
}

.compare-reset[hidden] {
    display: none;
}

.compare-status {
    margin: 0 0 8px;
    color: var(--color-text);
}

.compare-status:empty {
    display: none;
}

.compare-notes summary {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.compare-sources {
    margin-bottom: 0;
}

/* EPEX/EEX licensed series (internal Tau site only): the licence line is
   plain text in the ink colour, so it reads in both themes. */
.compare-licence {
    color: var(--color-ink);
    font-weight: 600;
}

.compare-licence[hidden] {
    display: none;
}

@media (max-width: 600px) {
    /* The heading takes the full width; the button sits under it. */
    .page-title-row {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Independent scales: keep every axis title (letter and unit), which
       the shared phone rule hides on other charts. */
    .chart-graph-frame.compare-chart-frame .xtitle,
    .chart-graph-frame.compare-chart-frame .ytitle,
    .chart-graph-frame.compare-chart-frame .y2title,
    .chart-graph-frame.compare-chart-frame .y3title,
    .chart-graph-frame.compare-chart-frame .y4title {
        display: inline;
    }

    .compare-modal {
        --bs-modal-padding: 12px;
        --bs-modal-header-padding: 12px;
    }

    .compare-actions .compare-run {
        width: 100%;
    }

    .compare-remove {
        width: var(--touch-target);
        min-height: var(--touch-target);
    }

    /* The dialog's close button reaches the touch target too. */
    .compare-modal .btn-close {
        box-sizing: border-box;
        width: var(--touch-target);
        height: var(--touch-target);
        padding: 0;
        background-size: 1em;
    }
}
