:root {
  --bg: #0f1720;
  --panel: #16212e;
  --panel-2: #1d2b3a;
  --line: #2a3b4d;
  --ink: #e6edf3;
  --ink-dim: #9fb0c0;
  --ink-faint: #6b7d8f;
  --live: #3fd08a;      /* reserved: good/live fix only */
  --warn: #e0a95b;
  --bad: #e06b6b;
  --focus: #5aa9e6;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--focus); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- login ---------- */
.auth-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
}
.brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.brand span { color: var(--live); }
.auth-sub { color: var(--ink-dim); margin: 0 0 24px; font-size: 14px; }

label { display: block; font-size: 13px; color: var(--ink-dim); margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 15px;
}
input:focus { border-color: var(--focus); outline: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 20px;
  padding: 11px 14px;
  background: var(--focus);
  color: #06121d;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn.secondary {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--line);
}
.toggle-line { margin-top: 16px; font-size: 13px; color: var(--ink-faint); text-align: center; }
.msg { margin-top: 14px; font-size: 13px; min-height: 18px; }
.msg.error { color: var(--bad); }
.msg.ok { color: var(--live); }

/* ---------- dashboard layout ---------- */
.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100%;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar-actions .who { color: var(--ink-faint); font-size: 13px; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 4px 12px;
}
.side-head h2 { font-size: 13px; font-weight: 600; color: var(--ink-dim); margin: 0; }
.count { color: var(--ink-faint); font-size: 12px; }

.device {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 11px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.device:hover { background: var(--panel-2); }
.device.active { background: var(--panel-2); border-color: var(--line); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-faint); }
.dot.live { background: var(--live); box-shadow: 0 0 0 3px rgba(63,208,138,.16); }
.dot.stale { background: var(--warn); }
.dot.alert { background: var(--bad); box-shadow: 0 0 0 3px rgba(224,107,107,.18); }
.device .name { font-weight: 600; }
.device .meta { color: var(--ink-faint); font-size: 12px; }
.device .spd { font-variant-numeric: tabular-nums; color: var(--ink-dim); font-size: 13px; }
.badge { padding: 2px 7px; border-radius: 6px; background: var(--panel-2); }
.badge.alert { background: rgba(224,107,107,.16); color: var(--bad); font-weight: 600; }

#map { height: 100%; width: 100%; background: #0b1016; }

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 14px;
}
.empty b { color: var(--ink-dim); display:block; margin-bottom: 6px; }

/* leaflet marker label */
.mk-label {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

/* hover panel with sensor readings — strip Leaflet's default white chrome
   and let .mk-panel below do the styling */
.leaflet-tooltip.mk-tooltip {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}
.leaflet-tooltip.mk-tooltip::before { display: none; }

.mk-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 200px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  font-family: var(--font);
}
.mk-panel .mk-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}
.mk-panel .mk-err {
  color: var(--bad);
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 6px;
}
.mk-panel .mk-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  font-size: 12px;
  color: var(--ink-dim);
  padding: 1px 0;
  white-space: nowrap;
}
.mk-panel .mk-row b {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px 40vh 1fr; }
  .sidebar { max-height: 40vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
