:root {
  --bg: #0a0e1a;
  --bg-2: #0f1424;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf5;
  --text-dim: #98a2bd;
  --accent: #38e8c8;
  --accent-2: #6aa6ff;
  --warm: #ff7a59;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------------- Sidebar ---------------- */
#sidebar {
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(56, 232, 200, 0.10), transparent 60%),
    radial-gradient(120% 80% at 100% 100%, rgba(106, 166, 255, 0.10), transparent 60%),
    var(--bg-2);
  border-right: 1px solid var(--panel-border);
  padding: 22px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 1100;
}

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

.brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(56, 232, 200, 0.35);
}
.brand-mark .pulse {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #06121a;
  position: relative;
}
.brand-mark .pulse::after {
  content: "";
  position: absolute; inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(6, 18, 26, 0.5);
  animation: ping 2s ease-out infinite;
}
@keyframes ping {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(1.8); opacity: 0; }
}

.brand-text h1 { font-size: 18px; margin: 0; font-weight: 800; letter-spacing: -0.02em; }
.brand-text p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(6px);
}

.panel-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 10px;
  display: block;
}

.input-row { display: flex; gap: 8px; }

input[type="text"] {
  flex: 1;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 232, 200, 0.15);
}
input::placeholder { color: #5b647d; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, background 0.15s, opacity 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a;
}
.btn-primary:hover { opacity: 0.92; }
.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--panel-border);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.09); }
.btn-block { width: 100%; margin-top: 10px; }

.status { font-size: 12.5px; color: var(--text-dim); margin: 10px 0 0; min-height: 16px; }
.status.error { color: var(--warm); }
.status.ok { color: var(--accent); }

/* Stats */
.stats { display: flex; gap: 14px; }
.stat { flex: 1; text-align: center; }
.stat-num {
  display: block;
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}
.stat-label { font-size: 11px; color: var(--text-dim); }

/* Toggles */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  padding: 6px 0;
  cursor: pointer;
  color: var(--text);
}
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* Nearest list */
.nearest-panel { flex: 1; min-height: 120px; }
.nearest-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.nearest-list .muted { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.nearest-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.nearest-item:hover { background: rgba(56, 232, 200, 0.08); border-color: rgba(56, 232, 200, 0.3); }
.nearest-rank {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a;
  font-weight: 700;
  font-size: 12px;
  display: grid; place-items: center;
}
.nearest-body { min-width: 0; flex: 1; }
.nearest-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nearest-meta { font-size: 11.5px; color: var(--text-dim); }
.nearest-dist { font-size: 12px; font-weight: 600; color: var(--accent); white-space: nowrap; }

.sidebar-footer { margin-top: auto; }
.fineprint { font-size: 10.5px; color: #5b647d; margin: 10px 2px 0; line-height: 1.4; }

/* ---------------- Map ---------------- */
#map-wrap { position: relative; }
#map { position: absolute; inset: 0; background: #0a0e1a; }

.map-legend {
  position: absolute;
  left: 16px; bottom: 16px;
  z-index: 1000;
  background: rgba(12, 16, 30, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 14px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.legend-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); font-weight: 600; }
.legend-bar {
  width: 180px; height: 10px;
  border-radius: 6px;
  margin: 8px 0 4px;
  background: linear-gradient(90deg, #1b3a6b 0%, #2bd1ff 35%, #38e8c8 55%, #f7e463 78%, #ff7a59 100%);
}
.legend-scale { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-dim); }
.legend-markers { display: flex; flex-direction: column; gap: 4px; margin-top: 9px; font-size: 11px; color: var(--text-dim); }
.legend-markers span { display: flex; align-items: center; gap: 7px; }
.legend-markers .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-markers .dot-campus { background: #38e8c8; box-shadow: 0 0 6px #38e8c8aa; }
.legend-markers .dot-pop { background: #6aa6ff; box-shadow: 0 0 6px #6aa6ffaa; }

.mobile-toggle {
  display: none;
  position: absolute;
  top: 14px; left: 14px;
  z-index: 1200;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(12, 16, 30, 0.9);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

/* ---------------- Popups ---------------- */
.leaflet-popup-content-wrapper {
  background: #11172b;
  color: var(--text);
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: #11172b; border: 1px solid var(--panel-border); }
.leaflet-popup-content { margin: 14px 16px; font-size: 13px; line-height: 1.5; }
.dc-popup h3 { margin: 0 0 4px; font-size: 14.5px; }
.dc-popup .dc-op { color: var(--accent); font-weight: 600; font-size: 12.5px; }
.dc-popup .dc-loc { color: var(--text-dim); font-size: 12px; margin: 2px 0 8px; }
.dc-popup .dc-tag {
  display: inline-block;
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(106, 166, 255, 0.15);
  color: var(--accent-2);
  margin-bottom: 8px;
}
.dc-popup a { color: var(--accent); font-size: 12px; text-decoration: none; }
.dc-popup a:hover { text-decoration: underline; }

/* "You are here" marker */
.you-marker {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--warm);
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(255, 122, 89, 0.25), 0 2px 8px rgba(0,0,0,0.5);
}

/* Cluster styling tweak */
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div {
  background: linear-gradient(135deg, rgba(56,232,200,0.85), rgba(106,166,255,0.85));
  color: #04121a; font-weight: 700;
}
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large {
  background: rgba(56, 232, 200, 0.25);
}

/* ---------------- Modal ---------------- */
.modal { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 8, 18, 0.7); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  width: min(640px, 92vw);
  max-height: 84vh;
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 24px 26px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 26px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-intro { color: var(--text-dim); font-size: 13px; line-height: 1.6; margin: 12px 0 18px; }
.sources-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.sources-list li {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}
.sources-list a { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 14px; }
.sources-list a:hover { text-decoration: underline; }
.sources-list .src-url { display: block; color: var(--text-dim); font-size: 11.5px; margin-top: 3px; word-break: break-all; }

/* ---------------- Latest news ---------------- */
.news-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.news-updated { font-size: 10px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--text-dim); }

.news-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.news-chip {
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.news-chip:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.news-chip.is-active {
  color: #04121a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.news-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.news-list .muted { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.news-item {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--cat, var(--accent));
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.news-item:hover { background: rgba(255, 255, 255, 0.07); transform: translateX(2px); }
.news-title { font-size: 13px; font-weight: 600; line-height: 1.35; color: var(--text); }
.news-meta { display: flex; align-items: center; gap: 7px; margin-top: 6px; font-size: 11px; color: var(--text-dim); }
.news-cat {
  flex-shrink: 0;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cat, var(--accent));
}
.news-source { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.news-dot { color: var(--panel-border); }
.news-time { flex-shrink: 0; margin-left: auto; }

/* ---------------- Power plants overlay ---------------- */
.muted-inline { color: var(--text-dim); font-size: 11px; font-weight: 500; }
.power-fuels {
  margin: 8px 0 2px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
}
.fuel-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
}
.fuel-row input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; flex-shrink: 0; }
.fuel-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 5px currentColor; }
.fuel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fuel-count { color: var(--text-dim); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.dc-attr { display: block; margin-top: 8px; color: var(--text-dim); font-size: 10px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(86vw, 360px);
    transform: translateX(-102%);
    transition: transform 0.25s ease;
  }
  #sidebar.open { transform: translateX(0); }
  .mobile-toggle { display: block; }
}
