/* Live Disaster Tracker Styles */
/* Mobile-first, performance optimized */

.live-tracker-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 70px);
    max-height: calc(100vh - 70px);
    overflow: hidden;
    background: #f8fafc;
}

/* Header */
.tracker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.header-left h1 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e3a5f;
    margin: 0;
}

.pulse-icon {
    color: #ef4444;
    animation: pulse 2s ease-in-out infinite;
}

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

.last-updated {
    font-size: 0.75rem;
    color: #64748b;
    margin: 0.25rem 0 0 0;
}

.header-right {
    display: flex;
    gap: 0.5rem;
}

.refresh-btn,
.fullscreen-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    color: #475569;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}

.refresh-btn:hover,
.fullscreen-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.refresh-btn.loading svg {
    animation: spin 1s linear infinite;
}

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

/* Layer Controls */
.layer-controls {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    overflow-x: auto;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.layer-controls::-webkit-scrollbar {
    display: none;
}

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    opacity: 0.6;
}

.layer-toggle.active {
    opacity: 1;
    background: white;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.layer-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.earthquake-icon {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #b45309;
}

.wildfire-icon {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #dc2626;
}

.alert-icon {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: #2563eb;
}

.hurricane-icon {
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
    color: #4f46e5;
}

.layer-info {
    display: flex;
    flex-direction: column;
}

.layer-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1e293b;
}

.layer-count {
    font-size: 0.7rem;
    color: #64748b;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch label {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: 0.3s;
    border-radius: 20px;
}

.toggle-switch label:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + label {
    background-color: #3b82f6;
}

.toggle-switch input:checked + label:before {
    transform: translateX(16px);
}

/* Map Container */
.map-container {
    flex: 1;
    position: relative;
    min-height: 300px;
}

#map {
    width: 100%;
    height: 100%;
    background: #1a1a2e;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-overlay p {
    color: #94a3b8;
    margin-top: 1rem;
    font-size: 0.95rem;
}

/* Map Legend */
.map-legend {
    position: absolute;
    bottom: 24px;
    left: 12px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    z-index: 500;
    max-width: 200px;
    font-size: 0.8rem;
}

.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    color: #1e293b;
}

.legend-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: #64748b;
    transition: transform 0.2s;
}

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

.legend-content {
    padding: 0.5rem 0.75rem;
    max-height: 300px;
    overflow-y: auto;
}

.legend-content.collapsed {
    display: none;
}

.legend-section {
    margin-bottom: 0.75rem;
}

.legend-section:last-child {
    margin-bottom: 0;
}

.legend-section[data-layer] {
    display: none;
}

.legend-section.visible {
    display: block;
}

.legend-title {
    font-weight: 600;
    color: #475569;
    margin-bottom: 0.4rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    color: #64748b;
}

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

.legend-marker.eq-marker {
    border-radius: 50%;
}

.legend-line {
    width: 20px;
    height: 3px;
    border-radius: 2px;
}

.hurricane-marker {
    width: 14px;
    height: 14px;
    background: #4f46e5;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
}

/* Event Feed */
.event-feed {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 320px;
    max-height: calc(100% - 24px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 500;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.feed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.feed-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
}

.feed-filters select {
    padding: 0.35rem 0.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.8rem;
    color: #475569;
    background: white;
}

.feed-list {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
}

.feed-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.2s;
}

.feed-item:hover {
    background: #f8fafc;
}

.feed-item.earthquake .feed-icon {
    background: #fef3c7;
    color: #b45309;
}

.feed-item.wildfire .feed-icon {
    background: #fee2e2;
    color: #dc2626;
}

.feed-item.alert .feed-icon {
    background: #dbeafe;
    color: #2563eb;
}

.feed-item.hurricane .feed-icon {
    background: #e0e7ff;
    color: #4f46e5;
}

.feed-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.feed-icon svg {
    width: 18px;
    height: 18px;
}

.feed-details {
    flex: 1;
    min-width: 0;
}

.feed-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 0.2rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.feed-meta {
    font-size: 0.75rem;
    color: #64748b;
    display: flex;
    gap: 0.5rem;
}

.feed-empty {
    padding: 2rem;
    text-align: center;
    color: #94a3b8;
    font-size: 0.9rem;
}

/* Info Panel */
.info-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 380px;
    height: 100%;
    background: white;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 600;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.info-panel.open {
    transform: translateX(0);
}

.close-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: #64748b;
    border-radius: 8px;
    transition: background 0.2s;
}

.close-panel:hover {
    background: #f1f5f9;
}

.panel-content {
    padding: 1.5rem;
}

.panel-content h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 0.5rem 0;
    padding-right: 2rem;
}

.panel-content .event-type {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.panel-content .event-type.earthquake {
    background: #fef3c7;
    color: #b45309;
}

.panel-content .event-type.wildfire {
    background: #fee2e2;
    color: #dc2626;
}

.panel-content .event-type.alert {
    background: #dbeafe;
    color: #2563eb;
}

.panel-content .event-type.hurricane {
    background: #e0e7ff;
    color: #4f46e5;
}

.panel-content .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0;
    border-bottom: 1px solid #f1f5f9;
}

.panel-content .detail-label {
    color: #64748b;
    font-size: 0.85rem;
}

.panel-content .detail-value {
    color: #1e293b;
    font-weight: 500;
    font-size: 0.85rem;
    text-align: right;
}

.panel-content .description {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #475569;
    line-height: 1.6;
}

.panel-content .action-btn {
    display: block;
    width: 100%;
    padding: 0.75rem;
    margin-top: 1rem;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background 0.2s;
}

.panel-content .action-btn:hover {
    background: #2563eb;
}

/* Fullscreen mode */
.live-tracker-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    z-index: 9999;
}

/* ==================== */
/* Mobile Optimizations */
/* ==================== */

@media (max-width: 768px) {
    .live-tracker-container {
        height: calc(100vh - 60px);
    }

    .tracker-header {
        padding: 0.5rem 0.75rem;
    }

    .header-left h1 {
        font-size: 1.1rem;
    }

    .btn-text {
        display: none;
    }

    .refresh-btn,
    .fullscreen-btn {
        padding: 0.5rem;
    }

    /* Layer controls scroll horizontally */
    .layer-controls {
        padding: 0.5rem;
        gap: 0.4rem;
    }

    .layer-toggle {
        padding: 0.4rem 0.6rem;
    }

    .layer-icon {
        width: 28px;
        height: 28px;
    }

    .layer-name {
        font-size: 0.8rem;
    }

    .layer-count {
        display: none;
    }

    /* Event feed becomes bottom sheet on mobile */
    .event-feed {
        position: absolute;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 40%;
        border-radius: 16px 16px 0 0;
        transform: translateY(calc(100% - 50px));
        transition: transform 0.3s ease;
    }

    .event-feed.expanded {
        transform: translateY(0);
    }

    .feed-header {
        cursor: pointer;
    }

    .feed-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 2px;
    }

    .feed-list {
        max-height: none;
    }

    /* Info panel full screen on mobile */
    .info-panel {
        width: 100%;
    }

    /* Legend smaller on mobile */
    .map-legend {
        bottom: 60px;
        max-width: 160px;
        font-size: 0.7rem;
    }
}

@media (max-width: 480px) {
    .layer-info {
        display: none;
    }

    .layer-toggle {
        padding: 0.5rem;
    }

    .toggle-switch {
        display: none;
    }
}

/* Landscape phone */
@media (max-width: 768px) and (orientation: landscape) {
    .live-tracker-container {
        height: 100vh;
    }

    .tracker-header {
        display: none;
    }

    .layer-controls {
        position: absolute;
        top: 8px;
        left: 8px;
        right: auto;
        z-index: 500;
        background: rgba(255, 255, 255, 0.95);
        border-radius: 8px;
        padding: 0.4rem;
    }

    .event-feed {
        max-height: 50%;
    }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
    .event-feed {
        width: 280px;
    }

    .info-panel {
        width: 340px;
    }
}

/* Custom Leaflet marker styles */
.earthquake-marker {
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.wildfire-marker {
    background: #ff6b35;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    animation: fire-pulse 1.5s ease-in-out infinite;
}

@keyframes fire-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 53, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(255, 107, 53, 0); }
}

/* Leaflet popup customization */
.leaflet-popup-content-wrapper {
    border-radius: 10px;
    padding: 0;
}

.leaflet-popup-content {
    margin: 0;
    min-width: 200px;
}

.popup-content {
    padding: 0.75rem;
}

.popup-content h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    color: #1e293b;
}

.popup-content p {
    margin: 0.25rem 0;
    font-size: 0.8rem;
    color: #64748b;
}

.popup-content .magnitude {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    background: #fef3c7;
    color: #b45309;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Alert Notification Button */
.alert-notification-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    color: #475569;
    transition: all 0.2s;
}

.alert-notification-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.alert-notification-btn.has-alerts {
    border-color: #f59e0b;
    color: #f59e0b;
}

.alert-notification-btn.has-alerts:hover {
    background: #fffbeb;
}

.alert-notification-btn.has-extreme {
    border-color: #dc2626;
    color: #dc2626;
    animation: alert-pulse 2s ease-in-out infinite;
}

.alert-notification-btn.has-extreme:hover {
    background: #fef2f2;
}

@keyframes alert-pulse {
    0%, 100% { 
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4);
    }
    50% { 
        box-shadow: 0 0 0 8px rgba(220, 38, 38, 0);
    }
}

.alert-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #dc2626;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s;
}

.alert-badge.visible {
    opacity: 1;
    transform: scale(1);
}

/* Alerts Panel */
.alerts-panel {
    position: fixed;
    top: 70px;
    right: -400px;
    width: 380px;
    max-width: calc(100vw - 20px);
    height: calc(100vh - 90px);
    background: white;
    border-left: 1px solid #e2e8f0;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}

.alerts-panel.open {
    right: 0;
}

.alerts-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, #fef3c7 0%, #fef9c3 100%);
}

.alerts-panel-header h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #92400e;
}

.alerts-panel-header svg {
    color: #f59e0b;
}

.close-alerts-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    cursor: pointer;
    color: #78716c;
    transition: all 0.2s;
}

.close-alerts-panel:hover {
    background: rgba(255, 255, 255, 0.8);
    color: #1c1917;
}

.alerts-panel-filters {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #fafaf9;
}

.alerts-panel-filters select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: white;
    font-size: 0.85rem;
    color: #374151;
    cursor: pointer;
}

.alerts-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.alert-item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: #f8fafc;
    border-radius: 8px;
    border-left: 4px solid #3b82f6;
    cursor: pointer;
    transition: all 0.2s;
}

.alert-item:hover {
    background: #f1f5f9;
    transform: translateX(2px);
}

.alert-item.severity-extreme {
    border-left-color: #dc2626;
    background: #fef2f2;
}

.alert-item.severity-extreme:hover {
    background: #fee2e2;
}

.alert-item.severity-severe {
    border-left-color: #f59e0b;
    background: #fffbeb;
}

.alert-item.severity-severe:hover {
    background: #fef3c7;
}

.alert-item.severity-moderate {
    border-left-color: #3b82f6;
}

.alert-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.alert-item-type {
    font-weight: 600;
    font-size: 0.9rem;
    color: #1e293b;
}

.alert-item-severity {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    background: #e2e8f0;
    color: #64748b;
}

.alert-item-severity.extreme {
    background: #dc2626;
    color: white;
}

.alert-item-severity.severe {
    background: #f59e0b;
    color: white;
}

.alert-item-headline {
    font-size: 0.8rem;
    color: #475569;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.alert-item-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: #94a3b8;
}

.alerts-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: #94a3b8;
    text-align: center;
}

.alerts-empty svg {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Alerts Panel Overlay (mobile) */
.alerts-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.alerts-panel-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* Mobile: Alerts Panel full width */
@media (max-width: 480px) {
    .alerts-panel {
        width: 100%;
        right: -100%;
    }
    
    .alert-notification-btn {
        width: 36px;
        height: 36px;
    }
    
    .alert-badge {
        top: -4px;
        right: -4px;
        min-width: 16px;
        height: 16px;
        font-size: 0.65rem;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .pulse-icon,
    .loading-spinner,
    .wildfire-marker,
    .alert-notification-btn.has-extreme {
        animation: none;
    }

    .info-panel,
    .event-feed,
    .alerts-panel {
        transition: none;
    }
}
