:root {
  --bg: #0f1216;
  --panel: #171c22;
  --panel2: #1e252d;
  --line: #2a333d;
  --ink: #e7edf3;
  --dim: #8a97a4;
  --accent: #4aa8ff;
  --on: #37d67a;
  --off: #6b7784;
  --cut: #ff5252;
  --stale: #5b6570;
  --warn: #ffb020;
  --crit: #ff4d4f;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr 340px;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

.detail-scrim {
  display: none;
}

@media (max-width: 1100px) {
  body { grid-template-columns: 240px 1fr; }
  .detail { display: none; }
  body.detail-open .detail-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 12, 0.55);
    z-index: 750;
  }
  body.detail-open .detail {
    display: flex;
    position: fixed;
    inset: 24px 12px 12px;
    z-index: 800;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  }
}

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

.brand {
  padding: 12px 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.brand small { color: var(--dim); font-weight: 400; }

.brand .session {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand .session button {
  background: none;
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
}

.brand .session button:hover { color: var(--ink); }

.search, .token-bar {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.search {
  display: flex;
  gap: 6px;
  align-items: center;
}

.search input, .token-bar input {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}

.search input { flex: 1; min-width: 0; }

.search button {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.search button:hover, .search button.open { border-color: var(--accent); color: var(--accent); }

.add-form {
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--panel2);
}
.add-form[hidden] { display: none; }
.add-form label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.add-form input {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
.add-actions { display: flex; gap: 6px; margin-top: 2px; }
.add-actions button {
  flex: 1;
  padding: 7px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
}
.add-actions button[type="submit"] {
  background: var(--accent);
  color: #04121f;
  border-color: var(--accent);
  font-weight: 600;
}

.list-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.list { overflow-y: auto; flex: 1; }

.alerts {
  border-top: 1px solid var(--line);
  max-height: 45%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.alerts h3 {
  margin: 0;
  padding: 8px 12px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid var(--line);
}

.alerts .feed { overflow-y: auto; flex: 1; }

.dev {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex;
  gap: 9px;
  align-items: center;
}

.dev:hover { background: var(--panel2); }
.dev.sel { background: #20303f; box-shadow: inset 3px 0 0 var(--accent); }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  position: relative;
}

.dot.on { background: var(--on); }
.dot.off { background: var(--off); }
.dot.unknown {
  background: transparent;
  border: 2px solid var(--dim);
}
.dot.stale {
  background: var(--stale);
  outline: 2px solid #3a444e;
  outline-offset: 1px;
}
.dot.cut::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--cut);
  border-radius: 50%;
}

.marker-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #0f1216;
  position: relative;
}
.marker-dot.on { background: var(--on); }
.marker-dot.off { background: var(--off); }
.marker-dot.unknown {
  background: transparent;
  border: 2px solid var(--dim);
}
.marker-dot.stale {
  background: var(--stale);
  outline: 2px solid #3a444e;
  outline-offset: 1px;
}
.marker-dot.cut::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--cut);
  border-radius: 50%;
}

.dev .meta { flex: 1; min-width: 0; }
.dev .name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dev .sub {
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--panel2);
  color: var(--dim);
  border: 1px solid var(--line);
}
.badge.cut { color: var(--cut); border-color: #5a2b2b; }
.badge.unprov { color: var(--warn); border-color: #5a4620; }

.mapwrap { position: relative; }
#map {
  position: absolute;
  inset: 0;
  background: #0b0e11;
}

.legend {
  position: absolute;
  z-index: 500;
  bottom: 12px;
  left: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--dim);
  line-height: 1.7;
}
.legend b { color: var(--ink); font-weight: 500; }
.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.toast {
  position: absolute;
  z-index: 600;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  display: none;
}
.toast.show { display: block; }

.detail {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.detail .hd {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.detail .hd .titles { flex: 1; min-width: 0; }
.detail .hd h2 { margin: 0 0 2px; font-size: 15px; }
.detail .hd .imei {
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.detail .hd .close {
  flex: none;
  width: 32px;
  height: 32px;
  margin: -4px -6px 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel2);
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.detail .hd .close:hover { border-color: var(--accent); color: var(--accent); }

.edit-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.edit-fields label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.edit-fields input {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
.edit-fields .edit-actions {
  display: flex;
  gap: 8px;
}
.edit-fields .edit-actions button {
  flex: 1;
  padding: 7px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
}
.edit-fields .edit-actions button.save {
  border-color: var(--accent);
  color: var(--accent);
}
.edit-fields .edit-actions button.retire {
  border-color: #5a2b2b;
  color: var(--cut);
}
.edit-fields .edit-actions button:disabled { opacity: 0.4; cursor: not-allowed; }

.kv {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 4px 10px;
  padding: 12px 14px;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
}
.kv .k { color: var(--dim); }
.kv .v { font-variant-numeric: tabular-nums; }

.pill {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.pill.on { color: var(--on); border-color: #2c5a3f; }
.pill.off { color: var(--off); }
.pill.cut { color: var(--cut); border-color: #5a2b2b; }
.pill.conn { color: var(--dim); }

.actions {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.actions button {
  flex: 1;
  min-width: 120px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
}
.actions button.restore { border-color: #2c5a3f; color: var(--on); }
.actions button.cutoff { border-color: #5a2b2b; color: var(--cut); }
.actions button:disabled { opacity: 0.4; cursor: not-allowed; }

.feed { flex: 1; overflow-y: auto; min-height: 0; }
.feed .ev {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  display: flex;
  gap: 9px;
  cursor: pointer;
}
.feed .ev .sev {
  width: 6px;
  flex: none;
  border-radius: 3px;
  background: var(--dim);
}
.feed .ev .sev.warning { background: var(--warn); }
.feed .ev .sev.critical { background: var(--crit); }
.feed .ev .txt { flex: 1; }
.feed .ev .when { color: var(--dim); font-size: 11px; }
.feed .ev.unacked .txt b { color: var(--warn); }

.foot {
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--dim);
  display: flex;
  justify-content: space-between;
}

.tzhint {
  cursor: help;
  border-bottom: 1px dotted var(--dim);
}

.empty {
  padding: 16px;
  color: var(--dim);
  font-size: 12px;
}

/* login */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 10%, #1a2733 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, #1a222c 0%, transparent 45%),
    var(--bg);
}

.login-card {
  width: min(360px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
}

.login-card p {
  margin: 0 0 18px;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.45;
}

.login-card label {
  display: block;
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 6px;
}

.login-card input {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 14px;
}

.login-card button {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #04121f;
  font-weight: 600;
  cursor: pointer;
}

.login-card .err {
  color: var(--crit);
  font-size: 12px;
  margin-bottom: 10px;
  display: none;
}
.login-card .err.show { display: block; }
