/* Tokens. --brand is per country (config.theme). Series colours are the
   validated categorical slots 1-3 (all-pairs, both themes); the rest is "other". */
:root {
  color-scheme: light;
  --brand-light: #0e6577;
  --brand-dark: #5cb8c8;
  --brand: var(--brand-light);
  --brand-ink: #ffffff;
  --brand-tint: color-mix(in srgb, var(--brand) 9%, transparent);
  --page: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #dfe2dd;
  --border-strong: #c9cdc6;
  --text-primary: #111312;
  --text-secondary: #4f5450;
  --text-muted: #6b706c;
  --danger: #b42318;
  --ok-bg: #e3f4e8; --ok-ink: #1d6b37;
  --warn-bg: #fdf1d3; --warn-ink: #7a4f00;
  --off-bg: #eceeeb; --off-ink: #4f5450;
  --info-bg: #e6eef8; --info-ink: #24508a;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-other: #8a8984;
  --overlay: #b4483c;
  --halo: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 20 / 0.06), 0 6px 20px rgb(16 24 20 / 0.05);
  --rail-w: 280px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: var(--brand-dark);
    --brand-ink: #0b1a1d;
    --page: #121312;
    --surface: #1a1b1a;
    --surface-2: #222422;
    --border: #333632;
    --border-strong: #454944;
    --text-primary: #eff0ed;
    --text-secondary: #c1c4bd;
    --text-muted: #a0a49c;
    --danger: #f97066;
    --ok-bg: #173a24; --ok-ink: #8fdba6;
    --warn-bg: #3d2f00; --warn-ink: #ffd666;
    --off-bg: #2a2c29; --off-ink: #c1c4bd;
    --info-bg: #1b2d47; --info-ink: #a9c7f0;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-other: #8f8e88;
    --overlay: #e07a6e;
    --halo: #1a1b1a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: var(--brand-dark);
  --brand-ink: #0b1a1d;
  --page: #121312;
  --surface: #1a1b1a;
  --surface-2: #222422;
  --border: #333632;
  --border-strong: #454944;
  --text-primary: #eff0ed;
  --text-secondary: #c1c4bd;
  --text-muted: #a0a49c;
  --danger: #f97066;
  --ok-bg: #173a24; --ok-ink: #8fdba6;
  --warn-bg: #3d2f00; --warn-ink: #ffd666;
  --off-bg: #2a2c29; --off-ink: #c1c4bd;
  --info-bg: #1b2d47; --info-ink: #a9c7f0;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-other: #8f8e88;
  --overlay: #e07a6e;
  --halo: #1a1b1a;
}

* { box-sizing: border-box; }
/* Author display rules must not defeat the hidden attribute. */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}
.masthead { grid-row: 1; }
.banner { grid-row: 2; }
.shell { grid-row: 3; }
.footer { grid-row: 4; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Masthead + main navigation */
.masthead { background: var(--surface); border-bottom: 1px solid var(--border); }
.masthead-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px 10px; }
.brand { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; min-width: 0; }
.emblem {
  flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; overflow: hidden;
  background: var(--brand); color: var(--brand-ink); font-weight: 700; letter-spacing: 0.04em;
}
.emblem img { width: 100%; height: 100%; object-fit: contain; background: var(--surface); }
.brand-text { display: grid; min-width: 0; }
.eyebrow { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand); }
.site-name { font-size: 1.45rem; font-weight: 650; letter-spacing: -0.01em; }
.authority { font-size: 0.85rem; color: var(--text-secondary); }
.masthead-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.updated { color: var(--text-muted); font-size: 0.82rem; }
.updated.is-stale { color: var(--warn-ink); background: var(--warn-bg); padding: 2px 8px; border-radius: 999px; }
.mainnav { display: flex; gap: 4px; padding: 0 16px; overflow-x: auto; }
.mainnav a {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 12px 11px; border-bottom: 3px solid transparent;
  color: var(--text-secondary); text-decoration: none; font-weight: 550; white-space: nowrap;
}
.mainnav a:hover { color: var(--text-primary); }
.mainnav a.is-active { color: var(--brand); border-bottom-color: var(--brand); }

.banner { padding: 10px 24px; font-weight: 500; background: var(--warn-bg); color: var(--warn-ink); }

/* Shell: context rail + view */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 0; }
.rail { background: var(--surface-2); border-right: 1px solid var(--border); padding: 22px 20px; overflow-y: auto; min-height: 0; }
.view { overflow-y: auto; min-height: 0; position: relative; }
.view:focus { outline: none; }
.rail-section { display: grid; gap: 16px; }
.rail-label {
  font-size: 0.72rem; font-weight: 650; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted);
  border-left: 3px solid var(--brand); padding-left: 9px;
}
.rail-hint { margin: 0; color: var(--text-secondary); font-size: 0.88rem; }
.rail-entity { display: grid; gap: 8px; justify-items: start; }
.rail-entity strong { font-size: 1.1rem; overflow-wrap: anywhere; }
.stat { display: grid; }
.stat-value { font-size: 2rem; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--text-secondary); }
.stat-sub { color: var(--text-muted); font-size: 0.82rem; }
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 550; text-decoration: none; }
.back:hover { text-decoration: underline; }

.page { padding: 24px 28px 40px; max-width: 1320px; display: grid; gap: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; }
.page-title { font-size: 1.5rem; font-weight: 650; }
.page-sub { margin: 4px 0 0; color: var(--text-secondary); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.search-box {
  display: flex; align-items: center; gap: 8px; flex: 1 1 320px; max-width: 520px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); color: var(--text-muted);
}
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.search-box .search { border: 0; background: none; padding: 10px 0; box-shadow: none; }
.search-box .search:focus { outline: none; }

.title-card {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--brand); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow);
}
.title-card h1 { font-size: 1.4rem; font-weight: 650; overflow-wrap: anywhere; }
.title-card .swatch { width: 14px; height: 14px; margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-title { font-size: 0.8rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  display: inline-flex; gap: 6px; align-items: center; padding: 9px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent;
  color: var(--text-secondary); text-decoration: none; font-weight: 550; white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-count { font-size: 0.75rem; background: var(--surface-2); color: var(--text-secondary); border-radius: 999px; padding: 1px 7px; }

/* Key/value grid: two pairs per row on wide screens */
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; }
.fact { display: grid; grid-template-columns: minmax(130px, 38%) 1fr; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.fact dt { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); padding-top: 2px; }
.fact dd { margin: 0; overflow-wrap: anywhere; }
.facts .fact:nth-child(odd) { padding-right: 24px; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 550; padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-primary); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-muted); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--brand); }
.btn-quiet { background: transparent; justify-self: start; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.link { color: var(--brand); font-weight: 550; text-decoration: none; }
.link:hover { text-decoration: underline; }
input, select, textarea {
  font: inherit; color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input[type="checkbox"] { width: auto; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
.field { display: grid; gap: 4px; font-size: 0.82rem; font-weight: 550; color: var(--text-secondary); }
.icon-btn { font-size: 1.5rem; line-height: 1; background: none; border: 0; color: var(--text-secondary); cursor: pointer; padding: 2px 6px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .table-wrap { box-shadow: none; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.data-table thead th {
  font-size: 0.74rem; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-muted);
  background: var(--surface); white-space: nowrap;
}
.data-table .filter-row td { padding: 0 8px 10px; }
.data-table .filter-row input, .data-table .filter-row select { padding: 5px 8px; font-size: 0.85rem; min-width: 110px; }
.data-table tbody tr[data-href] { cursor: pointer; }
.data-table tbody tr:hover { background: var(--brand-tint); }
.data-table tbody tr:last-child td, .data-table tbody tr:last-child th { border-bottom: 0; }
.data-table tbody a { font-weight: 550; text-decoration: none; }
.data-table tbody a:hover { text-decoration: underline; }
.data-table tr.empty td { color: var(--text-muted); text-align: center; padding: 28px; }
.data-table.compact th, .data-table.compact td { padding: 7px 10px; }
.data-table tbody th { font-weight: 600; }
.col-date { white-space: nowrap; font-variant-numeric: tabular-nums; }
.col-num { text-align: right !important; font-variant-numeric: tabular-nums; }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sort { all: unset; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.sort:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sort-mark { font-size: 0.7rem; color: var(--text-muted); }
.sort.is-asc .sort-mark, .sort.is-desc .sort-mark { color: var(--brand); }
.type-cell { display: inline-flex; gap: 8px; align-items: center; }
.type-cell .swatch { margin: 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.badge-active { background: var(--ok-bg); color: var(--ok-ink); }
.badge-pending { background: var(--warn-bg); color: var(--warn-ink); }
.badge-inactive { background: var(--off-bg); color: var(--off-ink); }
.badge-neutral { background: var(--info-bg); color: var(--info-ink); }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 1px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.8rem; white-space: nowrap; }
.chip-more { color: var(--text-muted); }

.pager { display: flex; gap: 4px; align-items: center; }
.pager .pg {
  min-width: 32px; height: 32px; display: inline-grid; place-items: center; padding: 0 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-primary); text-decoration: none; font-size: 0.9rem;
}
.pager .pg:hover { border-color: var(--text-muted); }
.pager .pg.is-current { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.pager .pg.is-disabled { color: var(--text-muted); opacity: 0.5; }
.pg-gap { color: var(--text-muted); padding: 0 2px; }
.pager-slot:empty { display: none; }
.pager-slot:last-child { justify-self: end; }

.message { margin: 0; color: var(--text-secondary); }
.message-error { color: var(--danger); }

/* Licence type colour: one custom property per slot drives map, tables and legend. */
.lic-slot-1 { --c: var(--series-1); }
.lic-slot-2 { --c: var(--series-2); }
.lic-slot-3 { --c: var(--series-3); }
.lic-slot-other { --c: var(--series-other); }
.swatch { flex: none; display: inline-block; width: 11px; height: 11px; border-radius: 3px; background: var(--c); }

/* Maps */
.leaflet-container { font: inherit; background: var(--surface-2); }
.map-full { position: absolute; inset: 0; }
.map-split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); gap: 20px; align-items: start; }
.detail-map-wrap { position: relative; min-height: 460px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.detail-map { position: absolute; inset: 0; }
.beacons { min-width: 0; }
path.lic { fill: var(--c); fill-opacity: 0.22; stroke: var(--c); stroke-width: 2px; stroke-opacity: 0.95; }
path.lic:hover { fill-opacity: 0.42; }
path.lic.is-selected { fill-opacity: 0.45; stroke-width: 3.5px; filter: drop-shadow(0 0 2px var(--halo)) drop-shadow(0 0 1px var(--halo)); }
path.lic.is-hidden { display: none; }
path.overlay { fill: var(--overlay); fill-opacity: 0.12; stroke: var(--overlay); stroke-dasharray: 5 4; }
path.beacon { fill: var(--surface); stroke: var(--text-primary); }
path.beacon.is-active { fill: var(--brand); stroke: var(--brand); }
.legend {
  background: var(--surface); color: var(--text-primary); padding: 8px 10px; border-radius: 8px; box-shadow: var(--shadow);
  font-size: 0.85rem; min-width: 170px;
}
.legend-title { font-weight: 650; margin-bottom: 4px; }
.legend-row { display: grid; grid-template-columns: 11px 1fr auto; gap: 8px; align-items: center; padding: 2px 0; }
.legend-count { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.leaflet-control-layers { background: var(--surface); color: var(--text-primary); border-radius: 8px !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text-primary); }
.popup { display: grid; gap: 4px; justify-items: start; }
.popup-sub { color: var(--text-secondary); font-size: 0.85rem; }
.popup-link { font-weight: 600; margin-top: 4px; }
.map-filters { display: grid; gap: 12px; }

.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 24px; font-size: 0.8rem; color: var(--text-muted); background: var(--surface); border-top: 1px solid var(--border);
}

/* Signup dialog */
dialog {
  width: min(480px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; background: var(--surface); color: var(--text-primary); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog .muted, .muted { color: var(--text-muted); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { font-size: 1.2rem; }
dialog form { display: grid; gap: 12px; margin-top: 12px; }
dialog form > label { display: grid; gap: 4px; font-weight: 500; }
dialog label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.field-error { color: var(--danger); font-size: 0.85rem; font-weight: 400; }
.field-error:empty { display: none; }
.honeypot { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-status { margin: 12px 0 0; }
.form-status:empty { display: none; }
.form-status.is-ok { color: var(--ok-ink); }
.form-status.is-error { color: var(--danger); }

/* Narrow screens: rail above content; tables scroll inside their frame. */
@media (max-width: 1000px) {
  .map-split { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .facts .fact:nth-child(odd) { padding-right: 4px; }
}
@media (max-width: 800px) {
  body { height: auto; min-height: 100dvh; }
  .masthead-inner { padding: 12px 16px 8px; align-items: flex-start; }
  .site-name { font-size: 1.2rem; }
  .updated { display: none; }
  .mainnav { padding: 0 8px; }
  .shell { display: block; }
  .rail { border-right: 0; border-bottom: 1px solid var(--border); padding: 16px; }
  .rail-hint { display: none; }
  .stat-value { font-size: 1.5rem; }
  .view { overflow: visible; }
  .page { padding: 16px; }
  body[data-view="map"] .view { height: 70vh; }
  .fact { grid-template-columns: 1fr; gap: 2px; }
  .footer { padding: 8px 16px; }
}
