/* ================================
   CSS Variables & Reset
================================ */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0a0a0a;
    --bg-secondary: #111111;
    --bg-card: #1a1a1a;
    --bg-hover: #222222;

    --text-primary: #f5f5f5;
    --text-secondary: #a3a3a3;
    --text-muted: #666666;

    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-subtle: rgba(59, 130, 246, 0.15);

    --border: #262626;
    --border-light: #333333;

    --success: #22c55e;
    --warning: #f59e0b;

    /* Surfaces & Shadows (for cards, charts) */
    --surface: #1f2937;
    --radius: 8px;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Merriweather', Georgia, serif;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ================================
   Layout
================================ */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

[hidden] {
    display: none !important;
}

/* ================================
   Header
================================ */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: var(--space-md) 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-md);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-decoration: none;
    color: var(--text-primary);
}

.logo-icon {
    font-size: 1.5rem;
}

.logo-text {
    font-family: var(--font-serif);
    font-size: 1rem;
    font-weight: 700;
}

@media (min-width: 640px) {
    .logo-text {
        font-size: 1.125rem;
    }
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
}

.github-link:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.lang-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition-fast);
}

.lang-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.lang-active {
    color: var(--accent);
    font-weight: 600;
}

.lang-inactive {
    color: var(--text-muted);
}

.lang-separator {
    color: var(--text-muted);
}

/* ================================
   Hero Section
================================ */
.hero {
    padding: var(--space-2xl) 0;
    text-align: center;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

.hero-badge {
    display: inline-block;
    background: var(--accent-subtle);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 500;
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-full);
    margin-bottom: var(--space-md);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.hero-title {
    font-family: var(--font-serif);
    font-size: clamp(1.5rem, 5vw, 2.25rem);
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: var(--space-sm);
}

.hero-subtitle {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    margin-bottom: var(--space-xl);
}

.hero-cta {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: var(--space-lg);
    margin-bottom: 0;
}

/* Search */
.search-container {
    position: relative;
    max-width: 500px;
    margin: 0 auto var(--space-xl);
}

.search-icon {
    position: absolute;
    left: var(--space-md);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: var(--space-md) var(--space-md) var(--space-md) calc(var(--space-md) * 2 + 20px);
    font-size: 1rem;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    transition: var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* Autosuggest */
.search-container {
    position: relative;
}

.autosuggest {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    max-height: 250px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.autosuggest[hidden] {
    display: none;
}

.autosuggest-item {
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    transition: var(--transition-fast);
}

.autosuggest-item:hover,
.autosuggest-item.active {
    background: var(--bg-hover);
}

.autosuggest-item .type {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.autosuggest-item .name {
    color: var(--text-primary);
}

/* Stats */
.stats {
    display: flex;
    justify-content: center;
    gap: var(--space-xl);
    flex-wrap: wrap;
}

.stat {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ================================
   Tabs Navigation
================================ */
.tabs-nav {
    position: sticky;
    top: 60px;
    z-index: 90;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: var(--space-sm) 0;
}

.tabs {
    display: flex;
    gap: var(--space-sm);
}

.tab {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
}

.tab:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.tab.active {
    color: var(--accent);
    background: var(--accent-subtle);
    border-color: var(--accent);
}

@media (min-width: 480px) {
    .tabs {
        justify-content: center;
    }

    .tab {
        flex: none;
        min-width: 120px;
    }
}

/* ================================
   Tab Content
================================ */
.main-content {
    min-height: 60vh;
}

.tab-content {
    display: none;
    padding: var(--space-xl) 0;
}

.tab-content.active {
    display: block;
}

/* ================================
   Timeline
================================ */
.timeline-filters {
    margin-bottom: var(--space-lg);
}

.timeline {
    position: relative;
    padding-left: var(--space-xl);
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: var(--space-lg);
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: calc(-1 * var(--space-xl) + 4px);
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-primary);
}

.timeline-year {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-xs);
}

.timeline-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    transition: var(--transition-fast);
}

.timeline-card:hover {
    border-color: var(--border-light);
}

.timeline-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.timeline-flag {
    font-size: 1.5rem;
}

.timeline-country {
    font-weight: 600;
    font-size: 1rem;
}

.timeline-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: var(--space-sm);
}

.timeline-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--accent);
    font-size: 0.8125rem;
    text-decoration: none;
}

.timeline-link:hover {
    text-decoration: underline;
}

/* ================================
   Filters
================================ */
.timeline-filters,
.table-filters {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.filter-select {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    min-width: 140px;
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ================================
   Unified Filters
================================ */
.unified-filters {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: var(--space-md) 0;
    position: sticky;
    top: 60px;
    z-index: 100;
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-lg);
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: var(--bg-card);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.btn-clear-filters {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-clear-filters:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

@media (max-width: 768px) {
    .unified-filters {
        position: relative;
        top: 0;
    }

    .filters-row {
        gap: var(--space-sm);
    }

    .filter-group {
        flex: 1 1 calc(50% - var(--space-sm));
        min-width: 140px;
    }

    .btn-clear-filters {
        width: 100%;
    }
}

/* ================================
   Data Table
================================ */
.table-filters {
    margin-bottom: var(--space-lg);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    align-items: center;
}

/* Year Range Slider */
.year-range-filter {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: var(--bg-card);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

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

.year-slider-container {
    position: relative;
    width: 200px;
    height: 24px;
    display: flex;
    align-items: center;
}

/* Background track */
.slider-track-bg {
    position: absolute;
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 0;
}

/* Active range bar (draggable) */
.slider-track-active {
    position: absolute;
    height: 4px;
    background: var(--accent);
    border-radius: 2px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    cursor: grab;
    pointer-events: auto;
    /* Allow dragging */
}

.slider-track-active:active {
    cursor: grabbing;
}

.year-slider {
    position: absolute;
    width: 100%;
    height: 24px;
    /* Ensure thumb is clickable */
    top: 0;
    pointer-events: none;
    -webkit-appearance: none;
    background: transparent;
    z-index: 2;
    /* Thumbs above track */
    margin: 0;
}

.year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    pointer-events: all;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 3;
}

.year-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    pointer-events: all;
    border: 2px solid white;
    position: relative;
    z-index: 3;
}


.year-labels {
    display: flex;
    gap: var(--space-xs);
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 500;
    min-width: 100px;
}

.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-md);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    table-layout: fixed;
}

.data-table th {
    background: var(--bg-secondary);
    padding: var(--space-md);
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s, color 0.2s;
}

th.sortable:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sort-icon {
    display: inline-block;
    margin-left: 0.5rem;
    font-size: 0.8em;
    width: 1em;
    opacity: 0.5;
}

th.active-sort .sort-icon {
    opacity: 1;
}

th.active-sort {
    color: var(--text-primary);
}

.data-table td {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table tbody tr {
    transition: var(--transition-fast);
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.table-country {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    white-space: normal;
    word-break: break-word;
    min-width: 120px;
    max-width: 180px;
}

.table-flag {
    font-size: 1.25rem;
}

.table-description {
    line-height: 1.5;
    white-space: normal;
    word-break: break-word;
}

.table-link {
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
}

.table-link:hover {
    text-decoration: underline;
}

.continent-badge {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

/* ================================
   Pagination
================================ */
.pagination,
.timeline-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
    padding: var(--space-md) 0;
}

.pagination-info {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-right: var(--space-md);
}

.pagination-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 var(--space-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
}

.pagination-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.pagination-ellipsis {
    color: var(--text-muted);
    padding: 0 var(--space-xs);
}

/* ================================
   About Section
================================ */
.about-section {
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    padding: var(--space-2xl) 0;
}

.about-section h2 {
    font-size: 1.25rem;
    margin-bottom: var(--space-lg);
    text-align: center;
}

.about-content {
    max-width: 800px;
    margin: 0 auto;
}

.about-content p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.7;
    margin-bottom: var(--space-md);
}

.about-content p:last-child {
    margin-bottom: 0;
}

.about-content strong {
    color: var(--accent);
}

/* ================================
   Open Data Section
================================ */
.open-data-section {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: var(--space-2xl) 0;
    text-align: center;
}

.open-data-section h2 {
    font-size: 1.25rem;
    margin-bottom: var(--space-sm);
}

.open-data-section>.container>p {
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

.download-buttons {
    display: flex;
    justify-content: center;
    gap: var(--space-md);
    flex-wrap: wrap;
    margin-bottom: var(--space-md);
}

.download-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
}

.download-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.license {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

/* ================================
   Footer
================================ */
.footer {
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    padding: var(--space-2xl) 0 var(--space-lg);
}

.footer-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-xl);
    margin-bottom: var(--space-xl);
}

@media (min-width: 768px) {
    .footer-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.footer-section h4 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: var(--space-md);
}

.sources-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.sources-list a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.875rem;
    transition: var(--transition-fast);
}

.sources-list a:hover {
    text-decoration: underline;
}

.disclaimer {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: var(--space-md);
}

.github-footer-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-decoration: none;
    transition: var(--transition-fast);
}

.github-footer-link:hover {
    color: var(--text-primary);
}

.footer-bottom {
    text-align: center;
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border);
}

.footer-bottom p {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

/* ================================
   Utilities
================================ */
.no-results {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
}

.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-2xl);
    gap: var(--space-md);
    color: var(--text-muted);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ================================
   Responsive Adjustments
================================ */
@media (max-width: 480px) {
    .hero {
        padding: var(--space-xl) 0;
    }

    .stats {
        gap: var(--space-lg);
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .timeline {
        padding-left: var(--space-lg);
    }

    .timeline-item::before {
        left: calc(-1 * var(--space-lg) + 4px);
    }

    .pagination-btn {
        min-width: 36px;
        height: 36px;
    }
}

/* ================================
   Scroll to Top Button
================================ */
.scroll-top {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-xl);
    width: 48px;
    height: 48px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-full);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: var(--transition-fast);
    z-index: 99;
}

.scroll-top:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.scroll-top[hidden] {
    display: none;
}

/* ================================
   Animations
================================ */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.timeline-item {
    animation: fadeInUp 0.4s ease forwards;
}

.data-table tbody tr {
    animation: fadeInUp 0.3s ease forwards;
}

/* ================================
   Interactive Map
================================ */
.map-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 200px);
    min-height: 500px;
    background: var(--bg-secondary);
}

.leaflet-map {
    width: 100%;
    height: 100%;
    background: #1a1a2e;
}

/* Leaflet dark theme overrides */
.leaflet-container {
    background: #1a1a2e;
    font-family: var(--font-sans);
}

.leaflet-control-zoom {
    border: none !important;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
}

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

.leaflet-control-attribution {
    background: rgba(26, 26, 26, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 10px;
}

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

/* Map Legend */
.map-legend {
    position: absolute;
    bottom: 30px;
    left: 10px;
    background: rgba(26, 26, 26, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    z-index: 1000;
    min-width: 150px;
}

.map-legend h4 {
    margin: 0 0 var(--space-sm) 0;
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 600;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 20px;
    height: 14px;
    border-radius: 2px;
    flex-shrink: 0;
}

.legend-divider {
    height: 1px;
    background: var(--border);
    margin: var(--space-sm) 0;
}

.legend-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.legend-toggle input {
    accent-color: var(--accent);
}

/* Map Info Panel */
.map-info {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(26, 26, 26, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    z-index: 1000;
    min-width: 200px;
    max-width: 280px;
}

.map-info h4 {
    margin: 0 0 var(--space-sm) 0;
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.map-info .info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-xs) 0;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.map-info .info-row:last-child {
    border-bottom: none;
}

.map-info .info-row span {
    color: var(--text-secondary);
}

.map-info .info-row strong {
    color: var(--text-primary);
}

/* Leaflet Popup Styles */
.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.leaflet-popup-content {
    margin: var(--space-sm);
    font-family: var(--font-sans);
}

.leaflet-popup-tip {
    background: var(--bg-card);
}

.map-popup-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: var(--space-xs);
}

.map-popup-stat {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 2px 0;
}

.map-popup-stat strong {
    color: var(--accent);
}

/* Regime border colors */
.regime-democracy {
    stroke: #10b981 !important;
    stroke-width: 2 !important;
}

.regime-hybrid {
    stroke: #fbbf24 !important;
    stroke-width: 2 !important;
}

.regime-autocracy {
    stroke: #ef4444 !important;
    stroke-width: 2 !important;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .map-container {
        height: calc(100vh - 160px);
        min-height: 400px;
    }

    .map-legend {
        bottom: 10px;
        left: 10px;
        padding: var(--space-sm);
        min-width: 120px;
    }

    .map-legend h4 {
        font-size: 0.75rem;
    }

    .legend-item {
        font-size: 0.625rem;
    }

    .map-info {
        top: auto;
        bottom: 10px;
        right: 10px;
        left: auto;
        max-width: 180px;
        padding: var(--space-sm);
    }

    .map-info h4 {
        font-size: 0.875rem;
    }

    .map-info .info-row {
        font-size: 0.75rem;
    }
}

/* =========================================
   CHARTS TAB STYLES
   ========================================= */

/* Intro text */
.charts-intro {
    text-align: center;
    padding: var(--space-md) 0;
    margin-bottom: var(--space-md);
}

.charts-intro-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
}

/* Grid layout */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-lg);
    padding: 0;
}

@media (min-width: 768px) {
    .charts-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Individual chart cards */
.chart-card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.chart-header {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}

.chart-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
}

.chart-subtitle {
    margin: var(--space-xs) 0 0 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.chart-body {
    padding: var(--space-md);
    height: 280px;
    position: relative;
}

.chart-body canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-body-doughnut {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 300px;
}

/* Charts note */
.charts-note {
    text-align: center;
    padding: var(--space-lg) 0;
    margin-top: var(--space-md);
}

.charts-note p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}

/* Legacy support (if needed) */
.chart-container {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow);
    min-height: 350px;
}

.chart-container h3 {
    margin-bottom: var(--space-md);
    color: var(--text-primary);
    font-size: 1.1rem;
    text-align: center;
}

.chart-container canvas {
    max-height: 280px;
}

.chart-wrapper-doughnut {
    position: relative;
    max-width: 300px;
    height: 280px;
    margin: 0 auto;
}

/* Mobile optimizations for charts */
@media (max-width: 640px) {
    .charts-intro {
        padding: var(--space-sm) var(--space-md);
    }

    .charts-intro-text {
        font-size: 0.875rem;
    }

    .chart-card {
        border-radius: var(--radius-md);
    }

    .chart-header {
        padding: var(--space-sm) var(--space-md);
    }

    .chart-header h3 {
        font-size: 0.9rem;
    }

    .chart-subtitle {
        font-size: 0.75rem;
    }

    .chart-body {
        padding: var(--space-sm);
        height: 240px;
    }

    .chart-body-doughnut {
        height: 260px;
    }

    .charts-note p {
        font-size: 0.8rem;
        padding: 0 var(--space-md);
    }
}


/* =========================================
   MAP OVERLAY CONTROLS
   ========================================= */
.map-controls-overlay {
    position: absolute;
    top: auto;
    bottom: 30px;
    right: 10px;
    background: rgba(17, 24, 39, 0.95);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    z-index: 1000;
    color: var(--text-primary);
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.map-mode-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.map-mode-label:last-child {
    margin-bottom: 0;
}

.map-mode-label input[type="radio"] {
    accent-color: var(--accent);
    cursor: pointer;
}

@media (max-width: 640px) {
    .map-controls-overlay {
        position: relative;
        top: auto;
        right: auto;
        margin: 10px;
        background: var(--surface);
    }
}

/* =========================================
   MOBILE ENHANCEMENTS
   ========================================= */
@media (max-width: 640px) {

    /* Header mobile */
    .header {
        padding: var(--space-sm) 0;
    }

    .logo-text {
        font-size: 0.875rem;
    }

    .logo-icon {
        font-size: 1.25rem;
    }

    /* Hero mobile */
    .hero {
        padding: var(--space-lg) 0;
    }

    .hero-title {
        font-size: 1.25rem;
        padding: 0 var(--space-sm);
    }

    .hero-subtitle {
        font-size: 0.8rem;
        padding: 0 var(--space-sm);
    }

    /* Stats mobile - 2x2 grid */
    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-md);
        padding: 0 var(--space-sm);
    }

    .stat {
        padding: var(--space-sm);
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    /* Tabs mobile */
    .tabs-nav {
        padding: var(--space-sm) 0;
    }

    .tabs {
        gap: var(--space-xs);
    }

    .tab {
        padding: var(--space-sm) var(--space-md);
        font-size: 0.8rem;
    }

    /* Filters mobile */
    .unified-filters {
        padding: var(--space-sm) 0;
    }

    .filters-row {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .filter-group {
        flex: 1 1 100%;
        min-width: 100%;
    }

    .filter-label {
        font-size: 0.75rem;
    }

    .filter-select {
        font-size: 0.85rem;
        padding: var(--space-sm);
    }

    /* Year slider mobile */
    .year-slider-container {
        height: 40px;
    }

    .year-labels {
        font-size: 0.8rem;
    }

    /* Map mobile */
    .map-container {
        min-height: 350px;
    }

    .leaflet-map {
        min-height: 300px;
    }

    .map-legend {
        position: relative;
        bottom: auto;
        left: auto;
        margin: var(--space-sm);
        min-width: auto;
    }

    .map-info {
        position: relative;
        top: auto;
        right: auto;
        margin: var(--space-sm);
    }

    /* Timeline mobile */
    .timeline-item {
        padding-left: var(--space-md);
    }

    .timeline-year {
        font-size: 0.9rem;
    }

    .timeline-card {
        padding: var(--space-md);
    }

    .timeline-flag {
        font-size: 1.25rem;
    }

    .timeline-country {
        font-size: 0.9rem;
    }

    .timeline-description {
        font-size: 0.85rem;
    }

    /* Table mobile */
    .table-container {
        font-size: 0.75rem;
    }

    .data-table th,
    .data-table td {
        padding: var(--space-sm);
    }

    /* Pagination mobile */
    .pagination {
        gap: var(--space-xs);
    }

    .pagination-info {
        display: none;
    }

    .pagination-btn {
        min-width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    /* Footer mobile */
    .footer-grid {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }

    .footer-section h4 {
        font-size: 0.9rem;
    }

    .sources-list {
        font-size: 0.8rem;
    }

    /* About section mobile */
    .about-section,
    .open-data-section {
        padding: var(--space-xl) 0;
    }

    .about-section h2,
    .open-data-section h2 {
        font-size: 1.1rem;
    }

    .about-content p {
        font-size: 0.85rem;
    }

    .download-buttons {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .download-btn {
        width: 100%;
        justify-content: center;
    }

    /* Scroll to top mobile */
    .scroll-top {
        width: 40px;
        height: 40px;
        right: var(--space-md);
        bottom: var(--space-md);
    }
}

/* Extra small devices */
@media (max-width: 360px) {
    .container {
        padding: 0 var(--space-sm);
    }

    .hero-title {
        font-size: 1.1rem;
    }

    .stats {
        gap: var(--space-sm);
    }

    .stat-number {
        font-size: 1.25rem;
    }

    .tab {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.75rem;
    }
}