/* Filter chips, segmented rows and sortable headers, for the reader and the admin
   (spec 2026-11-26-chips-and-sorting, B271 to B273; DESIGN.md "Filters and chips", "Sortable tables").
   Borders are neutral grey; the active chip carries a light tint. No round pills, no coloured edges. */

/* --- Filter chips (B271) --- */
.fchips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.fchip { position: relative; display: inline-flex; align-items: stretch; min-height: var(--filter-h); border: 1px solid var(--filter-rule); border-radius: 6px; background: var(--card, var(--page)); color: var(--ink-2); font-size: var(--fs-meta); }
.fchip.is-on { background: var(--filter-on-bg); color: var(--filter-on-fg); font-weight: 600; }
.fchip-d { display: flex; }
.fchip-sum { position: relative; display: inline-flex; align-items: center; gap: 4px; padding: 0 10px; list-style: none; cursor: pointer; white-space: nowrap; border-radius: 5px; }
.fchip-sum::-webkit-details-marker { display: none; }
.fchip-sum::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; min-height: var(--touch); transform: translateY(-50%); } /* the hit area */
.fchip-sum:hover { background: var(--hover); }
.fchip-sum:focus-visible, .fchip-x:focus-visible, .fchip-opt:focus-visible, .seg-link:focus-visible, .sort-h:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fchip-label { color: inherit; }
.fchip-colon { margin-left: -4px; } /* "Type: IP", not "Type : IP" (the summary's gap) */
.fchip-val { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }
.fchip-caret { margin-left: 2px; font-size: 11px; color: var(--ink-3); font-weight: 400; }
.fchip-x { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 30px; padding: 0 8px 0 4px; color: var(--ink-3); font-size: 16px; font-weight: 400; text-decoration: none; border-left: 1px solid var(--filter-rule); }
.fchip-x::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; min-height: var(--touch); transform: translateY(-50%); }
.fchip-x:hover { color: var(--ink); background: var(--hover); }
.fchip-menu { position: absolute; left: -1px; top: calc(100% + 4px); z-index: 20; min-width: 220px; max-height: 60vh; overflow: auto; margin: 0; padding: 6px; list-style: none; background: var(--card, var(--page)); border: 1px solid var(--filter-rule); border-radius: 8px; box-shadow: 0 8px 24px rgba(14, 23, 38, .12); font-weight: 400; }
.fchip-menu li { margin: 0; }
.fchip-opt { display: flex; align-items: center; gap: 10px; min-height: var(--touch); padding: 0 10px; border-radius: 6px; color: var(--ink); text-decoration: none; white-space: nowrap; cursor: pointer; list-style: none; }
.fchip-opt:hover { background: var(--hover); }
.fchip-opt.is-on { font-weight: 600; }
.fchip-box { flex: none; width: 14px; height: 14px; border: 1px solid var(--filter-rule); border-radius: 3px; background: var(--card, var(--page)); }
.fchip-opt.is-one .fchip-box { border-radius: 50%; }
.fchip-opt.is-on .fchip-box { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 2px var(--card, var(--page)); }
.fchip-add { border-style: dashed; color: var(--ink-3); }
.fchip-sub > summary::-webkit-details-marker { display: none; }
.fchip-sub-sum { justify-content: space-between; }
.fchip-sub[open] > .fchip-sub-sum { font-weight: 600; }
.fchip-sub > .fchip-menu { position: static; box-shadow: none; border: 0; padding: 0 0 4px 14px; min-width: 0; }
.fchips-clear { display: inline-flex; align-items: center; min-height: var(--touch); padding: 0 6px; color: var(--accent); font-size: var(--fs-meta); }
.fchips-clear:hover { text-decoration: underline; }

/* --- Segmented text row (B272): one of few; the active one bold with a 2 px neutral underline --- */
.seg { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; margin: 0; }
.seg-link { display: inline-flex; align-items: center; min-height: var(--touch); padding: 0 2px; border-bottom: 2px solid transparent; color: var(--ink-3); font-size: var(--fs-meta); text-decoration: none; white-space: nowrap; }
.seg-link:hover { color: var(--ink); border-bottom-color: var(--rule); }
.seg-link.is-on { color: var(--ink); font-weight: 700; border-bottom-color: var(--ink-3); }
.seg-n { margin-left: 5px; color: var(--ink-3); font-weight: 400; font-variant-numeric: tabular-nums; }

/* --- Sortable headers (B273) --- */
.sort-h { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; color: inherit; text-decoration: none; white-space: nowrap; }
.sort-h:hover { color: var(--ink); text-decoration: underline; }
.sort-mark { font-size: 11px; color: var(--ink-3); opacity: 0; }
.sort-h:hover .sort-mark, .sort-h:focus-visible .sort-mark { opacity: .7; }
.sort-h.is-on { color: var(--ink); font-weight: 700; }
.sort-h.is-on .sort-mark { opacity: 1; color: var(--ink-2); }
th.num .sort-h, th.reg-num .sort-h, th.stack-num .sort-h { justify-content: flex-end; }

@media (hover: none) { .sort-mark { opacity: .5; } }
@media (max-width: 900px) {
  .adm .fchip-sum, .adm .seg-link { min-height: 44px; }
  .fchip-menu { min-width: min(280px, calc(100vw - 32px)); }
}

/* --- The four charts (B610 to B613, DESIGN.md "Charts"; macros in templates/_charts.html) ---
   Server-side SVG, coloured here from the tokens by tone. Colour sits on the data; structure is neutral. Red is never
   tinted (a light red is pink): a bad cell is neutral with a red mark, or solid red with white text when filled. */
.ch-title { font-size: var(--fs-meta); font-weight: 600; color: var(--ink); }
.ch-tick, .ch-axis { font-family: var(--font); font-size: 12px; fill: var(--ink-3); }
.ch-axis { font-weight: 600; fill: var(--ink-2); }
.ch-grid { stroke: var(--card-rule, var(--rule)); stroke-width: 1; }
.ch-ok { fill: var(--c-ok); background: var(--c-ok); }
.ch-warn { fill: var(--c-warn); background: var(--c-warn); }
.ch-bad { fill: var(--c-bad); background: var(--c-bad); }
.ch-info { fill: var(--c-info); background: var(--c-info); }
.ch-none { fill: var(--rule-strong); background: var(--rule-strong); }
.ch-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; padding: 0; list-style: none; font-size: var(--fs-meta); color: var(--ink-2); }
.ch-legend li { display: inline-flex; align-items: center; gap: 6px; }
.ch-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.ch-count { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }

/* Stacked distribution bar */
.ch-stack { margin: 0; }
.ch-stack-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.ch-total { font-family: var(--mono); font-size: var(--fs-meta); color: var(--ink-3); }
.ch-stack-bar { display: block; width: 100%; height: 10px; border-radius: 3px; overflow: hidden; }
.ch-stack-bar rect + rect { stroke: var(--card, var(--page)); stroke-width: .6; }

/* Trend line with a soft area */
/* A chart holds its own hidden table: a table ignores .sr-only's 1 px width, so the figure contains it and the page never
   scrolls sideways at 375 px because of it */
.ch-trend, .ch-matrix { position: relative; overflow: hidden; }
.ch-trend { margin: 0; }
.ch-trend .ch-title { display: block; margin-bottom: 6px; }
.ch-trend-svg { display: block; width: 100%; height: auto; }
.ch-line { fill: none; stroke: var(--c-info); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.ch-area { fill: var(--c-info); fill-opacity: .12; stroke: none; }
.ch-dot { fill: var(--c-info); stroke: var(--card, var(--page)); stroke-width: 2; }
.ch-tone-ok .ch-line { stroke: var(--c-ok); } .ch-tone-ok .ch-area, .ch-tone-ok .ch-dot { fill: var(--c-ok); }
.ch-tone-warn .ch-line { stroke: var(--c-warn); } .ch-tone-warn .ch-area, .ch-tone-warn .ch-dot { fill: var(--c-warn); }
/* A bad trend keeps a neutral area under a red line: a red area would read pink */
.ch-tone-bad .ch-line { stroke: var(--c-bad); } .ch-tone-bad .ch-dot { fill: var(--c-bad); } .ch-tone-bad .ch-area { fill: var(--ink-3); fill-opacity: .08; }

/* A tolerance on a trend (B922): a dashed neutral line labelled at its right end; colour stays on the data line */
.ch-tol { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 4 4; fill: none; vector-effect: non-scaling-stroke; }
.ch-tol-label { font-family: var(--font); font-size: 12px; fill: var(--ink-2); paint-order: stroke; stroke: var(--card, var(--page)); stroke-width: 4px; stroke-linejoin: round; }

/* Risk matrix */
.ch-matrix { margin: 0; max-width: 640px; }
.ch-matrix .ch-title { display: block; margin-bottom: 6px; }
.ch-matrix-svg { display: block; width: 100%; height: auto; }
.ch-cell rect { stroke: none; }
.ch-cell-ok rect { fill: var(--t-ok); }
.ch-cell-warn rect { fill: var(--t-warn); }
.ch-cell-bad rect { fill: var(--t-none); }
.ch-cell-bad.is-filled rect { fill: var(--c-bad); }
.ch-mark { fill: var(--c-bad); }
.ch-cell-text { font-family: var(--font); font-size: 15px; font-weight: 700; }
.ch-cell-ok .ch-cell-text, .ch-cell-warn .ch-cell-text { fill: var(--ink); } /* a tint under coloured text falls under 4.5:1 */
.ch-cell-bad .ch-cell-text { fill: var(--c-bad); }
.ch-cell-bad.is-filled .ch-cell-text { fill: var(--grade-ink); }
.ch-matrix-x { margin: 2px 0 0; text-align: right; font-size: 12px; color: var(--ink-3); }
/* A count matrix (Hagl H-6, B1954): blue tint where a cell holds rows, no risk bands */
.ch-cell-info rect { fill: var(--t-info); }
.ch-cell-none rect { fill: var(--t-none); }
.ch-cell-info .ch-cell-text, .ch-cell-none .ch-cell-text { fill: var(--ink); }

/* Horizontal bars, stacked bars and a timeline (Hagl H-6, B1954): one blue ramp and grey for series */
.ch-bars { margin: 0; }
.ch-bars .ch-title { display: block; margin-bottom: 6px; }
.ch-bars-svg { display: block; width: 100%; height: auto; }
/* On a phone the bars keep readable text and scroll sideways with their labels (the left end) in view first */
@media (max-width: 760px) {
  .ch-bars-scroll { overflow-x: auto; }
  .ch-bars-svg { min-width: 520px; }
}
.ch-bar-value { font-family: var(--font); font-size: 12px; font-variant-numeric: tabular-nums; fill: var(--ink-2); }
.ch-axis-line { stroke: var(--rule-strong); stroke-width: 1; }
.ch-s0 { fill: var(--c-info); background: var(--c-info); }
.ch-s1 { fill: var(--c-info); fill-opacity: .62; background: color-mix(in srgb, var(--c-info) 62%, transparent); }
.ch-s2 { fill: var(--c-info); fill-opacity: .36; background: color-mix(in srgb, var(--c-info) 36%, transparent); }
.ch-s3 { fill: var(--ink-3); background: var(--ink-3); }
.ch-s4 { fill: var(--rule-strong); background: var(--rule-strong); }

/* Grade in a circle */
.ch-grade { flex: none; display: inline-block; vertical-align: middle; }
.ch-grade text { font-family: var(--font); font-size: 13px; font-weight: 700; fill: var(--grade-ink); }
.ch-grade-ok circle { fill: var(--c-ok); }
.ch-grade-warn circle { fill: var(--c-warn); }
.ch-grade-bad circle { fill: var(--c-bad); }
.ch-grade-info circle { fill: var(--c-info); }
.ch-grade-none circle { fill: var(--t-none); stroke: var(--rule-strong); }
.ch-grade-none text { fill: var(--ink-3); }

/* On a phone the matrix and the trend keep 12 px text at their drawn size and scroll sideways, the newest end
   (the trend's right, the matrix's high-impact columns) in view first, as the loss curve on /risk (B611, B612) */
@media (max-width: 760px) {
  .ch-matrix-scroll, .ch-trend-scroll { overflow-x: auto; direction: rtl; }
  .ch-matrix-svg { min-width: 520px; direction: ltr; }
  .ch-trend-svg { min-width: 640px; direction: ltr; }
}
