:root {
    --iqair-good: #a8e05f;
    --iqair-moderate: #fdd64b;
    --iqair-sensitive: #ff9b57;
    --iqair-unhealthy: #fe6a69;
    --iqair-very-unhealthy: #a97abc;
    --iqair-hazardous: #a87383;
    --bg-light: #f4f6f8;
    --bg-card: #ffffff;
    --text-dark: #3c4043;
    --text-muted: #70757a;
    --card-shadow: 0 4px 12px rgba(0,0,0,0.05);
    --border-color: #eeeeee;
    --nav-bg: #ffffff;
}

[data-theme="dark"] {
    --bg-light: #121212;
    --bg-card: #1e1e1e;
    --text-dark: #e8eaed;
    --text-muted: #9aa0a6;
    --card-shadow: 0 4px 12px rgba(0,0,0,0.3);
    --border-color: #333333;
    --nav-bg: #1e1e1e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Kanit', sans-serif;
}

body {
    background-color: var(--bg-light);
    color: var(--text-dark);
    padding: 2rem 1rem;
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
}

.nav-bar {
    display: flex;
    justify-content: space-between; /* Space for theme toggle */
    align-items: center;
    margin-bottom: 2rem;
    background: var(--nav-bg);
    padding: 1rem 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--card-shadow);
}

.nav-links {
    display: flex;
    gap: 2rem;
}

.theme-toggle {
    background: #eee;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: all 0.2s;
}

[data-theme="dark"] .theme-toggle {
    background: #333;
}

.nav-link {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    transition: color 0.2s;
}

.nav-link:hover, .nav-link.active {
    color: var(--primary);
}

.aqi-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: var(--card-shadow);
}

.aqi-table th, .aqi-table td {
    padding: 1.25rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.aqi-table th {
    background: #f8fafc;
    font-weight: 700;
    color: var(--text-dark);
}

.color-box {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 0.5rem;
}

header {
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-muted);
}

.main-dashboard {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.aqi-hero-card {
    flex: 2;
    min-width: 320px;
    border-radius: 1rem;
    padding: 2rem;
    color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--card-shadow);
    transition: background-color 0.5s ease;
}

.aqi-main-info {
    display: flex;
    flex-direction: column;
}

.aqi-number-container {
    display: flex;
    align-items: baseline;
    gap: 1rem;
}

.aqi-number {
    font-size: 4rem;
    font-weight: 700;
}

.aqi-status-text {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.pm25-detail {
    font-size: 1rem;
    font-weight: 500;
    opacity: 0.8;
    margin-bottom: 0.75rem;
}

.learn-more-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: inherit;
    padding: 0.4rem 0.8rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: fit-content;
}

.learn-more-btn:hover {
    background: rgba(255, 255, 255, 0.4);
}

.aqi-face-icon {
    font-size: 5rem;
    opacity: 0.3;
}

.weather-stats {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.weather-card, .forecast-section, .chart-container, .map-section, .aqi-table {
    background: var(--bg-card) !important;
    box-shadow: var(--card-shadow) !important;
}

.aqi-table th {
    background: var(--bg-light);
    color: var(--text-dark);
}

.aqi-table td {
    border-bottom: 1px solid var(--border-color);
}

.stat-icon-wrapper {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.temp-icon {
    background-color: #fef3c7;
    color: #f59e0b;
}

.humid-icon {
    background-color: #e0f2fe;
    color: #0ea5e9;
}

.stat-icon-wrapper svg {
    width: 100%;
    height: 100%;
}

.stat-label {
    font-size: 1.25rem;
    font-weight: 600;
}

.chart-container {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: var(--card-shadow);
}

.chart-header {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.forecast-section {
    background: white;
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 2rem;
    overflow: hidden;
}

.forecast-header {
    margin-bottom: 1.5rem;
}

.forecast-list {
    display: flex;
    overflow-x: auto;
    gap: 1rem;
    padding-bottom: 1rem;
    scrollbar-width: thin;
    scrollbar-color: #ddd transparent;
}

.forecast-list::-webkit-scrollbar {
    height: 6px;
}

.forecast-list::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 10px;
}

.forecast-item {
    min-width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
}

.forecast-time {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.forecast-aqi-box {
    width: 40px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #333;
}

.forecast-icon {
    font-size: 1.25rem;
}

.forecast-temp {
    font-size: 0.875rem;
    font-weight: 600;
}

.forecast-extra {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.forecast-extra span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

/* IQAir Color Classes */
#station-map {
    height: 400px;
    width: 100%;
    border-radius: 1rem;
    box-shadow: var(--card-shadow);
    background-color: #e5e7eb;
    border: 1px solid #ddd;
    z-index: 1;
}

.custom-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px !important;
    height: 40px !important;
    border-radius: 50%;
    color: #333;
    font-weight: 700;
    font-size: 1rem;
    border: 2px solid white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    text-align: center;
}

.map-section {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: var(--card-shadow);
    margin-bottom: 2rem;
}
.bg-good { background-color: var(--iqair-good); }
.bg-moderate { background-color: var(--iqair-moderate); }
.bg-sensitive { background-color: var(--iqair-sensitive); }
.bg-unhealthy { background-color: var(--iqair-unhealthy); }
.view-selector {
    display: flex;
    background: #eee;
    padding: 0.25rem;
    border-radius: 0.5rem;
    gap: 0.25rem;
}

.view-btn {
    padding: 0.5rem 1rem;
    border-radius: 0.4rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
}

.view-btn.active {
    background: var(--text-dark);
    color: var(--bg-card);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-value {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.card-unit {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 400;
}

.card-status {
    font-size: 0.875rem;
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    background: rgba(255, 255, 255, 0.1);
    display: inline-block;
}

/* PM2.5 Levels */
.level-good { color: #10b981; }
.level-moderate { color: #facc15; }
.level-unhealthy-sensitive { color: #f97316; }
.level-unhealthy { color: #ef4444; }
.level-very-unhealthy { color: #8b5cf6; }
.level-hazardous { color: #7f1d1d; }

.chart-section {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    padding: 2rem;
    margin-bottom: 2rem;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.chart-header h2 {
    font-size: 1.25rem;
}

.station-info {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 2rem;
    text-align: center;
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    width: 90%;
    max-width: 500px;
    border-radius: 1.5rem;
    overflow: hidden;
    animation: modalSlideUp 0.3s ease-out;
}

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

.modal-header {
    padding: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-dark); /* Changed from #333 */
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 2rem;
    color: inherit;
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 2rem;
}

.info-group {
    margin-bottom: 1.5rem;
}

.info-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.info-group p {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-dark); /* Changed from var(--text-dark) - wait, it was already var(--text-dark) but maybe not applied correctly if background was white? */
}

.modal-footer {
    padding: 1.5rem 2rem;
    background: var(--bg-light); /* Changed from #f8fafc */
    text-align: right;
}

/* Custom Map Popup Styling */
.leaflet-popup-content-wrapper {
    padding: 0 !important;
    overflow: hidden;
    border-radius: 12px;
}

.leaflet-popup-content {
    margin: 0 !important;
    width: 280px !important;
}

.map-popup-content {
    font-family: 'Inter', 'Noto Sans Thai', sans-serif;
}

.popup-header {
    padding: 0.75rem;
    color: #333;
    display: flex;
    flex-direction: row; /* Horizontal layout */
    align-items: center;
    justify-content: center;
    gap: 1rem;
    text-align: center;
}

.popup-aqi {
    font-size: 2rem;
    font-weight: 800;
}

.popup-status {
    font-size: 1rem;
    font-weight: 700;
}

.popup-body {
    padding: 1rem;
    background: white;
}

.popup-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 columns */
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #eee;
    font-size: 0.75rem;
}

.popup-info, .popup-advice {
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.popup-info strong, .popup-advice strong {
    color: var(--text-dark);
    display: block;
    margin-bottom: 0.25rem;
}
