:root{
  --bg: #0b0f16;
  --panel: #111827;
  --panel2: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: rgba(255,255,255,0.08);
  --btn: rgba(255,255,255,0.08);
  --btnHover: rgba(255,255,255,0.12);
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --accent: #60a5fa;
}

*{ box-sizing: border-box; }
html,body{ height:100%; margin:0; background:var(--bg); color:var(--text); font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial; }

a{ color: inherit; text-decoration: none; }
h1{ margin:0; font-size: 20px; font-weight: 700; letter-spacing: 0.2px; }

.muted{ color: var(--muted); font-size: 13px; }
.mono{ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }

.deviceLink{
  color: var(--accent);
  text-decoration: none;
}
.deviceLink:hover{ text-decoration: underline; }
.deviceLinkSecondary{
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}
.deviceLinkSecondary:hover{ color: var(--text); }
.deviceLinkGroup{
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.topbar{
  height: 54px;
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(17,24,39,0.8);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top:0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.brand{ font-weight: 800; letter-spacing: 0.3px; }
.nav{ display:flex; gap:10px; }
.navlink{
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--muted);
}
.navlink:hover{ background: var(--btnHover); color: var(--text); }
.navlink.active{ background: var(--btn); color: var(--text); }

.user-info{
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-info .username{
  color: var(--muted);
  font-size: 13px;
}
.user-info .logout{
  color: var(--bad);
  font-size: 13px;
}
.user-info .logout:hover{
  background: rgba(239, 68, 68, 0.15);
}

.page{
  max-width: 1800px;
  margin: 0 auto;
  padding: 16px;
}

.pageHdr{
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 14px 0;
}

.actions{ display:flex; gap: 10px; align-items:center; }

.cards{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 10px 0 14px;
}

.card{
  background: linear-gradient(180deg, rgba(17,24,39,0.95), rgba(15,23,42,0.95));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 12px 35px rgba(0,0,0,0.35);
}
.cardLabel{ color: var(--muted); font-size: 13px; }
.cardValue{ font-size: 26px; font-weight: 800; margin-top: 6px; }

.split{
  display:grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 12px;
}

.panel{
  background: rgba(17,24,39,0.9);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow:hidden;
  box-shadow: 0 12px 35px rgba(0,0,0,0.25);
}

.panelHdr{
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display:flex;
  align-items:center;
  justify-content: space-between;
}

.panelTitle{ font-weight: 800; }
.panelActions{ display:flex; gap:8px; align-items:center; }

.panelBody{
  padding: 14px;
}

.checkpointLayout{
  display:grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.checkpointMap{
  height: 320px;
  border-radius: 4px;
}

.checkpointMapModal{
  height: 100%;
  min-height: 520px;
}

.modalWide{
  max-width: 1350px;
  width: 1350px;
  max-height: 90vh;
  height: 90vh;
  display: flex;
  flex-direction: column;
}

.checkpointModalGrid{
  display:grid;
  grid-template-columns: minmax(300px, 1fr) minmax(600px, 2fr);
  gap: 14px;
  align-items: stretch;
  height: 78vh;
  min-height: 620px;
  flex: 1;
}

.checkpointModalFields{
  overflow: auto;
  padding-right: 4px;
  min-height: 0;
}

.checkpointModalMapWrap{
  display:flex;
  flex-direction:column;
  height: 100%;
  min-height: 0;
}

.checkpointModalMapWrap .field{
  display:flex;
  flex-direction:column;
  height: 100%;
}

.checkpointModalMapWrap .field .checkpointMap{
  flex: 1;
  min-height: 0;
}

.checkpointRowHighlight{
  background: rgba(96,165,250,0.14);
}

.checkpointRowStart{
  background: rgba(16,185,129,0.14);
}

.checkpointRowFinish{
  background: rgba(59,130,246,0.14);
}

.checkpointRowBoth{
  background: rgba(245,158,11,0.16);
}

.alertList{
  display:grid;
  gap: 10px;
}

.alertCard{
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
}

.alertOffCourse{
  border-color: rgba(239,68,68,0.35);
  background: rgba(239,68,68,0.08);
}

.alertStopped{
  border-color: rgba(245,158,11,0.35);
  background: rgba(245,158,11,0.08);
}

.alertTitle{
  font-weight: 700;
}

.alertMeta{
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.alertSub{
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.notificationList{
  display:grid;
  gap: 10px;
}

.notificationRow{
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
}

.notificationTop{
  display:flex;
  justify-content:space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.notificationTitle{
  font-weight: 700;
}

.notificationMeta{
  font-size: 12px;
  color: var(--muted);
}

.notificationMsg{
  margin-top: 6px;
}

.ruleToggle{
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  background: rgba(255,255,255,0.05);
  color: var(--text);
}
.ruleToggle.isEnabled{
  background: rgba(16,185,129,0.18);
  border-color: rgba(16,185,129,0.6);
  color: #10b981;
}
.ruleToggle.isDisabled{
  background: rgba(239,68,68,0.18);
  border-color: rgba(239,68,68,0.6);
  color: #ef4444;
}

.notificationSub{
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.runnerDetailGrid{
  display:grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 16px;
}

.runnerSummary{
  display:flex;
  flex-direction:column;
  gap: 12px;
}

.runnerHero{
  display:flex;
  align-items:center;
  gap: 14px;
  flex-wrap: wrap;
}

.runnerHeroBib{
  min-width: 70px;
  height: 70px;
  border-radius: 18px;
  background: rgba(96,165,250,0.16);
  border: 1px solid rgba(96,165,250,0.35);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 900;
  font-size: 20px;
}

.runnerHeroMeta{
  display:flex;
  flex-direction:column;
  gap: 4px;
}

.runnerHeroName{
  font-size: 20px;
  font-weight: 800;
}

.runnerMeta{
  display:grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.runnerProgressCard{
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 16px 14px;
}

.progressTitle{
  font-weight: 700;
  margin-bottom: 8px;
}

.progressTrack{
  position: relative;
  min-height: 80px;
  margin: 6px 0 10px 0;
}

.progressRail{
  position:absolute;
  top: 36px;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
}

.progressFill{
  position:absolute;
  top: 36px;
  left: 0;
  height: 4px;
  background: linear-gradient(90deg, rgba(96,165,250,0.25), rgba(96,165,250,0.8));
  border-radius: 999px;
}

.progressMarker{
  position:absolute;
  top: 20px;
  transform: translateX(-50%);
  display:flex;
  flex-direction:column;
  align-items:center;
  gap: 6px;
  max-width: 120px;
  text-align:center;
}

.progressDot{
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.65);
  border: 2px solid rgba(15,23,42,0.9);
}

.progressMarker.is-checkpoint .progressDot{
  background: rgba(255,255,255,0.5);
}

.progressMarker.is-checkpoint.is-passed .progressDot{
  background: var(--good);
}

.progressMarker.is-current{
  top: 10px;
}

.progressMarker.is-current .progressDot{
  width: 14px;
  height: 14px;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(96,165,250,0.18);
}

.progressLabel{
  font-size: 11px;
  color: var(--muted);
}

.progressMarker.is-current .progressLabel{
  color: var(--text);
  font-weight: 700;
}

.progressLegend{
  font-size: 12px;
  color: var(--muted);
  text-align:right;
}

.runnerSignals{
  display:grid;
  gap: 10px;
}

.runnerSignalRow{
  display:grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 8px;
  font-size: 13px;
}

.runnerSignalKey{
  color: var(--muted);
}

.runnerSignalVal{
  font-weight: 600;
}

.grid2{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.bigLink{
  display:block;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
}
.bigLink:hover{
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.14);
}
.bigLinkTitle{ font-weight: 800; margin-bottom: 4px; }

.btn{
  background: var(--btn);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover{ background: var(--btnHover); }
.btn.small{ padding: 6px 8px; border-radius: 10px; font-size: 12px; }
.btn.primary{ background: rgba(96,165,250,0.18); border-color: rgba(96,165,250,0.35); }
.btn.primary:hover{ background: rgba(96,165,250,0.24); }
.btn.danger{ background: rgba(239,68,68,0.16); border-color: rgba(239,68,68,0.35); }
.btn.danger:hover{ background: rgba(239,68,68,0.24); }

.pill{
  display:inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
}
.pill.good{ border-color: rgba(16,185,129,0.35); background: rgba(16,185,129,0.16); }
.pill.warn{ border-color: rgba(245,158,11,0.35); background: rgba(245,158,11,0.14); }

.flashWrap{ margin-bottom: 10px; }
.flash{
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.flashOk{ border-color: rgba(16,185,129,0.35); background: rgba(16,185,129,0.12); }
.flashErr{ border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.12); }

.formGrid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items:normal;
}
.field{ display:flex; flex-direction: column; gap: 6px; }
.field label{ color: var(--muted); font-size: 12px; }
.inp{
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 10px;
  border-radius: 12px;
  outline: none;
}
.inp option,
.inp optgroup{
  background: #0d1117;
  color: var(--text);
}
.inp:focus{
  border-color: rgba(96,165,250,0.5);
  box-shadow: 0 0 0 3px rgba(96,165,250,0.12);
}
.hint{ color: var(--muted); font-size: 12px; }
.fieldActions{ display:flex; justify-content:flex-end; }

.tableWrap{ width:100%; overflow:auto; }
.tbl{
  width:100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th, .tbl td{
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.tbl th{
  text-align:left;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}
.tbl td.right{ text-align:right; white-space: nowrap; }

.progressInline{
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
}
.progressInline > span{ white-space: nowrap; }

.statusPill{
  display:inline-flex;
  gap: 8px;
  align-items:center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  font-size: 12px;
}
.dot{
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display:inline-block;
}
.dotOnline{ background: var(--good); box-shadow: 0 0 0 4px rgba(16,185,129,0.12); }
.dotOffline{ background: var(--bad); box-shadow: 0 0 0 4px rgba(239,68,68,0.10); }

.blink{
  animation: blink 1.2s infinite;
}
@keyframes blink{
  0%{ opacity: 1; }
  50%{ opacity: 0.25; }
  100%{ opacity: 1; }
}

.codeBlock{
  margin:0;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  overflow:auto;
  font-size: 12px;
}

.kv{
  display:grid;
  grid-template-columns: 150px 1fr;
  gap: 10px 12px;
}
.kv .k{ color: var(--muted); }
.kv .v{ }

.bullets{ margin:0; padding-left: 18px; }
.bullets li{ margin: 8px 0; }

/* ===== Map layout (kept compatible) ===== */
#wrap{
  height: calc(100vh - 54px);
  display:flex;
}
#sidebar{
  width: 420px;
  border-right: 1px solid var(--line);
  background: rgba(17,24,39,0.9);
  overflow:auto;
}
#map{
  flex:1;
}
.hdr{
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--line);
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 10px;
}
.title{ font-weight: 900; }
.hdrBtns{ display:flex; gap:8px; flex-wrap: wrap; justify-content:flex-end; }
.row.small{
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  display:flex;
  align-items:center;
  gap: 8px;
  flex-wrap: wrap;
}
.spacer{ height: 8px; }

.device{
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  cursor:pointer;
}
.device:hover{ background: rgba(255,255,255,0.03); }
.device.sel{ background: rgba(96,165,250,0.10); }
.devTop{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 8px;
}
.toggle{ display:flex; align-items:center; gap: 8px; }
.devMeta{ margin-top: 6px; }
.pill{
  display:inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
}

/* responsive */
@media (max-width: 980px){
  .cards{ grid-template-columns: 1fr; }
  .split{ grid-template-columns: 1fr; }
  .runnerDetailGrid{ grid-template-columns: 1fr; }
  .formGrid{ grid-template-columns: 1fr; }
  #sidebar{ width: 100%; max-width: 520px; }
  .checkpointLayout{ grid-template-columns: 1fr; }
  .checkpointModalGrid{ grid-template-columns: 1fr; }
  .modalWide{ width: 100%; max-width: 100%; }
  .checkpointModalGrid{ height: auto; }
  .modalWide{ height: auto; }
}


.evtRow{
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.evtTop{
  display:flex;
  gap: 10px;
  align-items:center;
  flex-wrap: wrap;
}
.evtKind{
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(96,165,250,0.14);
}
.evtDev{ font-weight: 800; }
.evtTs{ font-size: 12px; }
.evtMsg{ margin-top: 6px; }
.evtPayload{
  margin-top: 8px;
  margin-bottom: 0;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  overflow:auto;
  font-size: 12px;
}

.dot{
  width:10px;
  height:10px;
  border-radius:999px;
  display:inline-block;
  border:1px solid rgba(255,255,255,0.25);
}
.dotOnline{ background: #10b981; }
.dotOffline{ background: #ef4444; }

.blink{
  animation: blink 1.1s infinite;
}
@keyframes blink{
  0% { opacity: 1; }
  50% { opacity: 0.25; }
  100% { opacity: 1; }
}

.statusPill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 4px 8px;
  border:1px solid var(--line);
  border-radius:999px;
  font-size:12px;
  background: rgba(255,255,255,0.03);
}

.bat{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding: 4px 8px;
  border:1px solid var(--line);
  border-radius:999px;
  font-size:12px;
}
.batIcon{
  width:14px;
  height:10px;
  border-radius:2px;
  border:1px solid currentColor;
  position:relative;
  display:inline-block;
}
.batIcon::after{
  content:"";
  position:absolute;
  right:-3px;
  top:2px;
  width:2px;
  height:6px;
  border-radius:1px;
  background: currentColor;
}
.bpLow{ color:white; }
.bpMid{ color:white; }
.bpHigh{ color:white; }
.bpUnknown{ color:white; }


/* JSON syntax highlighting (events) */
.evtPayload { line-height: 1.35; }
.jKey  { color: #60a5fa; }   /* blue */
.jStr  { color: #34d399; }   /* green */
.jNum  { color: #fbbf24; }   /* amber */
.jBool { color: #f472b6; }   /* pink */
.jNull { color: #a78bfa; }   /* purple */

/* Optional: highlight point events slightly */
.evtRow.k_point { border-left: 3px solid #10b981; }


.hdrRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-top:6px;
}

.batCard{
  min-width: 320px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
}

.batTop{
  display:flex;
  align-items:center;
  gap:10px;
}

.batIcon{
  width: 18px;
  height: 10px;
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 2px;
  position: relative;
  flex: 0 0 auto;
}
.batIcon::after{
  content:"";
  position:absolute;
  right:-5px;
  top:2px;
  width:3px;
  height:6px;
  border-radius:1px;
  background: rgba(255,255,255,0.35);
}

.batMeter{
  flex: 1 1 auto;
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.10);
  overflow:hidden;
}

.batFill{
  height:100%;
  border-radius: 999px;
}

/* If you already have these from the map: keep them.
   Otherwise, add a minimal fallback: */
.bpLow { background: #ef4444; }
.bpMid { background: #f59e0b; }
.bpHigh { background: #10b981; }
.bpUnknown { background: #9ca3af; }

.batNums{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  line-height:1.15;
  white-space: nowrap;
}

.batEta{
  margin-top:8px;
  line-height:1.25;
}

/* Modal */
.modal{
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modalContent{
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  width: 100%;
  max-width: 1350px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.modalHdr{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modalTitle{
  font-weight: 800;
  font-size: 16px;
}
.modalClose{
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
.modalClose:hover{ color: var(--text); }
.modalContent form{
  padding: 16px;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.modalContent .field{
  margin-bottom: 12px;
}
.modalContent .fieldActions{
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}
.modalContent .fieldActions .btn{
  min-width: 120px;
}
.btn-sm{
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 8px;
}

/* Sortable drag-and-drop styles */
.sortable-ghost {
  opacity: 0.4;
  background: rgba(59, 130, 246, 0.1);
}
