:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #2b3442;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #ff5d5d;
  --accent-soft: rgba(255, 93, 93, 0.15);
  --active: #b92828;
  --potential: #f0883e;
  --potential-soft: rgba(240, 136, 62, 0.15);
  --unrest: #e3b341;
  --unrest-soft: rgba(227, 179, 65, 0.15);
  --single: #58a6ff;
  --single-soft: rgba(88, 166, 255, 0.15);
  --verified: #3fb950;
  --link: #58a6ff;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body { display: flex; flex-direction: column; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.3px; }
.brand .tagline { color: var(--muted); font-size: 12px; margin-top: 2px; }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 93, 93, 0.55); }
  70% { box-shadow: 0 0 0 9px rgba(255, 93, 93, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 93, 93, 0); }
}

.status { display: flex; align-items: center; gap: 14px; font-size: 12px; color: var(--muted); }

main { flex: 1; display: flex; min-height: 0; position: relative; }

#map { flex: 1; background: #0a0e14; }

/* Sidebar */
#sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#sidebar { display: flex; flex-direction: column; }

.sidebar-head { padding: 13px 16px 11px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.sidebar-head .hint { font-size: 11px; color: var(--muted); margin-top: 5px; }

#conflict-list { flex: 1; overflow-y: auto; }

.sidebar-foot {
  flex-shrink: 0;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.6;
}

/* Region dropdowns */
.region-group { border-bottom: 1px solid var(--border); }

.region-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  background: var(--panel);
  transition: background 0.15s;
}
.region-group summary::-webkit-details-marker { display: none; }
.region-group summary:hover { background: var(--panel-2); }

.region-name {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.region-meta { display: flex; align-items: center; gap: 8px; }
.chevron { color: var(--muted); font-size: 11px; transition: transform 0.2s; }
.region-group[open] .chevron { transform: rotate(180deg); }

.region-group ul { list-style: none; background: rgba(0, 0, 0, 0.18); }

.region-group li {
  padding: 10px 16px 10px 22px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.region-group li:hover { background: var(--panel-2); }

.conflict-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conflict-name { font-size: 13.5px; font-weight: 600; }
.conflict-country { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.verified-badge { background: rgba(63, 185, 80, 0.15); color: var(--verified); }
.count-badge { background: var(--accent-soft); color: var(--accent); }
.quiet-badge { background: rgba(139, 152, 169, 0.15); color: var(--muted); }
.active-badge { background: rgba(185, 40, 40, 0.22); color: #ff8080; }
.potential-badge { background: var(--potential-soft); color: var(--potential); }
.unrest-badge { background: var(--unrest-soft); color: var(--unrest); }

.popup-badges { margin: 5px 0 2px; display: flex; gap: 5px; }

/* Map markers: compact colour-coded dots */
.conflict-marker {
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
}
.conflict-marker.active {
  background: var(--active);
  box-shadow: 0 0 9px rgba(185, 40, 40, 0.75);
}
.conflict-marker.potential {
  background: var(--potential);
  box-shadow: 0 0 9px rgba(240, 136, 62, 0.65);
}
.conflict-marker.unrest {
  background: var(--unrest);
  box-shadow: 0 0 9px rgba(227, 179, 65, 0.6);
}
.conflict-marker.suggested {
  box-shadow: none;
  border-style: dashed;
  border-width: 2px;
}
.conflict-marker.suggested.single {
  background: rgba(88, 166, 255, 0.2);
  border-color: var(--single);
}
.conflict-marker.suggested.corr {
  background: rgba(63, 185, 80, 0.22);
  border-color: var(--verified);
}
.conflict-marker.quiet { opacity: 0.55; box-shadow: none; }

.cluster-bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 2px solid var(--muted);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
.cluster-bubble:hover { border-color: var(--text); }

.leaflet-tooltip {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 11.5px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.leaflet-tooltip-top:before { border-top-color: var(--border); }

/* Status indicators */
.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 7px;
}
.status-dot.active { background: var(--active); }
.status-dot.potential { background: var(--potential); }
.status-dot.unrest { background: var(--unrest); }
.status-dot.suggested { border-width: 1.5px; border-style: dashed; }
.status-dot.suggested.single { background: var(--single-soft); border-color: var(--single); }
.status-dot.suggested.corr { background: rgba(63, 185, 80, 0.2); border-color: var(--verified); }

.suggested-group summary { background: rgba(88, 166, 255, 0.05); }
.suggested-badge { background: var(--unrest-soft); color: var(--unrest); border: 1px dashed var(--unrest); }
.single-badge { background: var(--single-soft); color: var(--single); }
.corr-badge { background: rgba(63, 185, 80, 0.15); color: var(--verified); }

.legend { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; flex-wrap: wrap; }
.legend .status-dot { margin-right: 2px; }

.lang-caveat {
  font-size: 10.5px;
  color: var(--muted);
  font-style: italic;
  margin-top: 7px;
  line-height: 1.55;
}

/* About the data */
.about-data { margin-top: 8px; }
.about-data summary {
  cursor: pointer;
  color: var(--link);
  font-weight: 600;
  user-select: none;
}
.about-data ul { margin: 7px 0 0 15px; }
.about-data li { margin-bottom: 6px; line-height: 1.55; }

/* Live coverage */
.live-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #ff4747;
  margin-right: 6px;
  animation: pulse 2s infinite;
}

.popup-live {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 8px;
  line-height: 1.6;
}
.popup-live a { color: var(--link); text-decoration: none; }
.popup-live a:hover { text-decoration: underline; }

#lang-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  max-width: 150px;
  cursor: pointer;
}

.translate-note { padding: 4px 2px; font-style: italic; }

#live-tv-toggle {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
#live-tv-toggle:hover { border-color: var(--muted); }
#live-tv-toggle.on { background: rgba(255, 71, 71, 0.15); border-color: #ff4747; color: #ff7b7b; }

#live-tv-panel {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 420px;
  max-width: calc(100vw - 28px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  z-index: 1100;
  display: none;
  overflow: hidden;
}
#live-tv-panel.open { display: block; }

.live-tv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}
#live-tv-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
#live-tv-close:hover { color: var(--text); }

#live-tv-tabs { display: flex; gap: 6px; padding: 9px 12px; flex-wrap: wrap; }
#live-tv-tabs button {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
#live-tv-tabs button.on { color: #ff7b7b; border-color: #ff4747; background: rgba(255, 71, 71, 0.12); }

#live-tv-frame {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  background: #000;
}

.live-tv-foot {
  padding: 8px 12px;
  font-size: 10.5px;
  color: var(--muted);
}
.live-tv-foot a { color: var(--link); }

/* Popup */
.leaflet-popup-content-wrapper {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
}
.leaflet-popup-tip { background: var(--panel-2); }
.leaflet-popup-content { margin: 12px 14px; width: 320px !important; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

.popup-title { font-size: 15px; font-weight: 700; }
.popup-sub { font-size: 11.5px; color: var(--muted); margin: 3px 0 8px; }
.popup-sources { font-size: 11px; color: var(--muted); margin-bottom: 8px; }

.popup-links summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--link);
  padding: 6px 0;
  user-select: none;
}

.popup-links ul {
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}
.popup-links li { padding: 8px 2px; border-bottom: 1px solid var(--border); }
.popup-links a {
  color: var(--link);
  text-decoration: none;
  font-size: 12.5px;
  line-height: 1.4;
  display: block;
}
.popup-links a:hover { text-decoration: underline; }
.popup-links .meta { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

.empty-note { font-size: 12px; color: var(--muted); padding: 6px 0; }

/* Linked entities dropdown */
.popup-entities { margin-top: 4px; }
.popup-entities summary { color: #d2a8ff; }

/* Money trail dropdown */
.popup-finance { margin-top: 4px; }
.popup-finance summary { color: #39c5cf; }
.entity-name { font-size: 12.5px; font-weight: 700; }
.entity-name a { color: var(--link); text-decoration: none; }
.entity-name a:hover { text-decoration: underline; }
.connection-tag {
  background: rgba(210, 168, 255, 0.12);
  color: #d2a8ff;
  margin-left: 5px;
  font-weight: 600;
  text-transform: lowercase;
}
.entity-role { font-size: 11.5px; color: var(--muted); line-height: 1.45; margin-top: 2px; }
.entity-disclaimer {
  font-size: 10.5px;
  color: var(--muted);
  font-style: italic;
  padding-top: 7px;
}

/* Menu button (mobile only) */
#menu-toggle {
  display: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
#menu-toggle.on { border-color: var(--accent); color: var(--accent); }

/* Phone layout: fullscreen map, sidebar becomes a slide-out drawer */
@media (max-width: 760px) {
  #menu-toggle { display: block; }
  .brand { gap: 8px; }
  .brand h1 { font-size: 16px; }
  .brand .tagline { display: none; }
  #source-status { display: none; }
  header { padding: 8px 10px; }
  .status { gap: 8px; }
  #last-updated { display: none; }
  #lang-select { max-width: 92px; padding: 4px 5px; }
  #live-tv-toggle { padding: 4px 8px; font-size: 11px; }

  #sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(85vw, 340px);
    z-index: 1200;
    border-right: 1px solid var(--border);
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.55);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }
  #sidebar.open { transform: translateX(0); }
  html[dir="rtl"] #sidebar {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid var(--border);
    transform: translateX(105%);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.55);
  }
  html[dir="rtl"] #sidebar.open { transform: translateX(0); }

  /* Larger touch targets in the drawer */
  .region-group summary { padding: 14px 16px; }
  .region-group li { padding: 12px 16px 12px 22px; }

  /* Popups sized to the phone screen */
  .leaflet-popup-content { width: 76vw !important; }
  .popup-links ul { max-height: 38vh; }

  /* Live TV panel spans the bottom of the screen */
  #live-tv-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
  }
}
