/* The legend (legend.js; UI_RULES.md 18): one component for every legend, two states. Shown: the header (the title at
   body size, the quiet "Minimize" button), the scale with units (a bar with its ends and a few ticks labelled, or the
   legend's own swatches), the colour-by switch where there is one. Minimized: one line, the title, the range in words
   and a mini colour bar, "Show". No notes, help or source lines in either state (a source line is the legend's credit,
   shown in the map's ⓘ panel). Colours from tokens, light and dark (a dark basemap: data-dark on the map, map-gl.mjs;
   data-basemap on the console's map frame, app.js). The map's legends: one stack in the bottom-left corner, clear of
   the control column, every card the same width, one padding, one gap. */
.tg-legend{--lg-bg:#fffffff5;--lg-ink:#222924;--lg-muted:#5b655e;--lg-line:#d3d9cf;--lg-hover:#0000000d;--lg-accent:var(--accent,#3156d7);--lg-shadow:0 2px 8px #16240f1f;--lg-w:280px;--lg-bar-h:8px;--lg-bar-r:2px}
.map-wrap[data-basemap="dark"] .tg-legend,.map-wrap:has(>.maplibregl-map[data-dark]) .tg-legend,.opt-map-wrap:has(>.maplibregl-map[data-dark]) .tg-legend{--lg-bg:#1d2226f2;--lg-ink:#e8ece9;--lg-muted:#b4beb7;--lg-line:#3d464c;--lg-hover:#ffffff1a;--lg-accent:#9db4ff;--lg-shadow:0 2px 10px #0008}
/* a legend outside the map (the Water flow key in the results, the tool pages' chart keys) follows the page theme (owner 2026-11-24: dark text on a dark panel) */
:root[data-theme="dark"] .tg-legend:not(.map-wrap .tg-legend):not(.opt-map-wrap .tg-legend){--lg-bg:#1d2226f2;--lg-ink:#e8ece9;--lg-muted:#b4beb7;--lg-line:#3d464c;--lg-hover:#ffffff1a;--lg-accent:#9db4ff;--lg-shadow:none}
.tg-legend{position:relative;box-sizing:border-box;min-width:0;max-width:100%;color:var(--lg-ink);font:13px/1.3 var(--sans,system-ui,sans-serif);overflow-wrap:anywhere}
.tg-legend[hidden]{display:none!important}
.tg-legend{grid-template-columns:minmax(0,1fr)}.tg-legend>*{min-width:0;max-width:100%}   /* (a grid legend, the flow key: its one-line header never widens it) */

/* the header: title, summary (minimized), button; about 28 px */
.tg-legend>.tg-legend-head{display:flex;flex-wrap:nowrap;align-items:center;column-gap:6px;row-gap:4px;min-height:28px;margin:0;padding:0;position:static;background:none}
.tg-legend-head>.tg-legend-title{flex:0 0 auto;max-width:60%;min-width:0;margin:0!important;font:600 13px/1.25 var(--sans,system-ui,sans-serif);color:var(--lg-ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;overflow-wrap:normal}
.tg-legend-head>.tg-legend-title .legend-title-u{display:none}
.tg-legend-sum{display:none;flex:1 1 auto;min-width:0;align-items:center;gap:6px}
.tg-legend-range{flex:1 1 auto;min-width:0;color:var(--lg-muted);font-size:12px;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;overflow-wrap:normal}
.tg-legend-mini{display:flex;flex:none;width:32px;height:var(--lg-bar-h);border-radius:var(--lg-bar-r);overflow:hidden;box-shadow:inset 0 0 0 1px #0000001a}
.tg-legend-mini>span{flex:1 1 0;min-width:1px}
.tg-legend-btn{flex:none;margin-left:auto;min-height:24px;padding:2px 6px;border:0;border-radius:5px;background:none;color:var(--lg-accent);font:550 12px/1 var(--sans,system-ui,sans-serif);white-space:nowrap;cursor:pointer;overflow-wrap:normal}
.tg-legend-btn:hover{background:var(--lg-hover)}
.tg-legend-btn:focus-visible{outline:2px solid var(--lg-accent);outline-offset:1px}
@media(pointer:coarse){.tg-legend-btn{min-height:28px}}
/* the legend's own controls (the colour-by switch, moved under the header by legend.js) */
.tg-legend>.buildings-colour{margin:2px 0 2px}

/* no notes, help, zoom hints or source lines, in any state */
.tg-legend .tg-legend-note,.tg-legend .legend-source,.tg-legend .legend-zoom,.tg-legend .buildings-legend-tap,.tg-legend .buildings-legend-what,.tg-legend .flow-legend-note{display:none!important}

/* minimized: the one line */
.tg-legend[data-legend-state="minimized"]>:not(.tg-legend-head){display:none!important}
.tg-legend[data-legend-state="minimized"] .tg-legend-sum{display:flex}
.tg-legend[data-legend-state="minimized"]>.tg-legend-head{flex-wrap:nowrap}
.tg-legend[data-legend-state="minimized"] .tg-legend-btn{margin-left:0}

/* a scale: the bar (equal steps), its ends and a few ticks labelled with units; the rows stay for readers */
.tg-legend:has(>.tg-legend-bar) .legend-scale{display:none!important}
.tg-legend-bar{margin:4px 0 0}
.tg-legend-track{display:flex;height:var(--lg-bar-h);border-radius:var(--lg-bar-r);overflow:hidden;box-shadow:inset 0 0 0 1px #0000001a}
.tg-legend-track>span{flex:1 1 0}
.tg-legend-ticks{position:relative;height:15px;margin-top:3px;font:11px/15px var(--sans,system-ui,sans-serif);font-variant-numeric:tabular-nums;color:var(--lg-muted)}
.tg-tick{position:absolute;top:0;white-space:nowrap;transform:translateX(-50%);overflow-wrap:normal}
.tg-tick-first{left:0;transform:none}
.tg-tick-last{right:0;left:auto;transform:none}

/* swatch lists (a categorical legend: building sources, rings, routes, chart keys): the same type */
.tg-legend .legend-scale{display:grid;gap:2px;margin-top:4px}
.tg-legend .legend-row{display:flex;align-items:center;gap:6px;font:12px/1.3 var(--sans,system-ui,sans-serif);color:var(--lg-ink)}
.tg-legend .legend-row i{flex:none;width:14px;height:var(--lg-bar-h);border-radius:var(--lg-bar-r);box-shadow:inset 0 0 0 1px #0000001a}
.tg-legend .legend-row .legend-m,.tg-legend .legend-row .legend-u{color:var(--lg-muted)}

/* ---- the map's legends: one stack, bottom left, clear of the control column; cards of one width ---- */
.map-wrap>.map-legends{position:absolute;top:auto!important;left:var(--uf-ctl-edge,10px)!important;bottom:var(--uf-ctl-edge,10px)!important;right:auto!important;z-index:var(--z-legend,5);display:flex!important;flex-direction:column!important;flex-wrap:nowrap!important;align-items:stretch!important;justify-content:flex-end;gap:6px;width:var(--lg-w,280px);max-width:calc(100% - var(--uf-ctl,40px) - 3 * var(--uf-ctl-edge,10px));max-height:calc(100% - 2 * var(--uf-ctl-edge,10px));overflow-y:auto;overscroll-behavior:contain;pointer-events:none}
.map-wrap>.map-legends>*{pointer-events:auto}
.map-legends>.tg-legend,.opt-map-wrap>.tg-legend.map-legend{flex:none;width:100%!important;min-width:0!important;max-width:100%!important;margin:0!important;padding:2px 6px 8px 10px!important;border:1px solid var(--lg-line)!important;border-radius:8px!important;background:var(--lg-bg)!important;box-shadow:var(--lg-shadow)!important;font-size:13px!important}
.map-legends>.tg-legend[data-legend-state="minimized"],.opt-map-wrap>.tg-legend.map-legend[data-legend-state="minimized"]{padding-bottom:2px!important}
.map-legends>.map-ix-legend:not([hidden]){position:relative!important;left:auto!important;top:auto!important;display:block!important;cursor:default}
/* a one-symbol key (the street intersection): the symbol, its words are the title */
.tg-legend-text[data-same]{display:none}
.opt-map-wrap>.tg-legend.map-legend{position:absolute!important;top:auto!important;right:auto!important;left:var(--uf-ctl-edge,10px)!important;bottom:var(--uf-ctl-edge,10px)!important;width:var(--lg-w,280px)!important;max-width:calc(100% - var(--uf-ctl,40px) - 3 * var(--uf-ctl-edge,10px))!important;max-height:calc(100% - 2 * var(--uf-ctl-edge,10px));overflow-y:auto}
/* the ring buttons in the card's type */
.map-legends .map-ring-buttons{margin-top:4px}
.map-legends .map-ring-legend button{font-size:12px;background:none;color:var(--lg-ink)}
.map-legends .map-ring-legend button[aria-pressed="true"]{border-color:var(--lg-line)}
/* the building colour-by switch in the card's type */
.map-legends .buildings-colour{color:var(--lg-muted)}
