:root {
    --bg: #0f1115;
    --panel: #151923;
    --text: #e6e6e6;
    --muted: #a8b0c2;
    --accent2: #359a28;
    --border: #1f2940;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app {
    display: grid;
    grid-template-rows: auto 1fr;
    height: 100%;
}

header {
    padding: 10px 12px;
    background: var(--panel);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    position: relative;
}

header h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-btn {
    background: #0e1220;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.dropdown-btn:hover {
    background: var(--accent2);
    border-color: var(--accent2);
    color: white;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% - 2px);
    background: var(--panel);
    min-width: 220px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: 6px;
    z-index: 10000;
    overflow: hidden;
}

.dropdown-content a {
    color: var(--text);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 13px;
    transition: all 0.2s;
    border-bottom: 1px solid var(--border);
}

.dropdown-content a:last-child {
    border-bottom: none;
}

.dropdown-content a:hover {
    background: var(--accent2);
    color: white;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.control {
    background: #0e1220;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    display: flex;
    gap: 8px;
    align-items: center;
    color: var(--muted);
    font-size: 12px;
}

select {
    background: var(--panel);
    color: var(--text);
    border: none;
    outline: none;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

select:focus {
    background: #0e1220;
    outline: 1px solid var(--accent2);
}

select:hover {
    background: #0e1220;
}

select option {
    background: var(--panel);
    color: var(--text);
    padding: 4px;
    border: none;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    height: 100%;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
    touch-action: pan-x pan-y;
    z-index: 1;
}

.sidebar {
    background: var(--panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-header h2 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
}

.filters {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 11px;
    color: var(--muted);
    font-weight: 500;
}

.filter-input {
    background: #0e1220;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    color: var(--text);
    font-size: 12px;
}

.filter-input:focus {
    outline: none;
    border-color: var(--accent2);
}

.sort-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.sort-btn {
    background: #0e1220;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.sort-btn:hover {
    background: var(--accent2);
    border-color: var(--accent2);
}

.sort-btn.active {
    background: var(--accent2);
    border-color: var(--accent2);
    color: white;
}

.cities-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    height: 0;
    min-height: 150px;
    max-height: calc(100vh - 280px);
    -webkit-overflow-scrolling: touch;
}

.city-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.city-item:hover {
    background: #0e1220;
}

.city-item:active {
    background: #0a0d14;
}

.city-info {
    flex: 1;
}

.city-name {
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 2px;
}

.city-state {
    font-size: 11px;
    color: var(--muted);
}

.city-population {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent2);
    text-align: right;
}

.stats {
    padding: 16px;
    background: #0e1220;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--muted);
    flex-shrink: 0;
    min-height: 80px;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.stats-row:last-child {
    margin-bottom: 0;
}

.stats-value {
    font-weight: 600;
    color: var(--text);
}

.cities-list::-webkit-scrollbar {
    width: 6px;
}

.cities-list::-webkit-scrollbar-track {
    background: #0e1220;
}

.cities-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.cities-list::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr 350px;
    }
}

@media (max-width: 768px) {
    body {
        overflow-y: auto;
    }

    .app {
        height: auto;
        min-height: 100vh;
    }

    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: 40vh auto;
        height: auto;
        min-height: calc(100vh - 60px);
        overflow: visible;
    }

    #map {
        height: 40vh;
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .sidebar {
        height: auto;
        max-height: none;
        min-height: 100vh;
        border-left: none;
        border-top: 2px solid var(--border);
        position: relative;
        z-index: 2;
    }

    .sidebar-header {
        padding: 10px 12px;
    }

    .sidebar-header h2 {
        margin: 0 0 8px 0;
        font-size: 14px;
    }

    .filters {
        gap: 6px;
    }

    .filter-group {
        gap: 3px;
    }

    .filter-group label {
        font-size: 12px;
    }

    .filter-input {
        font-size: 16px;
        padding: 10px;
    }

    .sort-btn {
        font-size: 13px;
        padding: 10px;
    }

    .cities-list {
        flex: 1;
        max-height: none;
        min-height: 60vh;
        overflow-y: visible;
    }

    .city-item {
        padding: 14px;
        min-height: 56px;
    }

    .city-name {
        font-size: 14px;
    }

    .city-state {
        font-size: 12px;
    }

    .city-population {
        font-size: 13px;
    }

    .stats {
        font-size: 12px;
        padding: 10px 12px;
        min-height: 70px;
    }

    header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
        padding: 10px;
        position: sticky;
        top: 0;
        z-index: 1001;
    }

    header h1 {
        font-size: 15px;
        text-align: center;
    }

    .dropdown {
        width: 100%;
    }

    .dropdown-btn {
        width: 100%;
        font-size: 14px;
        padding: 10px 12px;
    }

    .dropdown-content {
        width: 100%;
        min-width: auto;
        right: 0;
        left: 0;
    }

    .dropdown-content a {
        font-size: 14px;
        padding: 12px 16px;
    }

    .controls {
        flex-direction: column;
        gap: 8px;
    }

    .control {
        width: 100%;
        justify-content: center;
        font-size: 13px;
        padding: 8px;
    }

    select {
        font-size: 16px;
        padding: 6px;
    }
}

@media (max-width: 480px) {
    .main-content {
        grid-template-rows: 35vh auto;
    }

    #map {
        height: 35vh;
    }

    header h1 {
        font-size: 14px;
    }

    .dropdown-btn {
        font-size: 13px;
    }

    .sidebar-header h2 {
        font-size: 13px;
    }

    .sidebar-header {
        padding: 8px 10px;
    }

    .filters {
        gap: 5px;
    }

    .stats {
        padding: 8px 10px;
        min-height: 65px;
    }
}

@media (max-width: 360px) {
    header {
        padding: 8px;
    }

    header h1 {
        font-size: 13px;
    }

    .dropdown-btn {
        font-size: 12px;
        padding: 8px 10px;
    }

    .control {
        font-size: 12px;
        padding: 6px;
    }

    .sidebar-header {
        padding: 8px;
    }

    .city-item {
        padding: 12px;
    }

    .city-name {
        font-size: 13px;
    }

    .city-state {
        font-size: 11px;
    }

    .city-population {
        font-size: 12px;
    }

    .stats {
        font-size: 11px;
        padding: 8px;
    }
}

@media (orientation: landscape) and (max-height: 600px) {
    .app {
        height: 100%;
    }

    .main-content {
        grid-template-rows: 1fr;
        grid-template-columns: 1fr 300px;
        height: 100%;
        overflow: hidden;
    }

    #map {
        height: 100%;
        position: static;
    }

    .sidebar {
        max-height: calc(100vh - 60px);
        min-height: auto;
        height: calc(100vh - 60px);
        border-left: 1px solid var(--border);
        border-top: none;
    }

    .cities-list {
        overflow-y: auto;
        min-height: 0;
    }

    header {
        position: static;
    }

    body {
        overflow-y: hidden;
    }
}