:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0ea5e9;
  --brand-dark: #0284c7;
  --sidebar-w: 280px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ---------- Login ---------- */
.login-page {
  position: relative;
  height: 100%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #0f172a, #0e7490);
}

.login-card {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 45px rgba(2, 6, 23, 0.35);
  display: flex;
  flex-direction: column;
}

.login-brand { text-align: center; margin-bottom: 14px; }
.login-brand h1 { margin: 10px 0 2px; font-size: 22px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 13px; }

.login-card label,
.filter-group label,
.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.login-card input,
.filter-group input[type="search"],
.filter-group input[type="date"] {
  width: 100%;
  padding: 9px 11px;
  margin: 4px 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

.login-card input:focus,
.filter-group input:focus {
  outline: 2px solid rgba(14, 165, 233, 0.4);
  border-color: var(--brand);
}

.btn-primary {
  margin-top: 8px;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover { background: var(--brand-dark); }

.btn-primary:disabled {
  background: #93c5fd;
  cursor: progress;
}

/* Server-side login failure, rendered above the button. */
.login-error {
  margin: 2px 0 0;
  font-size: 12.5px;
  font-weight: 500;
  color: #b91c1c;
}

.btn-secondary {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.btn-secondary:hover { background: var(--bg); }

/* ---------- Version badge ---------- */
/* Written by deploy.sh into CONFIG.APP_VERSION / CONFIG.BUILD_NUMBER. */
.version-badge {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  user-select: none;
}

.version-badge-login {
  position: absolute;
  right: 12px;
  bottom: 10px;
  color: rgba(255, 255, 255, 0.6);
}

.version-badge-sidebar {
  margin-top: 10px;
  text-align: left;
  color: var(--muted);
}

/* ---------- App shell ---------- */
.app-shell { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 1200;
}

.topbar-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }

.app-body { flex: 1 1 auto; display: flex; min-height: 0; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Filters scroll; the footer below stays pinned to the bottom-left. */
.sidebar-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
}

.sidebar-footer {
  flex: 0 0 auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.btn-logout {
  width: 100%;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-logout:hover { background: #fef2f2; border-color: #fecaca; }

.sidebar h2 { margin: 0 0 14px; font-size: 15px; }

.filter-group { margin-bottom: 16px; }
.filter-group input[type="range"] { width: 100%; }

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

.content { flex: 1 1 auto; min-width: 0; position: relative; }

/* ---------- Map ---------- */
.map-wrap { position: absolute; inset: 0; }
.map { width: 100%; height: 100%; }

.attribution {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 500;
  padding: 1px 6px;
  font-size: 10px;
  color: #334155;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 4px 0 0 0;
}

.basemap-switch {
  position: absolute;
  right: 12px;
  bottom: 26px;
  z-index: 600;
  display: flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(2, 6, 23, 0.25);
}

.basemap-switch button {
  border: 0;
  background: none;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.basemap-switch button.active { background: var(--brand); color: #fff; font-weight: 600; }

/* ---------- Map markers ---------- */
.popup strong { display: block; margin-bottom: 5px; font-size: 13px; }
.popup div { font-size: 12px; color: var(--muted); }
.popup div span {
  display: inline-block;
  min-width: 68px;
  font-weight: 600;
  color: var(--text);
}

.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 600;
  display: flex;
  gap: 10px;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(2, 6, 23, 0.25);
}

.legend-item { display: flex; align-items: center; gap: 5px; }

.legend-item i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
}

/* Failed wifi_status load, shown in the top bar. */
.topbar-error { color: #b91c1c; font-weight: 600; }

/* Grey basemap: OpenStreetMap's standard tiles desaturated. Applied to the
   tile layer's container so only the basemap greys out - the markers drawn
   above it keep their colour. */
.tiles-grey { filter: grayscale(1); }

/* Zoom-to-extent control, stacked under Leaflet's +/- bar. Leaflet styles the
   anchor itself (30x30, white, bordered); this only centres the icon. */
.leaflet-bar a.zoom-extent {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #334155;
}

.leaflet-bar a.zoom-extent:hover { color: var(--brand-dark); }

/* Hover tooltip: same content as the click popup, so it reuses .popup for the
   label/value rows and only restyles the Leaflet tooltip chrome. */
.leaflet-tooltip.wifi-tip {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(2, 6, 23, 0.28);
  white-space: nowrap;
  /* The tooltip follows the cursor; letting it swallow pointer events would
     make it flicker as the pointer enters it. */
  pointer-events: none;
}

.leaflet-tooltip.wifi-tip::before { border-top-color: var(--border); }

/* Multi-network location: compact list on hover, full cards on click. */
.tip-list div {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.tip-list div span {
  display: inline-block;
  min-width: 130px;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  color: var(--text);
}

.tip-more {
  margin-top: 5px;
  font-size: 11px;
  font-style: italic;
  color: var(--muted);
}

/* The popup can hold every network at a location, so it scrolls. */
.popup-scroll {
  max-height: 300px;
  overflow-y: auto;
  margin-top: 4px;
}

.popup-entry + .popup-entry {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Nested cards keep only their own heading spacing. */
.popup-entry .popup strong { margin-bottom: 3px; }

/* Mobility values come from the wifi.mac_mobility enum in lowercase; shown
   capitalised without changing the value the filter matches on. */
.check-mobility { text-transform: capitalize; }
