/* World Map Widget Styles */
/* CSS Custom Properties for Light/Dark Mode Support */
:root,
[scheme="light"] {
    --wm-bg-primary: #ffffff;
    --wm-bg-secondary: #f8f9fa;
    --wm-bg-tertiary: #f0f8ff;
    --wm-text-primary: #2c3e50;
    --wm-text-secondary: #7f8c8d;
    --wm-text-muted: #95a5a6;
    --wm-border-light: #e8e8e8;
    --wm-border-medium: #ddd;
    --wm-border-dark: #e0e0e0;
    --wm-shadow-light: rgba(0, 0, 0, 0.1);
    --wm-shadow-medium: rgba(0, 0, 0, 0.3);
    --wm-country-stroke: #ffffff;
    --wm-country-no-data: #e8e8e8;
    --wm-loading-border: #ddd;
    --wm-error-bg: #ffeaea;
    --wm-tooltip-bg: rgba(0, 0, 0, 0.9);
    --wm-tooltip-text: white;
}

[scheme="dark"] {
    --wm-bg-primary: #1e1e1e;
    --wm-bg-secondary: #2d2d30;
    --wm-bg-tertiary: #252526;
    --wm-text-primary: #cccccc;
    --wm-text-secondary: #9cdcfe;
    --wm-text-muted: #6a9955;
    --wm-border-light: #3e3e42;
    --wm-border-medium: #464647;
    --wm-border-dark: #404040;
    --wm-shadow-light: rgba(0, 0, 0, 0.3);
    --wm-shadow-medium: rgba(0, 0, 0, 0.6);
    --wm-country-stroke: #404040;
    --wm-country-no-data: #404040;
    --wm-loading-border: #464647;
    --wm-error-bg: #3c1f1f;
    --wm-tooltip-bg: rgba(45, 45, 48, 0.95);
    --wm-tooltip-text: #cccccc;
}

/* Auto-detect system preference */
@media (prefers-color-scheme: dark) {
    :root:not([scheme]) {
        --wm-bg-primary: #1e1e1e;
        --wm-bg-secondary: #2d2d30;
        --wm-bg-tertiary: #252526;
        --wm-text-primary: #cccccc;
        --wm-text-secondary: #9cdcfe;
        --wm-text-muted: #6a9955;
        --wm-border-light: #3e3e42;
        --wm-border-medium: #464647;
        --wm-border-dark: #404040;
        --wm-shadow-light: rgba(0, 0, 0, 0.3);
        --wm-shadow-medium: rgba(0, 0, 0, 0.6);
        --wm-country-stroke: #404040;
        --wm-country-no-data: #404040;
        --wm-loading-border: #464647;
        --wm-error-bg: #3c1f1f;
        --wm-tooltip-bg: rgba(45, 45, 48, 0.95);
        --wm-tooltip-text: #cccccc;
    }
}

.world-map-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: var(--wm-bg-primary);
    border-radius: 12px;
    box-shadow: 0 4px 20px var(--wm-shadow-light);
    position: relative;
    color: var(--wm-text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Widget Header */
.widget-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--wm-border-light);
}

.widget-header h2 {
    color: var(--wm-text-primary);
    font-size: 28px;
    font-weight: 600;
    margin: 0 0 10px 0;
}

.widget-header p {
    color: var(--wm-text-secondary);
    font-size: 16px;
    margin: 0;
}

/* Controls Panel */
.controls-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding: 15px 20px;
    background: var(--wm-bg-secondary);
    border-radius: 8px;
    flex-wrap: wrap;
    gap: 15px;
}

.metric-selector label {
    font-weight: 600;
    color: var(--wm-text-primary);
    margin-right: 10px;
}

.metric-selector select {
    padding: 8px 15px;
    border: 2px solid var(--wm-border-medium);
    border-radius: 6px;
    background: var(--wm-bg-primary);
    color: var(--wm-text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.metric-selector select:focus {
    outline: none;
    border-color: #3498db;
}

.us-comparison label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--wm-text-primary);
    cursor: pointer;
}

.us-comparison input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #3498db;
}

/* Legend */
.legend {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--wm-bg-secondary);
    border-radius: 8px;
}

.legend-title {
    font-weight: 600;
    color: var(--wm-text-primary);
    margin-bottom: 10px;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--wm-text-secondary);
}

.legend-color {
    width: 20px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid var(--wm-border-medium);
}

/* Map Container */
.map-container {
    position: relative;
    background: var(--wm-bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--wm-border-dark);
    margin-bottom: 20px;
}

#world-map {
    display: block;
    width: 100%;
    height: auto;
    min-height: 500px;
}

/* Map Countries Styling */
.country {
    stroke: var(--wm-country-stroke);
    stroke-width: 0.5;
    cursor: pointer;
    transition: all 0.3s ease;
}

.country:hover {
    stroke: var(--wm-text-primary);
    stroke-width: 2;
    filter: brightness(1.1);
}

.country.no-data {
    fill: var(--wm-country-no-data);
    cursor: default;
}

.country.no-data:hover {
    stroke-width: 0.5;
    filter: none;
}

.country.us-highlighted {
    stroke: #e74c3c;
    stroke-width: 3;
    stroke-dasharray: 5, 3;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%,
    100% {
        stroke-opacity: 1;
    }
    50% {
        stroke-opacity: 0.6;
    }
}

/* Info Panel */
.info-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 450px;
    background: var(--wm-bg-primary);
    border-radius: 12px;
    box-shadow: 0 10px 40px var(--wm-shadow-medium);
    z-index: 1000;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--wm-border-light);
}

.info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: #3498db;
    color: white;
    border-radius: 12px 12px 0 0;
}

.info-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.info-content {
    padding: 25px;
}

.metric-info {
    margin-bottom: 25px;
}

.metric-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--wm-border-light);
}

.metric-item:last-child {
    border-bottom: none;
}

.metric-label {
    font-weight: 600;
    color: var(--wm-text-primary);
}

.metric-value {
    font-weight: 700;
    font-size: 16px;
    color: #e74c3c;
}

.comparison-section {
    border-top: 2px solid var(--wm-border-light);
    padding-top: 20px;
}

.comparison-section h4 {
    margin: 0 0 15px 0;
    color: var(--wm-text-primary);
    font-size: 16px;
}

.comparison-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 14px;
}

.comparison-label {
    color: var(--wm-text-secondary);
}

.comparison-diff {
    font-weight: 600;
}

.comparison-diff.positive {
    color: #e74c3c;
}

.comparison-diff.negative {
    color: #27ae60;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: var(--wm-tooltip-bg);
    color: var(--wm-tooltip-text);
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1001;
    max-width: 200px;
    border: 1px solid var(--wm-border-medium);
    backdrop-filter: blur(10px);
}

.tooltip-country {
    font-weight: 600;
    margin-bottom: 4px;
}

.tooltip-value {
    font-size: 11px;
    opacity: 0.9;
}

/* Attribution */
.attribution {
    text-align: center;
    padding-top: 15px;
    border-top: 1px solid var(--wm-border-light);
}

.attribution small {
    color: var(--wm-text-muted);
    font-style: italic;
}

/* Responsive Design */
@media (max-width: 768px) {
    .world-map-container {
        padding: 15px;
    }

    .widget-header h2 {
        font-size: 24px;
    }

    .controls-panel {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    .legend-items {
        justify-content: center;
    }

    .info-panel {
        width: 95%;
        max-width: none;
    }

    #world-map {
        min-height: 350px;
    }
}

@media (max-width: 480px) {
    .widget-header h2 {
        font-size: 20px;
    }

    .widget-header p {
        font-size: 14px;
    }

    .legend-items {
        flex-direction: column;
        align-items: flex-start;
    }

    #world-map {
        min-height: 300px;
    }
}

/* Loading State */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    color: var(--wm-text-secondary);
    font-size: 16px;
}

.loading::after {
    content: "";
    width: 20px;
    height: 20px;
    border: 2px solid var(--wm-loading-border);
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Error State */
.error {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    color: #e74c3c;
    font-size: 16px;
    font-weight: 600;
    background: var(--wm-error-bg);
    border: 1px solid #e74c3c;
    border-radius: 8px;
    margin: 20px 0;
}
