/* BayAware Map Page Styles — dark professional theme */

/* Map Container */
.map-container {
    position: relative;
    height: calc(100vh - 64px);
    width: 100%;
    overflow: hidden;
    background: var(--bg);
}

.incident-map {
    height: 100%;
    width: 100%;
    border-radius: 0;
    z-index: 1;
}

/* Shared panel chrome */
.map-controls,
.map-legend,
.map-stats {
    position: absolute;
    z-index: 1000;
    background: rgba(17, 19, 23, 0.96);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 14px 12px;
    color: var(--text);
    font-size: 13px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.map-controls { top: 16px;    right: 16px;  width: 240px; max-height: calc(100vh - 96px); overflow-y: auto; }
.map-legend   { bottom: 16px; right: 16px;  width: 200px; }
.map-stats    { bottom: 16px; left: 16px;   width: 240px; }

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.panel-header h3 {
    margin: 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.toggle-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.toggle-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.panel-content {
    transition: max-height 0.25s ease, opacity 0.2s ease;
    overflow: hidden;
}

/* Controls */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}
.control-group:last-child { margin-bottom: 0; }

.control-group label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.control-group select {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%238a8f9a' d='M5 6L0 0h10z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
    cursor: pointer;
}

.control-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.control-actions {
    flex-direction: row;
    gap: 6px;
}

.map-btn {
    flex: 1;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    font-family: inherit;
}

.map-btn-primary {
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
}
.map-btn-primary:hover { background: #2563eb; border-color: #2563eb; }
.map-btn-primary:not(.active) {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.map-btn-primary:not(.active):hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.map-btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.map-btn-secondary:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

/* Legend */
.legend-section { margin-bottom: 12px; }
.legend-section:last-child { margin-bottom: 0; }

.map-legend h4 {
    margin: 0 0 8px 0;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Category palette */
.legend-dot.cat-traffic     { background: #60a5fa; }
.legend-dot.cat-theft       { background: #f59e0b; }
.legend-dot.cat-medical     { background: #10b981; }
.legend-dot.cat-disturbance { background: #f97316; }
.legend-dot.cat-fire        { background: #ef4444; }
.legend-dot.cat-other       { background: #8a8f9a; }

/* Recency palette */
.legend-dot.rec-new    { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18); }
.legend-dot.rec-recent { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
.legend-dot.rec-old    { background: #5d6270; }

/* Live stats */
.live-pip {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
    animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

/* Live Radio Player */
.map-radio {
    position: absolute;
    top: 1rem;
    left: 1rem;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid var(--fog-dark);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    backdrop-filter: blur(15px);
    min-width: 280px;
    max-width: 320px;
    max-height: 80vh;
    overflow-y: auto;
}

.radio-player {
    margin-top: 1rem;
}

#radio-audio {
    width: 100%;
    height: 32px;
    margin-bottom: 0.75rem;
    border-radius: 8px;
}

.radio-info {
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    background: var(--fog-light);
    border-radius: 8px;
    border-left: 4px solid var(--bay-blue);
}

.feed-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

#feed-name {
    font-weight: 600;
    color: var(--charcoal);
    font-size: 0.875rem;
}

.feed-description {
    font-size: 0.75rem;
    color: var(--tech-gray);
    line-height: 1.3;
}

.status-indicator {
    font-size: 0.75rem;
    animation: blink 2s infinite;
}

.radio-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.radio-btn {
    background: var(--bay-blue);
    color: var(--fog-white);
    border: none;
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.radio-btn:hover {
    background: var(--bay-blue-dark);
    transform: translateY(-1px);
}

#volume-slider {
    flex: 1;
    height: 4px;
    background: var(--fog-dark);
    border-radius: 2px;
    outline: none;
    appearance: none;
}

#volume-slider::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bay-blue);
    cursor: pointer;
}

#volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bay-blue);
    cursor: pointer;
    border: none;
}

.radio-disclaimer {
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: rgba(255, 193, 7, 0.1);
    border-radius: 6px;
    border-left: 3px solid var(--warning);
}

.radio-disclaimer small {
    font-size: 0.7rem;
    color: var(--tech-gray);
    line-height: 1.4;
}

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

/* Live Stats */
.map-stats {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid var(--fog-dark);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    backdrop-filter: blur(15px);
    min-width: 200px;
    max-width: 260px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.stat-item:last-child {
    margin-bottom: 0;
}

.stat-item {
    margin-bottom: 8px;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.stat-value {
    font-size: 13px;
    color: var(--text);
    font-weight: 600;
}

.stat-value.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
}

/* Optimized Radar Ping Animation - Reduced intensity for better performance */
@keyframes radar-ping {
    0% {
        transform: scale(0.5);
        opacity: 0.8;
    }
    50% {
        opacity: 0.4;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

@keyframes pulse-new {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.08);
    }
}

@keyframes pulse-recent {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

@keyframes incident-pulse {
    0%, 100% {
        opacity: 0.85;
        box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    }
    50% {
        opacity: 1;
        box-shadow: 0 3px 10px rgba(0,0,0,0.35);
    }
}

.incident-marker {
    /* Remove conflicting positioning styles - let Leaflet handle positioning */
    position: absolute !important;
}

.incident-marker .marker-content {
    /* Apply animation to content, not the positioned container */
    animation: incident-pulse 4s infinite;
    will-change: transform, opacity; /* Optimize for hardware acceleration */
}

.incident-marker.new .marker-content {
    animation: incident-pulse 2.5s infinite;
    will-change: transform, opacity;
}

.incident-marker.recent .marker-content {
    animation: incident-pulse 3.5s infinite;
    will-change: transform, opacity;
}

.incident-marker.old .marker-content {
    animation: none;
    opacity: 0.7;
}

/* Condensed marker styles for performance optimization */
.condensed-marker {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.condensed-marker:hover {
    transform: scale(1.1);
    z-index: 1000;
}

.condensed-content {
    transition: all 0.2s ease;
    will-change: transform;
}

.condensed-popup .leaflet-popup-content-wrapper {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb;
}

.condensed-popup-content {
    padding: 4px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.condensed-header {
    font-size: 14px;
    color: #111827;
    margin-bottom: 8px;
}

.condensed-details {
    font-size: 12px;
    color: #4b5563;
    line-height: 1.4;
}

.condensed-details div {
    margin-bottom: 4px;
}

/* Optimize hover effects for better performance */
.condensed-marker .condensed-content:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* Radar Overlay */
.radar-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200px;
    height: 200px;
    margin: -100px 0 0 -100px;
    border: 2px solid #ef4444;
    border-radius: 50%;
    opacity: 0.3;
    z-index: 500;
    pointer-events: none;
}

.radar-sweep {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 2px;
    margin: -1px 0 0 0;
    background: linear-gradient(90deg, transparent, #ef4444);
    transform-origin: left center;
    animation: radar-sweep 4s linear infinite;
}

/* Standardized Precinct Radar Markers - Same style for all cities */
.precinct-radar-marker {
    background: transparent !important;
    border: none !important;
}

.radar-station {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(239, 68, 68, 0.2) 0%, rgba(239, 68, 68, 0.1) 50%, transparent 70%);
    border: 2px solid #ef4444;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
    animation: pulse-radar 2s ease-in-out infinite;
}

.radar-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
}

.radar-station .radar-sweep {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 2px;
    margin: -1px 0 0 0;
    background: linear-gradient(90deg, transparent, #ef4444);
    transform-origin: left center;
    animation: radar-sweep 3s linear infinite;
}

@keyframes pulse-radar {
    0%, 100% {
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 30px rgba(239, 68, 68, 0.8);
        transform: scale(1.05);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-nav {
        gap: 0.5rem;
    }
    
    .nav-link {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    .map-container {
        height: calc(100vh - 100px);
        margin: 0;
    }
    
    .incident-map {
        border-radius: 0;
    }
    
    /* Mobile-friendly panel positioning */
    .map-controls {
        position: fixed;
        bottom: 1rem;
        left: 1rem;
        right: 1rem;
        top: auto;
        min-width: auto;
        max-width: none;
        padding: 0.75rem;
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
        z-index: 1001; /* Higher than legend/stats */
    }
    
    .panel-header h3 {
        font-size: 0.85rem;
    }
    
    .toggle-btn {
        width: 24px;
        height: 24px;
        font-size: 0.9rem;
    }
    
    .control-group {
        margin-bottom: 0.75rem;
        gap: 0.5rem;
    }
    
    .control-group label {
        font-size: 0.8rem;
        margin-bottom: 0.25rem;
    }
    
    .control-group select {
        padding: 0.6rem;
        font-size: 0.85rem;
        border-radius: 8px;
        width: 100%;
    }
    
    .radar-btn, .refresh-btn {
        padding: 0.7rem 1rem;
        font-size: 0.85rem;
        width: 100%;
        border-radius: 8px;
        min-height: 44px; /* Touch-friendly size */
    }
    
    /* Compact legend for mobile - move to top right */
    .map-legend {
        bottom: auto;
        top: 1rem;
        right: 1rem;
        left: auto;
        padding: 0.6rem;
        min-width: 140px;
        max-width: 160px;
        border-radius: 12px;
        max-height: 30vh;
        z-index: 999; /* Lower than controls */
    }
    
    .legend-section {
        margin-bottom: 0.75rem;
    }
    
    .legend-section h4 {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }
    
    .legend-items {
        gap: 0.25rem;
        margin-bottom: 0.5rem;
    }
    
    .legend-item {
        font-size: 0.75rem;
        gap: 0.4rem;
    }
    
    /* Compact stats for mobile - move to top left */
    .map-stats {
        top: 1rem;
        bottom: auto;
        left: 1rem;
        right: auto;
        padding: 0.6rem;
        min-width: 140px;
        max-width: 160px;
        border-radius: 12px;
        z-index: 999; /* Lower than controls */
    }
    
    .stat-item {
        margin-bottom: 0.5rem;
        gap: 0.25rem;
        align-items: flex-start;
    }
    
    .stat-item:last-child {
        margin-bottom: 0;
    }
    
    .stat-label {
        font-size: 0.75rem;
        line-height: 1.2;
    }
    
    .stat-value {
        font-size: 0.8rem;
        font-weight: 700;
    }
}

/* Tablet screens */
@media (max-width: 1024px) and (min-width: 769px) {
    .map-controls {
        min-width: 200px;
        max-width: 220px;
        padding: 0.8rem;
    }
    
    .map-legend {
        min-width: 160px;
        max-width: 180px;
        max-height: 50vh;
    }
    
    .map-stats {
        min-width: 160px;
        max-width: 180px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .map-controls {
        left: 0.5rem;
        right: 0.5rem;
        bottom: 0.5rem;
        padding: 0.6rem;
    }
    
    /* Stack panels vertically on small screens */
    .map-legend {
        top: 0.5rem;
        right: 0.5rem;
        left: auto;
        min-width: 120px;
        max-width: 140px;
        padding: 0.5rem;
        max-height: 25vh;
    }
    
    .map-stats {
        top: 0.5rem;
        left: 0.5rem;
        right: auto;
        min-width: 120px;
        max-width: 140px;
        padding: 0.5rem;
    }
    
    .panel-header h3 {
        font-size: 0.75rem;
    }
    
    .toggle-btn {
        width: 20px;
        height: 20px;
        font-size: 0.7rem;
    }
    
    /* Smaller text on very small screens */
    .legend-item {
        font-size: 0.65rem;
    }
    
    .stat-label {
        font-size: 0.65rem;
    }
    
    .stat-value {
        font-size: 0.7rem;
    }
    
    .control-group label {
        font-size: 0.7rem;
    }
    
    .control-group select {
        font-size: 0.75rem;
        padding: 0.5rem;
    }
}

/* Custom Leaflet Popup Styles — dark theme */
.leaflet-popup-content-wrapper {
    background: #15171c;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    color: var(--text);
}

.leaflet-popup-content {
    margin: 0;
    padding: 14px;
    color: var(--text);
    font-family: inherit;
    line-height: 1.5;
    font-size: 13px;
}

.leaflet-popup-tip {
    background: #15171c;
    border: 1px solid var(--border);
    border-top: none;
    border-right: none;
}

.leaflet-popup-close-button {
    color: var(--text-muted) !important;
    font-size: 18px !important;
    padding: 6px 8px 0 0 !important;
}
.leaflet-popup-close-button:hover { color: var(--text) !important; }

.popup-incident { max-width: 280px; }

.popup-header {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.popup-category { display: none; }

.popup-header { flex-wrap: wrap; }

.popup-city {
    color: var(--text);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-right: auto;
}

.popup-cat-tag,
.popup-sev-tag {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.popup-cat-tag.cat-traffic     { color: #93c5fd; border-color: rgba(96,165,250,0.35); }
.popup-cat-tag.cat-medical     { color: #6ee7b7; border-color: rgba(16,185,129,0.35); }
.popup-cat-tag.cat-fire        { color: #fca5a5; border-color: rgba(239,68,68,0.35); }
.popup-cat-tag.cat-theft       { color: #fcd34d; border-color: rgba(245,158,11,0.35); }
.popup-cat-tag.cat-disturbance { color: #fdba74; border-color: rgba(249,115,22,0.35); }

.popup-sev-tag.sev-major    { color: #fca5a5; border-color: rgba(239,68,68,0.45); }
.popup-sev-tag.sev-moderate { color: #fdba74; border-color: rgba(249,115,22,0.45); }
.popup-sev-tag.sev-minor    { color: #fde68a; border-color: rgba(234,179,8,0.45); }

.popup-description {
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text);
}

.popup-time {
    color: var(--text-muted);
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.popup-source-btn {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: border-color 0.15s ease, color 0.15s ease;
    font-family: inherit;
}

.popup-source-btn:hover {
    border-color: var(--accent);
    color: #60a5fa;
}