/* CSS Variables for Theme Colors */
:root {
    /* Light Mode Colors */
    --bg-color: hsl(0, 0%, 99%);
    --element-color: hsl(0, 100%, 100%);
    --text-color: hsl(200, 15%, 8%);
    --input-color: hsl(0, 0%, 50%);

    /* Typography */
    --font-family: 'Nunito Sans', sans-serif;
    --font-size-homepage: 14px;
    --font-size-detail: 16px;
    --font-weight-light: 300;
    --font-weight-semibold: 600;
    --font-weight-extra-bold: 800;

    /* Spacing */
    --container-padding: 1rem;
    --border-radius: 5px;
    --box-shadow: 0 2px 9px rgba(0, 0, 0, 0.05);
}

/* Dark Mode Colors */
[data-theme="dark"] {
    --bg-color: hsl(207, 26%, 17%);
    --element-color: hsl(209, 23%, 22%);
    --text-color: hsl(0, 100%, 100%);
    --input-color: hsl(0, 100%, 100%);
    --box-shadow: 0 2px 9px rgba(0, 0, 0, 0.2);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-homepage);
    font-weight: var(--font-weight-light);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 var(--container-padding);
}

/* Header Styles */
.header {
    background-color: var(--element-color);
    box-shadow: var(--box-shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color 0.3s ease;
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem var(--container-padding);
}

.header__title {
    font-size: 1.5rem;
    font-weight: var(--font-weight-extra-bold);
    color: var(--text-color);
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: var(--font-size-homepage);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.3s ease;
}

.theme-toggle:hover {
    opacity: 0.8;
}

/* Main Content */
.main {
    padding: 2rem 0;
}

/* Controls Section */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    gap: 2rem;
}

/* Search Container */
.search-container {
    position: relative;
    flex: 1;
    max-width: 480px;
}

.search-icon {
    position: absolute;
    left: 2rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--input-color);
    font-size: 1rem;
}

.search-input {
    width: 100%;
    padding: 1rem 1rem 1rem 4rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--element-color);
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: var(--font-size-homepage);
    box-shadow: var(--box-shadow);
    transition: all 0.3s ease;
}

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

.search-input:focus {
    outline: none;
    box-shadow: 0 2px 9px rgba(0, 0, 0, 0.1);
}

/* Filter Container */
.filter-container {
    position: relative;
    min-width: 200px;
}

.filter-select {
    width: 100%;
    padding: 1rem 3rem 1rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--element-color);
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: var(--font-size-homepage);
    font-weight: var(--font-weight-semibold);
    box-shadow: var(--box-shadow);
    cursor: pointer;
    appearance: none;
    transition: all 0.3s ease;
}

.filter-icon {
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-color);
    pointer-events: none;
    font-size: 0.8rem;
}

.filter-select:focus {
    outline: none;
    box-shadow: 0 2px 9px rgba(0, 0, 0, 0.1);
}

/* Countries Grid */
.countries-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(264px, 1fr));
    gap: 4.5rem;
    margin-bottom: 2rem;
}

/* Country Card */
.country-card {
    background-color: var(--element-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
}

.country-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.country-flag {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}

.country-info {
    padding: 1.5rem;
}

.country-name {
    font-size: 1.125rem;
    font-weight: var(--font-weight-extra-bold);
    margin-bottom: 1rem;
    color: var(--text-color);
}

.country-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.country-detail-item {
    font-size: var(--font-size-homepage);
    color: var(--text-color);
}

.country-detail-label {
    font-weight: var(--font-weight-semibold);
}

/* Loading and Error States */
.loading, .error {
    text-align: center;
    padding: 3rem;
    color: var(--text-color);
}

.loading i {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--input-color);
}

.error {
    background-color: var(--element-color);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin: 2rem 0;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 1000;
    overflow-y: auto;
}

.modal.active {
    display: block;
}

.modal-content {
    max-width: 1440px;
    margin: 0 auto;
    padding: 2rem var(--container-padding);
}

.back-button {
    background-color: var(--element-color);
    border: none;
    padding: 0.5rem 2rem;
    border-radius: var(--border-radius);
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: var(--font-size-homepage);
    font-weight: var(--font-weight-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--box-shadow);
    margin-bottom: 4rem;
    transition: all 0.3s ease;
}

.back-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Country Detail Styles */
.country-detail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8rem;
    align-items: center;
}

.country-detail-flag {
    width: 100%;
    max-width: 560px;
    height: auto;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.country-detail-info h2 {
    font-size: 2rem;
    font-weight: var(--font-weight-extra-bold);
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.country-detail-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem 4rem;
    margin-bottom: 2rem;
}

.country-detail-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.country-detail-item {
    font-size: var(--font-size-detail);
    color: var(--text-color);
    line-height: 1.8;
}

.country-detail-label {
    font-weight: var(--font-weight-semibold);
}

.border-countries {
    margin-top: 2rem;
}

.border-countries h3 {
    font-size: var(--font-size-detail);
    font-weight: var(--font-weight-semibold);
    margin-bottom: 1rem;
    color: var(--text-color);
}

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

.border-country {
    background-color: var(--element-color);
    border: none;
    padding: 0.25rem 1.5rem;
    border-radius: var(--border-radius);
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: var(--font-weight-light);
    cursor: pointer;
    box-shadow: var(--box-shadow);
    transition: all 0.3s ease;
}

.border-country:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* No Results Styles */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--input-color);
    font-size: 1.125rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }

    .header .container {
        padding: 1rem;
    }

    .header__title {
        font-size: 1rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 2.5rem;
        margin-bottom: 2rem;
    }

    .search-container {
        max-width: none;
    }

    .filter-container {
        min-width: auto;
        max-width: 200px;
    }

    .countries-grid {
        grid-template-columns: 1fr;
        gap: 2.5rem;
        justify-items: center;
    }

    .country-card {
        max-width: 264px;
        width: 100%;
    }

    .country-detail {
        grid-template-columns: 1fr;
        gap: 2.5rem;
        text-align: left;
    }

    .country-detail-content {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .border-countries h3 {
        margin-bottom: 1rem;
    }

    .border-list {
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .header__title {
        font-size: 0.875rem;
    }

    .theme-toggle {
        font-size: 0.75rem;
    }

    .theme-toggle span {
        display: none;
    }

    .main {
        padding: 1.5rem 0;
    }

    .modal-content {
        padding: 1.5rem 1rem;
    }

    .back-button {
        margin-bottom: 2rem;
    }

    .country-detail-info h2 {
        font-size: 1.375rem;
    }
}
