:root {
    --primary-grad: linear-gradient(135deg, #1f6feb 0%, #4338ca 100%);
    --hero-grad: linear-gradient(135deg, #0ea5e9 0%, #1e3a8a 60%, #312e81 100%);
    --footer-grad: linear-gradient(135deg, #0b1d3b 0%, #1f2937 100%);
    --color-text: #1f2937;
    --color-bg: #f3f5f9;
    --color-surface: #ffffff;
    --color-muted: #6b7280;
    --color-border: #d1d5db;
    --color-thead: #f8fafc;
    --shadow-sm: 0 4px 12px rgba(15,23,42,0.06);
    --shadow-md: 0 6px 18px rgba(15,23,42,0.08);
    --shadow-lg: 0 12px 28px rgba(15,23,42,0.12);
}

html.theme-dark {
    --color-text: #e5e7eb;
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-muted: #94a3b8;
    --color-border: #334155;
    --color-thead: #1f2937;
    --primary-grad: linear-gradient(135deg, #2563eb 0%, #6366f1 100%);
    --hero-grad: linear-gradient(135deg, #0c4a6e 0%, #1e293b 100%);
    --footer-grad: linear-gradient(135deg, #020617 0%, #0f172a 100%);
    --shadow-sm: 0 4px 12px rgba(0,0,0,0.35);
    --shadow-md: 0 6px 18px rgba(0,0,0,0.45);
    --shadow-lg: 0 12px 28px rgba(0,0,0,0.55);
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

main { flex: 1; }

.navbar {
    background: var(--primary-grad) !important;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

.navbar-brand { font-size: 1.35rem; letter-spacing: 0.02em; }

.nav-link {
    position: relative;
    transition: opacity 0.2s ease;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 4px;
    height: 2px;
    background: white;
    border-radius: 2px;
}

.bg-gradient-primary { background: var(--primary-grad) !important; }

.hero-section {
    background: var(--hero-grad);
    color: white;
    padding: 80px 0 100px;
    position: relative;
    overflow: hidden;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: -100px;
    right: -100px;
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
}

.hero-illustration {
    font-size: 14rem;
    color: rgba(255,255,255,0.18);
    text-shadow: 0 12px 30px rgba(0,0,0,0.25);
}

.min-vh-75 { min-height: 70vh; }

.stat-card {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 22px;
    background: var(--color-surface);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    height: 100%;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    width: 58px;
    height: 58px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 1.6rem;
}

.stat-value {
    font-weight: 700;
    margin: 0;
    font-size: 1.85rem;
    color: var(--color-text);
}

.stat-label {
    color: #6b7280;
    margin: 0;
    font-size: 0.85rem;
}

.region-card {
    background: var(--color-surface);
    border-radius: 14px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border-left: 5px solid #cbd5e1;
    height: 100%;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.region-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.region-card.aqi-good { border-left-color: #16a34a; }
.region-card.aqi-moderate { border-left-color: #facc15; }
.region-card.aqi-sensitive { border-left-color: #fb923c; }
.region-card.aqi-unhealthy { border-left-color: #ef4444; }
.region-card.aqi-very_unhealthy { border-left-color: #b91c1c; }
.region-card.aqi-hazardous { border-left-color: #7f1d1d; }

.metric-mini {
    text-transform: uppercase;
    font-size: 0.7rem;
    color: #6b7280;
    letter-spacing: 0.05em;
}

.metric-mini-value {
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--color-text);
}

.aqi-badge-good { background: #dcfce7; color: #166534; }
.aqi-badge-moderate { background: #fef9c3; color: #854d0e; }
.aqi-badge-sensitive { background: #ffedd5; color: #9a3412; }
.aqi-badge-unhealthy { background: #fee2e2; color: #991b1b; }
.aqi-badge-very_unhealthy { background: #fecaca; color: #7f1d1d; }
.aqi-badge-hazardous { background: #fca5a5; color: #450a0a; }
.aqi-badge-unknown { background: #e5e7eb; color: #374151; }

.feature-card {
    background: var(--color-surface);
    border-radius: 16px;
    padding: 28px 20px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    height: 100%;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.feature-card:hover { transform: translateY(-4px); }

.feature-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    margin: 0 auto 16px;
    display: grid;
    place-items: center;
    background: var(--primary-grad);
    color: white;
    font-size: 1.7rem;
}

.tech-card {
    background: var(--color-surface);
    border-radius: 14px;
    padding: 24px 18px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    height: 100%;
}

.region-detail-card {
    background: var(--color-surface);
    border-radius: 16px;
    padding: 22px;
    box-shadow: var(--shadow-sm);
    height: 100%;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.region-detail-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.region-stat {
    background: var(--color-bg);
    border-radius: 10px;
    padding: 10px 4px;
    border: 1px solid var(--color-border);
}

.region-stat-label {
    text-transform: uppercase;
    font-size: 0.7rem;
    color: #6b7280;
    letter-spacing: 0.04em;
}

.region-stat-value {
    font-weight: 700;
    font-size: 1.05rem;
}

.error-card {
    background: var(--color-surface);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 50px 30px;
    margin: 0 auto;
    max-width: 540px;
}

.kg-map {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    background: var(--color-surface);
    border-radius: 16px;
    padding: 18px;
    box-shadow: var(--shadow-sm);
}
.kg-map .kg-tile {
    padding: 14px 12px;
    border-radius: 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
    color: inherit;
}
.kg-map .kg-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.kg-tile-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; }
.kg-tile-aqi { font-size: 1.4rem; font-weight: 700; }
.kg-tile-meta { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-muted); }

.kg-tile-good { border-color: #16a34a; box-shadow: inset 0 0 0 2px rgba(22,163,74,0.15); }
.kg-tile-moderate { border-color: #facc15; box-shadow: inset 0 0 0 2px rgba(250,204,21,0.18); }
.kg-tile-sensitive { border-color: #fb923c; box-shadow: inset 0 0 0 2px rgba(251,146,60,0.22); }
.kg-tile-unhealthy { border-color: #ef4444; box-shadow: inset 0 0 0 2px rgba(239,68,68,0.25); }
.kg-tile-very_unhealthy { border-color: #b91c1c; box-shadow: inset 0 0 0 2px rgba(185,28,28,0.25); }
.kg-tile-hazardous { border-color: #7f1d1d; }

@media (max-width: 576px) {
    .kg-map { grid-template-columns: repeat(2, 1fr); }
}

/* Sensor cards */
.sensor-card {
    display: block;
    background: var(--color-surface);
    border-radius: 14px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    height: 100%;
    color: var(--color-text);
}
.sensor-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); color: var(--color-text); }
.sensor-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: grid; place-items: center;
    color: #fff;
    font-size: 1.3rem;
    flex-shrink: 0;
}

/* Observations */
.observation-card {
    display: block;
    background: var(--color-surface);
    border-radius: 14px;
    padding: 18px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    color: var(--color-text);
    text-decoration: none;
    height: 100%;
}
.observation-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); color: var(--color-text); }

.comment-box {
    background: var(--color-bg);
    border-left: 3px solid var(--color-border);
    padding: 12px 14px;
    border-radius: 10px;
}

html.theme-dark .dropdown-menu { background: var(--color-surface); border-color: var(--color-border); }
html.theme-dark .dropdown-item { color: var(--color-text); }
html.theme-dark .dropdown-item:hover { background: rgba(255,255,255,0.06); color: var(--color-text); }
html.theme-dark .dropdown-divider { border-color: var(--color-border); }

.nav-tabs .nav-link { color: var(--color-muted); }
.nav-tabs .nav-link.active { color: var(--color-text); background: var(--color-surface); border-color: var(--color-border) var(--color-border) var(--color-surface); }
html.theme-dark .nav-tabs { border-bottom-color: var(--color-border); }

.card {
    border: none;
    border-radius: 16px;
    overflow: hidden;
    background: var(--color-surface);
    color: var(--color-text);
}

.card-header {
    font-weight: 600;
    border-bottom: none;
    padding: 14px 20px;
}

html.theme-dark .card-header.bg-light,
html.theme-dark .card-header.bg-warning {
    background-color: #1f2937 !important;
    color: #fde68a !important;
}

.btn { border-radius: 10px; font-weight: 500; }
.btn-lg { padding: 10px 20px; font-size: 1rem; }
.btn:hover { transform: translateY(-1px); }

.form-control, .form-select {
    border-radius: 10px;
    border: 1px solid var(--color-border);
    padding: 10px 14px;
    background: var(--color-surface);
    color: var(--color-text);
}

.form-control::placeholder { color: var(--color-muted); }

.form-control:focus, .form-select:focus {
    border-color: #4338ca;
    box-shadow: 0 0 0 0.18rem rgba(67, 56, 202, 0.18);
    background: var(--color-surface);
    color: var(--color-text);
}

.table {
    color: var(--color-text);
    --bs-table-bg: transparent;
}

.table thead {
    background: var(--color-thead);
}

.table thead th {
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    background: var(--color-thead);
}

html.theme-dark .table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-bg-state: rgba(255,255,255,0.03); }
html.theme-dark .table-hover > tbody > tr:hover > * { --bs-table-bg-state: rgba(255,255,255,0.06); }

.alert { border-radius: 12px; }

.footer {
    background: var(--footer-grad);
    color: #e2e8f0;
    margin-top: auto;
}

.footer .text-white-50 { color: rgba(226,232,240,0.7) !important; }

.text-purple { color: #6f42c1 !important; }

@media (max-width: 768px) {
    .hero-section { padding: 60px 0; }
    .stat-card { flex-direction: row; }
}
