/* =========================================================
   GOOGLE FONTS
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Syne:wght@600;700;800&display=swap');


/* =========================================================
   ROOT VARIABLES — PREMIUM MED THEME
   ========================================================= */
:root {
    /* Core palette */
    --bg: #eef2f9;
    --panel: rgba(255, 255, 255, 0.96);
    --panel-border: rgba(30, 58, 138, 0.07);
    --text: #0d1b3e;
    --muted: #5a6e96;

    /* Brand */
    --primary: #1a56db;
    --primary-hover: #1448c7;
    --primary-soft: rgba(26, 86, 219, 0.08);
    --primary-glow: rgba(26, 86, 219, 0.22);
    --accent: #0891b2;
    --accent-soft: rgba(8, 145, 178, 0.10);

    /* Topbar — deep navy with subtle gradient */
    --topbar-bg: linear-gradient(135deg, #0d1b3e 0%, #162152 50%, #1a2c6b 100%);
    --topbar-border: rgba(255, 255, 255, 0.06);
    --topbar-text: #e8edf8;
    --topbar-muted: rgba(200, 215, 255, 0.55);

    /* Semantic */
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;

    /* Spacing & shape */
    --radius: 20px;
    --radius-sm: 12px;
    --radius-xs: 8px;

    /* Shadows */
    --shadow: 0 8px 32px rgba(13, 27, 62, 0.10);
    --shadow-soft: 0 2px 12px rgba(13, 27, 62, 0.06);
    --shadow-lg: 0 20px 48px rgba(13, 27, 62, 0.15);
    --shadow-glow: 0 0 0 3px var(--primary-glow);

    /* Layout */
    --topbar-h: 66px;
    --gap: 14px;
    --panel-pad: 18px;

    /* Transitions */
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in: cubic-bezier(0.4, 0, 1, 1);
}


/* =========================================================
   GLOBAL RESET / BASE
   ========================================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    overflow: hidden;
}

.hidden {
    display: none !important;
}

#app-shell {
    height: 100vh;
    display: grid;
    grid-template-rows: var(--topbar-h) 1fr;
}


/* =========================================================
   TOPBAR — PREMIUM DARK NAVY
   ========================================================= */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: relative;
    z-index: 100;
    box-shadow: 0 4px 24px rgba(13, 27, 62, 0.28);
}

/* Subtle topbar shimmer line */
.topbar::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(99, 150, 255, 0.35) 30%,
            rgba(56, 189, 248, 0.35) 60%,
            transparent 100%);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 20px;
    min-width: 0;
}

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

.topbar-nav {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 13px;
    text-decoration: none;
    color: var(--topbar-text);
    transition: opacity 0.2s;
}

.brand-link:hover {
    opacity: 0.88;
}

.app-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 11px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.12);
    transition: transform 0.3s var(--ease), box-shadow 0.3s ease;
}

.brand-link:hover .app-logo {
    transform: scale(1.05) rotate(-2deg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.app-brand h1 {
    margin: 0;
    font-family: 'Inter', sans-serif;

    font-size: 17px;
    font-weight: 800;
    line-height: 1.1;
    color: #ffffff;
    letter-spacing: -0.01em;
}

.app-brand p {
    margin: 3px 0 0;
    font-size: 11px;
    color: var(--topbar-muted);
    font-weight: 400;
    letter-spacing: 0.01em;
}

.partner-logos {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 16px;
    border-left: 1px solid rgba(255, 255, 255, 0.10);
}

.partner-logo {
    height: 26px;
    width: auto;
    object-fit: contain;
    opacity: 0.70;
    transition: opacity 0.25s ease, transform 0.25s var(--ease), filter 0.25s ease;
    filter: brightness(1.4) saturate(0.7);
}

.partner-logo:hover {
    opacity: 1;
    transform: scale(1.1) translateY(-1px);
    filter: brightness(1.5) saturate(1);
}

.partner-logos:hover .partner-logo {
    opacity: 0.5;
}

.partner-logos .partner-logo:hover {
    opacity: 1;
}


/* =========================================================
   MAIN APP LAYOUT
   ========================================================= */
.main-layout {
    display: grid;
    grid-template-columns: clamp(280px, 22vw, 320px) 1fr clamp(320px, 26vw, 380px);
    gap: clamp(8px, 1.5vw, var(--gap));
    padding: clamp(8px, 1.5vw, var(--gap));
    min-height: 0;
    height: 100%;
}

.sidebar-left,
.sidebar-right {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: auto;
    padding: var(--panel-pad);
    min-height: 0;
    scroll-behavior: smooth;
    animation: fadeInSlide 0.45s var(--ease) forwards;
    opacity: 0;
    position: relative;
}

/* Top accent line on sidebars */
.sidebar-left::before,
.sidebar-right::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 2px;
    background: linear-gradient(90deg,
            transparent,
            var(--primary) 40%,
            var(--accent) 60%,
            transparent);
    border-radius: 0 0 4px 4px;
    opacity: 0.5;
}

@keyframes fadeInSlide {
    0% {
        opacity: 0;
        transform: translateY(12px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.map-area {
    position: relative;
    min-height: 0;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: #dde8f5;
    animation: fadeInSlide 0.45s var(--ease) 0.05s forwards;
    opacity: 0;
}

#map {
    width: 100%;
    height: 100%;
    min-height: 500px;
}


/* =========================================================
   GENERIC PANELS / CONTENT BLOCKS
   ========================================================= */
.panel-section+.panel-section {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid rgba(30, 58, 138, 0.06);
}

.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.panel-title-row h2,
.details-header h2 {
    margin: 0;
    font-family: 'Syne', sans-serif;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Decorative dot before section titles */
.panel-title-row h2::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}

.panel-block {
    display: flex;
    flex-direction: column;
    gap: 12px;
}


/* =========================================================
   ACTIVE CONTEXT CHIPS
   ========================================================= */
.active-context {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.context-chip {
    background: linear-gradient(135deg, rgba(26, 86, 219, 0.07), rgba(8, 145, 178, 0.07));
    border: 1px solid rgba(26, 86, 219, 0.12);
    color: var(--primary);
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: all 0.2s ease;
}

.context-chip:hover {
    background: var(--primary-soft);
    border-color: rgba(26, 86, 219, 0.22);
}


/* =========================================================
   NAVIGATION BUTTONS (TOPBAR)
   ========================================================= */
.nav-btn {
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(220, 232, 255, 0.80);
    border-radius: 10px;
    padding: 9px 16px;
    cursor: pointer;
    transition: all 0.22s var(--ease);
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    letter-spacing: 0.01em;
    white-space: nowrap;
    backdrop-filter: blur(8px);
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.16);
    transform: translateY(-1px);
}

.nav-btn.active {
    background: rgba(26, 86, 219, 0.9);
    color: #ffffff;
    border-color: rgba(99, 150, 255, 0.4);
    box-shadow: 0 4px 16px rgba(26, 86, 219, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
    font-weight: 600;
}

/* Active indicator underline */
.nav-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), #38bdf8);
    border-radius: 2px 2px 0 0;
}


/* =========================================================
   GENERIC BUTTONS
   ========================================================= */
.btn,
.icon-btn {
    border: 1px solid var(--panel-border);
    background: white;
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    cursor: pointer;
    transition: all 0.22s var(--ease);
    box-shadow: var(--shadow-soft);
    font-size: 13.5px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
}

.btn:hover,
.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn:active,
.icon-btn:active {
    transform: translateY(0px);
    box-shadow: var(--shadow-soft);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #1448c7 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 16px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-primary:hover {
    box-shadow: 0 8px 24px var(--primary-glow), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    background: linear-gradient(135deg, #1d62f0 0%, #1448c7 100%);
}

.btn-secondary {
    background: #f5f8ff;
    color: var(--muted);
    border-color: #dde4ef;
}

/* Download button in topbar */
#dlTrigger {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(220, 232, 255, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 10px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.22s var(--ease);
    backdrop-filter: blur(8px);
}

#dlTrigger:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.3);
}

.icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    border-radius: var(--radius-xs);
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    color: var(--text);
    background: rgba(26, 86, 219, 0.06);
}


/* =========================================================
   FORM ELEMENTS
   ========================================================= */
select,
input,
textarea {
    width: 100%;
    border: 1px solid #dde4ef;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: #fafbff;
    color: var(--text);
    font-size: 13.5px;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

select:hover,
input:hover,
textarea:hover {
    border-color: #c5d0e8;
    background: #fff;
}

select:focus,
input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.10);
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-group label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.02em;
}


/* =========================================================
   DETAILS PANEL
   ========================================================= */
.details-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(30, 58, 138, 0.07);
}

.details-subtitle {
    margin: 4px 0 0;
    font-size: 11.5px;
    color: var(--muted);
    font-weight: 400;
}

.details-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}


/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .sidebar-left,
    .sidebar-right {
        display: none;
    }
}

@media (max-width: 768px) {
    .partner-logo {
        height: 20px;
    }

    .partner-logos {
        gap: 8px;
    }

    .topbar {
        padding: 0 14px;
    }

    .topbar-left {
        gap: 12px;
    }

    .nav-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
}


/* =========================================================
   MAP TILE RENDERING
   ========================================================= */
.leaflet-tile {
    image-rendering: auto;
}


/* =========================================================
   LEAFLET POPUP — PREMIUM STYLE
   ========================================================= */
.leaflet-popup-content-wrapper {
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(30, 58, 138, 0.08);
    border-radius: 16px !important;
    box-shadow: 0 16px 40px rgba(13, 27, 62, 0.18),
        0 0 0 1px rgba(255, 255, 255, 0.6) inset !important;
    padding: 0 !important;
    backdrop-filter: blur(16px);
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 14px 16px !important;
    font-family: 'Inter', sans-serif;
    font-size: 13.5px;
    color: var(--text);
    line-height: 1.5;
}

.leaflet-popup-content strong {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    display: block;
    margin-bottom: 4px;
}

.leaflet-popup-tip {
    background: rgba(255, 255, 255, 0.97) !important;
}

.leaflet-popup-close-button {
    color: var(--muted) !important;
    font-size: 18px !important;
    width: 28px !important;
    height: 28px !important;
    line-height: 28px !important;
    top: 6px !important;
    right: 8px !important;
    border-radius: 8px !important;
    transition: all 0.18s ease;
}

.leaflet-popup-close-button:hover {
    background: rgba(220, 38, 38, 0.08) !important;
    color: var(--danger) !important;
}

/* Leaflet attribution */
.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.82) !important;
    backdrop-filter: blur(8px);
    border-radius: 10px 0 0 0 !important;
    font-size: 10px !important;
    font-family: 'Inter', sans-serif;
    padding: 4px 8px !important;
}

/* Leaflet zoom controls */
.leaflet-bar a {
    border-radius: 10px !important;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    color: var(--text) !important;
    border-bottom: 1px solid rgba(30, 58, 138, 0.08) !important;
    transition: background 0.18s ease, transform 0.18s ease !important;
}

.leaflet-bar a:hover {
    background: #f0f5ff !important;
}

.leaflet-bar {
    border: 1px solid rgba(30, 58, 138, 0.10) !important;
    border-radius: 12px !important;
    box-shadow: 0 6px 16px rgba(13, 27, 62, 0.12) !important;
    overflow: hidden;
}


/* =========================================================
   DETAILS HEADER — prevent double dot for non-panel h2
   ========================================================= */
.details-header h2::before {
    display: none;
}

.details-header h2 {
    margin: 0;    
    font-family: 'Syne', sans-serif;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;

}

/* =========================================================
   EMPTY STATE ICON
   ========================================================= */
.empty-state::before {
    content: '🗺';
    display: block;
    font-size: 28px;
    margin-bottom: 12px;
    opacity: 0.6;
}


/* =========================================================
   STORY SIDEBAR HERO
   ========================================================= */
.story-hero {
    background: linear-gradient(135deg, #f0f5ff 0%, #e8f0fe 100%);
    border: 1px solid rgba(26, 86, 219, 0.10);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 18px;
}

.story-eyebrow {
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 8px;
}

.story-lead {
    margin: 0;
    font-size: 14px;
    line-height: 1.65;
    color: var(--muted);
    font-weight: 400;
}


/* =========================================================
   STORY PROGRESS BAR
   ========================================================= */
.story-progress {
    height: 4px;
    background: rgba(30, 58, 138, 0.08);
    border-radius: 999px;
    margin-bottom: 18px;
    overflow: hidden;
}

.story-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 999px;
    transition: width 0.5s var(--ease);
    width: 0%;
}


/* =========================================================
   SMOOTH TRANSITIONS FOR SIDEBAR VISIBILITY
   ========================================================= */
.sidebar-left,
.sidebar-right {
    transition: opacity 0.22s ease;
}

/* Pulse animation for status messages */
@keyframes statusPulseIn {
    0% {
        opacity: 0;
        transform: scale(0.97);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.map-status {
    animation: statusPulseIn 0.25s var(--ease);
}

/* =========================================================
   RESPONSIVE LAYOUT SCALING
   ========================================================= */

.mobile-toggles {
    display: none;
}

@media (max-width: 1100px) {
    .main-layout {
        grid-template-columns: 280px 1fr;
    }

    .sidebar-right {
        position: absolute;
        right: 14px;
        top: 14px;
        bottom: 14px;
        width: 320px;
        z-index: 1000;
        transform: translateX(calc(100% + 40px));
        transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    }

    .sidebar-right.mobile-open {
        transform: translateX(0);
    }
}

@media (max-width: 768px) {
    #app-shell {
        grid-template-rows: auto 1fr;
    }

    .topbar {
        padding: 10px 14px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .topbar-right {
        width: 100%;
        justify-content: space-between;
        overflow-x: auto;
        padding-bottom: 4px;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .topbar-right::-webkit-scrollbar {
        display: none;
    }

    .topbar-nav {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .nav-btn {
        white-space: nowrap;
        padding: 7px 12px;
        font-size: 12px;
    }

    .main-layout {
        grid-template-columns: 1fr;
        padding: 8px;
        gap: 8px;
    }

    .sidebar-left,
    .sidebar-right {
        position: absolute;
        left: 8px;
        right: 8px;
        bottom: 8px;
        top: auto;
        height: 55vh;
        width: auto;
        z-index: 1000;
        border-radius: 20px;
        transform: translateY(calc(100% + 40px));
        transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
        box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.25);
    }

    .sidebar-left.mobile-open,
    .sidebar-right.mobile-open {
        transform: translateY(0);
    }

    .partner-logos {
        display: none;
    }

    .mobile-toggles {
        display: flex;
        position: absolute;
        bottom: 24px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 1000;
        gap: 12px;
    }
    
    .mobile-toggles .btn {
        border-radius: 999px;
        padding: 8px 18px;
        font-weight: 600;
        font-size: 13.5px;
        box-shadow: 0 10px 24px rgba(13, 27, 62, 0.35), 0 0 0 1px rgba(255,255,255,0.1) inset;
        backdrop-filter: blur(12px);
    }
}