/* ============================================================================
   map-v4.css – FM-Funknetz Live Map v4
   Features: Eigene Icons mit Status-Overlay, Zoom-Anpassung, Monitor-TG Suche
   ============================================================================ */

:root { 
  color-scheme: light dark;
  --bg-dark: #0b0c10;
  --bg-panel: rgba(15, 23, 42, 0.95);
  --border: #1f2937;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --accent-blue: #3b82f6;
  --color-tx: #ef4444;
  --color-rx: #fbbf24;
}

* { box-sizing: border-box; }

body { 
  margin: 0; 
  font-family: system-ui, -apple-system, sans-serif; 
  background: var(--bg-dark); 
  color: var(--text); 
}

/* =================== HEADER =================== */
header { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  gap: 12px; 
  padding: 8px 16px; 
  background: #111827; 
  border-bottom: 1px solid #374151;
  position: relative;
  z-index: 1000;
}

h1 { margin: 0; font-size: 18px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--text-muted); font-size: 12px; }

/* Karten-Auswahl Dropdown */
.map-select {
  background: #1f2937;
  color: var(--text);
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

.map-select:hover {
  border-color: var(--accent-blue);
}

.map-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

:root[data-theme="light"] .map-select {
  background: #f3f4f6;
  color: #1f2937;
  border-color: #d1d5db;
}

/* =================== KARTE =================== */
#map { 
  width: 100%; 
  height: calc(100vh - 46px); 
}

/* Attribution Styling */
.leaflet-control-attribution {
  background: rgba(0,0,0,0.6) !important;
  color: #9ca3af !important;
  font-size: 10px;
}

.leaflet-control-attribution a {
  color: var(--accent-blue) !important;
}

:root[data-theme="light"] .leaflet-control-attribution {
  background: rgba(255,255,255,0.8) !important;
  color: #4b5563 !important;
}

/* =================== MARKER STYLES =================== */
.custom-marker {
  transition: transform 0.15s ease, filter 0.15s ease;
}

.custom-marker:hover {
  transform: scale(1.2);
  z-index: 1000 !important;
}

/* Icon-Bilder im Dunkelmodus invertieren */
.marker-icon {
  filter: invert(1) brightness(1.2);
  transition: filter 0.2s;
}

/* RX Status - Dezenter Glow, keine Animation */
.marker-icon.marker-rx {
  filter: invert(1) brightness(1.2) drop-shadow(0 0 4px rgba(251, 191, 36, 0.6));
}

/* Inaktiv - Ausgegraut */
.marker-icon.marker-inactive {
  filter: invert(1) grayscale(100%) opacity(0.35);
}

/* Eigener Standort */
.marker-me-icon {
  filter: invert(1) drop-shadow(0 0 6px rgba(59, 130, 246, 0.7));
}

/* =================== TX WELLEN ANIMATION =================== */
.marker-tx-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-tx-container .marker-icon {
  position: relative;
  z-index: 10;
  filter: invert(1) brightness(1.3) drop-shadow(0 0 8px rgba(239, 68, 68, 0.9));
}

.tx-waves {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tx-wave {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 3px solid #ef4444;
  border-radius: 50%;
  opacity: 0;
  animation: tx-wave-expand 1.5s ease-out infinite;
}

.tx-wave-1 { animation-delay: 0s; }
.tx-wave-2 { animation-delay: 0.5s; }
.tx-wave-3 { animation-delay: 1s; }

@keyframes tx-wave-expand {
  0% {
    width: 20px;
    height: 20px;
    opacity: 0.9;
    border-width: 3px;
  }
  100% {
    width: 80px;
    height: 80px;
    opacity: 0;
    border-width: 1px;
  }
}

/* Alternative: Halbkreis-Wellen links und rechts */
.tx-wave-left, .tx-wave-right {
  position: absolute;
  top: 50%;
  width: 30px;
  height: 60px;
  border: 3px solid #ef4444;
  opacity: 0;
}

.tx-wave-left {
  left: -10px;
  transform: translateY(-50%);
  border-radius: 60px 0 0 60px;
  border-right: none;
  animation: tx-wave-left 1s ease-out infinite;
}

.tx-wave-right {
  right: -10px;
  transform: translateY(-50%);
  border-radius: 0 60px 60px 0;
  border-left: none;
  animation: tx-wave-right 1s ease-out infinite;
}

@keyframes tx-wave-left {
  0% { width: 10px; height: 20px; opacity: 0.9; left: 5px; }
  100% { width: 40px; height: 80px; opacity: 0; left: -25px; }
}

@keyframes tx-wave-right {
  0% { width: 10px; height: 20px; opacity: 0.9; right: 5px; }
  100% { width: 40px; height: 80px; opacity: 0; right: -25px; }
}

/* =================== TOOLTIP/LABEL STYLES =================== */
.node-tooltip {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
}

.node-tooltip::before { display: none !important; }

.lbl { 
  background: rgba(0, 0, 0, 0.85); 
  color: #fff; 
  padding: 4px 10px; 
  border-radius: 6px; 
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,0.1);
}

.lbl-tx {
  background: rgba(239, 68, 68, 0.95) !important;
  border-color: #fff !important;
  animation: label-pulse-tx 0.5s ease-in-out infinite;
}

.lbl-rx {
  background: rgba(100, 100, 100, 0.9) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,0.3) !important;
}

.lbl-me {
  background: rgba(59, 130, 246, 0.9) !important;
  border-color: #fff !important;
}

@keyframes label-pulse-tx {
  0%, 100% { box-shadow: 0 0 8px rgba(239, 68, 68, 0.6); }
  50% { box-shadow: 0 0 16px rgba(239, 68, 68, 1); }
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.tx { background: #fff; animation: dot-blink 0.3s infinite; }
.status-dot.rx { background: #000; }

@keyframes dot-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.talk-call { font-weight: 700; }

.talk-tg, .talk-tg-small {
  font-size: 9px;
  padding: 2px 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  font-weight: 600;
}

/* =================== PANELS GEMEINSAM =================== */
.tg-panel, .talker-panel, .controls {
  position: absolute;
  z-index: 500;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  backdrop-filter: blur(12px);
  font-size: 13px;
}

.panel-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.no-items {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 12px 0;
}

/* =================== TG PANEL =================== */
.tg-panel {
  top: 56px;
  left: 12px;
  width: 260px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.tg-panel .panel-title { color: var(--accent-blue); }

.tg-filter-options {
  margin-bottom: 10px;
  padding: 8px;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
}

.tg-filter-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
}

.tg-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tg-item {
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border: 2px solid var(--tg-color, var(--border));
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.tg-item:hover {
  background: rgba(255,255,255,0.08);
  transform: translateX(4px);
}

.tg-item.selected {
  background: rgba(255,255,255,0.1);
  box-shadow: 0 0 12px rgba(255,255,255,0.1), inset 0 0 20px rgba(255,255,255,0.05);
}

.tg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.tg-name {
  font-weight: 700;
  font-size: 14px;
  flex: 1;
}

.tg-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.tg-badge.tx { background: var(--color-tx); color: #fff; }
.tg-badge.rx { background: #6b7280; color: #fff; }

.tg-talker {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-clear {
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  background: var(--accent-blue);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-clear:hover { background: #2563eb; }

/* =================== TALKER PANEL =================== */
.talker-panel {
  top: 56px;
  left: 284px;
  width: 200px;
  max-height: 280px;
  overflow-y: auto;
}

.talker-panel .panel-title { color: var(--color-tx); }

.talker-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.talker-item {
  padding: 8px 10px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  animation: pulse-bg 1.5s ease-in-out infinite;
}

.talker-item:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--color-tx);
}

@keyframes pulse-bg {
  0%, 100% { box-shadow: 0 0 4px rgba(239, 68, 68, 0.2); }
  50% { box-shadow: 0 0 12px rgba(239, 68, 68, 0.4); }
}

.talker-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.talker-call { font-weight: 700; color: #fff; }

.talker-tg {
  font-size: 10px;
  padding: 2px 6px;
  background: var(--color-tx);
  border-radius: 4px;
  color: #fff;
}

.talker-sub {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

/* =================== CONTROLS (rechts) =================== */
.controls {
  top: 56px;
  right: 12px;
  width: 240px;
}

.controls label { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
  margin: 4px 0;
  cursor: pointer;
  font-size: 12px;
}

.controls label:hover { color: var(--accent-blue); }
.controls hr { border-color: var(--border); margin: 10px 0; }

/* Suche */
.search-section {
  margin-bottom: 12px;
}

.search-section .section-title {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--accent-blue);
}

.search-input-wrap {
  display: flex;
  gap: 6px;
}

.search-input-wrap input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  outline: none;
  font-size: 12px;
}

.search-input-wrap input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.search-input-wrap input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.search-input-wrap button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.controls label:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

.search-input-wrap input::placeholder {
  color: #6b7280;
}

.search-info {
  margin-top: 6px;
  font-size: 11px;
}

.search-result {
  color: var(--color-rx);
  font-weight: 600;
}

.hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Buttons */
.toggle, .btn, .btn-sm {
  font-size: 12px;
  border: 1px solid #374151;
  background: #1f2937;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-sm { padding: 6px 8px; font-size: 11px; }

.toggle:hover, .btn:hover, .btn-sm:hover { background: #374151; }

/* Control Icons (Stationstypen) */
.control-icon {
  width: 18px;
  height: 18px;
  filter: invert(1) brightness(1.2);
  transition: filter 0.2s;
}

/* Section Header mit Zähler */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

/* Zähler Badges */
.count-badge {
  background: var(--accent-blue);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.count-badge.small {
  background: #374151;
  padding: 1px 6px;
  font-size: 10px;
  margin-left: auto;
}

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: #1f2937;
  font-size: 12px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
}

.pill.ok { background: rgba(34, 197, 94, 0.2); border-color: #22c55e; }

/* =================== LEGENDE =================== */
.legend {
  position: absolute;
  bottom: 20px;
  right: 12px;
  z-index: 500;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 11px;
  backdrop-filter: blur(10px);
}

.legend-title { font-weight: 600; margin-bottom: 8px; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
}

.legend-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  filter: invert(1);
}

.legend-icon.tx { filter: invert(1) drop-shadow(0 0 4px rgba(239,68,68,0.8)); }
.legend-icon.rx { filter: invert(1); }
.legend-icon.inactive { filter: invert(1) grayscale(100%) opacity(0.5); }

/* TX Demo in Legende */
.legend-tx-demo {
  position: relative;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legend-tx-demo::before {
  content: '';
  width: 12px;
  height: 12px;
  background: #ef4444;
  border-radius: 50%;
  z-index: 2;
}

.legend-tx-demo .mini-wave {
  position: absolute;
  border: 2px solid #ef4444;
  border-radius: 50%;
  animation: mini-wave 1.2s ease-out infinite;
}

.legend-tx-demo .mini-wave:nth-child(2) {
  animation-delay: 0.4s;
}

@keyframes mini-wave {
  0% { width: 12px; height: 12px; opacity: 0.8; }
  100% { width: 28px; height: 28px; opacity: 0; }
}

/* =================== POPUP =================== */
.leaflet-popup-content-wrapper { 
  background: #fff; 
  color: #111827; 
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}

.leaflet-popup-tip { background: #fff; }

.popup-row { 
  display: flex; 
  justify-content: space-between; 
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
}

.popup-row:last-of-type { border-bottom: none; }
.popup-key { color: #6b7280; min-width: 100px; }
.popup-val { color: #111827; font-weight: 500; text-align: right; }

.popup-status {
  padding: 8px 12px;
  border-radius: 6px;
  margin: 10px 0;
  font-weight: 700;
  font-size: 13px;
}

.popup-status.tx {
  background: var(--color-tx);
  color: #fff;
  animation: pulse-bg 1s infinite;
}

.popup-status.rx {
  background: #e5e7eb;
  color: #374151;
}

/* =================== RESPONSIVE =================== */
@media (max-width: 1100px) {
  .talker-panel { display: none; }
}

@media (max-width: 800px) {
  .tg-panel {
    width: 220px;
  }
  
  .controls {
    width: 200px;
  }
  
  .legend { display: none; }
  h1 { font-size: 14px; }
}

@media (max-width: 600px) {
  .tg-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 35vh;
    border-radius: 12px 12px 0 0;
  }
  
  .controls {
    top: auto;
    bottom: 12px;
    right: 12px;
    width: 180px;
    max-height: 50vh;
    overflow-y: auto;
  }
}

/* =================== SCROLLBAR =================== */
.tg-panel::-webkit-scrollbar,
.talker-panel::-webkit-scrollbar,
.controls::-webkit-scrollbar {
  width: 6px;
}

.tg-panel::-webkit-scrollbar-track,
.talker-panel::-webkit-scrollbar-track,
.controls::-webkit-scrollbar-track {
  background: transparent;
}

.tg-panel::-webkit-scrollbar-thumb,
.talker-panel::-webkit-scrollbar-thumb,
.controls::-webkit-scrollbar-thumb {
  background: #374151;
  border-radius: 3px;
}

/* =================== LIGHT THEME =================== */
:root[data-theme="light"] body { background: #f3f4f6; color: #111827; }

:root[data-theme="light"] header {
  background: linear-gradient(180deg, #f59e0b, #fbbf24);
  color: #1b1300;
}

:root[data-theme="light"] .tg-panel,
:root[data-theme="light"] .talker-panel,
:root[data-theme="light"] .controls,
:root[data-theme="light"] .legend {
  background: rgba(255,255,255,0.95);
  border-color: #d1d5db;
  color: #111827;
}

:root[data-theme="light"] .panel-title {
  border-color: #e5e7eb;
}

:root[data-theme="light"] .tg-filter-options {
  background: rgba(0,0,0,0.05);
}

:root[data-theme="light"] .no-items {
  color: #6b7280;
}

:root[data-theme="light"] .lbl {
  background: rgba(255,255,255,0.95);
  color: #111827;
  border-color: #d1d5db;
}

:root[data-theme="light"] .tg-item { background: rgba(0,0,0,0.03); }
:root[data-theme="light"] .talker-call { color: #111827; }
:root[data-theme="light"] .search-input-wrap input { 
  background: #fff; 
  border-color: #d1d5db;
  color: #111827;
}
:root[data-theme="light"] .toggle,
:root[data-theme="light"] .btn,
:root[data-theme="light"] .btn-sm {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #111827;
}
:root[data-theme="light"] .btn-clear {
  background: var(--accent-blue);
  color: #fff;
}
:root[data-theme="light"] .hint {
  color: #6b7280;
}
:root[data-theme="light"] .section-title {
  color: var(--accent-blue);
}

/* Icons im Light Mode NICHT invertieren */
:root[data-theme="light"] .marker-icon {
  filter: none;
}

:root[data-theme="light"] .marker-icon.marker-rx {
  filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.6));
}

:root[data-theme="light"] .marker-icon.marker-inactive {
  filter: grayscale(100%) opacity(0.35);
}

:root[data-theme="light"] .marker-me-icon {
  filter: drop-shadow(0 0 6px rgba(59, 130, 246, 0.7));
}

:root[data-theme="light"] .marker-tx-container .marker-icon {
  filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.9));
}

/* Control Icons im Light Mode nicht invertieren */
:root[data-theme="light"] .control-icon {
  filter: none;
}

/* Zähler im Light Mode */
:root[data-theme="light"] .count-badge.small {
  background: #e5e7eb;
  color: #374151;
}

/* Status Dots für Online/Offline */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}

.status-dot.online {
  background: #22c55e;
  box-shadow: 0 0 6px #22c55e;
}

.status-dot.offline {
  background: #6b7280;
}

/* Online/Offline Badges */
.count-badge.online-badge {
  background: #166534;
}

.count-badge.offline-badge {
  background: #4b5563;
}

:root[data-theme="light"] .count-badge.online-badge {
  background: #dcfce7;
  color: #166534;
}

:root[data-theme="light"] .count-badge.offline-badge {
  background: #e5e7eb;
  color: #4b5563;
}

/* Offline Marker - Roter Glow */
.marker-offline-icon {
  filter: drop-shadow(0 0 4px #ef4444) drop-shadow(0 0 8px #ef4444);
  opacity: 0.9;
}

.marker-offline .marker-icon {
  filter: drop-shadow(0 0 4px #ef4444) drop-shadow(0 0 8px #ef4444);
  opacity: 0.9;
}

/* Popup Status Styling */
.popup-status.online {
  color: #22c55e;
  font-weight: 600;
  margin: 4px 0;
}

.popup-status.offline {
  color: #ef4444;
  font-weight: 600;
  margin: 4px 0;
}

/* Zoom Button */
.btn-zoom {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-zoom:hover {
  background: #2563eb;
}

:root[data-theme="light"] .btn-zoom {
  background: #3b82f6;
}

/* Legende Icons im Light Mode */
:root[data-theme="light"] .legend-icon {
  filter: none;
}

:root[data-theme="light"] .legend-icon.tx {
  filter: drop-shadow(0 0 4px rgba(239,68,68,0.8));
}

:root[data-theme="light"] .legend-icon.rx {
  filter: none;
}

:root[data-theme="light"] .legend-icon.inactive {
  filter: grayscale(100%) opacity(0.5);
}
