:root {
  --bg: #0f1420;
  --panel: #161d2e;
  --panel-2: #1d2740;
  --border: #2a3450;
  --text: #e8ecf5;
  --text-dim: #8b96b3;
  --free: #3ddc84;
  --incoming: #f5c453;
  --active: #ff8a3d;
  --stopped: #ff4d4f;
  --accent: #5b8cff;
  --node-color: #8b5bff;
  --intersection-color: #2d2323;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---------- Login ---------- */

.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #1a2340, var(--bg) 70%);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 320px;
  text-align: center;
}

.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { color: var(--text-dim); margin: 0 0 24px; font-size: 14px; }

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

.login-card button {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.login-card button:hover { opacity: 0.9; }
.error { color: var(--stopped); font-size: 13px; min-height: 18px; margin-top: 10px; }

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.node-label-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.node-label-toggle input[type="checkbox"] {
  accent-color: var(--node-color);
  cursor: pointer;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block;
}
.dot-online { background: var(--free); box-shadow: 0 0 8px var(--free); }
.dot-offline { background: var(--text-dim); }

.layout { flex: 1; display: flex; overflow: hidden; }

#map { flex: 1; }

.sidebar {
  width: 340px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
}

.sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 20px 0 10px;
}
.sidebar section:first-child h2 { margin-top: 0; }

/* ---------- Alert cards ---------- */

.alert-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--free);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.alert-card.incoming { border-left-color: var(--incoming); }
.alert-card.active { border-left-color: var(--active); }
.alert-card.stopped { border-left-color: var(--stopped); }

.alert-card .name { font-weight: 600; font-size: 14px; }
.alert-card .level {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 4px;
  background: var(--panel);
  color: var(--free);
}
.alert-card.incoming .level { color: var(--incoming); }
.alert-card.active .level { color: var(--active); }
.alert-card.stopped .level { color: var(--stopped); }

.alert-card .detail { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.alert-card .flag {
  display: inline-block;
  font-size: 11px;
  margin-top: 6px;
  margin-right: 6px;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(255, 138, 61, 0.15);
  color: var(--active);
}
.alert-card .flag.drift { background: rgba(255, 77, 79, 0.15); color: var(--stopped); }

/* ---------- Node cards ---------- */

.node-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 13px;
}
.node-card.offline { border-color: var(--stopped); }
.node-card .node-name { font-weight: 500; }
.node-card .node-meta { color: var(--text-dim); font-size: 12px; text-align: right; }

.node-admin-actions { display: flex; gap: 6px; margin-top: 6px; }
.node-cmd-btn {
  background: var(--panel-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 11px;
  cursor: pointer;
}
.node-cmd-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* ---------- Leaflet marker tweaks ---------- */

.train-marker {
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid white;
  width: 14px; height: 14px;
}
.train-marker.stopped { background: var(--stopped); }
.train-marker.slowing { background: var(--incoming); }

/* Nodes (radar/PIR units) - purple circular pins */
.node-marker-icon {
  background: var(--node-color);
  border-radius: 50%;
  border: 2px solid white;
  width: 14px; height: 14px;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.45);
}

/* Intersections (alert zones) - an X mark, kept visually distinct
   in both shape and color from the round node/train pins */
.intersection-marker-icon {
  position: relative;
  width: 14px; height: 14px;
}
.intersection-marker-icon::before,
.intersection-marker-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 6px;
  background: var(--intersection-color);
  border-radius: 2px;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.55);
}
.intersection-marker-icon::before { transform: translate(-50%, -50%) rotate(45deg); }
.intersection-marker-icon::after { transform: translate(-50%, -50%) rotate(-45deg); }

/* Permanent tooltips (node/intersection labels) styled to match the
   dark dashboard theme instead of Leaflet's default white bubble */
.leaflet-tooltip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  border-radius: 4px;
  padding: 2px 6px;
  box-shadow: none;
}
.leaflet-tooltip-top:before {
  border-top-color: var(--border);
}

.user-display {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
  margin-right: 4px;
}

/* ---------- Admin Panel Styles ---------- */

.admin-panel {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.admin-help {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 0;
  margin-bottom: 12px;
}

.admin-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
}

.delete-btn {
  background: rgba(255, 77, 79, 0.15);
  color: var(--stopped);
  border: 1px solid var(--stopped);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

.delete-btn:hover {
  background: var(--stopped);
  color: white;
}