:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #ec2f7b; /* Horizon pink */
  --accent-soft: rgba(236, 47, 123, 0.15);
  --warn: #f5a524;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 10px;
  font-family: 'Satoshi', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 1000; }
.brand { font-weight: 500; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand b { font-weight: 700; }
.brand .logo { height: 30px; width: auto; display: block; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
.tab { background: none; border: 1px solid transparent; padding: 6px 12px; border-radius: 999px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.tab.soon { opacity: 0.45; cursor: not-allowed; }
.tab.soon::after { content: ' · next'; font-size: 11px; }
.actions { display: flex; gap: 6px; }
.ghost { background: var(--panel-2); border: 1px solid var(--line); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.ghost:hover { border-color: var(--accent); }
.filebtn { display: inline-flex; align-items: center; }
.only-narrow { display: none; }

.layout { display: grid; grid-template-columns: 380px 1fr; height: calc(100vh - 51px); }
.sidebar { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); padding: 10px 12px 40px; }
.workspace { display: flex; flex-direction: column; min-width: 0; overflow-y: auto; }
.map { height: 62vh; min-height: 380px; flex-shrink: 0; }
.below { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; padding: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.results { grid-column: 1 / -1; overflow-x: auto; }
.notes { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.notes b { color: var(--text); }

.sec { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: var(--panel-2); }
.sec > summary { cursor: pointer; padding: 9px 12px; font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.sec .body { padding: 4px 12px 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
.row.one { grid-template-columns: 1fr; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.f input, label.f select { background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; color: var(--text); width: 100%; }
label.f input:focus, label.f select:focus { outline: none; border-color: var(--accent); }
label.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-top: 6px; }
.small { font-size: 11.5px; color: var(--muted); }
.pill { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.btn { background: var(--accent); border: none; color: white; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.alt { background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.btn.placing { background: var(--warn); color: #111; }
.pos { border-left: 4px solid var(--c); }
.pos .head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.pos .swatch { width: 12px; height: 12px; border-radius: 50%; background: var(--c); display: inline-block; }
.wind-compass { width: 64px; height: 64px; }

table.res { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.res th, table.res td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.res th:first-child, table.res td:first-child { text-align: left; color: var(--muted); }
table.res thead th { color: var(--text); font-weight: 700; }
table.res tr.hl td { color: var(--text); font-weight: 700; }
table.res tr.group td { color: var(--accent); font-weight: 700; padding-top: 10px; text-align: left; }
.warnbox { border: 1px solid var(--warn); background: rgba(245, 165, 36, 0.1); color: #ffd58a; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; margin-top: 8px; }

.leaflet-container { background-color: #0b0d10; font-family: inherit;
  background-image: linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 40px 40px; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 9px 14px; border-radius: 10px; z-index: 2000; font-size: 13px; max-width: 90vw; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.map-note { background: rgba(23,26,33,0.92); color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; font-size: 11.5px; max-width: 260px; }
.wind-ctl { background: rgba(23, 26, 33, 0.9); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; text-align: center; font-size: 12px; }
.legend { background: rgba(23, 26, 33, 0.9); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 11.5px; line-height: 1.6; }
.legend:not(:has(.lg-hazards > div, .lg-plan > div)) { display: none; }
.legend .lg-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 2px solid; margin: 0 10px 0 4px; vertical-align: middle; box-sizing: border-box; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 6px; }
.legend .lg-box { display: inline-block; width: 14px; height: 9px; border: 2px solid; margin: 0 6px 0 2px; vertical-align: middle; box-sizing: border-box; }

/* ---------------------------------------------------------------- place search */
label.f:has(#place-search) { position: relative; }
.place-results { position: absolute; top: 100%; left: 0; right: 0; z-index: 1200; margin-top: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.45); overflow: hidden; }
.place-results > div[data-i] { padding: 6px 9px; cursor: pointer; color: var(--text); font-size: 12.5px; line-height: 1.3; }
.place-results > div[data-i] span { display: block; color: var(--muted); font-size: 11px; }
.place-results > div.on, .place-results > div[data-i]:hover { background: var(--accent-soft); }
.place-results .place-none, .place-results .place-attr { padding: 6px 9px; color: var(--muted); font-size: 11px; }
.place-results .place-attr { border-top: 1px solid var(--line); font-size: 10px; }

/* ---------------------------------------------------------------- saved shows */
.show-status { font-size: 12px; color: var(--text); white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; align-self: center; margin-right: 4px; }
.show-status .muted, .shows-page .muted { color: var(--muted); }
.unsaved { color: var(--warn); }
.shows-page { max-width: 1200px; margin: 0 auto; padding: 18px 20px 40px; }
body.on-shows .layout { display: none; }
body.on-shows .shows-page { display: block; }
.shows-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0 6px; }
.shows-tools .shows-search { flex: 1; min-width: 220px; margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel); border: none; border-right: 1px solid var(--line); color: var(--muted); padding: 6px 12px; cursor: pointer; font: inherit; font-size: 12.5px; }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent-soft); color: var(--text); }
.shows-list th button.sort { background: none; border: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; padding: 0; }
.shows-list th button.sort.on, .shows-list th button.sort:hover { color: var(--text); }
.shows-in { padding: 0; }
.shows-head { display: flex; justify-content: space-between; align-items: center; }
.shows-head h2 { margin: 0; font-size: 20px; }
.shows-login { display: flex; flex-direction: column; gap: 10px; max-width: 320px; }
.shows-cur { margin: 10px 0 8px; }
.shows-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.shows-search { width: 100%; box-sizing: border-box; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; color: var(--text); margin: 8px 0; }
.shows-list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 10px; }
.shows-list tr[data-open] { cursor: pointer; }
.shows-list tr[data-open]:hover td { background: var(--panel-2); }
.shows-list tr.grp td { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 10px; border-bottom: none; }
.shows-list .nowrap { white-space: nowrap; }
.shows-list a { color: var(--accent); }
.shows-list table { width: 100%; border-collapse: collapse; font-size: 13px; }
.shows-list th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.shows-list td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.shows-list tr.cur td:first-child { color: var(--accent); font-weight: 600; }
.shows-btns { white-space: nowrap; text-align: right; }
.shows-btns .btn { margin-left: 4px; }
.btn.danger { border-color: #ef4444; color: #fca5a5; }
.shows-foot { margin-top: 10px; }
.shows-foot a { color: var(--muted); }

/* ---------------------------------------------------------------- site plan */
.sp-tools { background: rgba(23, 26, 33, 0.94); border: 1px solid var(--line); border-radius: 10px; padding: 4px; color: var(--text); font-size: 12.5px; width: 196px; }
.sp-tools button { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 1px solid transparent; color: var(--text); padding: 5px 7px; border-radius: 7px; cursor: pointer; text-align: left; font: inherit; }
.sp-tools button:hover { border-color: var(--line); background: var(--panel-2); }
.sp-tools .sp-head { font-weight: 600; }
.sp-tools .sp-tool.on { border-color: var(--accent); background: var(--accent-soft); }
.sp-status { border-top: 1px solid var(--line); margin-top: 4px; padding: 6px 6px 3px; color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.sp-status b { display: block; color: var(--text); font-size: 14px; margin-top: 3px; }
.sp-row { display: flex; gap: 4px; margin: 6px 0 3px; }
.sp-row button, .sp-edit .sp-row button { flex: 1; justify-content: center; text-align: center; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 4px 6px; border-radius: 7px; cursor: pointer; font-size: 12px; }
.sp-edit .sp-row button.danger { border-color: #ef4444; color: #fca5a5; }
.sp-ic { display: inline-flex; align-items: center; justify-content: center; width: 18px; font-weight: 700; }
.sp-ic-barrier { color: #a3e635; } .sp-ic-safety { color: #e879f9; } .sp-ic-firing { color: #ec2f7b; }
.sp-ic-distance { color: #fff; } .sp-ic-access { color: #38bdf8; } .sp-ic-note { color: #e8eaf0; }
.map.sp-drawing, .map.sp-drawing .leaflet-interactive { cursor: crosshair !important; }
.sp-popup .leaflet-popup-content-wrapper, .sp-popup .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.sp-popup .leaflet-popup-content { margin: 10px 12px; }
.sp-edit-h { font-weight: 600; margin-bottom: 6px; }
.sp-edit input, .sp-edit textarea { width: 100%; box-sizing: border-box; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; color: var(--text); font: inherit; }
.sp-edit .sp-m { margin-top: 5px; }
.sp-label-wrap { background: none; border: none; }
.sp-label { transform: translate(-50%, -50%); display: inline-block; white-space: nowrap; background: rgba(15, 17, 21, 0.78); color: #fff; border-radius: 5px; padding: 1px 6px; font-size: 11px; line-height: 1.35; text-align: center; pointer-events: none; }
.sp-label span { opacity: 0.8; font-size: 10px; }
.sp-label-barrier { border: 1px solid #a3e635; } .sp-label-safety { border: 1px solid #e879f9; } .sp-label-firing { border: 1px solid #ec2f7b; }
.sp-label-distance { border: 1px solid #fff; }
.sp-pin { position: relative; transform: translate(-7px, -7px); white-space: nowrap; cursor: pointer; }
.sp-pin i { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: #38bdf8; border: 2px solid #fff; box-sizing: border-box; vertical-align: middle; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.sp-pin span { margin-left: 4px; background: rgba(15, 17, 21, 0.78); color: #fff; border-radius: 5px; padding: 1px 6px; font-size: 11px; vertical-align: middle; }
.sp-note { transform: translate(-50%, -50%); display: inline-block; max-width: 220px; white-space: normal; width: max-content; background: rgba(255, 255, 255, 0.92); color: #111; border-radius: 5px; padding: 3px 7px; font-size: 11.5px; line-height: 1.35; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.sp-handle { background: #fff; border: 2px solid #111; border-radius: 50%; box-sizing: border-box; cursor: move; }
table.sp-list { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.sp-list td { padding: 4px 3px; border-top: 1px solid var(--line); vertical-align: top; }
table.sp-list td:last-child { text-align: right; width: 1%; }
table.sp-list a { color: var(--text); text-decoration: none; }
table.sp-list a:hover { color: var(--accent); }
.fp-icon { width: 22px; height: 22px; border-radius: 50%; border: 2px solid white; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #111; box-shadow: 0 0 0 2px rgba(0,0,0,0.4); }
.print-only { display: none; }
.ver { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 6px; letter-spacing: 0.02em; }
/* while preparing to print, give the map its printed shape: 190 mm fits A4 portrait
   (Safari ignores @page landscape) and landscape alike */
body.printing .map { width: 190mm; height: 150mm; min-height: 0; flex: none; }
body.printing.print-landscape .map { width: 277mm; height: 150mm; }

@media (max-width: 900px) {
  .show-status { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 51px 0 0 0; z-index: 900; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: none; }
  .only-narrow { display: inline-block; }
  .below { grid-template-columns: 1fr; }
  .tabs { display: none; }
  .map { height: 58vh; }
}

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: white; color: black; }
  .topbar, .sidebar, .sp-tools, .leaflet-popup, .sp-handle, .leaflet-control-zoom, .leaflet-control-layers, .leaflet-control-attribution, .map-note { display: none !important; }
  .layout { display: block; height: auto; }
  .layout, .workspace { overflow: visible; }
  .map { width: 190mm; height: 150mm; min-height: 0; break-inside: avoid; margin: 0 auto; }
  body.print-landscape .map { width: 277mm; height: 150mm; }
  .leaflet-tile { opacity: 1 !important; }
  .map .legend { display: none !important; }
  .print-legend { display: block !important; padding: 2mm 0 0; font-size: 9px; line-height: 1.6; color: black; }
  .print-legend .pl-row { display: flex; flex-wrap: wrap; gap: 1px 16px; justify-content: center; }
  .print-legend .pl-row:empty { display: none; }
  .print-legend .pl-row > div { white-space: nowrap; }
  /* white lines (trajectory, blind, distance, rings) would vanish on paper: draw them dark */
  .print-legend i[style*="#fff;"], .print-legend i[style$="#fff"], .print-legend i[style*="#ffffff"], .print-legend i[style*="255,255,255"] { border-color: #222 !important; }
  .print-legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 4px; }
  .print-legend .lg-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 2px solid; margin-right: 4px; vertical-align: middle; box-sizing: border-box; }
  .print-legend .lg-box { display: inline-block; width: 12px; height: 8px; border: 2px solid; margin-right: 4px; vertical-align: middle; box-sizing: border-box; }
  /* keep label and key colours (Safari drops backgrounds otherwise) */
  .map, .map *, .print-legend * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-only { display: block; padding: 0 0 4px; font-size: 10px; }
  .print-only h2 { margin: 0 0 2px; font-size: 14px; }
  .print-only p { margin: 0; }
  .below { display: block; padding: 3mm 0 0; }
  .card { border-color: #ccc; background: white; color: black; margin-bottom: 3mm; }
  /* results: compact and never split across pages */
  .results { break-inside: avoid; padding: 2mm 3mm; }
  /* Safari can ignore break-before inside the layout, so also break after the key
     (a plain block) and use the older page-break properties */
  body.print-landscape .results { break-before: page; page-break-before: always; }
  body.print-landscape #print-legend { break-after: page; page-break-after: always; }
  .results, .sideview, .notes { page-break-inside: avoid; }
  table.res { font-size: 9.5px; }
  table.res th, table.res td { border-color: #ddd; color: black !important; padding: 1.2px 4px; }
  .warnbox { break-inside: avoid; }
  .notes { color: #333; font-size: 9.5px; }
  .sideview { break-inside: avoid; break-before: page; }
  /* landscape: table and side view share page 2 */
  body.print-landscape .sideview { break-before: auto; }
  body.print-landscape .sideview svg { height: 50mm; }
  body.print-landscape .notes { font-size: 8px; line-height: 1.35; padding: 2mm 3mm; }
  body.print-landscape .card { margin-bottom: 2mm; }
  /* the 'table' / 'measured' source tag is for the screen only */
  table.res .pill { display: none; }
  .notes { break-inside: avoid; }
}
