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

:root {
    --bg: #fff;
    --text: #333;
    --text-muted: #666;
    --text-faint: #888;
    --text-fainter: #999;
    --border: #ccc;
    --border-light: #eee;
    --border-lighter: #f0f0f0;
    --hover-bg: #f5f5f5;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-light: rgba(0, 0, 0, 0.15);
    --input-bg: #fff;
    --clear-btn-bg: #eee;
    --clear-btn-hover: #ddd;
    --popup-heading: #222;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1e1e2e;
        --text: #cdd6f4;
        --text-muted: #a6adc8;
        --text-faint: #7f849c;
        --text-fainter: #6c7086;
        --border: #45475a;
        --border-light: #313244;
        --border-lighter: #2a2a3c;
        --hover-bg: #313244;
        --shadow: rgba(0, 0, 0, 0.5);
        --shadow-light: rgba(0, 0, 0, 0.3);
        --input-bg: #313244;
        --clear-btn-bg: #45475a;
        --clear-btn-hover: #585b70;
        --popup-heading: #cdd6f4;
    }
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#map {
    width: 100%;
    height: 100%;
}

@media (prefers-color-scheme: dark) {
    .leaflet-tile-pane {
        filter: brightness(0.7) contrast(1.1) saturate(0.8);
    }

    .leaflet-popup-content-wrapper,
    .leaflet-popup-tip {
        background: var(--bg);
        color: var(--text);
    }

    .leaflet-popup-content-wrapper {
        box-shadow: 0 3px 14px var(--shadow);
    }

    .leaflet-control-zoom a {
        background: var(--bg);
        color: var(--text);
        border-color: var(--border);
    }

    .leaflet-control-zoom a:hover {
        background: var(--hover-bg);
    }

    .leaflet-control-attribution {
        background: rgba(30, 30, 46, 0.8);
        color: var(--text-fainter);
    }

    .leaflet-control-attribution a {
        color: var(--text-faint);
    }
}

#controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    background: var(--bg);
    border-radius: 8px;
    box-shadow: 0 2px 6px var(--shadow);
    padding: 10px 14px;
    width: 260px;
}

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

.band-label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    min-height: 36px;
    user-select: none;
}

.band-2m {
    color: #1976D2;
}

.band-70cm {
    color: #D32F2F;
}

@media (prefers-color-scheme: dark) {
    .band-2m {
        color: #64b5f6;
    }

    .band-70cm {
        color: #ef5350;
    }
}

#controls .controls-row:first-child input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.network-row {
    margin-top: 4px;
}

.net-label {
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    min-height: 28px;
    user-select: none;
    color: var(--text-muted);
}

.net-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

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

.advanced summary {
    cursor: pointer;
    user-select: none;
    font-size: 10px;
    letter-spacing: 0.03em;
}

.advanced summary:hover {
    color: var(--text-faint);
}

.advanced[open] {
    padding-bottom: 2px;
}

.hotspot-label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 4px;
    user-select: none;
}

.hotspot-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

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

.experimental summary {
    cursor: pointer;
    user-select: none;
    font-size: 10px;
    letter-spacing: 0.03em;
}

.experimental summary:hover {
    color: var(--text-faint);
}

.experimental[open] {
    padding-bottom: 2px;
}

.count {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-faint);
    white-space: nowrap;
}

.search-row {
    margin-top: 6px;
    position: relative;
}

.search-row input[type="text"] {
    width: 100%;
    padding: 7px 28px 7px 10px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 13px;
    outline: none;
    background: var(--input-bg);
    color: var(--text);
}

.search-row input[type="text"]:focus {
    border-color: #4CAF50;
}

.search-clear-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 16px;
    color: var(--text-fainter);
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    border-radius: 3px;
}

.search-clear-btn:hover {
    color: var(--text-muted);
    background: var(--hover-bg);
}

.search-more-msg {
    padding: 6px 2px;
    font-size: 11px;
    color: var(--text-fainter);
    text-align: center;
    border-top: 1px solid var(--border-lighter);
}

.route-row {
    margin-top: 6px;
}

.autocomplete-wrap {
    position: relative;
}

.autocomplete-list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1001;
    background: var(--bg);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 5px 5px;
    list-style: none;
    max-height: 180px;
    overflow-y: auto;
    box-shadow: 0 4px 8px var(--shadow-light);
}

.autocomplete-list.open {
    display: block;
}

.autocomplete-list li {
    padding: 7px 10px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-lighter);
    line-height: 1.3;
}

.autocomplete-list li:last-child {
    border-bottom: none;
}

.autocomplete-list li:hover,
.autocomplete-list li.active {
    background: var(--hover-bg);
}

.autocomplete-list li .ac-main {
    color: var(--text);
}

.autocomplete-list li .ac-sub {
    color: var(--text-fainter);
    font-size: 11px;
}

.autocomplete-list li.ac-loading {
    color: var(--text-fainter);
    display: flex;
    align-items: center;
    gap: 6px;
}

.autocomplete-list li.ac-loading:hover {
    background: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--text-faint);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

#route-btn .spinner {
    width: 14px;
    height: 14px;
    border-color: rgba(255,255,255,0.3);
    border-top-color: white;
    vertical-align: middle;
    margin-right: 4px;
}

.route-row input[type="text"] {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 13px;
    outline: none;
    background: var(--input-bg);
    color: var(--text);
}

.route-row input[type="text"]:focus {
    border-color: #4CAF50;
}

.route-row button {
    flex: 1;
    padding: 7px 0;
    border: none;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
}

#route-btn {
    background: #4CAF50;
    color: white;
}

#route-btn:hover {
    background: #43A047;
}

#route-btn:disabled {
    background: #A5D6A7;
    cursor: default;
}

@media (prefers-color-scheme: dark) {
    #route-btn:disabled {
        background: #2e7d32;
        color: #a5d6a7;
    }
}

#clear-btn {
    background: var(--clear-btn-bg);
    color: var(--text);
}

#clear-btn:hover {
    background: var(--clear-btn-hover);
}

.corridor-label {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.corridor-label input[type="range"] {
    flex: 1;
    cursor: pointer;
}

.corridor-label span {
    min-width: 20px;
    text-align: right;
}

.coords-row {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
    line-height: 1.5;
    min-height: 1.5em;
}

.coords-row .maidenhead {
    color: var(--text-fainter);
}

.pin-controls {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-light);
}

.pin-header {
    justify-content: space-between;
}

.pin-radius-label {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.pin-radius-label input[type="range"] {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.pin-radius-label span {
    min-width: 24px;
    text-align: right;
}

.pin-clear-btn {
    flex-shrink: 0;
    background: var(--clear-btn-bg);
    color: var(--text-muted);
    border: none;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
}

.pin-clear-btn:hover {
    background: var(--clear-btn-hover);
}

.pin-list {
    max-height: 220px;
    overflow-y: auto;
    margin-top: 4px;
}

.pin-list-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 4px 2px;
    border-bottom: 1px solid var(--border-lighter);
    font-size: 12px;
    cursor: pointer;
}

.pin-list-item:last-child {
    border-bottom: none;
}

.pin-list-item:hover {
    background: var(--hover-bg);
}

.pin-list-item .callsign {
    font-weight: 600;
    color: var(--text);
    min-width: 70px;
    text-decoration: none;
}

.pin-list-item .callsign:hover {
    text-decoration: underline;
}

.pin-list-item .freq {
    color: var(--text-muted);
    font-size: 11px;
}

.pin-list-item .dist {
    margin-left: auto;
    color: var(--text-fainter);
    font-size: 11px;
    white-space: nowrap;
}

.attribution {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
    font-size: 10px;
    color: var(--text-fainter);
    line-height: 1.4;
}

.attribution a {
    color: var(--text-faint);
}

/* Popups */

.rptr-popup h3 {
    margin: 0 0 6px 0;
    font-size: 15px;
}

.rptr-popup h3 a {
    color: var(--popup-heading);
    text-decoration: none;
}

.rptr-popup h3 a:hover {
    text-decoration: underline;
}

.rptr-popup table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.rptr-popup td {
    padding: 2px 6px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
    color: var(--text);
}

.rptr-popup td:first-child {
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    width: 80px;
}

.rptr-popup .band-tag {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    color: white;
}

.rptr-popup .band-2m {
    background: #2196F3;
}

.rptr-popup .band-70cm {
    background: #D32F2F;
}

@keyframes heatmap-pulse {
    0%   { opacity: 0.8; }
    50%  { opacity: 0.3; }
    100% { opacity: 0.8; }
}

.heatmap-glow {
    animation: heatmap-pulse 2s ease-in-out infinite;
}

@media (max-width: 768px) {
    #controls {
        top: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        padding: 8px 10px;
    }
}
