/* The tabs and the pages beyond the map (pages.js, ui.js). Each page's own styles are in page-<id>.css */

.tabs {
    display: flex;
    gap: 2px;
    padding: 2px;
    border-radius: 8px;
    background: var(--field);
    border: 1px solid var(--line);
}

.tab {
    all: unset;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--muted);
    white-space: nowrap;
}

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

.tab.active {
    color: var(--on-accent);
    background: var(--accent);
}

.tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.tab-picker {
    display: none;
}

/* Above the pages, so the settings menu opens over them */
.bar {
    z-index: 4;
}

/* Off the map: the map's own controls and overlays go */
body:not([data-page="map"]) .map-only,
body:not([data-page="map"]) #panel,
body:not([data-page="map"]) #legend,
body:not([data-page="map"]) #route-bar,
body:not([data-page="map"]) #tooltip {
    display: none !important;
}

body:not([data-page="map"]) #stage {
    visibility: hidden;
}

/* A page of its own: the whole screen under the bar, scrolling under the timeline, which floats over its foot */
.page {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    background: var(--bg);
    z-index: 2;
}

.timeline {
    z-index: 3;
}

/* Scrollbars in the theme's colours, not the browser's light ones */
.page,
.page * {
    scrollbar-color: var(--line) transparent;
}

.page-head {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 18px;
    padding: 14px 20px 10px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.page-head h2 {
    margin: 0;
    font-size: 20px;
}

.section-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.section-tab {
    all: unset;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 999px;
    color: var(--muted);
    border: 1px solid var(--line);
    white-space: nowrap;
}

.section-tab:hover {
    color: var(--text);
    background: var(--field-hover);
}

.section-tab.active {
    color: var(--text);
    border-color: var(--accent);
    background: var(--field);
}

.section-tab:focus-visible {
    outline: 2px solid var(--accent);
}

#page-body {
    padding: 16px 20px 96px; /* Clear of the timeline at the foot */
}

.section-body > * + * {
    margin-top: 14px;
}

.page-h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 22px 0 8px;
}

.section-body > .page-h3:first-child,
.card > .page-h3:first-child {
    margin-top: 0;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}

.card {
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px;
    min-width: 0;
}

.page-stats {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

/* Forms */
/* Fields lined up by their tops, so a hint under one doesn't lift it above the rest */
.page-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
}

/* Level with the inputs: below a label's height (.field > span) and the gap under it */
.page-form > button {
    margin-top: calc(12px * 1.4 + 4px);
}

.field {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 12px;
    min-width: 0;
}

.field > span {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.field input[type="text"],
.field input[type="number"],
.field input:not([type]),
.field select,
.page-form select {
    font-size: 14px;
    color: var(--text);
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 6px 10px;
    min-height: 34px;
    outline: none;
    min-width: 0;
}

.field input[type="number"] {
    width: 130px;
}

.field input[type="text"] {
    width: 220px;
}

.field input[type="checkbox"] {
    accent-color: var(--accent);
    width: 18px;
    height: 18px;
    margin: 8px 0;
}

.suggest input {
    width: 220px;
}

.text-button.primary {
    background: var(--accent);
    color: var(--on-accent);
    border-color: transparent;
    min-height: 34px;
}

.text-button.primary:hover {
    filter: brightness(1.08);
    background: var(--accent);
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    max-width: 100%;
}

/* Across the page: the numbers and the rank shrink to fit, the text columns (names) take the rest */
table.data {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

table.data th,
table.data td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

table.data th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
}

table.data .num {
    text-align: right;
    width: 1%;
}

/* Flush with the page's edges */
table.data th:first-child,
table.data td:first-child {
    padding-left: 0;
}

table.data th:last-child,
table.data td:last-child {
    padding-right: 0;
}

table.data tbody tr:hover {
    background: var(--field);
}

.th-sort {
    all: unset;
    cursor: pointer;
}

.th-sort:hover {
    color: var(--text);
}

.more {
    margin-top: 8px;
}

/* Links */
.link {
    all: unset;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.link:hover {
    text-decoration: underline;
}

.link:focus-visible {
    outline: 2px solid var(--accent);
}

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: none;
    border: 1px solid rgba(128, 128, 128, 0.5);
    margin-right: 4px;
    vertical-align: -1px;
}

.nation-link .dot {
    margin-right: 0;
}

/* Charts and bars */
.chart {
    position: relative;
}

.chart-svg {
    width: 100%;
    height: auto;
    display: block;
}

.chart-grid {
    stroke: var(--line);
}

.chart-label {
    fill: var(--muted);
    font-size: 12px;
}

.chart-cursor {
    stroke: var(--muted);
    stroke-dasharray: 3 3;
}

.chart-tip {
    position: absolute;
    pointer-events: none;
    background: var(--panel-solid);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 6px 9px;
    box-shadow: var(--shadow);
    font-size: 12px;
    white-space: nowrap;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    color: var(--muted);
    font-size: 12px;
}

.bars {
    display: grid;
    grid-template-columns: minmax(90px, 200px) 1fr auto;
    gap: 4px 10px;
}

/* Each row spans the list's columns, so every track is as wide as the others whatever its number */
.bar-row {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-items: center;
}

.bar-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    height: 10px;
    background: var(--field);
    border-radius: 3px;
    overflow: hidden;
}

.bar-fill {
    display: block;
    height: 100%;
    background: var(--accent);
}

.bar-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.page-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    padding: 24px 0;
}

.page-error {
    color: #ff8a8a;
}

/* The route bar over the map */
.route-bar {
    position: fixed;
    top: 66px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 6px 6px 14px;
    max-width: calc(100vw - 24px);
}

/* The bar's tabs give way to a picker where they don't fit */
@media (max-width: 1500px) {
    .brand {
        display: none;
    }
}

@media (max-width: 1180px) {
    .tabs {
        display: none;
    }

    .tab-picker {
        display: block;
    }
}

@media (max-width: 640px) {
    .page {
        top: 56px; /* Off the map the bar is one row: the page picker and settings */
    }

    .page-head {
        padding: 10px 12px 8px;
    }

    #page-body {
        padding: 12px 12px 84px;
    }

    .route-bar {
        top: 104px;
    }

    .field input[type="text"],
    .suggest input {
        width: 100%;
    }
}

/* Search above a table */
.table-block > .table-search {
    width: min(320px, 100%);
    margin-bottom: 8px;
}

/* A bar behind a number, against its column's largest */
td.bar-cell {
    position: relative;
    min-width: 120px;
}

.cell-bar {
    position: absolute;
    right: 0;
    top: 50%;
    height: 60%;
    transform: translateY(-50%);
    background: var(--accent);
    opacity: 0.18;
    border-radius: 3px;
}

.cell-value {
    position: relative;
}

.empty-state {
    padding: 22px;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 10px;
}

/* Toggle buttons */
.segmented {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 2px;
    border-radius: 8px;
    background: var(--field);
    border: 1px solid var(--line);
}

.segment {
    all: unset;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--muted);
    white-space: nowrap;
}

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

.segment[aria-checked="true"] {
    background: var(--accent);
    color: var(--on-accent);
}

.segment:focus-visible {
    outline: 2px solid var(--accent);
}

.badge-pill {
    display: inline-block;
    font-size: 12px;
    padding: 1px 8px;
    border-radius: 999px;
    border: 1px solid var(--pill, var(--line));
    color: var(--pill, var(--muted));
}

/* Headline figures */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.tile {
    /* Label, figure and sub-line rows are shared across a row of tiles, so the figures line up
       even when one label wraps onto two lines or a tile has no sub-line */
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;
    align-content: start;
    row-gap: 2px;
    /* A grid item won't shrink below its longest word by default, so one long figure
       would spill into the next tile */
    min-width: 0;
    padding: 14px 16px;
    border-radius: 10px;
    background: var(--field);
    border: 1px solid var(--line);
}

.tile-label {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tile-value {
    font-size: 24px;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.tile-sub {
    color: var(--muted);
    font-size: 12px;
}

/* Picking provinces for a page: a crosshair, and the bar's instructions stand out */
body.picking #stage {
    cursor: crosshair;
}

body.picking #route-bar {
    border-color: var(--accent);
}
