/* ── Statistics: shared UI components of the detail layer ─────────────────────
   Ported 1:1 from the approved mockups (`design/mockups/Stats*Tap*.dc.html`,
   `Stats*All*.dc.html`, `Stats*Card*.dc.html`); the generator is `reference/lib.mjs`. Each rule
   below has an inline `style=` twin in one of those files — when in doubt, the mockup decides.
   Only the class names changed (prefix `stats-ui-`), plus a handful of `--ui-*` tokens.

   The components are mounted outside `#view-stats` on some screens (a card can be lifted into a
   panel), so the tokens are declared on the component roots as well as on the view. Corner radii
   stay ≤ 6 px; touch targets are 44 px on a phone and 36 px from the desktop breakpoint, as the
   spec asks. */

/* The mockups' colour constants `C.*` that have no app token: card/track/unknown/chip already
   exist as `--stats-*` in `css/stats.css`; the two float values are new and live here. The block
   names every component root, because a component can be mounted on its own (a standalone search
   box, a card lifted out of its panel), and the tokens must travel with it. */
.stats-ui-search,
.stats-ui-chips,
.stats-ui-pill,
.stats-ui-compare,
.stats-ui-tile,
.stats-ui-legend,
.stats-ui-menu,
.stats-ui-menu-list,
.stats-ui-list,
.stats-ui-list-controls,
.stats-ui-desk-controls,
.stats-ui-sort-table,
.stats-ui-grid,
.stats-ui-hours,
.stats-ui-card,
.stats-ui-segmented {
    --ui-chip: var(--stats-chip);
    --ui-track: var(--stats-track);
    --ui-rule: var(--stats-rule);
    --ui-strong: var(--stats-strong);
    --ui-float-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
    --ui-float-border: rgba(56, 189, 248, 0.6);
}

/* ── Links, headings, breadcrumbs ─────────────────────────────────────────── */

.stats-ui-panel-link {
    min-height: 44px;
    margin: -12px 0;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    color: var(--accent);
}
.stats-ui-panel-link:hover { color: var(--stats-link-hover); }
.stats-ui-panel-link svg { flex-shrink: 0; }

.stats-ui-go-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--accent);
}
.stats-ui-go-link:hover { color: var(--stats-link-hover); }
.stats-ui-go-link-text { flex-grow: 1; }
.stats-ui-go-link svg { flex-shrink: 0; }

.stats-ui-crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 6px;
    font-size: 0.8125rem;
    color: var(--text-sec);
}
.stats-ui-crumb-link {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    color: var(--text-sec);
    text-decoration: none;
}
.stats-ui-crumb-link:hover { color: var(--stats-link-hover); }
.stats-ui-crumb-current { color: var(--text-main); font-weight: 600; }
.stats-ui-crumb-sep { color: var(--text-sec); }

.stats-ui-view-head { display: flex; flex-direction: column; gap: 4px; }
.stats-ui-view-head-title {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.3;
    font-weight: 800;
    color: var(--text-main);
}
.stats-ui-view-head-sub { margin: 0; font-size: 0.8125rem; line-height: 1.5; color: var(--text-sec); }

/* ── Search ───────────────────────────────────────────────────────────────── */

.stats-ui-search {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border-radius: 6px;
    border: 1px solid var(--tint-14);
    background: var(--ui-chip);
    color: var(--text-sec);
    flex: 1 1 auto;
    min-width: 0;
}
.stats-ui-search-input {
    flex-grow: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text-main);
    font: inherit;
    font-size: 0.9375rem;
    outline: none;
}

/* ── Chips, pills, control buttons ─────────────────────────────────────────── */

.stats-ui-ctl {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    border-radius: 6px;
    border: 1px solid var(--tint-14);
    background: transparent;
    color: var(--text-sec);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}
.stats-ui-ctl:hover { color: var(--text-main); }
.stats-ui-ctl--on {
    border-color: var(--accent);
    background: rgba(56, 189, 248, 0.14);
    color: var(--text-main);
}
.stats-ui-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.stats-ui-active-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.stats-ui-pill {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 0 0 10px;
    border-radius: 4px;
    background: rgba(56, 189, 248, 0.14);
    border: 1px solid rgba(56, 189, 248, 0.5);
    font-size: 0.8125rem;
    color: var(--text-main);
}
.stats-ui-pill-remove {
    width: 36px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--text-sec);
    cursor: pointer;
}
.stats-ui-pill-remove:hover { color: var(--text-main); }

.stats-ui-count { font-size: 0.75rem; color: var(--text-sec); }

/* ── Menus (sort / filters) ────────────────────────────────────────────────── */

.stats-ui-menu { position: relative; }
.stats-ui-menu-list {
    position: absolute;
    z-index: 8;
    top: calc(100% + 4px);
    left: 0;
    min-width: 200px;
    max-height: 60vh;
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    border-radius: 6px;
    border: 1px solid var(--tint-14);
    background: var(--select-option-bg);
    box-shadow: var(--ui-float-shadow);
}
.stats-ui-menu-heading {
    padding: 6px 10px 2px;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-sec);
}
.stats-ui-menu-option {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-sec);
    font: inherit;
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}
.stats-ui-menu-option:hover { color: var(--text-main); }
.stats-ui-menu-option[aria-selected="true"] { color: var(--text-main); font-weight: 700; }
.stats-ui-menu-option--on { background: rgba(56, 189, 248, 0.14); }

/* ── Controls compositions ─────────────────────────────────────────────────── */

.stats-ui-list-controls { display: flex; flex-direction: column; gap: 8px; }
.stats-ui-controls-row { display: flex; flex-wrap: wrap; gap: 8px; }
.stats-ui-desk-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.stats-ui-desk-search { flex: 0 1 320px; display: flex; }
.stats-ui-controls-spacer { flex-grow: 1; }
.stats-ui-controls-right { display: inline-flex; align-items: center; }

/* ── Segmented switch ───────────────────────────────────────────────────────── */

/* The segments are grid items laid out in one row: `grid-auto-flow: column` puts each next segment
   in the next column. Without it a bare `display: grid` stacks them vertically, which no mockup
   draws (every `Stats*All*` tablist is `repeat(2, minmax(0, 1fr))` side by side). Width is the
   caller's job: the switch fills its container, and a narrow desktop card narrows it through that
   container, as `StatsTrafficAllDesktop` does with its `max-width: 360px` wrapper. */
.stats-ui-segmented {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    border: 1px solid var(--tint-14);
    border-radius: 6px;
    overflow: hidden;
}
.stats-ui-seg {
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-sec);
    background: transparent;
}
.stats-ui-seg--active { font-weight: 700; color: var(--stats-seg-on-fg); background: var(--stats-seg-on-bg); }

/* ── Phone list ────────────────────────────────────────────────────────────── */

.stats-ui-list { display: flex; flex-direction: column; gap: 8px; }
.stats-ui-rows { display: flex; flex-direction: column; }
.stats-ui-foot {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: stretch;
}
.stats-ui-foot[hidden] { display: none; }
.stats-ui-foot-count { font-size: 0.75rem; color: var(--text-sec); text-align: center; }
.stats-ui-more-btn {
    min-height: 44px;
    border-radius: 6px;
    border: 1px solid var(--tint-14);
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}
.stats-ui-more-btn:hover { color: var(--stats-link-hover); }
.stats-ui-more-btn:focus-visible { outline: 2px solid var(--map-focus-ring); outline-offset: 2px; }

/* ── Desktop table ─────────────────────────────────────────────────────────── */

.stats-ui-table-scroll { overflow-x: auto; }
.stats-ui-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
}
.stats-ui-th {
    padding: 0 8px;
    text-align: left;
    font-weight: 600;
    color: var(--text-sec);
    border-bottom: 1px solid var(--tint-14);
}
.stats-ui-th--first { padding-left: 0; }
/* The chevron column is exactly as wide as its 16 px chevron: no padding, so the table gives it no
   room beyond the icon. Its header holds only the screen-reader label „Szczegóły”, which the
   `.stats-ui-visually-hidden` rule takes out of the layout and off the screen; no header is drawn. */
.stats-ui-th--chev { width: 16px; padding: 0; }
.stats-ui-th-btn {
    min-height: 36px;
    padding: 0;
    border: 0;
    background: transparent;
    font: inherit;
    color: var(--text-sec);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}
.stats-ui-th-btn--on { color: var(--text-main); }
.stats-ui-th-btn:focus-visible { outline: 2px solid var(--map-focus-ring); outline-offset: 2px; }
.stats-ui-th-arrow { font-size: 0.625rem; color: var(--slate, var(--text-sec)); }
.stats-ui-th-btn--on .stats-ui-th-arrow { color: var(--accent); }
.stats-ui-tr { border-top: 1px solid var(--ui-rule); }
.stats-ui-td { padding: 7px 8px; vertical-align: middle; }
.stats-ui-td--first { padding-left: 0; }
.stats-ui-td--chev { width: 16px; padding: 7px 0; text-align: right; color: var(--text-sec); }
.stats-ui-desk-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-sec);
}
.stats-ui-desk-foot[hidden] { display: none; }
.stats-ui-desk-foot .stats-ui-foot-count { flex-grow: 1; text-align: left; }
.stats-ui-more-btn--desk {
    min-height: 36px;
    padding: 0 12px;
    font-size: 0.8125rem;
}
.stats-ui-cell-link { color: var(--text-main); font-weight: 600; text-decoration: none; }
.stats-ui-cell-link:hover { color: var(--stats-link-hover); }

/* ── Small pieces ──────────────────────────────────────────────────────────── */

.stats-ui-kicker {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-sec);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.stats-ui-meter {
    height: 8px;
    background: var(--ui-track);
    display: flex;
    border-radius: 2px;
    overflow: hidden;
}
.stats-ui-meter-fill { width: 0; }
.stats-ui-stack { display: flex; height: 22px; border-radius: 3px; overflow: hidden; gap: 2px; }
.stats-ui-stack-seg { background: var(--ui-track); }

.stats-ui-legend {
    display: grid;
    gap: 6px 12px;
    font-size: 0.8125rem;
}
.stats-ui-legend-item { display: flex; align-items: center; gap: 6px; }
.stats-ui-swatch {
    display: inline-block;
    flex-shrink: 0;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: var(--ui-track);
}

.stats-ui-compare {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 6px 14px;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    align-items: baseline;
}
.stats-ui-compare-head { font-size: 0.6875rem; color: var(--text-sec); text-align: right; }
.stats-ui-compare-key { color: var(--text-sec); }
.stats-ui-compare-a { text-align: right; color: var(--text-main); }
.stats-ui-compare-b { text-align: right; color: var(--ui-strong); }
.stats-ui-verdict--bad { color: var(--warn-text); }
.stats-ui-verdict--good { color: var(--success); }

.stats-ui-tile { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stats-ui-tile-value {
    font-size: 1.375rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    color: var(--text-main);
}
.stats-ui-tile-label { font-size: 0.75rem; line-height: 1.35; color: var(--text-sec); }
.stats-ui-tile-sub { font-size: 0.75rem; color: var(--ui-strong); }

/* ── 24-hour chart ──────────────────────────────────────────────────────────── */

.stats-ui-hours {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    column-gap: 6px;
    row-gap: 4px;
}
.stats-ui-hours-ylabels { position: relative; }
.stats-ui-hours-tick {
    position: absolute;
    right: 0;
    font-size: 0.625rem;
    line-height: 12px;
    color: var(--text-sec);
    white-space: nowrap;
}
.stats-ui-hours-plot {
    position: relative;
    display: grid;
    grid-template-columns: repeat(24, minmax(0, 1fr));
    gap: 2px;
    align-items: end;
    border-bottom: 1px solid var(--stats-axis);
}
.stats-ui-hour {
    position: relative;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    display: flex;
    align-items: flex-end;
    cursor: pointer;
}
.stats-ui-hour-fill {
    position: relative; /* the value label is placed against its own bar */
    display: block;
    width: 100%;
    min-height: 2px;
    background: var(--stats-late);
    border-radius: 2px 2px 0 0;
}
.stats-ui-hour--missing { cursor: default; }
.stats-ui-hour--missing .stats-ui-hour-fill { background: var(--ui-track); }
/* Selection, as in the tap mockups: the other bars fade to 0.35, the chosen one gets the outline and
   a boxed value above it. The outline and the fade sit on the fill, not on the button: the button is
   the whole column (100% of the plot), so an outline there would frame the empty space too. */
.stats-ui-hour--dim .stats-ui-hour-fill { opacity: 0.35; }
.stats-ui-hour--sel .stats-ui-hour-fill { box-shadow: 0 0 0 2px var(--stats-seg-on-bg); z-index: 1; }
.stats-ui-hour-value {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--stats-seg-on-bg);
    color: var(--stats-seg-on-fg);
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
    pointer-events: none;
}
.stats-ui-hours-grid {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed var(--stats-axis);
}
.stats-ui-hours-xlabels {
    grid-column: 2;
    display: flex;
    justify-content: space-between;
    font-size: 0.6875rem;
    color: var(--text-sec);
    font-variant-numeric: tabular-nums;
}

/* ── Heat grid ──────────────────────────────────────────────────────────────── */

.stats-ui-grid {
    display: grid;
    gap: 2px;
    font-size: 0.5625rem;
    font-variant-numeric: tabular-nums;
}
.stats-ui-grid-corner { display: block; }
.stats-ui-grid-col { text-align: center; color: var(--text-sec); }
.stats-ui-grid-row { display: flex; align-items: center; color: var(--text-sec); }
.stats-ui-cell {
    height: 22px;
    padding: 0;
    border: 0;
    background: var(--ui-track);
    cursor: pointer;
}
.stats-ui-cell--missing { background: var(--ui-track); }
.stats-ui-cell--sel { box-shadow: 0 0 0 2px var(--stats-seg-on-bg); z-index: 1; }

/* ── Tap card ───────────────────────────────────────────────────────────────── */

/* The card is one step lighter than the page card (`--stats-card-bg`), as the tap mockups draw it
   (#1e293b on #151d2e). It must not take the track colour: a bar track inside the card is the same
   slate, so with a shared token the tracks vanish into the card. The arrow is the same surface. */
.stats-ui-card {
    position: relative;
    margin-top: 12px;
    padding: 12px 14px 6px;
    border-radius: 6px;
    background: var(--stats-tap-bg);
    border: 1px solid var(--ui-float-border);
    box-shadow: var(--ui-float-shadow);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.stats-ui-card-arrow {
    position: absolute;
    top: -7px;
    left: calc(50% - 6px);
    width: 12px;
    height: 12px;
    background: var(--stats-tap-bg);
    border-left: 1px solid var(--ui-float-border);
    border-top: 1px solid var(--ui-float-border);
    transform: rotate(45deg);
}
.stats-ui-card-head { display: flex; align-items: flex-start; gap: 8px; }
.stats-ui-card-title {
    flex-grow: 1;
    font-size: 0.9375rem;
    line-height: 1.35;
    color: var(--text-main);
}
.stats-ui-card-close {
    width: 44px;
    height: 44px;
    margin: -12px -14px -10px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--text-sec);
    flex-shrink: 0;
    cursor: pointer;
}
.stats-ui-card-close:hover { color: var(--text-main); }
.stats-ui-card-body { font-size: 0.8125rem; line-height: 1.5; color: var(--text-sec); }
.stats-ui-card-links {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--ui-rule);
}
.stats-ui-card-links[hidden] { display: none; }
.stats-ui-card--float {
    position: absolute;
    z-index: 5;
    width: 320px;
}
/* Mounted by `tapCard({host})` right after the chart. On the phone it is an ordinary block (the
   card pushes the content down); from 1024 px it has no height and the card floats. */
.stats-ui-card-slot { position: relative; }
.stats-ui-card-slot--float { height: 0; }

/* ── Desktop geometry ──────────────────────────────────────────────────────────
   From 960 px the desktop mockups use 36 px controls and a smaller table; the phone's 44 px
   rows would only inflate the table header. */
@media (min-width: 960px) {
    .stats-ui-ctl { min-height: 36px; }
    .stats-ui-more-btn { min-height: 36px; }
}

.stats-ui-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Tones ──────────────────────────────────────────────────────────────────────
   Shared by bars, cells, segments, meters and swatches. Values are the mockups' colours mapped to
   the tokens the app already defines: the mockups' slate grey is `--stats-unknown`, their amber is
   `--warn`, their sky blue is `--accent`. (The amber and sky hex values stay in the token blocks;
   a theme test bans them anywhere else.)

   This block stays LAST in the file, on purpose. A tone is one class (specificity 0,1,0), and so are
   the default fill `.stats-ui-hour-fill` and the cell track `.stats-ui-cell`. Declared after them, a
   tone wins at equal specificity. Declared before, the default fill silently repainted every bar
   orange. Rules that need to beat a tone have a higher specificity (`.stats-ui-hour--missing
   .stats-ui-hour-fill`), so they still do. */
.stats-ui-tone--early { background: var(--stats-early); }
.stats-ui-tone--waited { background: var(--stats-waited); }
.stats-ui-tone--ontime { background: var(--stats-ontime); }
.stats-ui-tone--late { background: var(--stats-late); }
.stats-ui-tone--unknown { background: var(--stats-unknown); }
.stats-ui-tone--neutral { background: var(--stats-meter); }
.stats-ui-tone--off { background: var(--ui-track); }
.stats-ui-tone--grey { background: var(--stats-unknown); }
.stats-ui-tone--warn { background: var(--warn); }
.stats-ui-tone--ok { background: var(--accent); }
.stats-ui-tone--fast { background: var(--accent); }
