* {
    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;
    }

}

