/* General Body Styling - themed to match DataLab Cuenca site */
:root {
    /* Core brand palette (blues inspired by landing page) */
    --bg-color: #0056A8;
    --bg-color-dark: #004183;
    --bg-gradient: linear-gradient(135deg, #0056A8 0%, #006CCB 35%, #004183 100%);

    /* Surface / card styles */
    --card-bg: #ffffff;
    --card-border: rgba(0, 0, 0, 0.06);
    --card-shadow-soft: 0 18px 45px rgba(0, 43, 89, 0.25);

    /* Typography */
    --text-primary: #0f172a;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;

    /* Accents taken from site CTAs / highlights */
    --accent-primary: #00b0ff;
    --accent-primary-dark: #0087d1;
    --accent-secondary: #00d2b9;
    --accent-tertiary: #ffc857;

    /* States */
    --danger: #e11d48;
    --success: #16a34a;

    --glass-shadow: 0 18px 45px rgba(0, 43, 89, 0.28);
}

body {
    /* Google font used by landing (fallbacks for safety) */
    font-family: "Montserrat", "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease-out;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-primary);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}

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

/* Dashboard Layout */
.dashboard-container {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0;
}

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 32px 8px;
    background: #ffffff;
    color: var(--bg-color-dark);
    box-shadow: 0 6px 20px rgba(0, 43, 89, 0.18);
    border-radius: 0 0 16px 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.dashboard-header img {
    height: 52px;
    width: auto;
}

.dashboard-header h2 {
    color: var(--bg-color-dark);
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.dashboard-nav {
    display: flex;
    align-items: center;
    gap: 28px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.nav-link {
    position: relative;
    color: rgba(0, 65, 131, 0.85);
    text-decoration: none;
    padding-bottom: 6px;
    transition: color 0.2s ease;
}

.nav-link::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 0;
    height: 2px;
    background: var(--bg-color-dark);
    border-radius: 999px;
    transition: width 0.2s ease;
}

.nav-link:hover {
    color: var(--bg-color-dark);
}

.nav-link:hover::after,
.nav-link.active::after {
    width: 100%;
}

.dashboard-content {
    display: grid;
    grid-template-columns: 2.5fr 1fr;
    gap: 24px;
    padding: 24px;
    height: calc(100vh - 80px);
    /* Subtract header height */
    box-sizing: border-box;
}

/* Common Card Styles */
.card,
.map-container,
.chart-container {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--card-shadow-soft);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover,
.map-container:hover,
.chart-container:hover {
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.45);
    border-color: rgba(255, 255, 255, 0.2);
}

h3,
.card-title {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin: 0 0 16px 0;
}

/* Left Column Layout */
.left-column {
    display: grid;
    grid-template-rows: 1.5fr 1fr;
    gap: 24px;
    height: 100%;
    overflow: hidden;
}

/* Map Container */
.map-container {
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 0;
    overflow: hidden;
}

.map-container h3 {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 10;
    background: rgba(0, 86, 168, 0.95);
    padding: 4px 12px;
    border-radius: 20px;
    color: #ffffff;
}

.map-container svg {
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.12) 0%, transparent 70%);
}

/* Bottom Charts Area */
.bottom-charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    min-height: 0;
    /* Important for nested grid scrolling */
}

.chart-container {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chart-container svg {
    flex: 1;
    width: 100%;
    min-height: 0;
}

/* Right Column (Stats) */
.stats-container {
    display: grid;
    grid-template-rows: repeat(3, 1fr);
    gap: 24px;
    height: 100%;
}

.card-chart {
    display: flex;
    flex-direction: column;
    position: relative;
}

.card-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    background: linear-gradient(to right, #fff, #cbd5e1);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.card-footer {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: auto;
}

/* SVG & Chart Specific Styles */
/* Globe */
.sphere {
    /* Light ocean blue to sit on top of site background */
    fill: #0b75d6;
    stroke: transparent;
}

.graticule {
    /* Hide graticule lines to remove visual artifacts on the globe */
    stroke: transparent;
}

.country {
    fill: #f7fbff;
    stroke: #c0d7ff;
    transition: fill 0.2s;
}

.country:hover {
    fill: #c3daf8;
}

/* Province Artifact Fix - Make them transparent */
.province {
    fill: transparent;
    stroke: transparent;
    stroke-width: 0px;
    pointer-events: none;
}

.province:hover {
    fill: transparent;
    stroke: transparent;
}

/* 2D Map */
#ecuador-map .province-2d {
    fill: #e5effa;
    stroke: #cbd5f5;
}

.bubble {
    fill-opacity: 0.75;
    stroke: #ffffff;
    stroke-width: 1px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bubble:hover {
    fill-opacity: 0.9;
    stroke-width: 2px;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.5));
}

/* Line Charts */
.line-chart-svg {
    overflow: visible;
}

.line {
    fill: none;
    stroke-width: 3px;
    stroke-linecap: round;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

#pib-line-chart .line {
    stroke: var(--accent-primary);
}

#inflation-line-chart .line {
    stroke: var(--danger);
}

/* Bar Chart */
.bar {
    fill: var(--accent-primary);
    rx: 4px;
    /* Rounded corners */
    transition: fill 0.2s;
}

.bar:hover {
    fill: var(--accent-primary-dark);
}

.bar-label {
    fill: var(--text-primary);
    font-size: 11px;
    font-weight: 500;
}

/* Tooltips */
.map-tooltip,
.treemap-tooltip {
    background: #ffffff;
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 10000;
}

/* Treemap Legend */
.treemap-legend {
    display: flex;
    gap: 16px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--card-border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-color.primary {
    background: var(--accent-primary);
}

.legend-color.secondary {
    background: var(--accent-secondary);
}

.legend-color.tertiary {
    background: var(--accent-tertiary);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .dashboard-content {
        grid-template-columns: 1fr;
        height: auto;
    }

    .left-column {
        height: auto;
        grid-template-rows: 500px 400px;
    }

    .stats-container {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        grid-template-rows: auto;
        height: auto;
    }
}

@media (max-width: 768px) {
    .bottom-charts-container {
        grid-template-columns: 1fr;
    }

    .left-column {
        grid-template-rows: 400px auto;
    }

    .dashboard-header {
        padding: 12px 20px;
    }

    .dashboard-header h2 {
        font-size: 1rem;
    }
}

/* Trade Flow Controls */
.trade-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 100;
}

.control-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    backdrop-filter: blur(4px);
    transition: all 0.2s ease;
    font-family: inherit;
}

.control-btn:hover {
    background: var(--accent-primary);
    color: #ffffff;
}

.control-btn.active {
    background: var(--accent-primary-dark);
    color: #ffffff;
    border-color: var(--accent-primary);
    font-weight: 600;
}

.control-btn.active[data-filter="exports"] {
    background: #F5A623;
}

/* Trade Legend */
.trade-legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    z-index: 100;
}

.legend-line {
    width: 20px;
    height: 3px;
    border-radius: 2px;
    display: inline-block;
}

.import-line {
    background: #4A90E2;
}

.export-line {
    background: #F5A623;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.legend-item:last-child {
    margin-bottom: 0;
}

/* Trade Tooltip */
.trade-tooltip {
    position: fixed;
    background: #ffffff;
    border: 1px solid var(--card-border);
    padding: 12px;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    z-index: 10000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    min-width: 150px;
    transition: opacity 0.2s ease;
}

.tooltip-country {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tooltip-type {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 600;
}

.tooltip-type.import {
    background: rgba(74, 144, 226, 0.2);
    color: #4A90E2;
}

.tooltip-type.export {
    background: rgba(245, 166, 35, 0.2);
    color: #F5A623;
}

.tooltip-volume {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.tooltip-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
}