:root {
  --bg: #ffffff;
  --fg: #1d2733;
  --muted: #5f6b7a;
  --border: #d9dee5;
  --panel: rgba(255, 255, 255, 0.95);
  --accent: #1864ab;
  --live: #2f9e44;
  --warn: #e8590c;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  z-index: 2;
}

.topbar h1 { font-size: 1.05rem; margin: 0; }

.topbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 0.9rem; }
.legend-btns { display: flex; gap: 6px; }

.count { color: var(--muted); font-variant-numeric: tabular-nums; }

.status { display: inline-flex; align-items: center; gap: 6px; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status[data-state="live"] .dot { background: var(--live); box-shadow: 0 0 0 3px rgba(47, 158, 68, 0.2); }
.status[data-state="offline"] .dot { background: var(--warn); }

.lang select {
  font: inherit;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

#map { position: relative; min-height: 0; }

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  padding: 10px 12px;
  font-size: 0.85rem;
  z-index: 3; /* above MapLibre's controls (z-index 2) */
  max-height: calc(100% - 140px);
  overflow-y: auto;
}
.panel h2 { font-size: 0.9rem; margin: 0 0 6px; }

.legend { top: 64px; right: 12px; max-width: 240px; }
.legend h2 { margin-right: 24px; }

.legend-btn {
  font: inherit;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
}
.legend-btn[aria-expanded="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.legend ul { list-style: none; margin: 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.legend #legend-list:empty + .legend-shapes { border-top: 0; margin-top: 0 !important; padding-top: 0 !important; }
.legend-shapes { border-top: 1px solid var(--border); margin-top: 6px !important; padding-top: 6px !important; }
.shape { width: 14px; height: 14px; flex: none; display: inline-block; background: var(--muted); }
.shape.arrow { clip-path: polygon(50% 0, 100% 100%, 50% 75%, 0 100%); }
.shape.circle { border-radius: 50%; width: 9px; height: 9px; margin: 0 2.5px; }
.shape.vector { height: 3px; border-radius: 2px; }
.shape.big { clip-path: polygon(50% 0, 100% 100%, 50% 75%, 0 100%); width: 18px; height: 18px; margin-left: -2px; }

.info { left: 12px; bottom: 44px; width: 280px; }
.info h2 { font-size: 1rem; margin-right: 24px; }
.info-type { margin: 0 0 8px; color: var(--muted); }
.info-note {
  margin: 0 0 8px;
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 600;
}
.info-note.warn { background: #fff4e6; color: #7a3b00; }
.info-note.danger { background: #fff5f5; color: #a51111; border-left: 3px solid #e03131; }
.info-note.patrol { background: #edf2ff; color: #273d9c; border-left: 3px solid #3b5bdb; }
.shape.patrol { background: rgba(59, 91, 219, 0.12); border: 2.5px solid #3b5bdb; border-radius: 50%; width: 10px; height: 10px; }
.shape.mpz { background: rgba(224, 49, 49, 0.35); border: 2px solid #e03131; border-radius: 2px; width: 14px; height: 10px; }
.shape.lane { background: rgba(217, 72, 15, 0.15); border-top: 2px solid #d9480f; border-radius: 2px; width: 14px; height: 8px; }
.shape.route { background: rgba(112, 72, 232, 0.15); border-top: 2px solid #7048e8; border-radius: 2px; width: 14px; height: 8px; }
/* Dashed lines: drawn with a gradient so the dashes show at this small size. */
.shape.predicted, .shape.track { position: relative; width: 18px; height: 3px; flex: none; }
.shape.predicted { background: repeating-linear-gradient(90deg, #7048e8 0 4px, transparent 4px 7px); }
.shape.track { background: repeating-linear-gradient(90deg, #1864ab 0 4px, transparent 4px 7px); }
.shape.predicted i { position: absolute; right: -2px; top: -3px; width: 5px; height: 5px; background: #fff; border: 2px solid #7048e8; border-radius: 50%; }
.info-note.route { background: #f3f0ff; color: #4c2a9e; border-left: 3px solid #7048e8; font-weight: 500; }
.map-styles { border: 0; margin: 0; padding: 0; display: grid; gap: 4px; }
.map-styles legend { padding: 0; margin-bottom: 4px; color: var(--muted); }
.shape.seamark { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(#ffd43b 50%, #212529 50%); flex: none; }
.legend .toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.legend .toggle input { margin: 0; }
.shape.area { background: rgba(224, 49, 49, 0.06); border: 1.5px dashed #e03131; border-radius: 2px; width: 14px; height: 10px; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-variant-numeric: tabular-nums; }
.info-track { margin: 8px 0 0; color: var(--muted); font-size: 0.78rem; }
.close {
  position: absolute; top: 6px; right: 8px;
  border: 0; background: none; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--muted);
}

.disclaimer {
  padding: 6px 16px;
  font-size: 0.8rem;
  text-align: center;
  background: #fff4e6;
  color: #7a3b00;
  border-top: 1px solid #ffd8a8;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

@media (max-width: 640px) {
  .legend { right: 8px; max-height: 55%; }
  .info { left: 8px; right: 8px; width: auto; bottom: 40px; max-height: 45%; }
  .topbar h1 { font-size: 0.95rem; }
}
