:root {
  --bg: #070b14;
  --panel: rgba(11, 17, 30, 0.86);
  --panel-border: rgba(148, 163, 184, 0.16);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #f59e0b;
  --green: #10b981;
  --red: #f43f5e;
  --purple: #a855f7;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
}

#map {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

#agent-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

/* Glass Panels */
.panel {
  position: fixed;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  z-index: 20;
}

#sidebar {
  top: 14px;
  left: 14px;
  bottom: 14px;
  width: 345px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--panel-border);
}

.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #f8fafc, #7dd3fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-header p {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 3px;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 5px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.25);
  border-radius: 99px;
}

.section-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.kpi-card {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 10px;
  padding: 9px 11px;
}

.kpi-val {
  font-size: 16px;
  font-weight: 800;
  color: #f8fafc;
}

.kpi-lbl {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 2px;
}

/* Layer Buttons */
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.14);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.layer-btn:hover {
  background: rgba(56, 189, 248, 0.09);
  border-color: rgba(56, 189, 248, 0.35);
}

.layer-btn.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--accent);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.15);
}

.layer-icon {
  font-size: 16px;
  width: 24px;
  text-align: center;
}

.layer-info strong {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
}

.layer-info span {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 1px;
}

/* Scenario Pills */
.pill-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.pill-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: var(--text);
  padding: 7px 9px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-btn:hover {
  border-color: rgba(245, 158, 11, 0.5);
}

.pill-btn.active {
  background: rgba(245, 158, 11, 0.18);
  border-color: var(--accent-2);
  color: #fde68a;
}

/* Controls & Sliders */
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.control-row input[type="range"] {
  width: 130px;
  accent-color: var(--accent);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 12px;
}

.toggle-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Interactive Tool Mode Buttons */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tool-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: var(--text);
  padding: 8px 6px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.tool-btn:hover {
  background: rgba(168, 85, 247, 0.12);
  border-color: rgba(168, 85, 247, 0.45);
}

.tool-btn.active {
  background: rgba(168, 85, 247, 0.22);
  border-color: var(--purple);
  color: #e9d5ff;
}

/* Hotspots List */
.hotspot-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hotspot-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.hotspot-item:hover {
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.4);
  transform: translateX(2px);
}

.hotspot-rank {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent-2);
  width: 24px;
}

.hotspot-name {
  flex: 1;
  min-width: 0;
  padding-right: 8px;
}

.hotspot-name strong {
  display: block;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hotspot-name span {
  font-size: 10.5px;
  color: var(--muted);
}

.hotspot-score {
  font-size: 13px;
  font-weight: 800;
  color: var(--green);
  background: rgba(16, 185, 129, 0.14);
  padding: 3px 7px;
  border-radius: 6px;
}

/* Top-Right Map Controls */
#top-bar {
  top: 14px;
  right: 14px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.mini-btn:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--accent);
}

.mini-btn.active {
  background: var(--accent);
  color: #04101d;
  border-color: var(--accent);
}

/* Inspector Panel (Right Side) */
#inspector {
  top: 66px;
  right: 14px;
  width: 325px;
  max-height: calc(100vh - 150px);
  overflow-y: auto;
  padding: 15px 16px;
  display: none;
}

#inspector.visible {
  display: block;
}

.inspector-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.inspector-header h2 {
  font-size: 15px;
  font-weight: 800;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: #fff;
}

.score-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.14), rgba(56, 189, 248, 0.12));
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.score-circle {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 3px solid var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 900;
  color: #ecfdf5;
  flex-shrink: 0;
}

.metric-bar {
  margin-bottom: 9px;
}

.metric-bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  margin-bottom: 4px;
}

.bar-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.35s ease;
}

.iso-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0;
}

.iso-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 8px;
  padding: 8px 6px;
  text-align: center;
}

.iso-card strong {
  display: block;
  font-size: 14px;
  font-weight: 800;
}

.iso-card span {
  font-size: 10px;
  color: var(--muted);
}

.nearby-list {
  font-size: 11.5px;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}

.nearby-item {
  display: flex;
  justify-content: space-between;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
}

/* Legend Bottom Right */
#legend {
  bottom: 14px;
  right: 14px;
  padding: 10px 14px;
  min-width: 240px;
}

.legend-bar {
  height: 8px;
  border-radius: 99px;
  margin: 6px 0 4px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
}

/* Toast / Mode Banner */
#mode-banner {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(168, 85, 247, 0.92);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  z-index: 30;
  display: none;
  box-shadow: 0 10px 30px rgba(168, 85, 247, 0.4);
}

#mode-banner.visible {
  display: block;
}

.action-btn {
  width: 100%;
  margin-top: 8px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.action-btn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.route-compare {
  margin-top: 10px;
  padding: 10px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 9px;
  font-size: 11.5px;
  line-height: 1.5;
}

/* 2x2 Tool Grid */
.tool-grid-4 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

/* Modal Overlay */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 15, 0.72);
  backdrop-filter: blur(6px);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.visible {
  display: flex;
}

.modal-card {
  width: 370px;
  max-width: 92vw;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.65);
}

.modal-card h3 {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 12px;
}

.form-group {
  margin-bottom: 11px;
}

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group select {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  outline: none;
}

.form-group select option {
  background: #0f172a;
  color: #f1f5f9;
}

.intensity-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.int-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: var(--text);
  padding: 6px 2px;
  border-radius: 7px;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.int-btn.active {
  background: rgba(56, 189, 248, 0.22);
  border-color: var(--accent);
  color: #bae6fd;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.btn-secondary {
  flex: 1;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.16);
  border: 1px solid rgba(244, 63, 94, 0.45);
  color: #fda4af;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  flex: 1.4;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  border: none;
  color: #fff;
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Calibration Box */
.calib-box {
  background: rgba(16, 185, 129, 0.07);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 10px;
  padding: 10px 11px;
}

.calib-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.calib-item:last-child {
  border-bottom: none;
}

.calib-del {
  background: none;
  border: none;
  color: #fb7185;
  cursor: pointer;
  font-weight: 700;
  margin-left: 6px;
}

.io-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.io-row button {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: var(--muted);
  padding: 6px;
  border-radius: 7px;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}

.io-row button:hover {
  color: #fff;
  border-color: var(--accent);
}

/* Sidebar collapse & mobile GPS-friendly layout */
#sidebar.collapsed {
  transform: translateX(-115%);
  pointer-events: none;
  opacity: 0;
}
#sidebar {
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.maplibregl-ctrl-bottom-left {
  bottom: 18px !important;
  left: 14px !important;
}
.maplibregl-ctrl-group {
  background: rgba(15, 23, 42, 0.92) !important;
  border: 1px solid rgba(148, 163, 184, 0.25) !important;
  border-radius: 10px !important;
}
.maplibregl-ctrl-group button {
  filter: invert(0.9);
}
@media (max-width: 768px) {
  #sidebar {
    width: calc(100vw - 24px);
    max-width: 360px;
    top: 58px;
  }
  #top-bar {
    flex-wrap: wrap;
    max-width: calc(100vw - 24px);
    justify-content: flex-end;
  }
  #legend {
    display: none;
  }
}
