/* public/css/components.css
   The game's components (the board's "A design system, then every page
   reworked", step 1), built on tokens.css only: a page and its header band,
   cards, stat tiles, badges and result chips, tables, tabs, a dashboard grid
   and a rating bar. Every class starts with ds- so nothing here touches a
   page until it is reworked onto them. All of them live at
   /admin/style-guide (views/admin/style-guide.ejs).

   Phones first: each block is laid out for a narrow screen, then widened at
   the tokens' breakpoints (769px tablet, 1024px desktop, 1216px wide). */

/* ---- Page: the content column, with the gutter on both sides. ---------- */
.ds-page {
    box-sizing: border-box;
    width: 100%;
    max-width: var(--ds-content-max);
    margin: 0 auto;
    padding: var(--ds-space-4) var(--ds-gutter) var(--ds-space-7);
    color: var(--ds-color-text);
    font-family: var(--ds-font-sans);
    line-height: var(--ds-line-height-body);
}

.ds-page > * + * {
    margin-top: var(--ds-space-5);
}

/* The bridge: on a reworked page, what is still drawn with style.css and
   Bulma (the app header, lists, notices, buttons) takes the tokens' colours
   through style.css's variables, until each part has its ds- component. */
body:has(.ds-page) {
    --primary-color: var(--ds-color-brand);
    --secondary-color: var(--ds-color-accent);
    --background-color: var(--ds-color-bg);
    --surface-color: var(--ds-color-surface);
    --text-color: var(--ds-color-text);
    --text-muted-color: var(--ds-color-text-muted);
    --danger-color: var(--ds-color-danger);
    --promotion-background: var(--ds-color-promotion-soft);
    --relegation-background: var(--ds-color-relegation-soft);
    --promotion-color: var(--ds-color-promotion);
    --relegation-color: var(--ds-color-relegation);
    --playoff-color: var(--ds-color-playoff);
    background: var(--ds-color-bg);
}

.ds-num {
    font-variant-numeric: tabular-nums;
}

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

/* ---- Page header: a night band, the title and what it is about, with the
   page's own actions at the end (below it on phones). ------------------- */
.ds-page-header {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--ds-space-3) var(--ds-space-5);
    padding: var(--ds-space-4) var(--ds-space-4) var(--ds-space-5);
    border-radius: var(--ds-radius-lg);
    background: linear-gradient(135deg, var(--ds-color-night) 0%, var(--ds-color-night-raised) 100%);
    color: var(--ds-color-on-night);
    overflow: hidden;
}

/* The pitch-to-trophy line along its foot. */
.ds-page-header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--ds-color-brand) 0%, var(--ds-color-accent) 100%);
}

.ds-page-header__main {
    min-width: 0;
}

.ds-page-header__eyebrow {
    margin: 0 0 var(--ds-space-1);
    color: var(--ds-color-on-night-muted);
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
    letter-spacing: var(--ds-label-tracking);
    text-transform: uppercase;
}

.ds-page-header__title {
    margin: 0;
    color: var(--ds-color-on-night);
    font-size: var(--ds-font-size-2xl);
    font-weight: var(--ds-font-weight-bold);
    line-height: var(--ds-line-height-tight);
    overflow-wrap: anywhere;
}

.ds-page-header__meta {
    margin: var(--ds-space-2) 0 0;
    color: var(--ds-color-on-night-muted);
    font-size: var(--ds-font-size-sm);
}

/* Links in the meta lines (last season's champion, the club page) on the band. */
.ds-page-header__meta a {
    color: var(--ds-color-on-night);
    text-decoration: underline;
    text-decoration-color: var(--ds-color-on-night-muted);
}

/* Bold words keep the band's colour (Bulma darkens strong). */
.ds-page-header strong {
    color: var(--ds-color-on-night);
}

.ds-page-header__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ds-space-2);
}

@media (min-width: 769px) {
    .ds-page-header {
        padding: var(--ds-space-5) var(--ds-space-6) var(--ds-space-6);
    }
}

/* ---- Card: a panel with a small uppercase title and its tools. ---------- */
.ds-card {
    min-width: 0;
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-color-surface);
    box-shadow: var(--ds-shadow-sm);
    color: var(--ds-color-text);
    overflow: hidden;
}

.ds-card__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-2) var(--ds-space-3);
    padding: var(--ds-space-3) var(--ds-space-4);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
}

.ds-card__title {
    margin: 0;
    color: var(--ds-color-text);
    font-size: var(--ds-font-size-sm);
    font-weight: var(--ds-font-weight-bold);
    letter-spacing: var(--ds-label-tracking);
    line-height: var(--ds-line-height-tight);
    text-transform: uppercase;
}

.ds-card__body {
    padding: var(--ds-space-4);
}

/* A table or a list edge to edge. */
.ds-card__body--flush {
    padding: 0;
}

.ds-card__footer {
    padding: var(--ds-space-3) var(--ds-space-4);
    border-top: var(--ds-border-width) solid var(--ds-color-border);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-font-size-sm);
}

/* The one card the page is about (the next match, the club's standing). */
.ds-card--featured {
    border-top: 4px solid var(--ds-color-brand);
}

/* ---- Stat tiles: a label and a big number, with how it moved. ---------- */
.ds-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
    gap: var(--ds-space-3);
    /* Sideways only: on a page, the space above it is the page's. */
    margin-inline: 0;
    padding: 0;
    list-style: none;
}

.ds-stat {
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-1);
    min-width: 0;
    padding: var(--ds-space-3) var(--ds-space-4);
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface-sunken);
}

.ds-stat__label {
    color: var(--ds-color-text-muted);
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
    letter-spacing: var(--ds-label-tracking);
    text-transform: uppercase;
}

.ds-stat__value {
    color: var(--ds-color-text);
    font-size: var(--ds-font-size-stat);
    font-weight: var(--ds-font-weight-bold);
    font-variant-numeric: tabular-nums;
    line-height: var(--ds-line-height-tight);
    overflow-wrap: anywhere;
}

/* The arrow is in the text (▲ ▼), so colour is never the only sign. */
.ds-stat__delta {
    font-size: var(--ds-font-size-sm);
    font-weight: var(--ds-font-weight-medium);
    font-variant-numeric: tabular-nums;
    color: var(--ds-color-text-muted);
}

.ds-stat__delta--up {
    color: var(--ds-color-success);
}

.ds-stat__delta--down {
    color: var(--ds-color-danger);
}

/* ---- Badges: a short word on a soft or solid ground. ------------------- */
.ds-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-1);
    padding: 0.125rem var(--ds-space-2);
    border-radius: var(--ds-radius-pill);
    background: var(--ds-color-surface-sunken);
    color: var(--ds-color-text);
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
    box-shadow: inset 0 0 0 var(--ds-border-width) var(--ds-color-border);
}

.ds-badge--brand { background: var(--ds-color-brand); color: var(--ds-color-on-brand); box-shadow: none; }
.ds-badge--accent { background: var(--ds-color-accent); color: var(--ds-color-on-accent); box-shadow: none; }
.ds-badge--success { background: var(--ds-color-success-soft); color: var(--ds-color-success); box-shadow: none; }
.ds-badge--warning { background: var(--ds-color-warning-soft); color: var(--ds-color-warning); box-shadow: none; }
.ds-badge--danger { background: var(--ds-color-danger-soft); color: var(--ds-color-danger); box-shadow: none; }
.ds-badge--info { background: var(--ds-color-info-soft); color: var(--ds-color-info); box-shadow: none; }

/* Positions: a square of the position's colour, the letters in white. */
.ds-badge--gk,
.ds-badge--df,
.ds-badge--mf,
.ds-badge--fw {
    min-width: 2.25rem;
    justify-content: center;
    border-radius: var(--ds-radius-sm);
    color: var(--ds-color-on-brand);
    box-shadow: none;
}

.ds-badge--gk { background: var(--ds-color-gk); }
.ds-badge--df { background: var(--ds-color-df); }
.ds-badge--mf { background: var(--ds-color-mf); }
.ds-badge--fw { background: var(--ds-color-fw); }

/* ---- Results: W · D · L chips, a club's form in a row. ----------------- */
.ds-form {
    display: inline-flex;
    gap: var(--ds-space-1);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ds-result {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: var(--ds-radius-sm);
    color: var(--ds-color-on-brand);
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
}

.ds-result--win { background: var(--ds-color-win); }
.ds-result--draw { background: var(--ds-color-draw); }
.ds-result--loss { background: var(--ds-color-loss); }

/* ---- Tables: text left, numbers right with figures of equal width, and
   wide tables scrolling sideways inside their card. A long table can scroll
   inside its own box too (.ds-table-wrap--tall), and only there does its
   head stay in view: a sticky head sticks to its nearest scrolling box, and
   the sideways-scrolling wrap is that box. ------------------------------ */
.ds-table-wrap {
    /* Positioned, so a visually hidden label in a cell (is-sr-only, absolute)
       stays inside the scroll box and can't widen the page. */
    position: relative;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ds-table-wrap--tall {
    max-height: min(70vh, 40rem);
    overflow-y: auto;
}

.ds-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--ds-color-text);
    font-size: var(--ds-font-size-sm);
}

.ds-table th,
.ds-table td {
    padding: var(--ds-space-2);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

.ds-table thead th {
    background: var(--ds-color-surface-sunken);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
    letter-spacing: var(--ds-label-tracking);
    text-transform: uppercase;
}

.ds-table-wrap--tall .ds-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}

.ds-table tbody tr:last-child td {
    border-bottom: 0;
}

.ds-table tbody tr:hover td {
    background: var(--ds-color-surface-sunken);
}

.ds-table .is-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* The column that names the row (a club, a player) takes the room left. */
.ds-table .is-name {
    width: 100%;
    min-width: 8rem;
    white-space: normal;
}

.ds-table .is-strong {
    font-weight: var(--ds-font-weight-bold);
}

/* Zones: an edge on the row's first cell, and a soft ground. */
.ds-table tr.is-promotion td { background: var(--ds-color-promotion-soft); }
.ds-table tr.is-promotion td:first-child { box-shadow: inset 4px 0 0 var(--ds-color-promotion); }
.ds-table tr.is-playoff td:first-child { box-shadow: inset 4px 0 0 var(--ds-color-playoff); }
.ds-table tr.is-relegation td { background: var(--ds-color-relegation-soft); }
.ds-table tr.is-relegation td:first-child { box-shadow: inset 4px 0 0 var(--ds-color-relegation); }

/* The player's own club: gold, and bold, so it's found at a glance
   (is-own-club: public/js/own-club.js marks its rows on every page). */
.ds-table tr.is-own td,
.ds-table tr.is-own-club td {
    background: var(--ds-color-own-soft);
    font-weight: var(--ds-font-weight-bold);
}

.ds-table tr.is-own td:first-child,
.ds-table tr.is-own-club td:first-child {
    box-shadow: inset 4px 0 0 var(--ds-color-own);
}

/* Wide tables on phones: the first column stays while the rest scroll. */
.ds-table--sticky-first th:first-child,
.ds-table--sticky-first td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--ds-color-surface);
}

.ds-table--sticky-first thead th:first-child {
    z-index: 2;
    background: var(--ds-color-surface-sunken);
}

/* Columns a phone can do without (a table's W, D, L, goals): from a
   tablet up they show. */
.ds-table .ds-col-optional {
    display: none;
}

@media (min-width: 769px) {
    .ds-table th,
    .ds-table td {
        padding: var(--ds-space-2) var(--ds-space-3);
    }

    .ds-table .ds-col-optional {
        display: table-cell;
    }
}

/* ---- Tabs: a segmented row; on phones it scrolls rather than wraps. ---- */
.ds-tabs {
    display: flex;
    gap: var(--ds-space-1);
    max-width: 100%;
    padding: var(--ds-space-1);
    overflow-x: auto;
    border-radius: var(--ds-radius-pill);
    background: var(--ds-color-surface-sunken);
    box-shadow: inset 0 0 0 var(--ds-border-width) var(--ds-color-border);
    scrollbar-width: none;
}

.ds-tabs::-webkit-scrollbar {
    display: none;
}

.ds-tab {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    padding: 0 var(--ds-space-4);
    border: 0;
    border-radius: var(--ds-radius-pill);
    background: transparent;
    color: var(--ds-color-text-muted);
    font: inherit;
    font-size: var(--ds-font-size-sm);
    font-weight: var(--ds-font-weight-medium);
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--ds-duration), color var(--ds-duration);
}

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

.ds-tab[aria-selected='true'],
.ds-tab[aria-current='page'] {
    background: var(--ds-color-surface);
    color: var(--ds-color-brand-strong);
    font-weight: var(--ds-font-weight-bold);
    box-shadow: var(--ds-shadow-sm);
}

.ds-tab:focus-visible,
.ds-page a:focus-visible,
.ds-page button:focus-visible {
    outline: none;
    box-shadow: var(--ds-focus-ring);
}

/* ---- Grid: the dashboard's cards, one column on phones. ---------------- */
.ds-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--ds-space-4);
}

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

    .ds-grid--auto {
        grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    }
}

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

    .ds-grid__wide {
        grid-column: span 2;
    }
}

/* ---- Rating bar: a skill out of 100, the number beside it. ------------- */
.ds-meters {
    display: grid;
    gap: var(--ds-space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ds-meter {
    display: grid;
    grid-template-columns: minmax(5rem, 8rem) minmax(0, 1fr) 2.5rem;
    align-items: center;
    gap: var(--ds-space-3);
    font-size: var(--ds-font-size-sm);
}

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

.ds-meter__value {
    text-align: right;
    font-weight: var(--ds-font-weight-bold);
    font-variant-numeric: tabular-nums;
}

.ds-meter__bar {
    width: 100%;
    height: 0.5rem;
    border: 0;
    border-radius: var(--ds-radius-pill);
    background: var(--ds-color-border);
    overflow: hidden;
    appearance: none;
    -webkit-appearance: none;
}

.ds-meter__bar::-webkit-progress-bar {
    border-radius: var(--ds-radius-pill);
    background: var(--ds-color-border);
}

.ds-meter__bar::-webkit-progress-value {
    border-radius: var(--ds-radius-pill);
    background: var(--ds-color-brand);
}

.ds-meter__bar::-moz-progress-bar {
    border-radius: var(--ds-radius-pill);
    background: var(--ds-color-brand);
}
