/* Outage Map — ServiceAlert.ai */

.outage-map-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 4.5rem);
    overflow: hidden;
}

/* ── Map Container ───────────────────────────────── */
.map-wrapper {
    flex: 1;
    position: relative;
    min-height: 0;
    isolation: isolate;
}

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

/* Override Leaflet controls for theme */
.leaflet-control-zoom a {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

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

.leaflet-control-attribution {
    background: var(--bg-secondary) !important;
    color: var(--text-tertiary) !important;
    font-size: 10px !important;
}

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

/* ── Sidebar ─────────────────────────────────────── */
.map-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 360px;
    height: 100%;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

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

.sidebar-toggle {
    position: absolute;
    top: 12px;
    left: 372px;
    z-index: 1001;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: left 0.3s ease, background 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.map-sidebar.collapsed + .sidebar-toggle {
    left: 12px;
}

.sidebar-toggle:hover {
    background: var(--bg-tertiary);
}

.sidebar-toggle svg {
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
}

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

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 4px 0;
    color: var(--text-primary);
}

.sidebar-meta {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-meta .live-dot {
    width: 6px;
    height: 6px;
    background: var(--status-operational);
    border-radius: 50%;
    animation: pulse-live 2s infinite;
}

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

/* ── Stats Bar ───────────────────────────────────── */
.sidebar-stats {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.stat-item {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    border-right: 1px solid var(--border-color);
}

.stat-item:last-child {
    border-right: none;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

/* ── Filters ─────────────────────────────────────── */
.sidebar-filters {
    display: flex;
    gap: 6px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.filter-chip {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 100px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.filter-chip.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.filter-chip:hover:not(.active) {
    border-color: var(--text-tertiary);
    color: var(--text-primary);
}

/* ── Event List ──────────────────────────────────── */
.sidebar-events {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.event-card {
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.event-card:hover {
    background: var(--bg-secondary);
    border-color: var(--text-tertiary);
}

.event-card.highlighted {
    border-color: var(--accent);
    background: var(--bg-secondary);
}

.event-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.event-type-badge {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.event-type-badge.service {
    background: rgba(59, 130, 246, 0.15);
    color: #3B82F6;
}

.event-type-badge.network {
    background: rgba(168, 85, 247, 0.15);
    color: #A855F7;
}

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

.event-severity.critical { background: var(--status-major); }
.event-severity.major { background: var(--status-partial); }
.event-severity.minor { background: var(--status-degraded); }

.event-entity {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.event-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.event-confidence {
    display: flex;
    align-items: center;
    gap: 4px;
}

.confidence-bar {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}

.confidence-fill.high { background: var(--status-major); }
.confidence-fill.medium { background: var(--status-partial); }
.confidence-fill.low { background: var(--status-degraded); }

.event-time {
    white-space: nowrap;
}

.event-signals {
    display: flex;
    gap: 3px;
}

.signal-dot {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.signal-dot svg {
    width: 10px;
    height: 10px;
}

.signal-dot.servicealert { background: rgba(59, 130, 246, 0.2); color: #3B82F6; }
.signal-dot.ioda { background: rgba(168, 85, 247, 0.2); color: #A855F7; }
.signal-dot.crowdsource { background: rgba(234, 179, 8, 0.2); color: #EAB308; }

/* ── Resolved Events ─────────────────────────────── */
.event-card.resolved {
    opacity: 0.55;
}

.event-card.resolved .event-entity::after {
    content: 'RESOLVED';
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--status-operational);
    margin-left: 8px;
    vertical-align: middle;
}

/* ── Empty State ─────────────────────────────────── */
.events-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
}

.events-empty svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.events-empty h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.events-empty p {
    font-size: 0.8rem;
    line-height: 1.5;
}

/* ── Map Popups ──────────────────────────────────── */
.leaflet-popup-content-wrapper {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-radius: 10px !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25) !important;
    border: 1px solid var(--border-color) !important;
}

.leaflet-popup-tip {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-top: none !important;
    border-left: none !important;
}

.popup-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.popup-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.popup-confidence {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* ── Loading Overlay ─────────────────────────────── */
.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999;
    text-align: center;
    color: var(--text-secondary);
}

.map-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

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

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 768px) {
    .map-sidebar {
        position: absolute;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 40vh;
        border-right: none;
        border-top: 1px solid var(--border-color);
        border-radius: 16px 16px 0 0;
        transform: translateY(0);
    }

    .map-sidebar.collapsed {
        transform: translateY(calc(100% - 48px));
    }

    .sidebar-toggle {
        display: none;
    }

    .sidebar-header {
        padding: 12px 16px;
        cursor: pointer;
        position: relative;
    }

    .sidebar-header::before {
        content: '';
        display: block;
        width: 32px;
        height: 4px;
        background: var(--text-tertiary);
        border-radius: 2px;
        margin: 0 auto 10px;
        opacity: 0.5;
    }

    .sidebar-stats .stat-item {
        padding: 8px 4px;
    }

    .stat-value {
        font-size: 1rem;
    }

    .sidebar-events {
        padding: 6px 10px;
    }

    .event-card {
        padding: 10px;
    }
}

@media (max-width: 480px) {
    .sidebar-filters {
        padding: 8px 12px;
    }

    .filter-chip {
        font-size: 0.7rem;
        padding: 3px 8px;
    }
}

/* ── Marker cluster overrides ────────────────────── */
.marker-cluster-small {
    background-color: rgba(234, 179, 8, 0.3) !important;
}

.marker-cluster-small div {
    background-color: rgba(234, 179, 8, 0.7) !important;
    color: #000 !important;
    font-weight: 600 !important;
}

.marker-cluster-medium {
    background-color: rgba(232, 116, 44, 0.3) !important;
}

.marker-cluster-medium div {
    background-color: rgba(232, 116, 44, 0.7) !important;
    color: #000 !important;
    font-weight: 600 !important;
}

.marker-cluster-large {
    background-color: rgba(229, 72, 77, 0.3) !important;
}

.marker-cluster-large div {
    background-color: rgba(229, 72, 77, 0.7) !important;
    color: #fff !important;
    font-weight: 600 !important;
}
