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

:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --bg-color: #f5f6fa;
    --text-color: #2d3436;
    --border-color: #dcdde1;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

header {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@media (min-width: 768px) {
    header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 0;
    }
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.custom-dropdown {
    position: relative;
    width: 200px;
    color: var(--text-color);
}

#compare-search {
    width: 100%;
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    box-sizing: border-box;
}

#clear-compare-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: #666;
}

.dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 250px;
    overflow-y: auto;
    background: white;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 4px 4px;
    list-style: none;
    padding: 0;
    margin: 0;
    z-index: 3000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.dropdown-list li {
    padding: 0.5rem;
    cursor: pointer;
    border-bottom: 1px solid #f1f2f6;
    display: flex;
    align-items: center;
}

.dropdown-list li:hover {
    background-color: #f1f2f6;
}

.dropdown-list li:last-child {
    border-bottom: none;
}

.app-container {
    display: flex;
    flex: 1;
    flex-direction: column;
}

@media (min-width: 768px) {
    .app-container {
        flex-direction: row;
    }
}

.map-section {
    flex: 2;
    position: relative;
    min-height: 50vh;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.map-container {
    flex: 1;
    width: 100%;
    z-index: 1;
}

.stats-section {
    flex: 1;
    padding: 1rem 0;
    background-color: white;
    overflow-y: auto;
}

@media (min-width: 768px) {
    .stats-section {
        padding: 1.5rem;
    }
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.stats-table th, .stats-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.stats-table th {
    background-color: #f8f9fa;
    color: #2c3e50;
    font-weight: bold;
}

.subheader-row td {
    background-color: #f1f5f9;
    color: #475569;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    padding: 0.4rem 0.75rem;
}

.metric-name {
    font-weight: bold;
    color: #334155;
}

.stats-table tbody tr {
    cursor: pointer;
    transition: background-color 0.2s;
}

.stats-table tbody tr:hover {
    background-color: #f1f2f6;
}

.hidden {
    display: none !important;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.close-btn {
    position: absolute;
    top: 1rem; right: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
}

.spinner {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.8);
    padding: 1rem;
    border-radius: 4px;
    font-weight: bold;
    z-index: 2000;
}

.country-pill {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

.flag-icon {
    width: 20px;
    height: auto;
    margin-right: 6px;
    border: 1px solid #ccc;
    border-radius: 2px;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0 1rem;
}

#selected-countries-list {
    padding: 0 1rem;
}

@media (min-width: 768px) {
    .stats-header {
        padding: 0;
    }
    #selected-countries-list {
        padding: 0;
    }
}

.stats-header h2 {
    margin: 0;
}

.btn-clear {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.btn-clear:hover {
    background-color: #c0392b;
}