:root {
    /* Light Theme */
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 0.75rem;
    --nav-height: 4rem;
}

[data-theme="dark"] {
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --bg-body: #111827;
    --bg-card: #1f2937;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --border: #374151;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

/* Navigation */
.top-nav {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    height: var(--nav-height);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.nav-btn, .theme-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.nav-btn:hover, .theme-btn:hover {
    background-color: var(--border);
}

.nav-dropdown-wrapper {
    position: relative;
}

.nav-dropdown-menu {
    position: absolute;
    top: 120%;
    right: 0;
    width: 220px;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    background: transparent;
    border: none;
    text-align: left;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: background-color 0.2s;
}

.nav-item:hover {
    background-color: var(--border);
}

.nav-item.active {
    background-color: var(--primary);
    color: white;
}

/* Main Layout */
.main-content {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    min-height: calc(100vh - var(--nav-height) - 4rem);
}

/* Search Section */
.search-section {
    margin-bottom: 2rem;
}

.search-wrapper {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
}

#country-input {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    border: 2px solid var(--border);
    border-radius: 2rem;
    background-color: var(--bg-card);
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#country-input:focus {
    border-color: var(--primary);
}

.clear-btn {
    position: absolute;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
}

.suggestions-dropdown {
    position: absolute;
    top: 110%;
    left: 0;
    right: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 10;
    max-height: 300px;
    overflow-y: auto;
}

.suggestion-item {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid var(--border);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background-color: var(--border);
}

.suggestion-flag {
    width: 30px;
    height: 20px;
    object-fit: cover;
    border-radius: 4px;
}

/* Explore View */
#country-detail-wrapper {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    animation: fadeIn 0.4s ease;
}

.country-header {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    align-items: center;
}

.flag-container {
    flex: 0 0 200px;
}

#main-flag {
    width: 100%;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    object-fit: cover;
}

.header-info {
    flex: 1;
}

.title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fav-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.fav-btn.active {
    color: #ef4444;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
}

.subtitle {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.badges {
    display: flex;
    gap: 0.5rem;
}

.badge {
    background-color: var(--primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background-color: var(--bg-body);
    padding: 1.5rem;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
}

.stat-card i {
    font-size: 1.5rem;
    color: var(--primary);
}

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

.stat-value {
    font-weight: 700;
    font-size: 1.25rem;
}

/* Details Section */
.details-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.detail-column h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

.detail-list {
    list-style: none;
}

.detail-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
}

/* Neighbors */
.neighbors-section h3 {
    margin-bottom: 1rem;
    color: var(--text-muted);
}

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

.neighbor-card {
    background-color: var(--bg-body);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    border: 1px solid var(--border);
}

.neighbor-card:hover {
    transform: translateY(-4px);
}

.neighbor-flag img {
    width: 100%;
    height: 100px;
    object-fit: cover;
}

.neighbor-info {
    padding: 0.75rem;
    text-align: center;
}

.neighbor-info h4 {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Map Mode */
#map-container {
    height: 600px;
    width: 100%;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 1;
}

/* Compare Mode */
.compare-controls {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 2rem;
    justify-content: center;
}

.compare-search {
    flex: 1;
    max-width: 300px;
    position: relative;
}

.compare-search label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.compare-search input {
    width: 100%;
    padding: 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background-color: var(--bg-card);
    color: var(--text-main);
}

.compare-vs {
    font-weight: 700;
    color: var(--primary);
    padding-bottom: 0.75rem;
}

.comparison-grid {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.cmp-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    text-align: center;
    margin-bottom: 2rem;
}

.cmp-flag {
    width: 80px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.cmp-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.cmp-label {
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 1rem;
    text-align: center;
}

.cmp-val {
    text-align: center;
    font-weight: 500;
}

.cmp-indicator {
    font-size: 0.8rem;
    margin: 0 0.25rem;
}

.up { color: #10b981; }
.down { color: #ef4444; }
.eq { color: #6b7280; }

/* Lists (Fav/History) */
.list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.list-card {
    background-color: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    position: relative;
    transition: transform 0.2s;
}

.list-card:hover {
    transform: translateY(-4px);
}

.list-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
}

.list-info {
    padding: 1rem;
    text-align: center;
}

.remove-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-btn:hover {
    background: #ef4444;
}

/* Utilities */
.hidden { display: none !important; }

.placeholder-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.placeholder-state i {
    font-size: 4rem;
    margin-bottom: 1rem;
    color: var(--border);
}

.error-message {
    background-color: #fef2f2;
    color: #b91c1c;
    padding: 1rem;
    border-radius: var(--radius);
    text-align: center;
    margin-bottom: 1rem;
    border: 1px solid #fecaca;
}

/* Skeleton Loading */
.skeleton-card {
    height: 400px;
    background: var(--border);
    border-radius: var(--radius);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

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

/* Responsive */
@media (max-width: 768px) {
    .country-header {
        flex-direction: column;
        text-align: center;
    }
    
    .flag-container {
        width: 100%;
    }

    .title-row {
        justify-content: center;
        gap: 1rem;
    }

    .badges {
        justify-content: center;
    }

    .details-section {
        grid-template-columns: 1fr;
    }

    .compare-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .compare-search {
        width: 100%;
    }
}