:root {
  --blue: #0b5cab;
  --blue-soft: #e8f2ff;
  --green: #138a52;
  --green-soft: #e7f8ef;
  --red: #c62637;
  --red-soft: #fdecee;
  --amber: #a15d13;
  --ink: #12304a;
  --muted: #5f7385;
  --line: #d9e3ec;
  --panel: #ffffff;
  --bg: #f4f8fb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --blue: #5aa2ec;
    --blue-soft: #16304b;
    --green: #4cc98a;
    --green-soft: #12352a;
    --red: #ff7a86;
    --red-soft: #3f1d22;
    --amber: #e0a35a;
    --ink: #e4edf5;
    --muted: #9db0c1;
    --line: #2a3b4b;
    --panel: #15212d;
    --bg: #0d1620;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  color: #fff; background: var(--blue); border-radius: 11px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-block;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.pill-online { color: var(--green); background: var(--green-soft); }
.pill-offline { color: var(--red); background: var(--red-soft); }
.pill-muted { color: var(--muted); background: var(--blue-soft); }
.pill-zone { color: var(--blue); background: var(--blue-soft); }

.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 10px;
  padding: 9px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 40px;
}
.btn-primary { color: #fff; background: var(--blue); width: 100%; margin-top: 14px; }
.btn-ghost { color: var(--ink); background: transparent; border-color: var(--line); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px;
  max-width: 1500px;
  margin: 0 auto;
}

.map-wrap {
  position: relative;
  min-height: 420px;
  height: calc(100vh - 90px);
  height: calc(100dvh - 90px);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
}
#map { position: absolute; inset: 0; background: #dfe8ef; }

.map-btn {
  position: absolute;
  z-index: 800;
  right: 12px;
  bottom: 24px;
  width: 46px; height: 46px;
  font-size: 22px;
  color: var(--blue);
  background: #fff;
  border: 1px solid #c8d5e0;
  border-radius: 50%;
  box-shadow: 0 4px 14px #0003;
  cursor: pointer;
}

.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 { margin: 0 0 8px; font-size: 17px; }

.facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.facts div { min-width: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 700; overflow-wrap: anywhere; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); font-weight: 700; }
.footnote { margin: 0 4px 12px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.seg button, .seg input {
  font: inherit;
  font-size: 14px;
  min-height: 38px;
  padding: 6px 12px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.seg button.active { color: #fff; background: var(--blue); border-color: var(--blue); }
.seg input { flex: 1 1 140px; min-width: 0; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }

.zones, .events { list-style: none; margin: 0; padding: 0; }
.zones li, .events li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.zones li:first-child, .events li:first-child { border-top: 0; }
.zones .inside { color: var(--green); font-weight: 700; }

.login { display: grid; place-items: center; padding: 24px 16px; min-height: calc(100dvh - 60px); }
.login-card { width: 100%; max-width: 420px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card label { display: block; margin-top: 12px; font-size: 13px; font-weight: 700; }
.login-card input {
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* Map markers */
.me-marker {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #0b5cab;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #0b5cab66, 0 2px 8px #0006;
}
.me-marker.stale { background: #8a96a3; box-shadow: 0 0 0 2px #8a96a366, 0 2px 8px #0006; }
.zone-label {
  font-weight: 700;
  color: #12304a;
  background: #ffffffe6;
  border: 0;
  box-shadow: 0 1px 4px #0003;
}
.leaflet-popup-content { font-size: 13px; line-height: 1.45; }

/* Phones, Fold cover screen: map on top, details below */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .map-wrap { height: 58vh; height: 58dvh; min-height: 320px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 16px; }
}

@media (max-width: 380px) {
  .facts { grid-template-columns: 1fr; }
  .brand span:last-child { display: none; }
}
