:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #dde1e6;
  --accent: #1f5fbf;
  --req: #d6336c;
  --ok: #2f9e44;
  --classb: #f08c00;
  --classa: #7048e8;
  --es: #0c8599;
  --err-bg: #fff4f4;
  --err: #b42318;
  --grid: #e6e9ee;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --panel: #181c21;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --border: #2a3038;
    --accent: #6ea8fe;
    --req: #f06595;
    --ok: #51cf66;
    --classb: #ffa94d;
    --classa: #9775fa;
    --es: #3bc9db;
    --err-bg: #2a1616;
    --err: #ff8787;
    --grid: #262c34;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --panel: #181c21; --text: #e7eaee; --muted: #9aa4b1; --border: #2a3038;
  --accent: #6ea8fe; --req: #f06595; --ok: #51cf66; --classb: #ffa94d; --classa: #9775fa; --es: #3bc9db;
  --err-bg: #2a1616; --err: #ff8787; --grid: #262c34;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  grid-template-columns: 460px 1fr;
  height: 100vh;
}
.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
h1 { font-size: 19px; margin: 0 0 4px; }
.sub { margin: 0; color: var(--muted); }
label { display: block; font-weight: 600; font-size: 12.5px; margin: 10px 0 4px; }
textarea, input, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--accent); font-size: 13px; }
button {
  margin-top: 14px;
  width: 100%;
  padding: 9px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
.errors {
  background: var(--err-bg);
  color: var(--err);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}
.summary {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.summary .big { font-size: 22px; font-weight: 700; }
.summary .big.req { color: var(--req); }
.summary .big.ok { color: var(--ok); }
.summary .bar { height: 8px; border-radius: 4px; background: var(--ok); overflow: hidden; display: flex; margin-top: 8px; }
.summary .bar span { display: block; height: 100%; }
.segments { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.segments li {
  border: 1px solid var(--border);
  border-left: 4px solid var(--ok);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}
.segments li.lvl-div { border-left-color: var(--req); }
.segments li.lvl-es { border-left-color: var(--es); }
.segments li:hover { background: var(--bg); }
.seg-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.seg-head .tag { font-size: 11.5px; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.tag.req { background: color-mix(in srgb, var(--req) 18%, transparent); color: var(--req); }
.tag.ok, .tag.lvl-none { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.tag.lvl-div { background: color-mix(in srgb, var(--req) 18%, transparent); color: var(--req); }
.tag.lvl-es { background: color-mix(in srgb, var(--es) 18%, transparent); color: var(--es); }
.seg-toggle { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-toggle button { margin: 0; border-radius: 0; background: transparent; color: var(--text); font-weight: 500; }
.seg-toggle button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
.cmp { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 12.5px; }
.cmp th { text-align: left; font-weight: 600; color: var(--muted); padding: 3px 4px; }
.cmp td { padding: 4px; border-top: 1px solid var(--border); vertical-align: top; }
.notes a { color: var(--accent); }
.seg-meta { color: var(--muted); font-size: 12.5px; }
.seg-why { font-size: 12.5px; margin-top: 4px; }
.notes { margin-top: auto; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.notes p { margin: 0 0 8px; }
.src { font-style: italic; }

.main { display: grid; grid-template-rows: 1fr 210px; min-width: 0; min-height: 0; }
#map { min-height: 0; }
.profile-wrap { background: var(--panel); border-top: 1px solid var(--border); padding: 8px 14px 6px; display: flex; flex-direction: column; min-height: 0; }
.profile-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; font-size: 12.5px; font-weight: 600; }
.legend { color: var(--muted); font-weight: 400; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.sw { display: inline-block; width: 12px; height: 10px; border-radius: 2px; margin-left: 8px; }
.sw.req { background: var(--req); }
.sw.ok { background: var(--ok); }
.sw.bandb { background: color-mix(in srgb, var(--classb) 35%, transparent); }
.sw.es { background: var(--es); }
.sw.bandx { background: color-mix(in srgb, var(--es) 30%, transparent); }
#profile { flex: 1; width: 100%; min-height: 0; }
#profile text { fill: var(--muted); font-size: 11px; }
.leaflet-container { background: var(--bg); font: inherit; }
.leaflet-control-layers label { display: flex; align-items: center; gap: 6px; margin: 2px 0; font-weight: 400; font-size: 13px; }
.leaflet-control-layers input[type="checkbox"] { width: auto; margin: 0; padding: 0; }
.leaflet-control-layers-expanded { color: #1b1f24; }
.leaflet-popup-content { font-size: 13px; }

@media (max-width: 820px) {
  body { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--border); padding: 16px; }
  .main { grid-template-rows: 60vh 200px; }
}

.toggle-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; font-size: 12.5px; font-weight: 600; margin-top: -6px; }
.toggle-row .seg-toggle button { padding: 6px; font-size: 13px; }
button.linkish { width: auto; margin: 0; padding: 1px 7px; font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
button.linkish:hover { filter: brightness(0.95); }
.panel > * { flex-shrink: 0; }

/* Muted grey basemap: desaturate OSM tiles (inverted to dark grey in dark mode) */
.leaflet-tile-pane { filter: grayscale(1) contrast(0.85) brightness(1.08); opacity: 0.85; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: grayscale(1) invert(1) contrast(0.8) brightness(0.9); opacity: 0.9; }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: grayscale(1) invert(1) contrast(0.8) brightness(0.9); opacity: 0.9; }

#profile { cursor: crosshair; touch-action: pan-y; }
.hover-tip { font-size: 12px; line-height: 1.35; padding: 4px 7px; }

/* map click popup: airspace stack */
.pop { font-size: 12.5px; line-height: 1.4; color: #1b1f24; }
.phead { font-weight: 700; font-size: 13.5px; }
.pcoord { color: #5d6673; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; margin-bottom: 6px; }
.pstack { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.prow { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; padding-top: 6px; border-top: 1px solid #e6e9ee; }
.pcls { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 5px; font-weight: 700; color: #fff; background: #868e96; }
.pcls.cls-A { background: #7048e8; } .pcls.cls-B { background: #e8590c; } .pcls.cls-C { background: #1971c2; }
.pcls.cls-D { background: #0c8599; } .pcls.cls-E { background: #868e96; }
.pname { font-weight: 600; }
.pmeta { color: #495057; }
.pref { color: #868e96; font-size: 11px; }
.pchips { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 0 1px; }
.pchip { font-size: 11px; padding: 1px 6px; border-radius: 9px; }
.pchip.req { background: #ffe3ec; color: #c2255c; }
.pchip.es { background: #e3fafc; color: #0b7285; }
.pnone { margin: 4px 0; }
.pfoot { color: #868e96; font-size: 11px; margin: 8px 0 0; }
