/* BulgariaLive — National Command Center UI (Dark/Light, Responsive, Crisp Glass/Card Grid) */
:root {
  --bg: #070d18;
  --bg-elev: #0e1729;
  --bg-card: #121d33;
  --bg-card-hover: #172540;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(56, 189, 248, 0.35);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --purple: #a855f7;
  --orange: #f97316;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

body.light {
  --bg: #f1f5f9;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --border: rgba(15, 23, 42, 0.12);
  --border-strong: rgba(2, 132, 199, 0.45);
  --text: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, 0.12);
  --green: #16a34a;
  --green-soft: rgba(22, 163, 74, 0.12);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.12);
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(14, 23, 41, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
body.light .topbar {
  background: rgba(255, 255, 255, 0.92);
}

.topbar-inner {
  max-width: 1520px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-flag {
  width: 28px;
  height: 20px;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.brand-flag span:nth-child(1) { flex: 1; background: #ffffff; }
.brand-flag span:nth-child(2) { flex: 1; background: #00966e; }
.brand-flag span:nth-child(3) { flex: 1; background: #d62612; }

.brand-title {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.pill-mono { font-family: var(--font-mono); }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse 2s infinite;
}
.dot.warn { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot.crit { background: var(--red); box-shadow: 0 0 8px var(--red); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s ease;
}
.btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}
.btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.nav-bar {
  max-width: 1520px;
  margin: 0 auto;
  padding: 0 18px 10px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}
.tab-btn {
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.tab-btn:hover {
  color: var(--text);
  background: var(--bg-card);
}
.tab-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.3);
}

.container {
  max-width: 1520px;
  margin: 0 auto;
  padding: 16px 18px 40px;
}

.alert-banner {
  display: none;
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  background: var(--amber-soft);
  color: var(--text);
  font-size: 13px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.alert-banner.crit {
  border-color: rgba(239, 68, 68, 0.5);
  background: var(--red-soft);
}
.alert-banner.visible { display: flex; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Map Section */
.map-shell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 18px;
}
.map-toolbar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.map-layers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.layer-toggle {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s ease;
}
.layer-toggle.on {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--accent-soft);
}
.swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
#bgMap {
  width: 100%;
  height: 500px;
  background: #08101e;
}
body.light #bgMap { background: #e2e8f0; }

/* Bento Grid */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.crit { background: var(--red-soft); color: var(--red); }

.big-metric {
  font-size: 28px;
  font-weight: 800;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}
.sub-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 7px;
}
.sub-val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
}

.mini-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.mini-bar-row {
  display: grid;
  grid-template-columns: 95px 1fr 56px;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}
.bar-track {
  height: 7px;
  background: rgba(148, 163, 184, 0.14);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

/* Split / Deep-Dive Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 1024px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  #bgMap { height: 390px; }
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13px;
  min-width: 240px;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
th, td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
}
tr:hover td { background: rgba(56, 189, 248, 0.04); }
.mono { font-family: var(--font-mono); }

.svg-box {
  width: 100%;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(8, 16, 30, 0.45);
  border: 1px solid var(--border);
  padding: 8px;
}
body.light .svg-box { background: #f8fafc; }

.pass-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}
.pass-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.footer {
  max-width: 1520px;
  margin: 0 auto;
  padding: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
}

/* Leaflet overrides & Dark-mode basemap filter */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.leaflet-container { font-family: inherit; }

.leaflet-tile-pane .osm-base-tiles {
  filter: invert(100%) hue-rotate(180deg) brightness(92%) contrast(92%) saturate(85%);
}
body.light .leaflet-tile-pane .osm-base-tiles {
  filter: none;
}

.layer-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  opacity: 0.8;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
}

.bg-mk {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  color: #ffffff;
  font-weight: 700;
}
.bg-mk.red { background: #ef4444; }
.bg-mk.amber { background: #f59e0b; }
.bg-mk.green { background: #16a34a; }
.bg-mk.blue { background: #0284c7; }
.bg-mk.cyan { background: #0891b2; }
.bg-mk.pink { background: #db2777; }
.bg-mk.yellow { background: #ca8a04; }
.bg-mk.pass { border-radius: 6px; }

.map-legend {
  padding: 7px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 11.5px;
  color: var(--text-muted);
}
