:root {
    --stats-card-bg: #0D0D0F;
    --stats-border: rgba(255, 255, 255, 0.05);
}

body.light-theme {
    --stats-card-bg: #eae2d2;
    --stats-border: rgba(0, 0, 0, 0.08);
}

.stats-section {
    padding-top: 20px !important;
}

/* Towns Layout Container (1400px) */
.stats-section .container {
    max-width: 1400px !important;
}

.stats-inner-container {
    max-width: 1400px !important;
    margin: 0 auto;
    width: 100%;
}

.stats-header-new {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-end !important;
    margin-bottom: 20px !important;
    width: 100%;
    margin-top: 10px !important;
    border-bottom: 1px solid var(--border-highlight) !important;
}

.stats-header-form {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 12px !important;
}

.filters-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Custom Select Dropdowns */
.custom-select-container {
    position: relative;
    z-index: 10;
    width: 190px;
}

.custom-select-container.open {
    z-index: 110 !important;
}

.custom-select-trigger {
    width: 100%;
    background: var(--stats-card-bg) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px;
    padding: 10px 16px;
    color: var(--text-main);
    font-size: 0.95rem;
    font-family: 'Onest', sans-serif;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    transition: all 0.2s ease;
    height: 44px;
    white-space: nowrap;
    gap: 8px;
}

.custom-select-trigger span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-select-trigger:hover {
    border-color: rgba(255, 255, 255, 0.25) !important;
}

.light-theme .custom-select-trigger:hover {
    border-color: rgba(0, 0, 0, 0.25) !important;
}

.chevron-icon {
    width: 12px;
    height: 12px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.custom-select-container.open .chevron-icon {
    transform: rotate(180deg);
}

.custom-select-options {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: max-content;
    min-width: 100%;
    background: var(--stats-card-bg) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px;
    padding: 6px;
    z-index: 100;
    box-sizing: border-box;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
    animation: dropdownFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
    flex-direction: column;
    gap: 4px;
}

.light-theme .custom-select-options {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}

.custom-select-container.open .custom-select-options {
    display: flex;
}

.custom-select-option {
    padding: 10px 14px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.custom-select-option:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.light-theme .custom-select-option:hover {
    background: rgba(0, 0, 0, 0.05);
}

.custom-select-option.selected {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
    font-weight: 600;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-row-new {
    position: relative;
    z-index: 1;
}

.search-input-new {
    width: 100%;
    height: 44px;
    background: var(--stats-card-bg) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px;
    padding: 0 16px 0 42px !important;
    color: var(--text-main);
    font-size: 0.95rem;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s;
}

.search-input-new:focus {
    border-color: rgba(255, 255, 255, 0.25) !important;
}

.light-theme .search-input-new:focus {
    border-color: rgba(0, 0, 0, 0.25) !important;
}

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

.search-icon-new {
    position: absolute;
    left: 16px !important;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    display: flex;
    align-items: center;
    z-index: 5;
}

.btn-create-town {
    height: 44px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    padding: 0 28px;
    background: var(--stats-card-bg) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px;
    color: var(--text-main) !important;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: none !important;
}

.btn-create-town:hover {
    background: var(--hover-bg) !important;
    border-color: rgba(255, 255, 255, 0.25) !important;
}

.btn-create-town:active {
    opacity: 0.8 !important;
}

.towns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 24px !important;
}

.town-banner-card {
    min-height: 280px;
    background: var(--stats-card-bg) !important;
    border-radius: 20px !important;
    border: 1px solid var(--stats-border) !important;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.2s, background-color 0.2s !important;
}

.town-banner-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.12) !important;
    background: var(--hover-bg) !important;
}

body.light-theme .town-banner-card:hover {
    border-color: rgba(0, 0, 0, 0.15) !important;
}

.my-town-card {
    border-color: rgba(59, 130, 246, 0.35) !important;
}

@media (max-width: 900px) {
    .stats-header-form {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 16px !important;
    }

    .filters-row {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
        gap: 12px !important;
    }

    .filters-row .custom-select-container {
        width: 100% !important;
    }

    .search-controls-wrapper {
        width: 100% !important;
        flex-direction: row !important;
        justify-content: space-between !important;
    }
}

@media (max-width: 600px) {
    .towns-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 500px) {
    .town-banner-card {
        flex-direction: column-reverse !important;
    }
    
    .card-icon-side-container {
        padding: 16px 16px 0 16px !important;
        width: 100% !important;
        height: 130px !important;
        box-sizing: border-box !important;
    }
    
    .card-icon-side {
        width: 100% !important;
        height: 100% !important;
        min-height: unset !important;
    }
}
