/* ── Reset & custom properties ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f8f9fa;
  --bg-card:     #ffffff;
  --bg-card-2:   #f8f9fa;
  --text:        #1a1a1a;
  --text-muted:  #666666;
  --border:      #e0e0e0;
  --accent:      #212121;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.07);
  --shadow-md:   0 2px 8px rgba(0,0,0,.08);

  --c-normal:    #6b7280;
  --c-flirting:  #d97706;
  --c-red-flag:  #dc2626;
  --c-ok:        #16a34a;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

/* ── Navbar ────────────────────────────────────────────────────────────── */
#navbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  height: 44px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 4px rgba(0,0,0,.05);
  flex-shrink: 0;
  z-index: 1000;
}

#nav-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

#nav-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.count-badge {
  font-size: 14px;
  font-weight: 600;
  padding: 5px 16px;
  border-radius: 20px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.count-badge.flirting {
  background: rgba(217,119,6,.08);
  color: var(--c-flirting);
  border-color: rgba(217,119,6,.2);
}
.count-badge.red-flag {
  background: rgba(220,38,38,.08);
  color: var(--c-red-flag);
  border-color: rgba(220,38,38,.2);
}
.count-badge.total {
  background: var(--bg-card-2);
  color: var(--text-muted);
  border-color: var(--border);
}

#nav-status {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d1d5db;
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.ok    { background: var(--c-ok); }
.status-dot.error { background: var(--c-red-flag); }

#refresh-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: color .15s, border-color .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
}
#refresh-btn:hover { color: var(--text); border-color: #bbb; box-shadow: var(--shadow-md); }
#refresh-btn.spinning { animation: spin .8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Headline ──────────────────────────────────────────────────────────── */
#headline {
  padding: 14px 24px;
  font-size: 20px;
  line-height: 1.4;
  text-align: center;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  transition: background .4s, border-color .4s;
  color: var(--text-muted);
}

#headline strong { color: var(--text); font-weight: 700; }

#headline.has-red-flag  {
  background: rgba(220,38,38,.05);
  border-bottom-color: rgba(220,38,38,.2);
  color: #7f1d1d;
}
#headline.has-flirting  {
  background: rgba(217,119,6,.05);
  border-bottom-color: rgba(217,119,6,.2);
  color: #78350f;
}

/* ── Main layout ───────────────────────────────────────────────────────── */
#main {
  position: relative;
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

#map { flex: 1; z-index: 1; }

/* ── Floating map controls (top-right, clear of Leaflet zoom) ──────────── */
#map-controls {
  position: absolute;
  top: 10px;
  right: 310px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-end;
}

.ctrl-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s, background .15s, color .15s;
}
.ctrl-btn:hover:not(:disabled) {
  box-shadow: var(--shadow-md);
  border-color: #bbb;
}
.ctrl-btn:disabled { opacity: .4; cursor: default; }
.ctrl-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.ctrl-btn.hidden { display: none; }

/* ── Legend ────────────────────────────────────────────────────────────── */
#legend {
  position: absolute;
  bottom: 36px;
  left: 10px;
  z-index: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-weight: 500;
}
.legend-item:last-child { margin-bottom: 0; }

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-dot.normal   { background: var(--c-normal); }
.legend-dot.flirting { background: var(--c-flirting); }
.legend-dot.red-flag { background: var(--c-red-flag); }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  width: 300px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  z-index: 10;
}

/* Top half: station detail (always occupies 50%, shows placeholder when empty) */
#station-panel {
  flex: 1;
  min-height: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#sidebar-header.hidden { display: none; }

#sidebar-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.7;
  padding: 20px;
}
#sidebar-placeholder.hidden { display: none; }

#sidebar-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
}

#sidebar-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: background .15s, color .15s;
}
#sidebar-close:hover { background: var(--bg-card-2); color: var(--text); }

#sidebar-content {
  padding: 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
#sidebar-content.hidden { display: none; }

/* ── Scorecards ────────────────────────────────────────────────────────── */
#scorecards {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  min-height: 0;
  padding: 8px 0;
}

.scorecard {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.sc-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-bottom: 4px;
}
.scorecard.flirting .sc-label { color: var(--c-flirting); }
.scorecard.red-flag .sc-label { color: var(--c-red-flag); }
.scorecard.total    .sc-label { color: var(--text-muted); }

.sc-value {
  font-size: 60px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 5px;
}
.scorecard.flirting .sc-value { color: var(--c-flirting); }
.scorecard.red-flag .sc-value { color: var(--c-red-flag); }
.scorecard.total    .sc-value { color: var(--text); }

.sc-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

/* Station detail */
.stn-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 2px;
  line-height: 1.3;
  color: var(--text);
}
.stn-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 500;
}

.status-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
  border: 1px solid transparent;
}
.status-pill.normal   {
  background: rgba(107,114,128,.08);
  color: var(--c-normal);
  border-color: rgba(107,114,128,.2);
}
.status-pill.flirting {
  background: rgba(217,119,6,.08);
  color: var(--c-flirting);
  border-color: rgba(217,119,6,.2);
}
.status-pill.red_flag {
  background: rgba(220,38,38,.08);
  color: var(--c-red-flag);
  border-color: rgba(220,38,38,.2);
}
.status-pill.unknown  {
  background: var(--bg-card-2);
  color: var(--text-muted);
  border-color: var(--border);
}

.obs-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.obs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 14px;
}

.obs-cell {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
}
.obs-cell.wide { grid-column: span 2; }

.obs-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 3px;
  font-weight: 600;
}

.obs-val {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.obs-val.rh   { color: #2563eb; }
.obs-val.wind { color: #7c3aed; }
.obs-val.temp { color: #ea580c; }
.obs-val.si   { color: var(--c-flirting); }
.obs-val.fuel { color: #16a34a; }

.obs-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.stn-link {
  display: block;
  text-align: center;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  background: var(--bg-card);
  transition: background .15s, border-color .15s, color .15s;
  box-shadow: var(--shadow-sm);
}
.stn-link:hover {
  background: var(--bg-card-2);
  border-color: #bbb;
  color: var(--text);
}

/* ── POI cursor mode ───────────────────────────────────────────────────── */
body.poi-mode      { cursor: crosshair !important; }
body.poi-mode #map { cursor: crosshair !important; }

/* ── Error toast ───────────────────────────────────────────────────────── */
#error-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: #dc2626;
  color: #fff;
  padding: 7px 18px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  display: none;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}
#error-toast.visible { display: block; }

/* ── Leaflet overrides ─────────────────────────────────────────────────── */
.leaflet-container { background: #e8edf2; }

.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text)         !important;
  border-color: var(--border) !important;
  box-shadow: var(--shadow-sm) !important;
  font-weight: 600            !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-card-2) !important; }

.leaflet-control-attribution {
  background: rgba(255,255,255,.8) !important;
  color: var(--text-muted)         !important;
  font-size: 9px                   !important;
}
.leaflet-control-attribution a { color: #2563eb !important; }

/* Station tooltip */
.leaflet-tooltip.stn-tip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}
.leaflet-tooltip.stn-tip::before { display: none; }

/* Ring label */
.ring-label {
  background: rgba(255,255,255,.85);
  border: 1px solid var(--border) !important;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  color: #374151;
  box-shadow: none;
  pointer-events: none;
  white-space: nowrap;
}
.ring-label::before { display: none; }

/* ── Filter bar (now lives in navbar) ──────────────────────────────────── */
.filter-group {
  display: flex;
  align-items: center;
  gap: 7px;
}

.filter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

.filter-pills {
  display: flex;
  gap: 3px;
}

.filter-pill {
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
  line-height: 1.4;
}
.filter-pill:hover:not(.active) {
  background: var(--bg-card-2);
  color: var(--text);
  border-color: #bbb;
}
.filter-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Compact sizing when filters live in the navbar */
#nav-filters .filter-label { font-size: 10px; }
#nav-filters .filter-divider { height: 14px; }
#nav-filters .filter-pill {
  font-size: 11px;
  padding: 2px 9px;
}

/* ── Footer ────────────────────────────────────────────────────────────── */
#footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 34px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
  gap: 12px;
}

#footer span { flex: 1; }
#footer a { color: var(--text-muted); text-decoration: underline; text-underline-offset: 2px; }
#footer a:hover { color: var(--text); }

#about-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s;
  flex-shrink: 0;
}
#about-btn:hover { color: var(--text); }

/* ── About modal ───────────────────────────────────────────────────────── */
#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}
#modal-backdrop.hidden { display: none; }

#modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#modal-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

#modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: background .15s, color .15s;
}
#modal-close:hover { background: var(--bg-card-2); color: var(--text); }

#modal-body {
  padding: 18px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

#modal-body h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin: 16px 0 6px;
}
#modal-body h3:first-child { margin-top: 0; }

#modal-body p { margin-bottom: 8px; color: var(--text); }
#modal-body p:last-child { margin-bottom: 0; }

#modal-body a { color: #2563eb; text-underline-offset: 2px; }
#modal-body a:hover { text-decoration: none; }

#modal-body strong { font-weight: 600; }
#modal-body em { font-style: italic; }

.formula {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 6px 0 !important;
  color: var(--text);
}
