:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #5f6672;
  --border: #d9dde3;
  --primary: #1f5fbf;
  --primary-text: #ffffff;
  --danger: #b42318;
  --ok: #157347;
  --warn: #a15c00;
  --pending: #1f5fbf;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1f2228;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --border: #353a42;
    --primary: #5b9bff;
    --primary-text: #0b1220;
    --danger: #ff7a6e;
    --ok: #4cc38a;
    --warn: #f0b44c;
    --pending: #5b9bff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { margin-right: 8px; }
#nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#nav button { border: none; background: none; padding: 6px 10px; border-radius: 6px; color: var(--muted); }
#nav button.active { background: var(--bg); color: var(--text); font-weight: 600; }
#who { color: var(--muted); font-size: 13px; }
#sim-banner { background: var(--warn); color: #000; text-align: center; padding: 4px 16px; font-size: 13px; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 16px; gap: 16px; overflow: auto; }
#view-map { padding: 0; position: relative; }
.centered { align-items: center; justify-content: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#login-form { width: min(360px, 100%); }
h1, h2 { margin: 0; font-size: 20px; }
h2 { font-size: 17px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
input, select {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin: 0; }
legend { font-size: 13px; color: var(--muted); }
small, .hint { color: var(--muted); font-size: 12px; margin: 0; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.checks { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow: auto; margin-bottom: 6px; }
.checks label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }

button {
  font: inherit;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.link { border: none; background: none; color: var(--primary); padding: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.error { color: var(--danger); margin: 0; min-height: 1em; font-size: 13px; }

.map-full { position: absolute; inset: 0; }
.map-admin { min-height: 360px; border-radius: 10px; border: 1px solid var(--border); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.split > .map-admin { height: 100%; }
@media (max-width: 800px) {
  .split { grid-template-columns: 1fr; }
}

.empty {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 500; background: var(--surface); padding: 10px 16px; border-radius: 8px;
  border: 1px solid var(--border); max-width: calc(100% - 32px); margin: 0;
}

.toolbar { display: flex; justify-content: space-between; align-items: center; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr[data-id] { cursor: pointer; }
tbody tr[data-id]:hover { background: var(--bg); }
tbody tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; border: 1px solid currentColor; }
.ok { color: var(--ok); }
.voicemail { color: var(--warn); }
.failed { color: var(--danger); }
.pending { color: var(--pending); }
.inactive { color: var(--muted); }

/* Popup on the map */
.gate-popup { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.gate-popup strong { font-size: 15px; }
.gate-popup p { margin: 0; }
.gate-popup button { width: 100%; padding: 10px; font-size: 16px; }
.gate-popup .status { font-size: 13px; min-height: 1.2em; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 2000; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }
