/* ═══════════════════════════════════════════════════════════════
   RadarRewind — Styles
   Dark radar-scope aesthetic with modern UI
   ═══════════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-surface: #1a2332;
    --bg-hover: #1e2d40;
    --bg-input: #0f1923;
    --border: #1e2d40;
    --border-focus: #00d4ff;
    --text-primary: #e0e6f0;
    --text-secondary: #8899aa;
    --text-muted: #556677;
    --accent: #00d4ff;
    --accent-dim: #00a0cc;
    --accent-glow: rgba(0, 212, 255, 0.15);
    --green: #00ff88;
    --green-dim: #00cc66;
    --red: #ff3355;
    --yellow: #ffd700;
    --sidebar-width: 340px;
    --radius: 8px;
    --radius-sm: 5px;
    --transition: 0.2s ease;
}

/* ── Reset & Base ──────────────────────────────────────────── */

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ────────────────────────────────────────────────── */

body {
    display: flex;
}

.map-container {
    flex: 1;
    position: relative;
    height: 100vh;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
}

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease, width 0.3s ease;
    flex-shrink: 0;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
    width: 0;
    border: none;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    color: var(--accent);
    flex-shrink: 0;
}

.logo h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-primary);
    line-height: 1.2;
}

.logo-tagline {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: var(--transition);
}

.sidebar-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.sidebar-toggle svg {
    width: 16px;
    height: 16px;
}

.sidebar.collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

.sidebar-content {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ── Control Groups ────────────────────────────────────────── */

.control-group {
    margin-bottom: 20px;
}

.control-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.control-label svg {
    opacity: 0.6;
}

.control-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.control-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.control-input::placeholder {
    color: var(--text-muted);
}

/* Date input styling */
input[type="date"] {
    color-scheme: dark;
}

select.control-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238899aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ── Station Search ────────────────────────────────────────── */

.station-search-container {
    position: relative;
}

.station-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    max-height: 240px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.station-dropdown.visible {
    display: block;
}

.station-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.1s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.station-option:hover,
.station-option.highlighted {
    background: var(--bg-hover);
}

.station-option .station-id {
    font-weight: 600;
    color: var(--accent);
    font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Cascadia Code', monospace;
}

.station-option .station-name {
    color: var(--text-secondary);
    margin-left: 4px;
}

.station-info {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.station-info .active {
    color: var(--green);
}

/* ── Time Controls ─────────────────────────────────────────── */

.time-controls {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.scan-count {
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
}

/* ── Interesting Events ────────────────────────────────────── */

.events-status {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.events-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
}

.event-item {
    width: 100%;
    text-align: left;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 8px 10px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.event-item:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.event-item-title {
    font-size: 12px;
    color: var(--accent);
    font-weight: 600;
}

.event-item-meta {
    margin-top: 2px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ── Product Buttons ───────────────────────────────────────── */

.product-buttons {
    display: flex;
    gap: 6px;
}

.product-btn {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.product-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.product-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Animation Controls ────────────────────────────────────── */

.animation-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.anim-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.anim-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.anim-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.anim-btn svg {
    width: 20px;
    height: 20px;
}

.play-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.play-btn:hover:not(:disabled) {
    background: rgba(0, 212, 255, 0.25);
}

.play-btn.playing {
    background: rgba(0, 255, 136, 0.15);
    border-color: var(--green);
    color: var(--green);
}

.anim-setting {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-top: 6px;
}

.anim-setting label {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 44px;
}

.anim-setting input[type="range"] {
    flex: 1;
    height: 4px;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.anim-setting input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-secondary);
}

.anim-setting-value {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    font-family: 'SF Mono', 'Fira Code', monospace;
    min-width: 20px;
    text-align: right;
}

/* ── Share Button ──────────────────────────────────────────── */

.share-btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--accent-glow);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
    font-family: inherit;
}

.share-btn:hover {
    background: rgba(0, 212, 255, 0.25);
    border-color: var(--accent);
}

.share-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.share-btn-secondary {
    width: auto;
    min-width: 96px;
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-secondary);
}

.share-btn-secondary:hover {
    color: var(--accent);
}

.share-toast {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--green-dim);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 12px;
    text-align: center;
    display: none;
    animation: toast-in 0.3s ease;
}

.share-toast.visible {
    display: block;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Color Legend ───────────────────────────────────────────── */

.legend-group {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.color-legend {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

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

.legend-swatch {
    width: 24px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

.legend-label {
    font-size: 11px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-muted);
}

/* ── Loading Overlay ───────────────────────────────────────── */

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 14, 23, 0.85);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 500;
    backdrop-filter: blur(4px);
}

.loading-overlay.visible {
    display: flex;
}

.radar-spinner {
    width: 100px;
    height: 100px;
    position: relative;
}

.spinner-ring {
    position: absolute;
    border: 1px solid;
    border-radius: 50%;
}

.ring-1 {
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    border-color: rgba(0, 212, 255, 0.15);
}

.ring-2 {
    width: 66%;
    height: 66%;
    top: 17%;
    left: 17%;
    border-color: rgba(0, 212, 255, 0.25);
}

.ring-3 {
    width: 33%;
    height: 33%;
    top: 33.5%;
    left: 33.5%;
    border-color: rgba(0, 212, 255, 0.35);
}

.spinner-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    top: calc(50% - 3px);
    left: calc(50% - 3px);
}

.spinner-sweep {
    position: absolute;
    width: 50%;
    height: 2px;
    top: calc(50% - 1px);
    left: 50%;
    background: linear-gradient(90deg, var(--accent), transparent);
    transform-origin: left center;
    animation: radar-sweep 2s linear infinite;
}

@keyframes radar-sweep {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.loading-progress {
    margin-top: 16px;
    width: 220px;
    display: none;
}

.loading-progress.visible {
    display: block;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--green));
    border-radius: 2px;
    transition: width 0.3s ease;
}

.progress-text {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ── Map Info Bar ──────────────────────────────────────────── */

.map-info-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(17, 24, 39, 0.9);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-secondary);
    display: none;
    font-family: 'SF Mono', 'Fira Code', monospace;
    z-index: 400;
}

.map-info-bar.visible {
    display: flex;
    align-items: center;
    gap: 20px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.info-label {
    color: var(--text-muted);
}

.info-value {
    color: var(--accent);
    font-weight: 600;
}

/* ── Mobile Toggle ─────────────────────────────────────────── */

.mobile-sidebar-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1001;
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* Show the reopen button only when sidebar is collapsed. */
.sidebar.collapsed + .mobile-sidebar-btn {
    display: flex;
}

.mobile-sidebar-btn svg {
    width: 20px;
    height: 20px;
}

/* ── Leaflet Overrides ─────────────────────────────────────── */

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

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

.leaflet-control-attribution {
    background: rgba(17, 24, 39, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
}

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

.leaflet-popup-content-wrapper {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.leaflet-popup-tip {
    background: var(--bg-surface);
    border: 1px solid var(--border);
}

.leaflet-popup-content {
    font-size: 13px;
    margin: 10px 14px;
}

.station-popup-title {
    font-weight: 700;
    color: var(--accent);
    font-family: 'SF Mono', monospace;
    font-size: 14px;
}

.station-popup-name {
    color: var(--text-secondary);
    margin-top: 2px;
}

.station-popup-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 10px;
    background: var(--accent-glow);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.station-popup-btn:hover {
    background: rgba(0, 212, 255, 0.25);
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .sidebar-toggle {
        display: flex;
    }

    .map-container {
        width: 100vw;
    }
}

@media (max-width: 480px) {
    :root {
        --sidebar-width: 300px;
    }
}
