:root {
  --ink: #1e3a5f;
  --muted: #5c6b7a;
  --line: #dfe5ec;
  --panel: #ffffff;
  --accent: #2b5797;
  --fountain: #1971c2;
  --assumption-bg: #fff4e6;
  --assumption-ink: #a8590a;
  --verified-bg: #e6f6ec;
  --verified-ink: #1b7a3d;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

html, body { margin: 0; height: 100%; background: #f4f6f8; }
#map { position: absolute; inset: 0; }
a { color: var(--accent); }
code { font-size: 0.92em; background: #f1f3f5; padding: 0 3px; border-radius: 3px; }

/* ---------- Panel ---------- */
#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 310px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(30, 58, 95, 0.18);
  font-size: 14px;
  z-index: 1;
}

summary { cursor: pointer; }
#panel > details > summary {
  list-style: none;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#panel > details > summary::-webkit-details-marker { display: none; }
.title { font-weight: 700; font-size: 17px; color: var(--accent); }
.subtitle { color: var(--muted); font-size: 13px; }

.panel-body { padding: 0 16px 14px; border-top: 1px solid var(--line); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 6px; }

.field[hidden] { display: none; }
.project-field { margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; font-size: 13px; color: var(--muted); }
select { font: inherit; color: var(--ink); padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

.legend { list-style: none; padding: 0; margin: 0; }
.legend li { margin: 3px 0; }
.legend label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.legend .group { font-weight: 600; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.legend .group > label { flex: 1; min-width: 0; }
.legend .sub { padding-left: 4px; }
.legend .group label { font-weight: 600; }
.legend .group.off > label { opacity: 0.55; }
.legend .group + .sub { margin-top: 4px; }
.legend .empty { color: var(--muted); font-size: 13px; }
.legend .empty.error { color: #c92a2a; }
.swatch-svg { width: 14px; height: 14px; flex: none; vertical-align: -2px; }
.popup h3 .swatch-svg, .defs .swatch-svg { margin-right: 6px; }

.note { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 14px 0 0; }
.note.error { color: #c92a2a; }
button.link { font: inherit; color: var(--accent); background: none; border: none; padding: 0; text-decoration: underline; cursor: pointer; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 999px; vertical-align: middle; white-space: nowrap; }
.badge-prototype, .badge-assumption { background: var(--assumption-bg); color: var(--assumption-ink); }
.badge-verified { background: var(--verified-bg); color: var(--verified-ink); }
.badge-rejected { background: #f1f3f5; color: var(--muted); text-decoration: line-through; }

/* ---------- Map buttons: | Docs | Settings | About | ---------- */
.ow-buttons {
  display: flex;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}
.ow-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  font: 600 14px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #222;
  background: #fff;
  border: none;
  text-decoration: none;
  cursor: pointer;
}
.ow-buttons .ow-button + .ow-button { border-left: 1px solid #ddd; }
.ow-button:hover { background: #f2f2f2; }
.ow-button svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.ow-button.inline { border: 1px solid var(--line); border-radius: 6px; color: var(--accent); }

/* ---------- Dialogs (About, Settings) ---------- */
dialog.ow-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 8px 28px 24px;
  border: none;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(30, 58, 95, 0.35);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
dialog.ow-dialog::backdrop { background: rgba(20, 30, 45, 0.45); }
dialog.ow-dialog h1 { font-size: 21px; color: var(--accent); margin: 16px 0 8px; }
dialog.ow-dialog h2 { font-size: 13px; margin-top: 22px; }
dialog#settings { width: min(620px, calc(100vw - 32px)); }
dialog.ow-dialog h3 { font-size: 14px; margin: 16px 0 4px; }
.about-layer { border-top: 1px solid var(--line); margin-top: 18px; }
.about-layer h2 { font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--ink); }

/* ---------- Tabs, layer list, style editor ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 8px 0 12px; flex-wrap: wrap; }
.tabs button { font: 600 13px system-ui, sans-serif; border: none; background: none; color: var(--muted); padding: 8px 10px; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.btn.icon { padding: 4px 9px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.form-ok { color: var(--verified-ink); background: var(--verified-bg); padding: 6px 10px; border-radius: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px 12px; margin: 12px 0; }
legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid2.disabled { opacity: 0.45; pointer-events: none; }
.field input[type="text"], .field input[type="number"], .field input[type="password"], .field textarea {
  font: inherit; color: var(--ink); padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.field input[type="color"] { width: 56px; height: 30px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.inline { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; margin: 4px 14px 4px 0; font-size: 13px; }
.inline-check { justify-content: flex-end; }
.checks { display: flex; flex-wrap: wrap; }
.cat-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.cat-table td { padding: 3px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
.cat-table input[type="color"] { width: 48px; height: 26px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.cat-table .count, .legend .count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Settings form ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.form-error { color: #c92a2a; background: #fff5f5; border-left: 3px solid #c92a2a; padding: 6px 10px; border-radius: 4px; }
.actions { display: flex; gap: 8px; margin-top: 18px; }
.actions .spacer { flex: 1; }
.btn { font: 600 13px system-ui, sans-serif; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; }
.btn:hover { background: #f1f3f5; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #224a82; }
.dialog-close { position: sticky; top: 0; display: flex; justify-content: flex-end; margin-right: -14px; }
.dialog-close button { font-size: 24px; line-height: 1; border: none; background: #fff; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.dialog-close button:hover { background: #f1f3f5; }
.callout { background: var(--assumption-bg); border-left: 3px solid var(--assumption-ink); padding: 8px 12px; border-radius: 4px; }
.defs { list-style: none; padding: 0; }
.defs li { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; }
.defs .dot { margin-top: 5px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.card header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card p { margin: 6px 0 0; }
.meta { color: var(--muted); font-size: 12.5px; }
.sources li { margin: 4px 0; }

.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex: none; margin-right: 6px; vertical-align: -1px; background: var(--c); }
.dot.hollow { background: #fff; border: 2.5px solid var(--c); width: 7px; height: 7px; }

/* ---------- Popups ---------- */
.maplibregl-popup-content { font: 13px system-ui, sans-serif; color: var(--ink); max-width: 320px; }
.popup .popup-layer { margin: 0 0 2px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding-right: 14px; }
.popup h3 { margin: 0 0 6px; font-size: 14px; padding-right: 14px; display: flex; align-items: center; }
.popup .why { margin: 4px 0; }
.popup ul.rules { margin: 2px 0 6px; padding-left: 18px; }
.popup ul.rules li { margin: 2px 0; }
/* Fixed layout: label column 42 %, values wrap at word boundaries (long tokens break only if needed) */
.popup table { border-collapse: collapse; width: 100%; table-layout: fixed; }
.popup td { padding: 2px 4px; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: break-word; }
.popup td:first-child { color: var(--muted); width: 42%; }
.popup .tags { margin-top: 6px; }
.popup .tags table { display: block; max-height: 160px; overflow-y: auto; }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  #panel { top: auto; bottom: 64px; left: 8px; right: 8px; width: auto; max-height: 50%; }
  .ow-button span { display: none; }
  dialog.ow-dialog { padding: 8px 16px 20px; }
}


/* ---------- Background map ---------- */
.basemap-form h2.plain { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 500; margin: 6px 0 10px; }
.radio-row { display: flex; gap: 22px; margin-bottom: 10px; font-size: 15px; }
.radio-row label { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.radio-row input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.url-input { width: 100%; box-sizing: border-box; font: 14px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink);
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; }
.url-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.help { color: var(--muted); font-size: 13px; line-height: 1.55; }
.help p { margin: 6px 0; }
.help code { color: #c2255c; background: none; padding: 0; overflow-wrap: anywhere; }
#basemap-msg { margin: 8px 0 0; }

/* ---------- Layer configuration ---------- */
.cat-table th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 2px 4px; }
.cat-table td.order { white-space: nowrap; }
.cat-table td.order .btn.icon { padding: 1px 6px; font-size: 12px; margin-right: 2px; }
.cat-table td.count { text-align: right; padding-right: 10px; }
.label-input { width: 100%; box-sizing: border-box; font: inherit; font-size: 13px; color: var(--ink); padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; }
.filter-row { display: grid; grid-template-columns: 130px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.filter-row:first-of-type { border-top: none; }
.filter-attr { font-size: 13px; font-weight: 600; padding-top: 5px; }
.filter-row .count { color: var(--muted); font-size: 12px; }
@media (max-width: 640px) { .filter-row { grid-template-columns: 1fr; } }

/* ---------- Heat map legend ---------- */
.heat-legend { display: flex; flex-direction: column; gap: 2px; margin: 4px 0 6px; }
.heat-ramp { display: block; width: 100%; max-width: 200px; height: 10px; border-radius: 3px; border: 1px solid var(--line); }
.swatch-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; margin: 0 3px; }
.ramp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.ramp-row .heat-ramp { width: 160px; }
.ramp-inputs { display: inline-flex; gap: 3px; }
.ramp-inputs input[type="color"] { width: 34px; height: 26px; padding: 0 2px; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.color-choice { display: flex; align-items: center; gap: 10px; }
.color-choice input[type="color"] { width: 56px; height: 30px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.color-choice input[type="color"]:disabled { opacity: 0.4; }

/* ---------- Legend: style button ---------- */
.icon-btn { flex: none; display: inline-flex; padding: 3px; border: none; border-radius: 5px; background: none; color: var(--muted); cursor: pointer; opacity: 0.55; }
.icon-btn:hover, .icon-btn:focus-visible { opacity: 1; background: #eef3fa; color: var(--accent); }
.legend .group.editing .icon-btn { opacity: 1; background: var(--accent); color: #fff; }
.icon-btn svg, .inline-icon { width: 16px; height: 16px; fill: currentColor; }
.inline-icon { vertical-align: -3px; }
.project-note { background: #f3f7fc; border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 4px; }

/* ---------- Settings → Projects ---------- */
.project-card { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; }
.project-card.current { border-color: var(--accent); }
.project-card > summary { display: flex; align-items: center; gap: 10px; padding: 9px 12px; list-style: none; }
.project-card > summary::-webkit-details-marker { display: none; }
.project-card > summary::before { content: "▸"; color: var(--muted); font-size: 11px; transition: transform 0.15s; }
.project-card[open] > summary::before { transform: rotate(90deg); }
.project-card summary .meta { flex: 1; }
.project-name { font-weight: 600; }
.project-desc { margin: 0 12px 8px; color: var(--muted); font-size: 13px; }
.layer-rows { list-style: none; margin: 0; padding: 0 12px 8px; }
.layer-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; padding: 5px 0; border-top: 1px solid var(--line); font-size: 13px; }
.layer-row .meta { font-variant-numeric: tabular-nums; }
.layer-row.missing .name { color: var(--muted); }
.layer-row .form-error { flex-basis: 100%; margin: 4px 0 0; font-size: 12px; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; margin-left: 4px; white-space: nowrap; }
.badge-current { background: #e7f0fb; color: var(--accent); }
.btn.small { padding: 3px 10px; font-size: 12px; }

/* ---------- Layer style editor: a panel docked to the right ---------- */
dialog.drawer {
  position: fixed; inset: 0 0 0 auto; z-index: 5;
  width: min(420px, 100vw); height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: none; border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(30, 58, 95, 0.18);
  background: #fff; color: var(--ink); font-size: 14px; line-height: 1.45;
}
dialog.drawer[open] { display: flex; }
#style-form { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.drawer-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 12px 0 20px; }
.drawer-head > div { flex: 1; min-width: 0; }
.eyebrow { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.drawer-head h1 { margin: 2px 0 0; font-size: 18px; line-height: 1.3; color: var(--accent); }
.close-btn { font-size: 24px; line-height: 1; border: none; background: none; color: var(--muted); cursor: pointer; padding: 2px 8px; border-radius: 6px; }
.close-btn:hover { background: #f1f3f5; }
dialog.drawer .tabs { padding: 0 16px; margin: 10px 0 0; flex-wrap: nowrap; }
.tab-count { display: inline-block; min-width: 16px; margin-left: 5px; padding: 0 4px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; line-height: 16px; text-align: center; }
.tab-count[hidden] { display: none; }
.drawer-body { flex: 1; overflow-y: auto; padding: 2px 20px 20px; }
.drawer-foot { border-top: 1px solid var(--line); padding: 10px 20px 12px; }
.drawer-foot .actions { margin: 0; align-items: center; }
.drawer-foot #style-msg { margin: 0 0 8px; }
.drawer-foot .hint { margin-top: 6px; }
.dirty-note { font-size: 12px; color: var(--assumption-ink); }
.dirty-note[hidden] { display: none; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.drawer .field > input[type="text"], .drawer .field > input[type="number"], .drawer .field > select { width: 100%; box-sizing: border-box; }
.drawer .cat-table { margin-top: 12px; }
.drawer .cat-table th { padding: 2px 3px; }
.drawer .cat-table td { padding: 3px 3px; }
.drawer .cat-table input[type="color"] { width: 36px; }
.cat-table .num { text-align: right; }
.cat-table td.num { padding-right: 8px; }
.cat-table .center { text-align: center; }
.other-row td:nth-child(4) { color: var(--muted); font-size: 13px; padding-left: 8px; }

.segmented { display: inline-flex; align-self: flex-start; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.segmented label { cursor: pointer; }
.segmented label + label { border-left: 1px solid var(--line); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 5px 14px; font-size: 13px; color: var(--ink); }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.sub-section { border-top: 1px solid var(--line); margin-top: 18px; }
.switch-row { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; cursor: pointer; }
.switch-row input { margin-top: 3px; }
.switch-row .hint { display: block; margin: 0; }

.filter-group { border-top: 1px solid var(--line); }
.filter-group:last-child { border-bottom: 1px solid var(--line); }
.filter-group > summary { display: flex; align-items: baseline; gap: 8px; padding: 9px 0; cursor: pointer; font-weight: 600; font-size: 13px; }
.filter-group > summary > span:first-child { flex: 1; }
.filter-group > summary .meta { font-weight: 400; }
.value-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.value-list .inline { margin: 3px 0; align-items: flex-start; color: var(--ink); }
.value-list .inline input { margin-top: 2px; }
.value-list .count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.mini-actions { font-size: 12px; margin: 4px 0 10px; color: var(--muted); }
.popup-tags { margin-top: 14px; }

@media (max-width: 640px) {
  dialog.drawer { inset: auto 0 0 0; width: 100%; height: 70vh; border-left: none; border-top: 1px solid var(--line); border-radius: 12px 12px 0 0; }
  .value-list { grid-template-columns: 1fr; }
}
