/* ========== RESET & BASE ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2235;
    --bg-card-hover: #1f2a40;
    --bg-sidebar: #0d1321;
    --border-color: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.1);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --accent-purple: #8b5cf6;

    --aqi-good: #22c55e;
    --aqi-moderate: #eab308;
    --aqi-unhealthy-sg: #f97316;
    --aqi-unhealthy: #ef4444;
    --aqi-very-unhealthy: #a855f7;
    --aqi-hazardous: #7f1d1d;

    --sidebar-width: 220px;
    --topbar-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo svg {
    color: var(--accent-cyan);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent-blue);
}

.nav-item.active svg {
    stroke: var(--accent-blue);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.last-updated {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

/* ========== MAIN CONTENT ========== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ========== TOP BAR ========== */
.top-bar {
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.search-container {
    flex: 1;
    max-width: 480px;
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0 14px;
    transition: border-color var(--transition);
}

.search-container:focus-within {
    border-color: var(--accent-blue);
}

.search-container svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

#city-search {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: inherit;
    padding: 10px 0;
}

#city-search::placeholder {
    color: var(--text-muted);
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    max-height: 280px;
    overflow-y: auto;
    box-shadow: var(--shadow);
    z-index: 100;
}

.search-results.hidden {
    display: none;
}

.search-result-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: background var(--transition);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.search-result-item .result-aqi {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    color: white;
}

.top-bar-actions {
    display: flex;
    gap: 6px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.icon-btn:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

.icon-btn.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== VIEWS ========== */
.view {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.view.active {
    display: block;
}

/* ========== HERO SECTION ========== */
.hero-section {
    margin-bottom: 28px;
}

.hero-aqi-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 28px 32px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(59, 130, 246, 0.08) 100%);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.hero-aqi-card::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.06) 0%, transparent 70%);
    pointer-events: none;
}

.hero-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 1;
}

.hero-location h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.hero-station {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.hero-aqi-display {
    display: flex;
    align-items: center;
    gap: 24px;
}

.aqi-ring {
    position: relative;
    width: 130px;
    height: 130px;
}

.aqi-ring svg {
    width: 100%;
    height: 100%;
}

.aqi-ring #aqi-progress {
    stroke-dasharray: 440;
    stroke-dashoffset: 440;
    transition: stroke-dashoffset 1.5s ease, stroke 0.5s ease;
}

.aqi-value-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.aqi-number {
    font-size: 36px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.03em;
}

.aqi-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}

.aqi-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.aqi-level {
    font-size: 18px;
    font-weight: 700;
}

.aqi-description {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 260px;
    line-height: 1.5;
}

.aqi-health-tip {
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border-left: 3px solid var(--accent-blue);
    margin-top: 4px;
    max-width: 280px;
    line-height: 1.4;
}

.hero-right {
    z-index: 1;
}

.weather-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.weather-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 120px;
}

.weather-item svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ========== SECTION HEADERS ========== */
.section-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.section-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

/* ========== POLLUTANT GRID ========== */
.pollutant-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 28px;
}

.pollutant-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.pollutant-card:hover {
    border-color: var(--border-light);
    transform: translateY(-1px);
}

.pollutant-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
}

.pollutant-name {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
}

.pollutant-value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 2px;
}

.pollutant-unit {
    font-size: 11px;
    color: var(--text-muted);
}

.pollutant-bar {
    margin-top: 10px;
    height: 4px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    overflow: hidden;
}

.pollutant-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 1s ease;
}

/* ========== CHARTS ========== */
.charts-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 28px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.chart-card.full-width {
    grid-column: 1 / -1;
}

.chart-header {
    padding: 16px 20px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.chart-body {
    padding: 16px 20px 20px;
    height: 220px;
}

.chart-body-polar {
    height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-body-wide {
    height: 300px;
}

.chart-legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* ========== CITIES GRID ========== */
.cities-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    padding-bottom: 24px;
}

.city-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.city-card:hover {
    border-color: var(--border-light);
    background: var(--bg-card-hover);
    transform: translateY(-1px);
}

.city-info h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 3px;
}

.city-info p {
    font-size: 12px;
    color: var(--text-muted);
}

.city-aqi {
    text-align: center;
}

.city-aqi-value {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
}

.city-aqi-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-top: 2px;
}

/* ========== MAP VIEW ========== */
.map-container {
    height: 100%;
}

.map-header {
    margin-bottom: 20px;
}

.map-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.map-header p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.map-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.map-region-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    transition: all var(--transition);
}

.map-region-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.region-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.region-name {
    font-size: 15px;
    font-weight: 600;
}

.region-avg-aqi {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.region-cities {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.region-city-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.region-city-aqi {
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    color: white;
}

/* ========== TRENDS VIEW ========== */
.trends-container {
    height: 100%;
}

.trends-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 20px;
    padding-bottom: 24px;
}

.trend-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px;
}

.trend-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.trend-card-header h4 {
    font-size: 14px;
    font-weight: 600;
}

.trend-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    color: white;
}

.trend-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.trend-stat {
    text-align: center;
}

.trend-stat-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 3px;
}

.trend-stat-value {
    font-size: 18px;
    font-weight: 700;
}

/* ========== RANKINGS VIEW ========== */
.rankings-container {
    height: 100%;
}

.rankings-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.rank-btn {
    padding: 8px 18px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
}

.rank-btn:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
}

.rank-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

.rankings-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 24px;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.ranking-item:hover {
    border-color: var(--border-light);
    background: var(--bg-card-hover);
}

.ranking-position {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    width: 28px;
    text-align: center;
}

.ranking-position.top-3 {
    color: var(--accent-blue);
}

.ranking-info {
    flex: 1;
}

.ranking-city {
    font-size: 14px;
    font-weight: 600;
}

.ranking-station {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.ranking-aqi-bar {
    flex: 1;
    max-width: 200px;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.ranking-aqi-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 1s ease;
}

.ranking-aqi-value {
    font-size: 20px;
    font-weight: 800;
    width: 52px;
    text-align: right;
    letter-spacing: -0.02em;
}

.ranking-level {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    color: white;
    white-space: nowrap;
    width: 100px;
    text-align: center;
}

/* ========== LOADING OVERLAY ========== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.4s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    text-align: center;
}

.spinner-ring {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}

.loading-spinner p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1100px) {
    .charts-section {
        grid-template-columns: 1fr;
    }
    .hero-aqi-card {
        flex-direction: column;
        gap: 20px;
    }
    .hero-right {
        width: 100%;
    }
    .weather-info {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    .view {
        padding: 16px;
    }
    .hero-aqi-card {
        padding: 20px;
    }
    .hero-aqi-display {
        flex-direction: column;
        align-items: flex-start;
    }
    .weather-info {
        grid-template-columns: 1fr 1fr;
    }
    .pollutant-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    .cities-grid {
        grid-template-columns: 1fr;
    }
    .ranking-aqi-bar {
        display: none;
    }
}

/* ========== UTILITY ========== */
.text-good { color: var(--aqi-good); }
.text-moderate { color: var(--aqi-moderate); }
.text-unhealthy-sg { color: var(--aqi-unhealthy-sg); }
.text-unhealthy { color: var(--aqi-unhealthy); }
.text-very-unhealthy { color: var(--aqi-very-unhealthy); }
.text-hazardous { color: var(--aqi-hazardous); }

.bg-good { background: var(--aqi-good); }
.bg-moderate { background: var(--aqi-moderate); }
.bg-unhealthy-sg { background: var(--aqi-unhealthy-sg); }
.bg-unhealthy { background: var(--aqi-unhealthy); }
.bg-very-unhealthy { background: var(--aqi-very-unhealthy); }
.bg-hazardous { background: var(--aqi-hazardous); }
