* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    background: #071018;
    color: #eaf5ff;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    min-height: 100vh;
}

header {
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #173143;
    background: #091722;
}

h1 {
    margin: 3px 0;
    font-size: 27px;
}

header p {
    margin: 0;
    color: #90aabd;
}

.eyebrow {
    color: #38d4ff;
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 2px;
}

.live {
    color: #4cff86;
    font-weight: bold;
}

#metrics {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1px;
    background: #173143;
}

.metric {
    background: #0c1c28;
    padding: 12px 16px;
}

.metric span {
    display: block;
    font-size: 10px;
    color: #7f9daf;
}

.metric strong {
    display: block;
    margin-top: 4px;
    font-size: 21px;
    color: #ffffff;
}

main {
    min-height: 0;
    display: grid;
    grid-template-columns: 280px 1fr 300px;
}

aside {
    background: #091722;
    padding: 15px;
    overflow-y: auto;
}

#layers {
    border-right: 1px solid #173143;
}

#intel {
    border-left: 1px solid #173143;
}

aside h2 {
    font-size: 14px;
    margin: 0 0 14px;
}

.layer-group {
    margin: 14px 0 6px;
    color: #38d4ff;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 1px;
}

.layer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 0;
    color: #cadbe6;
    font-size: 13px;
}

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

.intel-card {
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid #173143;
    background: #0c1c28;
}

.intel-card strong {
    color: #ffffff;
}

.intel-card p {
    color: #8fa9ba;
    font-size: 12px;
    line-height: 1.45;
}

footer {
    padding: 8px 20px;
    background: #091722;
    border-top: 1px solid #173143;
    color: #69889d;
    font-size: 11px;
}

@media (max-width: 950px) {

    main {
        grid-template-columns: 220px 1fr;
    }

    #intel {
        display: none;
    }

    #metrics {
        grid-template-columns: repeat(3, 1fr);
    }

}

@media (max-width: 650px) {

    main {
        grid-template-columns: 1fr;
    }

    #layers {
        max-height: 250px;
    }

    #metrics {
        grid-template-columns: repeat(2, 1fr);
    }

}


/* ============================================================
   METRIC LEGEND
   ============================================================ */

.metric-legend {
    background: rgba(5, 18, 27, 0.96);
    color: #eaf5ff;
    padding: 12px 14px;
    min-width: 210px;
    border: 1px solid #315062;
    border-radius: 5px;
    box-shadow: 0 4px 18px rgba(0,0,0,.45);
    font-size: 12px;
    line-height: 1.35;
}

.legend-title {
    font-weight: 700;
    font-size: 13px;
    color: #ffffff;
    margin-bottom: 2px;
}

.legend-unit {
    color: #80a8bd;
    font-size: 10px;
    margin-bottom: 8px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 5px 0;
}

.legend-swatch {
    width: 20px;
    height: 12px;
    border: 1px solid rgba(255,255,255,.5);
    flex: 0 0 auto;
}

.legend-note {
    margin-top: 8px;
    padding-top: 7px;
    border-top: 1px solid #284352;
    color: #8fb1c2;
    font-size: 10px;
}

.line-demo {
    display: inline-block;
    width: 30px;
    background: #54ff9b;
    border-radius: 5px;
}

.line-demo.thin {
    height: 2px;
}

.line-demo.medium {
    height: 5px;
}

.line-demo.thick {
    height: 9px;
}


/* ============================================================
   COUNTRY INTELLIGENCE PANEL
   ============================================================ */

.country-name {
    font-size: 20px;
    font-weight: 800;
    color: #ffffff;
    padding: 10px 0 14px;
    border-bottom: 1px solid #284352;
    margin-bottom: 12px;
}

.detail-section {
    margin-bottom: 16px;
}

.detail-heading {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.2px;
    color: #38d4ff;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(70,105,124,.25);
    font-size: 11px;
}

.detail-row span {
    color: #8fb0c2;
}

.detail-row strong {
    color: #ffffff;
    text-align: right;
    font-weight: 700;
}

.detail-source {
    color: #66889b;
    font-size: 9px;
    line-height: 1.4;
    border-top: 1px solid #284352;
    padding-top: 10px;
    margin-top: 12px;
}


/* ============================================================
   BETTER TOOLTIPS
   ============================================================ */

.leaflet-tooltip {
    background: rgba(5, 18, 27, .97);
    color: #ffffff;
    border: 1px solid #3c677d;
    box-shadow: 0 3px 14px rgba(0,0,0,.5);
    font-size: 12px;
    line-height: 1.45;
}

.leaflet-tooltip-top:before,
.leaflet-tooltip-bottom:before,
.leaflet-tooltip-left:before,
.leaflet-tooltip-right:before {
    border-top-color: #3c677d;
}



/* ============================================================
   SEARCH / ACTIVE METRIC TOOLBAR
   ============================================================ */

.metrics-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    background: #081722;
    border-bottom: 1px solid #244354;
    min-height: 48px;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 7px;
}

.toolbar-search {
    flex: 0 1 370px;
}

.toolbar-search input {
    width: 230px;
    background: #0d2532;
    border: 1px solid #355a6c;
    border-radius: 4px;
    color: #ffffff;
    padding: 8px 10px;
    outline: none;
}

.toolbar-search input:focus {
    border-color: #36d7ff;
}

.metrics-toolbar button {
    background: #102b39;
    color: #cce9f7;
    border: 1px solid #355a6c;
    border-radius: 4px;
    padding: 7px 10px;
    cursor: pointer;
    font-weight: 700;
    font-size: 11px;
}

.metrics-toolbar button:hover {
    background: #173b4c;
    color: #ffffff;
}

.metrics-toolbar button.toolbar-active {
    background: #1c6178;
    border-color: #38d4ff;
    color: #ffffff;
}

.toolbar-label {
    color: #678b9f;
    font-size: 9px;
    letter-spacing: 1px;
}

#activeMetricLabel {
    color: #38d4ff;
    font-size: 11px;
}


/* ============================================================
   RANKINGS
   ============================================================ */

.ranking-panel {
    position: absolute;
    z-index: 900;
    top: 60px;
    right: 12px;
    width: 270px;
    max-height: 405px;
    overflow-y: auto;
    background: rgba(5, 18, 27, .96);
    border: 1px solid #315062;
    border-radius: 5px;
    box-shadow: 0 5px 20px rgba(0,0,0,.45);
}

.ranking-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px;
    border-bottom: 1px solid #284352;
}

.ranking-title {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.2px;
    color: #38d4ff;
}

.ranking-metric {
    font-size: 12px;
    font-weight: 700;
    color: #ffffff;
    margin-top: 2px;
}

.ranking-unit {
    color: #7197aa;
    font-size: 9px;
}

.ranking-row {
    width: 100%;
    display: grid;
    grid-template-columns: 26px 1fr auto;
    align-items: center;
    gap: 7px;
    background: transparent;
    color: #d9edf7;
    border: 0;
    border-bottom: 1px solid rgba(55,84,101,.35);
    padding: 7px 9px;
    text-align: left;
    cursor: pointer;
}

.ranking-row:hover {
    background: rgba(45,212,255,.12);
}

.ranking-number {
    color: #5d8498;
    font-size: 10px;
}

.ranking-country {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 10px;
}

.ranking-value {
    color: #ffffff;
    font-size: 10px;
}

.ranking-empty {
    padding: 14px;
    color: #7799ab;
    font-size: 11px;
}


/*
   The ranking box is positioned relative to the
   center map section.
*/

main > section {
    position: relative;
}


/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 950px) {

    .metrics-toolbar {
        flex-wrap: wrap;
    }

    .toolbar-search {
        flex: 1 1 100%;
    }

    .ranking-panel {
        width: 220px;
    }

}



/* ============================================================
   FIX MAP CENTER COLUMN
   Toolbar + rankings must remain INSIDE this one grid column.
   ============================================================ */

.map-shell {
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #071018;
}

.map-shell #map {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 500px;
    height: auto;
}

.map-shell .metrics-toolbar {
    flex: 0 0 auto;
    width: 100%;
}

.map-shell .ranking-panel {
    position: absolute;
    z-index: 1000;
    top: 60px;
    right: 12px;
}


/*
   Undo the overly broad rule added in the previous patch.
*/

main > section {
    position: relative;
}


/*
   MAIN must ALWAYS remain exactly:
   left controls | center map shell | right intelligence
*/

main {
    grid-template-columns: 280px minmax(0, 1fr) 300px;
}


/* Ensure Leaflet fills the restored center area */

.map-shell .leaflet-container {
    width: 100%;
    height: 100%;
}


@media (max-width: 950px) {

    main {
        grid-template-columns: 220px minmax(0, 1fr);
    }

    .map-shell {
        min-width: 0;
    }

}

/* MIGRATION_MOBILE_MAPFIRST_BEGIN */


#migration-mobile-layers,
#migration-mobile-info,
#migration-mobile-fullscreen,
#migration-mobile-backdrop {
    display: none;
}


@media (max-width: 700px) {

    html,
    body {
        width: 100% !important;
        height: 100% !important;

        margin: 0 !important;
        padding: 0 !important;

        overflow: hidden !important;

        background: #02070d !important;
    }


    body {
        position: fixed !important;

        inset: 0 !important;

        width: 100vw !important;
        height: 100dvh !important;
    }


    /*
     * APP SHELL
     */

    #app {
        position: fixed !important;

        inset: 0 !important;

        width: 100vw !important;
        height: 100dvh !important;

        overflow: hidden !important;
    }


    /*
     * COMPACT HEADER
     */

    header {
        position: fixed !important;

        top: 0 !important;
        left: 0 !important;
        right: 0 !important;

        height: 58px !important;
        min-height: 58px !important;

        box-sizing: border-box !important;

        padding: 6px 10px !important;

        overflow: hidden !important;

        z-index: 40000 !important;

        backdrop-filter:
            blur(8px);
    }


    header h1 {
        margin: 0 !important;

        font-size: 14px !important;
        line-height: 1.05 !important;
    }


    header p,
    header .subtitle,
    header .tagline {
        display: none !important;
    }


    /*
     * REMOVE DESKTOP METRIC WALL FROM INITIAL PHONE VIEW
     */

    .metrics,
    .metric-strip,
    .metric-grid {
        display: none !important;
    }


    footer {
        display: none !important;
    }


    /*
     * MAP OWNS THE PHONE SCREEN
     */

    main {
        position: fixed !important;

        top: 58px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;

        width: 100vw !important;
        height: calc(100dvh - 58px) !important;

        min-width: 0 !important;
        min-height: 0 !important;

        display: block !important;

        margin: 0 !important;
        padding: 0 !important;

        overflow: hidden !important;
    }


    #map {
        position: absolute !important;

        inset: 0 !important;

        width: 100% !important;
        height: 100% !important;

        min-width: 0 !important;
        min-height: 0 !important;

        z-index: 1 !important;
    }


    /*
     * DYNAMIC DRAWERS
     */

    .migration-mobile-layer-drawer,
    .migration-mobile-info-drawer {

        display: none !important;

        position: fixed !important;

        top: 58px !important;
        bottom: 0 !important;

        width:
            min(
                91vw,
                410px
            ) !important;

        max-width: 410px !important;

        height:
            calc(
                100dvh - 58px
            ) !important;

        box-sizing: border-box !important;

        overflow-x: hidden !important;
        overflow-y: auto !important;

        padding: 16px !important;

        z-index: 50000 !important;

        background:
            rgba(
                4,
                13,
                20,
                .98
            ) !important;

        -webkit-overflow-scrolling:
            touch;
    }


    .migration-mobile-layer-drawer {
        left: 0 !important;

        box-shadow:
            12px 0 35px
            rgba(0,0,0,.8) !important;
    }


    .migration-mobile-info-drawer {
        right: 0 !important;

        box-shadow:
            -12px 0 35px
            rgba(0,0,0,.8) !important;
    }


    .migration-mobile-layer-drawer.migration-mobile-open,
    .migration-mobile-info-drawer.migration-mobile-open {

        display: block !important;
    }


    /*
     * KEEP LAYER LIST TOUCH-FRIENDLY
     */

    #layerList label,
    #layerList .layer-row,
    #layerList > div {

        min-height: 44px !important;
    }


    #layerList input[type="checkbox"] {

        width: 20px !important;
        height: 20px !important;

        flex:
            0 0 auto !important;
    }


    /*
     * COUNTRY INTELLIGENCE
     */

    #intel {
        font-size: 13px !important;
    }


    #intel h2 {
        font-size: 15px !important;
    }


    .intel-card {
        line-height: 1.5 !important;
    }


    /*
     * RANKINGS
     */

    #rankingPanel,
    .ranking-panel {

        max-height: none !important;
    }


    .ranking-row {

        min-height: 42px !important;

        font-size: 12px !important;
    }


    /*
     * MOBILE CONTROL BUTTONS
     */

    #migration-mobile-layers,
    #migration-mobile-info,
    #migration-mobile-fullscreen {

        display: flex !important;

        position: fixed !important;

        align-items: center !important;
        justify-content: center !important;

        min-height: 42px !important;

        padding: 7px 12px !important;

        border:
            1px solid
            rgba(
                84,
                255,
                155,
                .75
            ) !important;

        border-radius: 22px !important;

        background:
            rgba(
                3,
                15,
                12,
                .94
            ) !important;

        color: #ffffff !important;

        font-size: 10px !important;
        font-weight: 900 !important;

        letter-spacing: .7px !important;

        box-shadow:
            0 5px 18px
            rgba(0,0,0,.72) !important;

        touch-action:
            manipulation !important;
    }


    #migration-mobile-layers {

        top: 68px !important;
        left: 10px !important;

        z-index: 45000 !important;
    }


    #migration-mobile-info {

        top: 68px !important;
        right: 10px !important;

        z-index: 45000 !important;
    }


    #migration-mobile-fullscreen {

        left: 50% !important;

        bottom:
            calc(
                12px
                + env(
                    safe-area-inset-bottom
                )
            ) !important;

        transform:
            translateX(-50%) !important;

        z-index: 45000 !important;
    }


    /*
     * BACKDROP
     */

    #migration-mobile-backdrop {

        display: none !important;

        position: fixed !important;

        inset:
            58px
            0
            0
            0 !important;

        z-index: 49000 !important;

        background:
            rgba(0,0,0,.50) !important;
    }


    #migration-mobile-backdrop.migration-mobile-open {

        display: block !important;
    }


    /*
     * LEAFLET CONTROLS
     */

    .leaflet-control-zoom a {

        width: 42px !important;
        height: 42px !important;

        line-height: 42px !important;

        font-size: 23px !important;
    }


    .leaflet-control-attribution {

        max-width: 72vw !important;

        font-size: 7px !important;
        line-height: 1.1 !important;
    }


    /*
     * LEGEND MUST NOT COVER HALF THE PHONE.
     */

    .legend,
    #legend,
    .map-legend {

        max-width: 150px !important;
        max-height: 34vh !important;

        overflow-y: auto !important;

        font-size: 9px !important;
    }


    /*
     * IMMERSIVE FULL SCREEN
     */

    body.migration-immersive header {

        display: none !important;
    }


    body.migration-immersive main {

        top: 0 !important;

        width: 100vw !important;
        height: 100dvh !important;
    }


    body.migration-immersive
    .migration-mobile-layer-drawer,

    body.migration-immersive
    .migration-mobile-info-drawer {

        top: 0 !important;

        height: 100dvh !important;

        padding-top:
            calc(
                62px
                + env(
                    safe-area-inset-top
                )
            ) !important;
    }


    body.migration-immersive
    #migration-mobile-backdrop {

        inset: 0 !important;
    }


    body.migration-immersive
    #migration-mobile-layers,

    body.migration-immersive
    #migration-mobile-info {

        top:
            calc(
                10px
                + env(
                    safe-area-inset-top
                )
            ) !important;
    }


    body.migration-immersive
    #migration-mobile-fullscreen {

        bottom:
            calc(
                10px
                + env(
                    safe-area-inset-bottom
                )
            ) !important;
    }

}


/*
 * LANDSCAPE PHONE
 */

@media
    (max-width: 900px)
    and (max-height: 520px)
    and (orientation: landscape) {

    header {

        height: 48px !important;
        min-height: 48px !important;
    }


    main {

        top: 48px !important;

        height:
            calc(
                100dvh - 48px
            ) !important;
    }


    .migration-mobile-layer-drawer,
    .migration-mobile-info-drawer {

        top: 48px !important;

        height:
            calc(
                100dvh - 48px
            ) !important;

        width:
            min(
                72vw,
                410px
            ) !important;
    }


    #migration-mobile-backdrop {

        inset:
            48px
            0
            0
            0 !important;
    }


    #migration-mobile-layers,
    #migration-mobile-info {

        top: 56px !important;
    }


    body.migration-immersive main {

        top: 0 !important;

        height: 100dvh !important;
    }


    body.migration-immersive
    .migration-mobile-layer-drawer,

    body.migration-immersive
    .migration-mobile-info-drawer {

        top: 0 !important;

        height: 100dvh !important;
    }

}


/* MIGRATION_MOBILE_MAPFIRST_END */

/* MIGRATION_MOBILE_TOPBOX_FIX_BEGIN */

@media (max-width: 700px) {

    /*
     * The population/search/rankings toolbar is useful,
     * but it must NOT float over the map on a phone.
     *
     * JavaScript moves it into the INFO drawer.
     */

    .migration-mobile-toolbar-relocated {
        position: static !important;

        top: auto !important;
        right: auto !important;
        bottom: auto !important;
        left: auto !important;

        width: 100% !important;
        max-width: none !important;

        height: auto !important;
        max-height: none !important;

        margin:
            0
            0
            16px
            0 !important;

        box-sizing: border-box !important;

        transform: none !important;

        z-index: auto !important;

        overflow: visible !important;
    }


    .migration-mobile-toolbar-relocated
    input,

    .migration-mobile-toolbar-relocated
    select {

        max-width: 100% !important;

        box-sizing: border-box !important;
    }


    .migration-mobile-toolbar-relocated
    button {

        min-height: 40px !important;
    }


    /*
     * Safety rule:
     * if the toolbar has been identified but cannot yet be
     * moved into INFO, keep it from covering the map.
     */

    .migration-mobile-toolbar-pending {
        visibility: hidden !important;
        pointer-events: none !important;
    }

}

/* MIGRATION_MOBILE_TOPBOX_FIX_END */

/* MIGRATION_PHONE_RANKING_FIX_BEGIN */

@media (max-width: 700px) {

    /*
     * TOP 10 / BOTTOM 10 rankings must NEVER float over
     * the map on a phone.
     */

    #rankingPanel,
    .ranking-panel {

        display: none !important;

        position: static !important;

        top: auto !important;
        right: auto !important;
        bottom: auto !important;
        left: auto !important;

        width: 100% !important;
        max-width: none !important;

        height: auto !important;
        max-height: none !important;

        margin: 14px 0 0 0 !important;

        transform: none !important;

        overflow: visible !important;

        z-index: auto !important;

        box-sizing: border-box !important;
    }


    /*
     * It only becomes visible while the INFO drawer is open.
     */

    .migration-mobile-info-drawer.migration-mobile-open
    #rankingPanel,

    .migration-mobile-info-drawer.migration-mobile-open
    .ranking-panel {

        display: block !important;
    }


    /*
     * Ranking rows become phone-friendly inside INFO.
     */

    #rankingPanel .ranking-row,
    .ranking-panel .ranking-row {

        width: 100% !important;

        min-height: 44px !important;

        box-sizing: border-box !important;
    }


    #rankingPanel table,
    .ranking-panel table {

        width: 100% !important;

        table-layout: fixed !important;
    }


    #rankingPanel *,
    .ranking-panel * {

        max-width: 100%;

        box-sizing: border-box;
    }

}

/* MIGRATION_PHONE_RANKING_FIX_END */
