:root {
  --panel-bg: rgba(255,255,255,0.95);
  --panel-border: rgba(15,23,42,0.08);
  --panel-shadow: 0 14px 32px rgba(15,23,42,0.14);
  --text: #0f172a;
  --muted: #64748b;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
}

body { background: #e5e7eb; }
#map { position: absolute; inset: 0; }

#topbar {
  position: absolute;
  z-index: 1000;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100vw - 24px), 1100px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(10px);
}

.brand { font-size: 20px; font-weight: 900; line-height: 1.05; }
.subbrand { margin-top: 3px; font-size: 12px; color: var(--muted); font-weight: 800; letter-spacing: 0.08em; }
.status-wrap { min-width: 0; }
.status-line {
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-line.muted { margin-top: 4px; font-size: 12px; color: var(--muted); }
.controls-wrap { display: flex; align-items: center; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.refresh-meta {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(37,99,235,0.08);
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 900;
}

.topbtn,
.langbtn,
.filter-chip,
.panel-toggle,
.spot-item {
  appearance: none;
  border: 1px solid rgba(15,23,42,0.12);
  background: rgba(255,255,255,0.96);
  color: var(--text);
  border-radius: 12px;
  font: inherit;
}

.topbtn,
.langbtn {
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}
.topbtn:hover,
.langbtn:hover { background: #fff; }
.lang-switch { display: flex; gap: 6px; }
.langbtn.is-active { background: #111827; color: #fff; }

#sidePanel {
  position: absolute;
  z-index: 950;
  top: 200px;
  left: 12px;
  width: 320px;
  max-height: calc(100vh - 216px);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid rgba(15,23,42,0.08);
}
.panel-title { font-size: 14px; font-weight: 900; }
.panel-toggle {
  width: 34px;
  height: 34px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}
.panel-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 10px 12px 12px;
}
#sidePanel.is-collapsed .panel-body { display: none; }

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}
.filter-chip .chip-count {
  min-width: 18px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(15,23,42,0.08);
  font-size: 11px;
}
.filter-chip.is-active {
  background: #111827;
  border-color: #111827;
  color: #fff;
}
.filter-chip.tota:not(.is-active) { color: #be185d; }
.filter-chip.bota:not(.is-active) { color: #92400e; }
.filter-chip.sota:not(.is-active) { color: #b45309; }
.filter-chip.wwff:not(.is-active) { color: #166534; }
.filter-chip.pota:not(.is-active) { color: #1d4ed8; }
.filter-chip.gma:not(.is-active) { color: #b91c1c; }
.filter-chip.other:not(.is-active) { color: #475569; }

.spot-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  min-height: 0;
  padding-right: 2px;
}
.spot-empty {
  padding: 12px;
  border: 1px dashed rgba(15,23,42,0.14);
  border-radius: 14px;
  background: rgba(248,250,252,0.85);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.spot-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 11px;
  cursor: pointer;
}
.spot-item:hover { background: #fff; }
.spot-item.is-selected {
  border-color: rgba(37,99,235,0.38);
  box-shadow: inset 0 0 0 1px rgba(37,99,235,0.18);
  background: rgba(239,246,255,0.95);
}
.spot-dot,
.dot,
.live-marker {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.94), 0 6px 16px rgba(15,23,42,0.22);
}
.spot-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.spot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.spot-call { font-size: 15px; font-weight: 900; }
.spot-program { font-size: 11px; font-weight: 900; color: var(--muted); }
.spot-ref, .spot-meta { font-size: 12px; font-weight: 700; }
.spot-ref { color: var(--text); }
.spot-meta { color: var(--muted); }
.spot-age {
  font-size: 11px;
  font-weight: 900;
  color: var(--muted);
  padding-top: 2px;
}

#legend {
  position: absolute;
  z-index: 900;
  right: 12px;
  bottom: 12px;
  padding: 12px 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--panel-shadow);
  min-width: 126px;
}
.legend-title { font-size: 13px; font-weight: 900; margin-bottom: 8px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; }
.legend-row + .legend-row { margin-top: 6px; }

.tota { background: #ec4899; }
.bota { background: #a16207; }
.sota { background: #f59e0b; }
.wwff { background: #15803d; }
.pota { background: #2563eb; }
.gma  { background: #dc2626; }
.other { background: #64748b; }
.live-marker.is-selected { transform: scale(1.22); box-shadow: 0 0 0 3px rgba(255,255,255,0.96), 0 0 0 6px rgba(37,99,235,0.18), 0 10px 20px rgba(15,23,42,0.24); }
.live-divicon { background: transparent !important; border: 0 !important; }

.leaflet-top.leaflet-left,
.leaflet-top.leaflet-right { margin-top: 108px; }
.leaflet-control-zoom a { width: 34px; height: 34px; line-height: 34px; }

.popup-card { min-width: 240px; }
.popup-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.popup-call { font-size: 18px; font-weight: 900; }
.popup-badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 900; color: #fff; }
.popup-badge.tota { background: #ec4899; }
.popup-badge.bota { background: #a16207; }
.popup-badge.sota { background: #f59e0b; }
.popup-badge.wwff { background: #15803d; }
.popup-badge.pota { background: #2563eb; }
.popup-badge.gma { background: #dc2626; }
.popup-badge.other { background: #64748b; }
.popup-row { display: grid; grid-template-columns: 88px 1fr; gap: 8px; margin-top: 6px; }
.popup-label { font-size: 12px; color: var(--muted); font-weight: 800; }
.popup-value { font-size: 13px; font-weight: 700; word-break: break-word; }

@media (max-width: 1180px) {
  #topbar {
    left: 12px;
    right: 12px;
    transform: none;
    width: auto;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .controls-wrap { justify-content: flex-start; }
}


/* final filter chip fix */
.filter-chip.tota,
.filter-chip.bota,
.filter-chip.sota,
.filter-chip.wwff,
.filter-chip.pota,
.filter-chip.gma,
.filter-chip.other {
  background: #fff !important;
}

.filter-chip.is-active {
  background: #fff !important;
}

.filter-chip.tota.is-active { border-color: #ec4899 !important; color: #be185d !important; }
.filter-chip.bota.is-active { border-color: #a16207 !important; color: #92400e !important; }
.filter-chip.sota.is-active { border-color: #f59e0b !important; color: #b45309 !important; }
.filter-chip.wwff.is-active { border-color: #15803d !important; color: #166534 !important; }
.filter-chip.pota.is-active { border-color: #2563eb !important; color: #1d4ed8 !important; }
.filter-chip.gma.is-active { border-color: #dc2626 !important; color: #b91c1c !important; }
.filter-chip.other.is-active { border-color: #64748b !important; color: #475569 !important; }

.filter-chip.tota .chip-count { color: #be185d !important; }
.filter-chip.bota .chip-count { color: #92400e !important; }
.filter-chip.sota .chip-count { color: #b45309 !important; }
.filter-chip.wwff .chip-count { color: #166534 !important; }
.filter-chip.pota .chip-count { color: #1d4ed8 !important; }
.filter-chip.gma .chip-count { color: #b91c1c !important; }
.filter-chip.other .chip-count { color: #475569 !important; }


/* fix active ALL chip visibility */
.filter-chip[data-program="ALL"].is-active {
  background: #111827 !important;
  border-color: #111827 !important;
  color: #fff !important;
}

.filter-chip[data-program="ALL"].is-active .chip-count {
  background: rgba(255,255,255,0.16) !important;
  color: #fff !important;
}


/* responsive polish */
#topbar {
  max-width: calc(100vw - 24px);
}

.topbtn,
.langbtn {
  transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}

.topbtn:hover,
.langbtn:hover,
.filter-chip:hover {
  transform: translateY(-1px);
}

.filter-chip {
  background: #fff !important;
}

.filter-chip.is-active {
  box-shadow: inset 0 0 0 1px rgba(15,23,42,0.04);
}

.filter-chip.tota.is-active { background: rgba(236,72,153,0.10) !important; }
.filter-chip.bota.is-active { background: rgba(161,98,7,0.10) !important; }
.filter-chip.sota.is-active { background: rgba(245,158,11,0.12) !important; }
.filter-chip.wwff.is-active { background: rgba(21,128,61,0.10) !important; }
.filter-chip.pota.is-active { background: rgba(37,99,235,0.10) !important; }
.filter-chip.gma.is-active  { background: rgba(220,38,38,0.10) !important; }
.filter-chip.other.is-active { background: rgba(100,116,139,0.10) !important; }

@media (max-width: 820px) {
  #topbar {
    gap: 8px;
    padding: 10px 11px;
    border-radius: 14px;
  }

  .brand { font-size: 18px; }
  .subbrand { font-size: 11px; letter-spacing: 0.04em; }
  .status-line { font-size: 13px; }
  .status-line.muted { font-size: 11px; margin-top: 3px; }
  .controls-wrap { gap: 6px; }
  .topbtn, .langbtn { padding: 8px 10px; font-size: 12px; border-radius: 11px; }
  .refresh-meta { padding: 5px 9px; font-size: 11px; }
  .lang-switch { gap: 5px; }

  #sidePanel {
    left: 12px;
    right: 12px;
    width: auto;
    top: 206px;
    max-height: min(38vh, 320px);
  }

  .panel-head { padding: 10px 12px 9px; }
  .panel-title { font-size: 13px; }
  .panel-body { gap: 8px; padding: 10px 10px 10px; }
  .filter-bar { gap: 6px; }
  .filter-chip { padding: 7px 9px; font-size: 12px; }
  .spot-item { padding: 9px 10px; }
  .spot-call { font-size: 14px; }
  .spot-ref, .spot-meta { font-size: 12px; }
  .spot-age { font-size: 10px; }

  #legend {
    right: 12px;
    bottom: 12px;
    left: auto;
    min-width: 104px;
    padding: 9px 10px;
    opacity: 0.96;
  }

  .legend-title { font-size: 12px; margin-bottom: 7px; }
  .legend-row { font-size: 12px; }

  .leaflet-top.leaflet-left,
  .leaflet-top.leaflet-right { margin-top: 112px; }
}

@media (max-width: 640px) {
  .leaflet-control-zoom { display: none !important; }

  #topbar {
    top: 10px;
    left: 10px;
    right: 10px;
    max-width: none;
    padding: 9px 10px;
  }

  .brand { font-size: 17px; }
  .subbrand { font-size: 10px; }
  .controls-wrap { justify-content: flex-start; }
  .topbtn, .langbtn { padding: 8px 9px; font-size: 11.5px; }
  .refresh-meta { padding: 4px 8px; font-size: 10px; }

  #sidePanel {
    top: 198px;
    max-height: min(35vh, 290px);
  }

  #legend {
    min-width: 98px;
    padding: 8px 9px;
  }
}
