:root {
  --bg: #ffffff;
  --bg2: #f4f6f8;
  --fg: #0f172a;
  --fg2: #475569;
  --line: #dde3ea;
  --accent: #0f766e;
  --good: #16a34a;
  --dir: #eab308;
  --off: #94a3b8;
  --excl: #dc2626;
  --unk: #3b82f6;
  --warn-fg: #b45309;
  --shadow: 0 6px 24px rgba(15, 23, 42, .18);
  --side-w: 340px;
  --detail-w: 400px;
  --top-h: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111827;
    --bg2: #1f2937;
    --fg: #e5e7eb;
    --fg2: #9ca3af;
    --line: #374151;
    --accent: #2dd4bf;
    --warn-fg: #fbbf24;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #111827;
    --bg2: #1f2937;
    --fg: #e5e7eb;
    --fg2: #9ca3af;
    --line: #374151;
    --accent: #2dd4bf;
    --warn-fg: #fbbf24;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  background: var(--bg); color: var(--fg);
  overflow: hidden;
}
a { color: var(--accent); }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg2); margin: 18px 0 6px; }
.hint { color: var(--fg2); font-size: 12px; margin: 6px 0; }
.warn { color: var(--warn-fg); }
#basemaps { grid-template-columns: 1fr; }
#basemaps label.unavail { opacity: .55; }
.danger { margin: 8px 0; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 600;
  color: #7f1d1d; background: #fee2e2; border: 1px solid #fca5a5; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top-h); z-index: 1001;
  display: flex; align-items: center; gap: 8px; padding: 0 8px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; line-height: 1.1; margin-right: 6px; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.brand-sub { font-size: 11px; color: var(--fg2); }
.wind-summary { flex: 1; min-width: 0; font-size: 13px; color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wind-summary b { color: var(--fg); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--fg); font-size: 18px; cursor: pointer; flex: none;
}
.icon-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- layout ---------- */
.layout { position: fixed; inset: var(--top-h) 0 0 0; }
.map { position: absolute; inset: 0; background: #dfe7ee; z-index: 0; }
.panel {
  position: absolute; z-index: 1000; background: var(--bg); color: var(--fg);
  overflow-y: auto; overscroll-behavior: contain;
}
.side { top: 0; bottom: 0; left: 0; width: var(--side-w); border-right: 1px solid var(--line); padding: 0 14px 24px; }
.side.closed { display: none; }
body.side-open .map { left: var(--side-w); }
.detail { top: 0; bottom: 0; right: 0; width: var(--detail-w); border-left: 1px solid var(--line); padding: 10px 16px 24px; box-shadow: var(--shadow); }
.close {
  position: sticky; top: 0; float: right; margin: 0 -6px 0 6px; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg2); color: var(--fg); font-size: 20px; line-height: 1; cursor: pointer; z-index: 2;
}

@media (max-width: 760px) {
  .brand-sub { display: none; }
  .side { width: 100%; box-shadow: var(--shadow); z-index: 1002; }
  body.side-open .map { left: 0; }
  .detail { left: 0; width: 100%; top: auto; max-height: 62%; border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; }
}

/* ---------- tabs & controls ---------- */
.tabs { position: sticky; top: 0; z-index: 3; display: flex; gap: 2px; background: var(--bg); padding: 10px 0 8px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 7px 2px; border: 0; border-radius: 6px; background: transparent; color: var(--fg2); font-weight: 600; font-size: 13px; cursor: pointer; }
.tabs button.active { background: var(--bg2); color: var(--fg); }
.tab-body { display: none; }
.tab-body.active { display: block; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 8px 0 10px; }
.seg button { flex: 1; padding: 8px; border: 0; background: var(--bg2); color: var(--fg2); cursor: pointer; font-weight: 600; }
.seg button.active { background: var(--accent); color: #fff; }
/* white on the light dark-mode accent is hard to read outdoors: use the deeper teal behind white text */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg button.active, :root:not([data-theme="light"]) .icon-btn.on { background: #0f766e; border-color: #0f766e; } }
:root[data-theme="dark"] .seg button.active, :root[data-theme="dark"] .icon-btn.on { background: #0f766e; border-color: #0f766e; }
label.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; }
label.row select { max-width: 60%; }
label.check { display: flex; gap: 8px; align-items: flex-start; margin: 7px 0; font-size: 13px; cursor: pointer; }
label.check input { margin-top: 2px; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 4px 0 0; }
select { padding: 5px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg2); color: var(--fg); }
output { font-variant-numeric: tabular-nums; font-weight: 600; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 6px 0; cursor: pointer; font-size: 13px; text-decoration: underline; }
.mini { border: 1px solid var(--line); background: var(--bg2); color: var(--fg); border-radius: 6px; width: 30px; height: 28px; cursor: pointer; }
.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.cats label.check { margin: 4px 0; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 2px; border: 1px solid rgba(0,0,0,.25); }

.days { display: flex; gap: 4px; overflow-x: auto; padding: 8px 0 4px; scrollbar-width: thin; }
.days button {
  flex: none; min-width: 58px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg2);
  color: var(--fg); cursor: pointer; font-size: 12px; line-height: 1.2; text-align: center;
}
.days button.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.days button .cnt { display: block; font-size: 11px; color: var(--good); font-weight: 700; }
.days button .cnt.zero { color: var(--fg2); font-weight: 400; }
.hour-row { display: flex; align-items: center; gap: 6px; }
.hour-row input { flex: 1; }
.hour-row output { width: 44px; text-align: right; }
.hour-strip { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin: 2px 94px 0 44px; }
.hour-strip i { flex: 1; background: var(--line); }
.hour-strip i.g1 { background: #86efac; } .hour-strip i.g2 { background: #22c55e; } .hour-strip i.g3 { background: #15803d; }
.hour-strip i.night { background: #334155; opacity: .35; }
.fc-status { font-size: 12px; color: var(--fg2); margin-top: 6px; }
.compass-wrap { display: flex; justify-content: center; margin: 4px 0; }
#compass { width: 180px; height: 180px; cursor: crosshair; touch-action: none; user-select: none; }

/* ---------- legend & toast ---------- */
.legend {
  position: fixed; z-index: 999; left: 12px; bottom: 18px;
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; padding: 5px 10px; border-radius: 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); box-shadow: var(--shadow); font-size: 12px; max-width: calc(100% - 24px);
}
body.side-open .legend { left: calc(var(--side-w) + 12px); }
@media (max-width: 1200px) { body.panel-open .legend { display: none; } }
@media (max-width: 760px) {
  body.side-open .legend, body.panel-open .legend { display: none; }
  .legend { left: 8px; right: 8px; bottom: 8px; gap: 8px; font-size: 11px; justify-content: center; }
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.dot.good { background: var(--good); } .dot.dir { background: var(--dir); } .dot.off { background: var(--off); }
.dot.excl { background: transparent; border: 2px solid var(--excl); }
.dot.warn { background: transparent; border: 2px solid #a21caf; }
.dot.unk { background: var(--unk); }
.toast { position: fixed; z-index: 1100; left: 50%; top: calc(var(--top-h) + 10px); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); max-width: 90vw; }
@media (min-width: 761px) { /* centred over the map, not over the right-hand panel */
  body.panel-open .toast { left: calc((100% - var(--detail-w)) / 2); max-width: calc(100vw - var(--detail-w) - 24px); }
  body.panel-open.side-open .toast { left: calc((100% + var(--side-w) - var(--detail-w)) / 2); max-width: calc(100vw - var(--side-w) - var(--detail-w) - 24px); }
}

/* ---------- detail panel ---------- */
.d-title { font-size: 18px; font-weight: 700; margin: 4px 0 0; padding-right: 30px; }
.d-sub { color: var(--fg2); font-size: 12px; margin-bottom: 8px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 10px; font-size: 12px; font-weight: 700; color: #fff; margin: 2px 4px 2px 0; }
.badge.good { background: var(--good); } .badge.dir { background: #ca8a04; } .badge.off { background: #64748b; }
.badge.excl { background: var(--excl); } .badge.unk { background: var(--unk); }
.reasons { font-size: 12px; color: var(--fg2); margin: 4px 0 6px; }
.reasons li { margin: 2px 0; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.stat { background: var(--bg2); border-radius: 8px; padding: 6px 8px; }
.stat .k { font-size: 11px; color: var(--fg2); }
.stat .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 11px; font-weight: 400; color: var(--fg2); }
.row-flex { display: flex; gap: 12px; align-items: center; }
.rose { width: 120px; height: 120px; flex: none; }
.profile { width: 100%; height: auto; display: block; background: var(--bg2); border-radius: 8px; }
.links { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.links .nav { display: contents; }
.links a, .links button {
  font-size: 12px; padding: 5px 9px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg2); color: var(--fg);
  text-decoration: none; cursor: pointer;
}
table.asp { width: 100%; border-collapse: collapse; font-size: 12px; }
table.asp td, table.asp th { padding: 3px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.asp tr.conf td:first-child { color: var(--excl); font-weight: 700; }

.fc-table { border-collapse: separate; border-spacing: 1px; font-size: 11px; width: 100%; table-layout: fixed; }
.fc-table th { font-weight: 600; color: var(--fg2); font-size: 10px; padding: 1px; text-align: center; }
.fc-table th.day { text-align: left; width: 44px; white-space: nowrap; }
.fc-table td { text-align: center; padding: 1px 0; border-radius: 3px; background: var(--bg2); line-height: 1.05; cursor: pointer; }
.fc-table td.good { background: #16a34a; color: #fff; }
.fc-table td.dir { background: #fde68a; color: #713f12; }
.fc-table td.off { background: var(--bg2); color: var(--fg2); }
.fc-table td.night { opacity: .45; }
.fc-table td.sel { outline: 2px solid var(--fg); }
.fc-table td .ar { display: inline-block; font-size: 10px; }
.fc-wrap { overflow-x: auto; }

.list-item { display: flex; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.list-item:hover { background: var(--bg2); }
.list-item .nm { font-weight: 600; }
.list-item .meta { font-size: 12px; color: var(--fg2); }
.list-item .q { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

dialog { max-width: 560px; border: 0; border-radius: 12px; box-shadow: var(--shadow); background: var(--bg); color: var(--fg); padding: 18px 22px; }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog h2 { margin-top: 0; }

/* ---------- leaflet tweaks ---------- */
.leaflet-container { font: inherit; }
.sites-canvas { pointer-events: none; }
.leaflet-tooltip.site-tip { font-size: 12px; padding: 4px 8px; }
.known-icon { font-size: 20px; line-height: 24px; text-align: center; filter: drop-shadow(0 1px 1px rgba(0,0,0,.5)); }
.car-icon { font-size: 14px; line-height: 20px; text-align: center; background: #fff; border: 2px solid #1d4ed8; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.45); }
.known-icon.popular { font-size: 24px; filter: drop-shadow(0 0 3px #fff) drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.as-popup b { font-size: 13px; }
.as-popup .lim { color: var(--fg2); }
.leaflet-popup-content { margin: 10px 12px; }

.cat-row { margin-top: 6px; }
.cat-row > span { font-size: 12px; }
.cat-row select { flex: none; font-size: 12px; }
input[type=text], input[type=password] { padding: 5px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg2); color: var(--fg); }

/* windguru-like multi model table */
.wg-days { display: flex; gap: 4px; overflow-x: auto; margin: 6px 0; }
.wg-days button { flex: none; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg2); color: var(--fg); font-size: 12px; cursor: pointer; }
.wg-days button.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.wg-days button .n { color: var(--good); font-weight: 700; margin-left: 3px; }
.wg { border-collapse: collapse; font-size: 11px; width: 100%; table-layout: fixed; }
.wg th, .wg td { text-align: center; padding: 2px 0; border: 1px solid var(--bg); }
.wg th.lbl, .wg td.lbl { text-align: left; width: 62px; padding-left: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--fg2); font-weight: 600; background: var(--bg); }
.wg tr.model td.lbl { color: var(--fg); font-weight: 700; padding-top: 6px; }
.wg tr.model td { border-top: 2px solid var(--line); }
.wg td.fly { font-weight: 700; color: #fff; }
.wg td.fly.good { background: #16a34a; }
.wg td.fly.dir { background: #fde68a; color: #713f12; }
.wg td.fly.off { background: transparent; color: var(--fg2); font-weight: 400; }
.wg tr.cons td.fly { height: 18px; }
.wg td.dark { color: #fff; }
.wg td.night { opacity: .5; }
.wg td.selc { outline: 2px solid var(--fg); outline-offset: -2px; }
.wg .ar { display: inline-block; }

.d-head { display: flex; align-items: flex-start; gap: 6px; padding-right: 30px; }
.d-head .d-title { padding-right: 0; flex: 1; }
.fav-btn { border: 1px solid var(--line); background: var(--bg2); color: #ca8a04; border-radius: 8px; font-size: 18px; width: 32px; height: 32px; cursor: pointer; flex: none; margin-top: 2px; }
.as-popup .as-item + .as-item { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.as-popup pre { white-space: pre-wrap; font-size: 11px; max-height: 160px; overflow: auto; margin: 4px 0; }
.wg td.wc { color: #0f172a; }
.wg td.fly.dir { color: #713f12; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg); color: var(--fg); }
.as-popup .as-item + .as-item { border-color: var(--line); }
@media (max-width: 760px) { .wg th.lbl, .wg td.lbl { width: 54px; } }
.known-box { margin: 10px 0; padding: 2px 10px 8px; border-radius: 8px; background: var(--bg2); border-left: 3px solid var(--accent); font-size: 13px; line-height: 1.45; }
.known-box h3 { margin: 8px 0 4px; color: var(--fg); }
.known-box small { color: var(--fg2); }
.known-box a { color: var(--accent); }
