:root {
  --bg: #0f0b16;
  --surface: #171122;
  --surface-2: #1e1730;
  --line: #2c2242;
  --text: #ece8f5;
  --muted: #a297bd;
  --accent: #9d5cff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(157, 92, 255, 0.16);
  --ok: #52d99a;
  --warn: #f5b43f;
  --danger: #ff6b81;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f1fa;
    --surface: #ffffff;
    --surface-2: #f7f4fd;
    --line: #e2dcf0;
    --text: #1d1630;
    --muted: #6b6288;
    --accent: #7b3fe4;
    --accent-soft: rgba(123, 63, 228, 0.12);
    --ok: #17924f;
    --warn: #a96a00;
    --danger: #c62a45;
    --shadow: 0 14px 32px rgba(40, 20, 80, 0.12);
    color-scheme: light;
  }
}

* {
  box-sizing: border-box;
}

/* A class that sets display beats the UA sheet's [hidden] rule, so .app and .login would
   stay on screen while "hidden". Everything here toggles visibility with el.hidden. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.error {
  color: var(--danger);
  margin: 0;
  font-size: 14px;
}

.boot {
  display: grid;
  place-items: center;
  height: 100dvh;
  color: var(--muted);
}

/* ---- brand ---------------------------------------------------------------- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.wordmark b {
  font-weight: 700;
}

.wordmark {
  font-weight: 400;
}

/* The mark is the radar sweep: a dot with a ring pushing out from it. */
.mark {
  position: relative;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.mark::before,
.mark::after {
  content: '';
  position: absolute;
  border-radius: 50%;
}

.mark::before {
  inset: 6px;
  background: var(--accent);
}

.mark::after {
  inset: 0;
  border: 2px solid var(--accent);
  opacity: 0.45;
  animation: sweep 2.6s ease-out infinite;
}

@keyframes sweep {
  0% {
    transform: scale(0.4);
    opacity: 0.75;
  }
  70%,
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mark::after {
    animation: none;
    opacity: 0.45;
  }
}

.brand-lg {
  font-size: 22px;
}

.brand-lg .mark {
  width: 26px;
  height: 26px;
  flex-basis: 26px;
}

/* ---- login ---------------------------------------------------------------- */

.login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}

.login-card {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
}

/* ---- shell ---------------------------------------------------------------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.pill.ageing {
  color: var(--muted);
  border-color: var(--line);
}

.pill.stale {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, var(--line));
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 380px;
}

.map-wrap {
  position: relative;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
}

.panel {
  border-left: 1px solid var(--line);
  background: var(--bg);
  overflow-y: auto;
  padding: 14px;
  display: grid;
  gap: 14px;
  align-content: start;
}

/* ---- cards & controls ------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.field b {
  color: var(--text);
  font-weight: 600;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='search'] {
  /* Chromium paints its own widget background over a search field unless appearance is
     cleared, which leaves the one input on the page stuck in a light box in dark mode. */
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

.check {
  display: flex;
  gap: 9px;
  align-items: center;
  font-size: 14px;
  margin-bottom: 12px;
  cursor: pointer;
}

.check input {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  padding: 10px 14px;
  border: 1px solid transparent;
}

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.primary:hover {
  filter: brightness(1.08);
}

.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.ghost:hover {
  background: var(--surface-2);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ---- search ---------------------------------------------------------------- */

.search {
  position: absolute;
  z-index: 500;
  top: 12px;
  left: 12px;
  right: 12px;
  max-width: 540px;
  display: flex;
  gap: 8px;
}

.search input {
  flex: 1;
  box-shadow: var(--shadow);
}

.search .primary {
  box-shadow: var(--shadow);
}

.results {
  position: absolute;
  z-index: 500;
  top: 60px;
  left: 12px;
  right: 12px;
  max-width: 540px;
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: 45%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.results li button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 9px 10px;
  color: var(--text);
  border-radius: 8px;
  font-size: 14px;
}

.results li button:hover {
  background: var(--accent-soft);
}

/* ---- lists ----------------------------------------------------------------- */

.targets,
.alerts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.targets li,
.alerts li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
}

.target-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.target-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.target-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.tag {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.tag.armed {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, var(--line));
}

.tag.alerted {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 45%, var(--line));
}

.target-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.target-actions button {
  padding: 4px 9px;
  font-size: 13px;
}

.alerts li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.alerts .bad {
  color: var(--danger);
}

/* ---- map bits -------------------------------------------------------------- */

.leaflet-container {
  background: var(--surface-2);
  font: inherit;
}

.me-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #3fa9ff;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px rgba(63, 169, 255, 0.35);
}

/* A position nobody has refreshed must not look like a live one. Filled means "he is
   here"; hollow means "this is the last we heard", and only the filled one is blue. */
.me-dot.ageing {
  background: transparent;
  border-color: #7d93b8;
  box-shadow: 0 0 0 2px rgba(125, 147, 184, 0.25);
}

.me-dot.stale {
  background: transparent;
  border-color: #8c8399;
  box-shadow: 0 0 0 2px rgba(140, 131, 153, 0.25);
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0 0 12px;
  align-items: center;
}

.kv dt {
  font-size: 13px;
  color: var(--muted);
}

.kv dd {
  margin: 0;
  min-width: 0;
}

.copy {
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy:hover {
  border-color: var(--accent);
}

.banner {
  margin: 0;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  color: var(--text);
  font-size: 14px;
  display: grid;
  gap: 9px;
  justify-items: start;
}

.banner p {
  margin: 0;
}

/* "Nothing has ever arrived" is a setup step, not a fault — it must not wear the same
   warning colours as "the phone has gone quiet". */
.banner.setup {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

/* The tiles are a light raster; in dark mode they are toned down so the purple
   overlays stay the brightest thing on the page. */
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane {
    filter: brightness(0.72) saturate(0.75) contrast(1.05);
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 900;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 18px;
  box-shadow: var(--shadow);
  font-size: 14px;
}

/* ---- phone ----------------------------------------------------------------- */

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 55dvh 1fr;
  }

  .panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .topbar {
    padding: 10px 12px;
  }

  .wordmark {
    font-size: 15px;
  }
}
