:root {
  --bg: #070b12;
  --panel: rgba(12, 18, 30, 0.88);
  --panel-solid: #101826;
  --line: rgba(140, 180, 220, 0.16);
  --text: #e8f1ff;
  --muted: #8aa0b8;
  --cyan: #3ee0c8;
  --amber: #f5b942;
  --red: #ff7a6e;
  --blue: #7ab8ff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --sans: "IBM Plex Sans", "Noto Sans SC", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: 56px 1fr 32px;
  height: 100%;
}

.topbar, .statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: #0b1220;
  border-bottom: 1px solid var(--line);
  z-index: 40;
}
.statusbar {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.brand .mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--cyan), #1a6cff);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #041018;
}
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }

.spacer { flex: 1; }

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #0e1726;
}
.chip[data-state="on"] { color: var(--cyan); border-color: rgba(62, 224, 200, 0.4); }
.chip[data-state="off"] { color: var(--muted); }

button {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #152033;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
}
button:hover { border-color: rgba(62, 224, 200, 0.45); }
button.is-on { background: rgba(62, 224, 200, 0.16); color: var(--cyan); border-color: rgba(62, 224, 200, 0.5); }
button.primary { background: linear-gradient(180deg, #1f8f82, #14756b); border-color: transparent; color: #041018; font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn { width: 32px; height: 32px; padding: 0; }

.stage {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 0;
  position: relative;
  isolation: isolate;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel-solid);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  z-index: 4;
}
.side-h {
  padding: 12px 14px 8px;
  display: flex; justify-content: space-between; align-items: baseline;
}
.side-h h3 { margin: 0; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.list { overflow: auto; padding: 6px 8px 16px; display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--muted); font-size: 13px; padding: 24px 12px; text-align: center; }

.ac-item {
  display: flex; gap: 10px; text-align: left; width: 100%;
  background: #121c2c; padding: 10px;
}
.ac-item.is-active { outline: 1px solid var(--cyan); background: #152433; }
.ac-item.is-gone { opacity: 0.5; }
.swatch { width: 4px; border-radius: 4px; flex: 0 0 4px; }
.ac-name { font-size: 13px; font-weight: 600; }
.ac-sub, .ac-stats { color: var(--muted); font-size: 11px; margin-top: 3px; font-family: var(--mono); }
.ac-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.msg-dots { display: flex; gap: 4px; margin-top: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #243044; }
.dot.on { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

.pill { padding: 1px 6px; border-radius: 999px; font-size: 10px; }
.st-air { background: rgba(62,224,200,.18); color: var(--cyan); }
.st-gnd { background: rgba(122,184,255,.18); color: var(--blue); }
.st-emg { background: rgba(255,122,110,.2); color: var(--red); }
.st-unk { background: #243044; color: var(--muted); }

.map-wrap { position: relative; min-width: 0; min-height: 0; z-index: 1; }
#map { position: absolute; inset: 0; background: #c5d4e0; }
.leaflet-container { width: 100%; height: 100%; font-family: var(--sans); }
.leaflet-control-zoom a { border-radius: 6px !important; }
.ac-icon, .op-icon { background: none !important; border: none !important; }
.ac-icon .ac-label {
  position: absolute; left: 34px; top: 0; white-space: nowrap;
  color: #102033; font-size: 11px; font-weight: 600; line-height: 1.2;
  text-shadow: 0 0 4px #fff, 0 1px 2px #fff;
}

.map-tools {
  position: absolute; top: 12px; left: 12px; z-index: 500;
  display: flex; gap: 8px;
}
.map-badge {
  position: absolute; left: 12px; bottom: 16px; z-index: 500;
  font-size: 11px; color: var(--muted);
  background: var(--panel); padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--line);
  pointer-events: none;
}

.detail {
  position: absolute; top: 12px; right: 12px; bottom: 48px;
  width: min(420px, 42vw); z-index: 30;
  background: var(--panel); backdrop-filter: blur(16px);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: auto; padding: 0 0 20px;
  pointer-events: auto;
}
.detail-head {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 16px 16px 8px; position: sticky; top: 0;
  background: linear-gradient(#101a2ad0, #101a2a);
}
.kicker { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
.detail h2 { margin: 4px 0 0; font-size: 18px; }
.mac { color: var(--muted); font-family: var(--mono); font-size: 11px; margin: 4px 0 0; }
.complete { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 16px; margin: 8px 0 12px; }
.complete li { display: flex; justify-content: space-between; font-size: 12px; padding: 6px 8px; border-radius: 8px; background: #0c1522; }
.complete .ok { color: var(--cyan); }
.complete .miss { color: var(--muted); }
.detail section { padding: 4px 16px 10px; }
.detail h3 { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--cyan); margin: 10px 0 8px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.kv { background: #0c1522; border-radius: 8px; padding: 7px 8px; }
.kv dt { font-size: 10px; color: var(--muted); }
.kv dd { margin: 2px 0 0; font-size: 12px; word-break: break-all; font-family: var(--mono); }
.hex, code { font-family: var(--mono); font-size: 11px; color: #c9e7ff; }
.hex { background: #0c1522; padding: 10px; border-radius: 8px; overflow: auto; white-space: pre; }
.muted { color: var(--muted); font-size: 12px; }
.auth-page { margin-bottom: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.ac-marker {
  width: 32px; height: 32px; display: grid; place-items: center;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.5));
}
.ac-body {
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 18px solid var(--c);
  transform: rotate(var(--r));
}
.ac-marker.is-sel .ac-body { border-bottom-color: #fff; }
.ac-marker.is-gone { opacity: 0.4; }
.ac-label { color: #fff; font-size: 11px; text-shadow: 0 1px 2px #000; line-height: 1.2; }
.ac-label small { display: block; opacity: 0.8; }
.op-pin span {
  display: block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--c); border: 2px solid #fff; box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 30%, transparent);
}

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20;
  display: grid; place-items: center;
}
.modal[hidden], [hidden] { display: none !important; }
.card {
  width: min(480px, 92vw); background: #121c2c; border: 1px solid var(--line);
  border-radius: 14px; padding: 18px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
input {
  width: 100%; background: #0c1522; border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-family: var(--mono);
}
.row-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }

#toast {
  position: fixed; bottom: 48px; left: 50%; transform: translateX(-50%);
  background: #1a2436; border: 1px solid var(--line); padding: 8px 14px;
  border-radius: 8px; z-index: 30; font-size: 13px;
}

#console-panel {
  position: absolute; left: 332px; right: 12px; bottom: 40px; height: 160px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  overflow: auto; z-index: 25; padding: 8px 10px; font-family: var(--mono); font-size: 11px;
}
#console-log .tx { color: var(--amber); }
#console-log .rx { color: var(--cyan); }

@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; }
  .sidebar { position: absolute; z-index: 5; width: min(100%, 320px); height: 42%; bottom: 0; border-right: 0; border-top: 1px solid var(--line); }
  .detail { width: calc(100% - 24px); left: 12px; right: 12px; top: auto; height: 46%; }
  #console-panel { left: 12px; }
  .map-wrap { min-height: 58%; }
}
