/* ==========================================================================
   SKY INCIDENT MAP — PROFESSIONAL AVIATION RESEARCH PLATFORM
   Human-crafted, calm, highly readable UI
   Refined with better-typography (13-15px readable scale), better-colors & better-ui
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap');

*, ::before, ::after {
    box-sizing: border-box;
    border-color: #1e293b;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: #0b0f19;
    color: #e2e8f0;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Map Canvas Container */
#map {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background-color: #0b0f19;
}

/* Top App Header */
.app-topbar {
    background: rgba(15, 23, 42, 0.95) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid #1e293b !important;
    height: 56px !important;
}

/* Left Sidebar Navigation & Incident List */
.modern-sidebar {
    position: absolute !important;
    top: 56px !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 420px !important;
    max-width: 95vw !important;
    background: rgba(15, 23, 42, 0.96) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid #1e293b !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35) !important;
    z-index: 25 !important;
    display: flex !important;
    flex-direction: column !important;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.modern-sidebar.is-collapsed {
    transform: translateX(-100%) !important;
}

/* Sidebar Toggle Handle */
.sidebar-toggle-btn {
    position: absolute;
    top: 20px;
    right: -28px;
    width: 28px;
    height: 48px;
    background: #1e293b;
    border: 1px solid #334155;
    border-left: none;
    border-radius: 0 8px 8px 0;
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 30;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-toggle-btn:hover {
    background: #2563eb;
    color: #ffffff;
}

.sidebar-toggle-btn:active {
    transform: scale(0.96);
}

/* Filter Buttons */
.filter-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1e293b;
    color: #cbd5e1;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.filter-chip:hover, .filter-chip.active {
    background: #2563eb;
    color: #ffffff;
    border-color: #3b82f6;
}

.filter-chip:active {
    transform: scale(0.96);
}

.chip-arrow {
    font-size: 10px;
    opacity: 0.8;
    margin-left: 6px;
}

/* Dropdown Menus */
.modern-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    margin-top: 6px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
    max-height: 280px;
    overflow-y: auto;
    z-index: 50;
}

.modern-dropdown a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    font-size: 13px;
    color: #cbd5e1;
    text-decoration: none;
    border-bottom: 1px solid #1e293b;
    transition: background 0.1s ease;
}

.modern-dropdown a:hover {
    background: #1e293b;
    color: #38bdf8;
    padding-left: 18px;
}

/* Incident Feed Item Cards */
.map-overlay .listing, .modern-sidebar .listing {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px !important;
}

.incident-card {
    display: block;
    background: #131c2e;
    border: 1px solid #1e293b;
    border-radius: 12px;
    padding: 14px 16px;
    text-decoration: none;
    color: #f1f5f9;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
    min-width: 0;
    max-width: 100%;
    flex: 0 0 auto;
    height: auto;
    min-height: max-content;
}

.incident-card:hover {
    background: #1a253c;
    border-color: #3b82f6;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.incident-card:active {
    transform: scale(0.98);
}

.card-date-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 500;
    color: #94a3b8;
    background: #0b1120;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid #1e293b;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.card-fatal-tag {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.fatal-tag-none {
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.fatal-tag-some {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
    margin: 8px 0 4px 0;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    min-width: 0;
}

.card-sub {
    font-size: 13px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

/* Generic Utility Truncate */
.truncate {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}

.break-words {
    overflow-wrap: break-word !important;
    word-wrap: break-word !important;
    word-break: break-word !important;
}

/* Severity Pills */
.severity-pill {
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 500;
    color: #94a3b8;
    background: #0b1120;
    border: 1px solid #1e293b;
    border-radius: 9999px;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.severity-pill:hover {
    color: #f1f5f9;
    border-color: #334155;
    background: #1e293b;
}

.severity-pill.active-severity {
    color: #ffffff;
    background: #2563eb;
    border-color: #3b82f6;
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.35);
}

/* Era Tabs & Decade Pills */
.era-tab {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 8px;
    color: #94a3b8;
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    line-height: 1.25;
}

.era-tab:hover {
    color: #f1f5f9;
    background: rgba(30, 41, 59, 0.7);
    border-color: #334155;
}

.era-tab.active {
    color: #38bdf8;
    background: rgba(14, 165, 233, 0.15);
    border-color: rgba(56, 189, 248, 0.45);
    font-weight: 600;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}

.decade-pill {
    padding: 4px 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    color: #94a3b8;
    background: #0b1120;
    border: 1px solid #1e293b;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    flex: 1;
    min-width: 36px;
    text-align: center;
    line-height: 1.25;
}

.decade-pill:hover {
    color: #38bdf8;
    border-color: #38bdf8;
    background: #1e293b;
}

.decade-pill.active {
    color: #ffffff;
    background: #2563eb;
    border-color: #3b82f6;
    font-weight: 700;
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.4);
}

/* Casualty Mini-Bar */
.casualty-ratio-bar {
    display: flex;
    height: 4px;
    width: 100%;
    border-radius: 2px;
    overflow: hidden;
    background: #1e293b;
    margin-top: 8px;
}

.casualty-ratio-fatal {
    background: #ef4444;
}

.casualty-ratio-survived {
    background: #10b981;
}

/* Floating Timeline Bottom Controller */
.timeline-floating-card {
    background: rgba(15, 23, 42, 0.94) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid #334155 !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45) !important;
    border-radius: 14px !important;
    padding: 12px 18px !important;
}

.map-legend-card {
    background: rgba(15, 23, 42, 0.94) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid #334155 !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4) !important;
    border-radius: 14px !important;
}

.sliderContainer {
    width: 100% !important;
    height: auto !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: none !important;
}

/* IonRangeSlider Theme Overrides */
.irs--round .irs-bar {
    background: #2563eb !important;
}
.irs--round .irs-handle {
    border: 2px solid #3b82f6 !important;
    background-color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}
.irs--round .irs-from, .irs--round .irs-to, .irs--round .irs-single {
    background-color: #1e293b !important;
    color: #ffffff !important;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    border: 1px solid #475569 !important;
    border-radius: 6px !important;
}
.irs--round .irs-line {
    background-color: #334155 !important;
}
.irs--round .irs-grid-text {
    color: #94a3b8 !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 11px !important;
}

/* Map Popup Styling */
.maplibregl-popup-content {
    background: #0f172a !important;
    color: #f8fafc !important;
    border: 1px solid #334155 !important;
    border-radius: 14px !important;
    padding: 16px !important;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5) !important;
    font-family: 'Inter', sans-serif !important;
    max-width: 300px !important;
    min-width: 220px !important;
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
    border-top-color: #0f172a !important;
}

/* Modal and Narrative Scroll Styling */
#modal-narrative-content {
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-line;
    line-height: 1.6;
}

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #475569;
}



#era-buttons, #decade-buttons {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}
.timeline-header {
    align-items: stretch !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
}
.timeline-era-buttons {
    display: flex !important;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 0;
    overflow: visible !important;
}
.timeline-era-buttons.space-x-1 > :not([hidden]) ~ :not([hidden]) {
    margin-left: 0 !important;
}
.timeline-era-buttons .era-tab,
.timeline-era-buttons .incident-era-btn {
    flex: 1 1 88px;
    min-width: 40px;
    max-width: 100%;
    height: auto;
    white-space: normal;
    overflow-wrap: break-word;
    text-align: center;
}
#decade-buttons {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
}
.decade-pill {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* Shared map accessibility and safe-area layout. Keep provider credits visible. */
:root { --map-credit-space: 56px; }
button, select, [role="button"], .maplibregl-ctrl-group button {
    min-height: 36px;
    min-width: 36px;
}
:focus-visible { outline: 3px solid #60a5fa !important; outline-offset: 3px; }
[hidden] { display: none !important; }
[inert] { pointer-events: none; }
.incident-card[role="button"] { text-align: left; }
[data-incident-card] {
    flex: 0 0 auto;
    height: auto;
    min-height: max-content;
    min-width: 0;
}
.map-status-panel {
    position: fixed; top: calc(64px + env(safe-area-inset-top, 0px)); left: 50%;
    transform: translateX(-50%); z-index: 35; width: min(90vw, 420px);
    pointer-events: none;
}
.map-status-panel > div {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 6px; padding: 10px 12px; color: #e2e8f0; background: #0f172a;
    border: 1px solid #475569; border-radius: 12px; font-size: 13px;
    box-shadow: 0 4px 16px #0004; pointer-events: none;
}
.map-status-panel button { pointer-events: auto; flex-shrink: 0; padding: 8px; border: 1px solid #60a5fa; border-radius: 8px; }
.map-status-panel > [data-state="error"] { border-color: #fbbf24; }
.maplibregl-ctrl-bottom-right {
    position: fixed !important; bottom: env(safe-area-inset-bottom, 0px) !important;
    right: env(safe-area-inset-right, 0px) !important; z-index: 60 !important; max-width: 100vw;
}
.maplibregl-ctrl-attrib {
    margin: 0 !important; padding: 0 8px !important; background: #fff !important;
    color: #111827 !important; max-width: 100vw; font-size: 11px !important;
}
.maplibregl-ctrl-attrib a { color: #111827 !important; display: inline-flex; align-items: center; min-height: 44px; text-decoration: underline; }
.maplibregl-ctrl-attrib-inner { white-space: normal; }
.timeline-floating-card { bottom: calc(var(--map-credit-space) + env(safe-area-inset-bottom, 0px)) !important; }
.classic-map-main .maplibregl-ctrl-top-right {
    top: 16px !important;
    right: 16px !important;
}
.classic-map-main .map-legend-card {
    top: 146px !important;
    right: 16px !important;
}
#incident-drawer {
    bottom: calc(var(--map-credit-space) + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 30 !important;
}
#mobile-filter-drawer { bottom: calc(var(--map-credit-space) + env(safe-area-inset-bottom, 0px)) !important; padding-bottom: 16px; }
#myModal { bottom: calc(var(--map-credit-space) + env(safe-area-inset-bottom, 0px)); }
#info-modal { max-height: calc(100dvh - 120px - env(safe-area-inset-bottom, 0px)) !important; }
#left-feed-panel { bottom: calc(180px + env(safe-area-inset-bottom, 0px)) !important; }
#incident-drawer.closed, #mobile-filter-drawer.closed { visibility: hidden; }
#drawer-title, #modal-title { white-space: normal; overflow-wrap: anywhere; }
#drawer-source-link, #myModal a[href] { display: inline-flex; align-items: center; min-height: 44px; }
@media (max-width: 767px) {
    :root { --map-credit-space: 96px; }
    body { height: 100dvh; }
    .timeline-floating-card { padding: 8px !important; max-height: 34dvh; overflow: auto; }
    #left-feed-panel { top: 116px !important; bottom: calc(280px + env(safe-area-inset-bottom, 0px)) !important; min-height: 100px; }
    #incident-drawer { top: 64px !important; }
    #mobile-filter-drawer { max-height: calc(100dvh - 170px) !important; }
    .modern-sidebar .listing { padding-bottom: calc(34dvh + var(--map-credit-space) + env(safe-area-inset-bottom, 0px)) !important; }
    .classic-timeline {
        left: 12px !important;
        width: calc(100vw - 64px) !important;
        max-width: none !important;
        transform: none !important;
        z-index: 26 !important;
    }
    .maplibregl-ctrl-top-right {
        top: calc(56px + env(safe-area-inset-top, 0px) + 4px) !important;
        right: 8px !important;
    }
    .classic-map-main .maplibregl-ctrl-top-right {
        top: 140px !important;
        right: 0 !important;
        z-index: 28 !important;
    }
    .classic-map-main .maplibregl-ctrl-top-right .maplibregl-ctrl {
        margin-right: 0 !important;
    }
    body:has(.incident-timeline) .maplibregl-ctrl-top-right {
        right: 0 !important;
        z-index: 21 !important;
    }
    body:has(.incident-timeline) .maplibregl-ctrl-top-right .maplibregl-ctrl {
        margin-right: 0 !important;
    }
}
@media (min-width: 768px) {
    .modern-sidebar:not(.is-collapsed) + .classic-map-main .classic-timeline {
        left: calc(50% + 210px) !important;
        width: min(672px, calc(100% - 456px)) !important;
    }
}
@media (min-width: 768px) and (max-width: 1279px) {
    #left-feed-panel { bottom: calc(260px + env(safe-area-inset-bottom, 0px)) !important; }
}
@media (max-width: 767px) {
    button, select, [role="button"], .maplibregl-ctrl-group button {
        min-height: 40px;
        min-width: 40px;
    }
    .decade-pill { min-width: 40px !important; min-height: 40px !important; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Detail retry stays inside the keyboard focus boundary. */
#detail-status:not([hidden]) { display: flex; align-items: center; gap: 12px; padding: 12px; color: #e2e8f0; background: #0f172a; border: 1px solid #fbbf24; border-radius: 8px; flex-shrink: 0; }
#detail-status button { padding: 8px; border: 1px solid #60a5fa; border-radius: 8px; }

#toggle-feed-btn { min-height: 36px; }

/* Let fixed provider credits rise above sibling panels. */
#map { z-index: auto; }
.decade-pill { min-width: 36px !important; min-height: 36px !important; }

/* Responsive safeguards: keep controls readable and inside the viewport. */
.filter-chip { min-width: 0; }
.filter-chip > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.incident-search-shell { min-width: 0; }
#listing-sort-select { max-width: min(42vw, 150px); }
#left-feed-panel, #left-feed-panel > * { min-width: 0; }
#left-feed-panel .truncate { min-width: 0; }
#left-feed-panel .feed-panel-header { flex-wrap: wrap; gap: 8px; }
#left-feed-panel .feed-heading { flex: 1 1 auto; min-width: 0; }
#left-feed-panel .feed-toolbar { flex: 1 1 100%; width: 100%; justify-content: flex-end; }
#left-feed-panel #feed-sort-select { flex: 1 1 auto; max-width: none; min-width: 0; }
@media (max-width: 767px) {
    .app-topbar { padding-inline: 12px !important; gap: 8px !important; }
    .app-topbar .topbar-optional { display: none !important; }
    .modern-sidebar .sidebar-control-panel { padding-inline: 12px !important; }
    .modern-sidebar .grid.grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .modern-sidebar .filter-chip { min-height: 42px; padding-inline: 10px; }
    #listing-sort-select { max-width: 38vw; }
    .map-status-panel { width: min(calc(100vw - 24px), 420px); }
}
@media (min-width: 768px) and (max-width: 1279px) {
    .incident-search-shell { flex-basis: 0; min-width: 280px; }
}
@media (min-width: 1280px) {
    .incident-search-shell { min-width: 300px; }
}
@media (max-width: 639px) {
    .incident-classic-link { display: none !important; }
    #mobile-filter-trigger-btn {
        width: auto !important;
        min-width: 72px !important;
        height: 40px !important;
        min-height: 40px !important;
        padding: 0 12px !important;
        border-radius: 9px !important;
        justify-content: center !important;
        gap: 6px !important;
    }
    #incident-search-input::placeholder { opacity: .8; }
    #left-feed-panel { width: min(320px, calc(100vw - 24px)); left: 12px; }
    #left-feed-panel #feed-sort-select { min-height: 40px; }
}

/* The filter trigger is an icon control; its hit area follows the icon instead of label width. */
#mobile-filter-trigger-btn {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    justify-content: center !important;
    gap: 0 !important;
}
#mobile-filter-trigger-btn span { display: none !important; }
#close-feed-btn {
    width: 32px !important;
    min-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 !important;
}
@media (max-width: 359px) {
    .app-topbar { padding-inline: 8px !important; }
    #mobile-filter-trigger-btn span { display: none !important; }
    #mobile-filter-trigger-btn { min-width: 40px !important; width: 40px !important; }
    #left-feed-panel { left: 8px; width: calc(100vw - 16px); }
}

/* Reserve the complete external sidebar handle inside narrow viewports. */
@media (max-width: 767px) {
    .modern-sidebar { max-width: calc(100vw - 40px) !important; }
    .sidebar-toggle-btn { right: -40px; width: 40px; }
}
/* Keep search usable before the desktop category bar becomes available. */
@media (max-width: 1279px) {
    .incident-search-shell { min-width: 0; }
    .incident-search-shell > .relative { min-width: 0; }
}
@media (max-width: 639px) {
    body:has(.incident-search-shell) header { gap: 8px; }
    body:has(.incident-search-shell) header > :first-child > :last-child { display: none; }
    body:has(.incident-search-shell) header > :last-child { display: none; }
    #incident-search-input { min-height: 40px; padding-right: 42px; }
}

/* Year navigator visibility and mobile bottom placement. */
.year-visibility-button {
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid #475569;
    border-radius: 8px;
    background: #0f172a;
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 600;
}
.year-visibility-button:hover { background: #1e293b; }
.year-visibility-button:active { transform: scale(0.96); }
.year-show-button {
    position: absolute;
    bottom: calc(var(--map-credit-space) + env(safe-area-inset-bottom, 0px));
    left: 12px;
    z-index: 26;
}
@media (max-width: 767px) {
    main { height: 100dvh !important; }
    #year-navigator, .year-show-button {
        bottom: calc(var(--year-credit-height, 48px) + env(safe-area-inset-bottom, 0px)) !important;
    }
    #year-navigator { z-index: 26; }
    body.years-hidden #left-feed-panel {
        bottom: calc(var(--year-credit-height, 48px) + 52px + env(safe-area-inset-bottom, 0px)) !important;
    }
}
