/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #09090b;
    --bg-card: #0f0f12;
    --bg-elevated: #141418;
    --bg-input: #111114;
    --text-primary: #e0e0e0;
    --text-secondary: #6e6e78;
    --text-muted: #38383f;
    --text-muted-interactive: #8a8a92;
    --border: rgba(255,255,255,0.06);
    --border-strong: rgba(255,255,255,0.1);
    --country-1: #7b7bff;
    --country-2: #ff6b6b;
    --country-3: #e2b855;
    --country-4: #5ec4d4;
    --country-5: #d4699b;
    --country-6: #5fbf8a;
    --transition: 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --sidebar-width: 280px;
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Grain — very subtle */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.022;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 128px 128px;
}

a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover { color: var(--text-primary); }

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); }

/* ===== Lang Toggle ===== */
.lang-toggle {
    position: absolute;
    top: 2rem;
    right: 2rem;
    display: flex;
    border: 1px solid var(--border);
}
.lang-btn {
    padding: 0.3rem 0.6rem;
    background: transparent;
    border: none;
    color: var(--text-muted-interactive);
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn.active { background: var(--text-primary); color: var(--bg-primary); }
.lang-btn:hover:not(.active) { color: var(--text-primary); }

/* ===== Header ===== */
.header {
    padding: 6rem 2rem 5rem;
    text-align: center;
    position: relative;
}

.header-eyebrow {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    margin-bottom: 1.75rem;
}

.header-title {
    font-size: clamp(2.6rem, 5.5vw, 4rem);
    font-weight: 600;
    letter-spacing: -0.045em;
    line-height: 1.0;
    color: var(--text-primary);
}

.header-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 1.25rem;
    font-weight: 400;
    max-width: 440px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.65;
}

/* ===== Layout ===== */
.section {
    padding: 0 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.section-label {
    font-size: 0.6rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-muted-interactive);
    margin-bottom: 1.25rem;
    padding-top: 3rem;
}

/* ===== Dashboard / Sidebar Layout ===== */
.dashboard {
    display: flex;
    max-width: 1680px;
    margin: 0 auto;
}

.main-content {
    flex: 1;
    min-width: 0;
}

.sidebar {
    width: var(--sidebar-width);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--bg-card);
    flex-shrink: 0;
    z-index: 10;
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) transparent;
}

.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--text-muted); }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3rem 1.25rem 1.25rem;
    background: var(--bg-primary);
}

.sidebar-label {
    font-size: 0.6rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-muted-interactive);
    margin: 0;
}

.sidebar-toggle-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted-interactive);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 0;
    transition: color var(--transition), transform var(--transition);
}

.sidebar-toggle-btn:hover { color: var(--text-primary); }

.sidebar-body {
    padding: 1.25rem;
}

.sidebar .controls-grid {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
    align-items: stretch;
}

.sidebar .custom-select-dropdown {
    bottom: auto;
    top: calc(100% + 4px);
}

.sidebar .custom-select-arrow {
    transform: rotate(0deg);
}

.sidebar .custom-select.open .custom-select-arrow {
    transform: rotate(180deg);
}

.sidebar .indicator-chip {
    padding: 0.3rem 0.45rem;
    font-size: 0.64rem;
}

.sidebar .year-single-display {
    font-size: 1.4rem;
}

/* ===== Map ===== */
.map-container {
    display: flex;
    height: min(60vh, 700px);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

#map {
    flex: 1;
    z-index: 1;
}

.selected-panel {
    width: 256px;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: width var(--transition), padding var(--transition);
}

.selected-panel.collapsed {
    width: 48px;
    padding: 1rem 0.5rem;
    overflow: hidden;
}

.selected-panel.collapsed .panel-header,
.selected-panel.collapsed .empty-state,
.selected-panel.collapsed .chip-name,
.selected-panel.collapsed .chip-remove {
    display: none;
}

.selected-panel.collapsed .selected-list {
    align-items: center;
    gap: 6px;
}

.selected-panel.collapsed .country-chip {
    padding: 0.4rem;
    justify-content: center;
}

.selected-panel.collapsed .country-chip .color-dot {
    margin-right: 0;
    width: 8px;
    height: 8px;
}

.panel-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0.25rem 0.4rem;
    margin-bottom: 0.5rem;
    align-self: flex-end;
    transition: color var(--transition);
}

.panel-toggle:hover {
    color: var(--text-primary);
}

.selected-panel.collapsed .panel-toggle {
    align-self: center;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.panel-header h3 {
    font-size: 0.6rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-secondary);
}

.panel-count {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.selected-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
    padding: 3rem 0.75rem;
    line-height: 1.8;
}

.country-chip {
    display: flex;
    align-items: center;
    padding: 0.55rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 400;
    transition: background var(--transition);
    animation: chipIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.country-chip:nth-child(1) { animation-delay: 0s; }
.country-chip:nth-child(2) { animation-delay: 0.04s; }
.country-chip:nth-child(3) { animation-delay: 0.08s; }
.country-chip:nth-child(4) { animation-delay: 0.12s; }
.country-chip:nth-child(5) { animation-delay: 0.16s; }
.country-chip:nth-child(6) { animation-delay: 0.2s; }

.country-chip:hover { background: var(--bg-elevated); }

@keyframes chipIn {
    from { opacity: 0; transform: translateX(8px) scale(0.97); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

.country-chip .color-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 0.6rem;
    flex-shrink: 0;
}

.country-chip .chip-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.country-chip .chip-remove {
    background: none;
    border: none;
    color: var(--text-muted-interactive);
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1;
    padding: 0;
    margin-left: 0.4rem;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition);
}

.country-chip .chip-remove:hover { color: var(--country-2); }

/* ===== Controls ===== */
.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1.3fr 0.7fr;
    gap: 2.5rem;
    align-items: start;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.control-group label {
    font-size: 0.68rem;
    font-weight: 400;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.control-group select {
    width: 100%;
    padding: 0.6rem 2rem 0.6rem 0.7rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 400;
    cursor: pointer;
    transition: border-color var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' fill='%236e6e78' viewBox='0 0 16 16'%3E%3Cpath d='M8 12L2 5h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
}

.control-group select:focus {
    outline: none;
    border-color: var(--border-strong);
}

/* Custom select dropdown */
.custom-select {
    position: relative;
}

.custom-select-trigger {
    width: 100%;
    padding: 0.6rem 2rem 0.6rem 0.7rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 400;
    cursor: pointer;
    transition: border-color var(--transition);
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
}

.custom-select-trigger:hover,
.custom-select.open .custom-select-trigger {
    border-color: var(--border-strong);
}

.custom-select-arrow {
    color: var(--text-muted);
    font-size: 0.75rem;
    transition: transform var(--transition);
    transform: rotate(180deg);
}

.custom-select.open .custom-select-arrow {
    transform: rotate(0deg);
}

.custom-select-dropdown {
    display: none;
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg-card);
    border: 1px solid var(--border);
    max-height: 320px;
    overflow-y: scroll;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) transparent;
}

.custom-select-dropdown::-webkit-scrollbar { width: 12px; }
.custom-select-dropdown::-webkit-scrollbar-track { background: transparent; }
.custom-select-dropdown::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }
.custom-select-dropdown::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

.custom-select.open .custom-select-dropdown {
    display: block;
}

.custom-select-group {
    padding: 0.25rem 0;
}

.custom-select-group + .custom-select-group {
    border-top: 1px solid var(--border);
}

.custom-select-group-label {
    font-size: 0.58rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    padding: 0.5rem 0.7rem 0.25rem;
}

.custom-select-option {
    padding: 0.45rem 0.7rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.custom-select-option:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.custom-select-option.selected {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

/* Year controls — adapt per chart type */

/* Dual-thumb range slider */
.dual-range {
    position: relative;
    height: 24px;
    display: flex;
    align-items: center;
}

.dual-range-track {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 1px;
    background: var(--text-muted);
    pointer-events: none;
}

.dual-range-track::after {
    content: '';
    position: absolute;
    height: 1px;
    background: var(--text-primary);
    top: 0;
    left: var(--track-left, 0%);
    right: var(--track-right, 0%);
}

.dual-range input[type="range"] {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    outline: none;
    pointer-events: none;
    margin: 0;
    padding: 0;
}

.dual-range input[type="range"]::-webkit-slider-runnable-track {
    background: transparent;
    height: 100%;
}

.dual-range input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
    pointer-events: auto;
    z-index: 2;
    margin-top: 6px;
}

.dual-range input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
    pointer-events: auto;
    z-index: 2;
}

.dual-range input[type="range"]::-moz-range-track {
    background: transparent;
    height: 0;
    border: none;
}

.year-labels {
    display: flex;
    justify-content: space-between;
}

.year-labels span {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* Single year mode */
.year-single-display {
    font-size: 1.8rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 0.35rem;
}

.year-single-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.year-single-wrapper input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 1px;
    background: var(--text-muted);
    outline: none;
}

.year-single-wrapper input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
}

.year-single-wrapper input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
}

.chart-type-buttons {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
}

.chart-type-btn {
    flex: 1;
    padding: 0.55rem 0.4rem;
    background: transparent;
    border: none;
    color: var(--text-muted-interactive);
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 400;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
}

.chart-type-btn + .chart-type-btn {
    border-left: 1px solid var(--border);
}

.chart-type-btn:hover { color: var(--text-primary); }

.chart-type-btn.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    font-weight: 500;
}

.chart-type-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* Indicator chips for radar */
.indicator-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.indicator-chip {
    padding: 0.35rem 0.55rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted-interactive);
    font-family: var(--font);
    font-size: 0.68rem;
    cursor: pointer;
    transition: all var(--transition);
}

.indicator-chip:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.indicator-chip.active {
    color: var(--text-primary);
    border-color: var(--text-secondary);
    background: var(--bg-elevated);
}

/* ===== Charts ===== */
.section-charts {
    padding-bottom: 3rem;
    border-top: 1px solid transparent;
    border-image: linear-gradient(to right, transparent, var(--border-strong), transparent) 1;
}

.chart-wrapper {
    position: relative;
    border: 1px solid var(--border);
    padding: 2.5rem;
    min-height: 440px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

#main-chart {
    width: 100% !important;
    max-height: 480px;
    transition: opacity 0.25s ease;
}

/* Skeleton loading */
.skeleton-loading {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 2.5rem 3rem;
    gap: 0.75rem;
}

.skeleton-loading.visible {
    display: flex;
}

.skeleton-bar {
    width: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.skeleton-bar:nth-child(1) { height: 60%; }
.skeleton-bar:nth-child(2) { height: 40%; }
.skeleton-bar:nth-child(3) { height: 75%; }

@keyframes shimmer {
    to { background-position: -200% 0; }
}

.empty-chart-state {
    color: var(--text-muted);
    text-align: center;
    font-size: 0.82rem;
    line-height: 2;
}

.empty-chart-state .sep {
    width: 24px;
    height: 1px;
    background: var(--text-muted);
    margin: 0.75rem auto;
    opacity: 0.5;
}

.empty-chart-state p:last-child { font-size: 0.72rem; }

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(9, 9, 11, 0.93);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    gap: 1rem;
}

.loading-overlay.visible { display: flex; }

.loading-overlay p {
    color: var(--text-muted);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--text-muted);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 3.5rem 2rem;
    color: var(--text-muted);
    font-size: 0.68rem;
    letter-spacing: 0.02em;
}

.footer p + p { margin-top: 0.3rem; }

/* ===== Leaflet overrides ===== */
.leaflet-container {
    background: #0b0b0e;
    font-family: var(--font);
    outline: none;
}

/* Remove white focus flash on SVG paths when clicking countries */
.leaflet-interactive {
    outline: none !important;
}

.leaflet-interactive:focus {
    outline: none !important;
}

.leaflet-container svg path {
    outline: none !important;
}

.leaflet-overlay-pane svg {
    outline: none !important;
}

.leaflet-control-zoom {
    border: 1px solid var(--border) !important;
    border-radius: 0 !important;
    overflow: hidden;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-secondary) !important;
    border-color: var(--border) !important;
    width: 26px !important;
    height: 26px !important;
    line-height: 26px !important;
    font-size: 11px !important;
    border-radius: 0 !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-elevated) !important;
    color: var(--text-primary) !important;
}

.leaflet-control-attribution {
    background: rgba(9, 9, 11, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 0.55rem !important;
    padding: 1px 5px !important;
}

.leaflet-control-attribution a { color: var(--text-muted) !important; }

.country-tooltip {
    background: var(--bg-elevated) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: 0 !important;
    padding: 3px 8px !important;
    font-family: var(--font) !important;
    font-size: 0.7rem !important;
    font-weight: 400 !important;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5) !important;
}

/* ===== Entrance ===== */
.header,
.section-map,
.sidebar,
.section-charts {
    animation: fadeIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.header { animation-delay: 0s; }
.section-map { animation-delay: 0.08s; }
.sidebar { animation-delay: 0.14s; }
.section-charts { animation-delay: 0.2s; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Quick Example Button ===== */
.quick-example-btn {
    padding: 0.5rem 1.5rem;
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 0.5rem;
}
.quick-example-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
    background: var(--bg-elevated);
}
.empty-hint {
    font-size: 0.68rem;
    color: var(--text-muted);
}

/* ===== Map Hint Overlay ===== */
.map-hint-overlay {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 15, 18, 0.9);
    color: var(--text-secondary);
    font-size: 0.72rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    z-index: 5;
    pointer-events: none;
    animation: hintFade 3s ease-in-out forwards;
    display: none;
}
@keyframes hintFade {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; visibility: hidden; }
}

/* ===== Mobile Nav ===== */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    z-index: 1000;
    padding: 0.5rem;
    gap: 0.5rem;
    justify-content: center;
}
.mobile-nav-btn {
    padding: 0.5rem 1.5rem;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    text-align: center;
    transition: all var(--transition);
}
.mobile-nav-btn:hover { color: var(--text-primary); border-color: var(--border-strong); }

/* ===== Country Search ===== */
.country-search-wrapper {
    position: relative;
    margin-bottom: 0.75rem;
}
.country-search {
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.75rem;
    outline: none;
    transition: border-color var(--transition);
}
.country-search:focus { border-color: var(--border-strong); }
.country-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    z-index: 50;
}
.country-search-result {
    padding: 0.45rem 0.6rem;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
}
.country-search-result:hover:not(.already-selected) {
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.country-search-result.highlighted {
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.country-search-result.already-selected {
    color: var(--text-muted);
    cursor: default;
    opacity: 0.5;
}
.country-search-result.already-selected::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-muted);
    margin-right: 0.5rem;
    vertical-align: middle;
}

/* Combobox input row */
.combobox-input-row {
    display: flex;
    align-items: stretch;
}
.combobox-input-row .country-search {
    flex: 1;
    border-right: none;
    min-width: 0;
}
.combobox-toggle {
    width: 32px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-left: none;
    color: var(--text-muted-interactive);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition), background var(--transition);
    flex-shrink: 0;
    padding: 0;
}
.combobox-toggle:hover {
    color: var(--text-primary);
}
.combobox-toggle.open svg {
    transform: rotate(180deg);
}
.combobox-toggle svg {
    transition: transform var(--transition);
}

/* Dropdown animation */
.country-search-results {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    border-color: transparent;
    transition: max-height 0.25s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease, border-color 0.2s ease;
}
.country-search-results.visible {
    max-height: 240px;
    opacity: 1;
    overflow-y: auto;
    border-color: var(--border);
}

.selected-panel.collapsed .country-search-wrapper { display: none; }

/* ===== Panel Clear Button ===== */
.panel-clear {
    background: none;
    border: none;
    color: var(--text-muted-interactive);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 2px 4px;
    transition: color var(--transition);
}
.panel-clear:hover { color: var(--country-2); }
.selected-panel.collapsed .panel-clear { display: none; }

/* ===== Share bar ===== */
.share-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-top: 1.25rem;
    margin-top: 1.25rem;
    border-top: 1px solid var(--border);
    justify-content: center;
    width: 100%;
}
.share-btn {
    padding: 0.4rem 0.7rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted-interactive);
    font-family: var(--font);
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: all var(--transition);
}
.share-btn--icon {
    padding: 0.45rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}
.share-btn--icon svg { display: block; }
.share-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--bg-elevated);
}
.share-btn.copied {
    color: var(--country-6);
    border-color: var(--country-6);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .dashboard {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sidebar-toggle-btn {
        display: block;
    }
    .sidebar.collapsed .sidebar-body {
        display: none;
    }
    .sidebar.collapsed .sidebar-toggle-btn svg {
        transform: rotate(0deg);
    }
    .sidebar:not(.collapsed) .sidebar-toggle-btn svg {
        transform: rotate(180deg);
    }
    .map-container {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }
    #map {
        height: 400px;
        min-height: 300px;
        flex-shrink: 0;
    }
    .selected-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }
    .panel-header {
        width: 100%;
        order: 3;
        margin-bottom: 0;
        padding-bottom: 0.5rem;
    }
    .country-search-wrapper {
        width: 100%;
        order: 1;
    }
    .selected-list {
        flex-direction: row;
        flex-wrap: wrap;
        order: 2;
    }
    .country-chip {
        padding: 0.35rem 0.45rem;
        font-size: 0.72rem;
        border: 1px solid var(--border);
        background: var(--bg-elevated);
    }
    .country-chip .color-dot {
        width: 5px;
        height: 5px;
        margin-right: 0.4rem;
    }
    .section { padding-left: 1.25rem; padding-right: 1.25rem; }
    .header { padding-left: 1.25rem; padding-right: 1.25rem; }
    .mobile-nav {
        display: flex;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }
    body {
        padding-bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px));
    }
    .map-hint-overlay { display: block; }
    .panel-toggle { display: none; }
}

@media (max-width: 600px) {
    .header { padding: 2rem 1.25rem 1.5rem; }
    .header-title { font-size: 2.2rem; }
    .header-subtitle { display: none; }
    .lang-toggle { top: 1rem; right: 1.25rem; }
    .empty-state { display: none; }
    .section-label { margin-bottom: 0.75rem; padding-top: 2rem; }
    #map {
        height: 300px;
        min-height: 250px;
        flex-shrink: 0;
    }
    .chart-wrapper { padding: 1.5rem; min-height: 320px; }

    /* Larger slider thumbs for touch */
    .dual-range {
        height: 34px;
    }
    .dual-range input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
        margin-top: 7px;
    }
    .dual-range input[type="range"]::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }
    .year-single-wrapper {
        padding: 10px 0;
    }
    .year-single-wrapper input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }
    .year-single-wrapper input[type="range"]::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }
}

/* ===== SEO Content (pre-rendered pages) ===== */
.seo-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 2rem 0;
}
.seo-content h1 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}
.seo-content p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.7;
    max-width: 720px;
}

/* ===== Update Toast ===== */
.update-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    font-family: var(--font);
    font-size: 0.8rem;
    color: var(--text-primary);
    z-index: 10000;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: toast-in 0.35s var(--transition);
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(1rem); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.update-toast button {
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.75rem;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    transition: background var(--transition);
}
.update-toast button:hover {
    background: rgba(255,255,255,0.14);
}
.update-toast-close {
    padding: 0.25rem 0.45rem !important;
    font-size: 0.7rem !important;
    line-height: 1;
}

/* ===== Table Component ===== */
.wm-table-wrapper {
    border: 1px solid var(--border);
    background: var(--bg-card);
}

.table-wrapper {
    position: relative;
    min-height: 200px;
}

.wm-table-filters {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.wm-table-filters select {
    padding: 0.4rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.72rem;
    cursor: pointer;
}

.wm-table-scroll {
    overflow-x: auto;
}

.wm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.wm-table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.wm-table th .sort-arrow::after {
    content: '↕';
    opacity: 0.3;
    margin-left: 2px;
}

.wm-table th.sorted-asc .sort-arrow::after { content: '↑'; opacity: 0.8; }
.wm-table th.sorted-desc .sort-arrow::after { content: '↓'; opacity: 0.8; }

.wm-table th.right,
.wm-table td.right {
    text-align: right;
}

.wm-table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.wm-table tr.clickable { cursor: pointer; }
.wm-table tr.clickable:hover td { background: var(--bg-elevated); color: var(--text-primary); }

.wm-table .flag-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.wm-table .flag-cell img {
    border-radius: 1px;
    flex-shrink: 0;
}

.wm-table .no-data { color: var(--text-muted); }

.wm-table .trend-positive { color: #5fbf8a; }
.wm-table .trend-negative { color: #ff6b6b; }
.wm-table .trend-neutral  { color: var(--text-muted); }

.wm-table-toggle {
    padding: 0.5rem 1rem;
    text-align: center;
    border-top: 1px solid var(--border);
}

.wm-table-toggle-btn {
    padding: 0.4rem 1rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all var(--transition);
}

.wm-table-toggle-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

/* ===== Profile Cards ===== */
.profile-wrapper {
    position: relative;
    min-height: 200px;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.profile-header img {
    border-radius: 2px;
}

.profile-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.profile-header .profile-subtitle {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.profile-category {
    margin-bottom: 1.5rem;
}

.profile-category h3 {
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}

.profile-card {
    border: 1px solid var(--border);
    padding: 0.75rem;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.profile-card-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 400;
}

.profile-card-value {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.profile-card-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.profile-card canvas {
    width: 120px !important;
    height: 32px !important;
}

.profile-empty {
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.profile-similar {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.profile-similar h3 {
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.profile-similar-list {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.profile-similar-chip {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    font-size: 0.72rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.profile-similar-chip:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

/* ===== Composite Controls ===== */
.composite-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0;
}

.composite-row input[type="checkbox"] {
    accent-color: var(--country-1);
}

.composite-row label {
    flex: 1;
    font-size: 0.72rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.composite-row input[type="range"] {
    width: 80px;
    -webkit-appearance: none;
    appearance: none;
    height: 1px;
    background: var(--text-muted);
}

.composite-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
}

.composite-row input[type="range"]::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    border: none;
}

.composite-row .weight-val {
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    width: 2.5rem;
    text-align: right;
}

.composite-total {
    font-size: 0.72rem;
    color: var(--text-secondary);
    padding: 0.5rem 0;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}

/* ===== Snapshot Highlight Cards ===== */
.snapshot-highlights {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.snapshot-highlight-group {
    flex: 1;
}

.snapshot-highlight-group h4 {
    font-size: 0.6rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.snapshot-card {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    margin-bottom: 4px;
    font-size: 0.72rem;
}

.snapshot-card img { border-radius: 1px; }

.snapshot-card .name {
    flex: 1;
    color: var(--text-secondary);
}

.snapshot-card .change {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* ===== Scatter indicator selects ===== */
.scatter-select {
    width: 100%;
    padding: 0.5rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.75rem;
    cursor: pointer;
}

.scatter-select:focus {
    outline: none;
    border-color: var(--border-strong);
}

.scatter-filter-wrapper {
    position: relative;
}

.scatter-country-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    max-height: 180px;
    overflow-y: auto;
    z-index: 100;
}

.scatter-country-option {
    padding: 0.4rem 0.6rem;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text-primary);
}

.scatter-country-option:hover {
    background: var(--bg-input);
}

.scatter-country-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.scatter-country-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 0.68rem;
}

.scatter-chip-remove {
    background: none;
    border: none;
    color: var(--text-muted-interactive);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
    line-height: 1;
}

.scatter-chip-remove:hover {
    color: var(--text-primary);
}

.scatter-filter-hint {
    font-size: 0.68rem;
    color: var(--text-muted-interactive);
    font-style: italic;
}

/* ===== Section visibility helpers ===== */
.section-table,
.section-profile {
    padding-bottom: 3rem;
    border-top: 1px solid transparent;
    border-image: linear-gradient(to right, transparent, var(--border-strong), transparent) 1;
}

/* ===== Responsive additions ===== */
@media (max-width: 900px) {
    .wm-table-filters {
        flex-wrap: wrap;
    }
    .snapshot-highlights {
        flex-direction: column;
    }
}

@media (max-width: 600px) {
    .profile-grid {
        grid-template-columns: 1fr;
    }
    .profile-header h2 { font-size: 1.2rem; }
    .wm-table th,
    .wm-table td {
        padding: 0.4rem 0.5rem;
        font-size: 0.72rem;
    }
}
