:root {
    color-scheme: light;
    --page-bg: #f4f7fb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --ink: #182338;
    --muted: #79869a;
    --line: #e8edf4;
    --accent: #5267e8;
    --accent-soft: #edf0ff;
    --green: #12a886;
    --green-soft: #e8f8f3;
    --shadow: 0 12px 34px rgba(32, 52, 91, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
    background:
        radial-gradient(ellipse at 85% 0%, rgba(105, 125, 244, 0.09), transparent 31rem),
        var(--page-bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app-main {
    flex: 1;
    padding-top: clamp(2.2rem, 5vw, 4.5rem);
    padding-bottom: 4rem;
}

.app-navbar {
    min-height: 76px;
    background: #19243a;
    box-shadow: 0 6px 24px rgba(20, 32, 55, 0.12);
}

.navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    color: #fff;
    font-size: 1.08rem;
    font-weight: 750;
    letter-spacing: -0.035em;
}

.navbar-brand:hover,
.navbar-brand:focus {
    color: #fff;
}

.brand-mark {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(145deg, #7889ff, #5267e8);
    color: #fff;
    font-size: 1rem;
}

.brand-light {
    color: #aeb9d0;
    font-weight: 500;
}

.app-navbar .nav-link {
    padding: 0.7rem 0.9rem;
    color: #aeb9d0;
    font-size: 0.9rem;
    font-weight: 550;
    transition: color 160ms ease;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus {
    color: #fff;
}

.navbar-actions {
    display: flex;
    gap: 0.55rem;
}

.btn-soft-light {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.07);
    color: #e8ecf6;
    font-size: 0.82rem;
    font-weight: 600;
}

.btn-soft-light:hover,
.btn-soft-light:focus {
    border-color: rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.13);
    color: #fff;
}

.navbar-toggler {
    border-color: rgba(255, 255, 255, 0.25);
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.15);
}

.navbar-toggler-icon {
    filter: invert(1);
}

.page-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 2rem;
    margin-bottom: clamp(2.2rem, 5vw, 3.6rem);
}

.page-hero h1 {
    margin: 0;
    color: var(--ink);
    font-size: clamp(2.15rem, 5vw, 3.55rem);
    font-weight: 760;
    letter-spacing: -0.065em;
    line-height: 1.08;
}

.hero-period {
    color: var(--accent);
}

.eyebrow {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.8rem;
    color: var(--muted);
    font-size: 0.69rem;
    font-weight: 750;
    letter-spacing: 0.13em;
}

.live-dot,
.footer-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #19bd91;
    box-shadow: 0 0 0 4px rgba(25, 189, 145, 0.12);
}

.hero-copy {
    max-width: 540px;
    margin: 0.9rem 0 0;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.65;
}

.hero-update {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    min-width: 205px;
    padding: 0.9rem 1rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.78);
}

.hero-update-icon {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    place-items: center;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.1rem;
}

.hero-update small,
.hero-update strong {
    display: block;
}

.hero-update small {
    margin-bottom: 0.15rem;
    color: var(--muted);
    font-size: 0.7rem;
}

.hero-update strong {
    color: var(--ink);
    font-size: 0.86rem;
    font-weight: 650;
}

.data-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    margin: -1.5rem 0 2.2rem;
    padding: 0.9rem 1rem;
    border: 1px solid #f0d9a7;
    border-radius: 12px;
    background: #fff8e8;
    color: #815d16;
    font-size: 0.86rem;
    line-height: 1.5;
}

.data-alert[hidden],
.chart-message[hidden] {
    display: none;
}

.data-alert i {
    margin-top: 0.12rem;
}

.overview-section + .overview-section {
    margin-top: 3rem;
}

.section-heading,
.range-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.15rem;
}

.section-heading .eyebrow,
.range-heading .eyebrow {
    margin-bottom: 0.35rem;
}

.section-heading h2,
.range-heading h2 {
    margin: 0;
    color: var(--ink);
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.035em;
}

.section-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 650;
    text-decoration: none;
}

.section-link:hover {
    color: #354bd1;
}

.metric-card {
    min-height: 190px;
    padding: 1.25rem;
    border: 1px solid rgba(225, 232, 243, 0.85);
    border-radius: 17px;
    background: var(--surface);
    box-shadow: var(--shadow);
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.metric-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 17px 38px rgba(32, 52, 91, 0.1);
}

.metric-topline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.15rem;
}

.metric-icon,
.chart-icon {
    display: grid;
    width: 39px;
    height: 39px;
    place-items: center;
    border-radius: 13px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.05rem;
}

.metric-system .metric-icon,
.chart-icon.system {
    background: var(--green-soft);
    color: var(--green);
}

.metric-category {
    color: #a1aaba;
    font-size: 0.62rem;
    font-weight: 750;
    letter-spacing: 0.1em;
}

.metric-card h3 {
    overflow: hidden;
    margin: 0 0 0.4rem;
    color: #66748a;
    font-size: 0.79rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.metric-reading {
    display: flex;
    align-items: baseline;
    gap: 0.42rem;
}

.metric-value {
    color: var(--ink);
    font-size: clamp(1.75rem, 3vw, 2.2rem);
    font-weight: 720;
    letter-spacing: -0.06em;
    line-height: 1.25;
}

.metric-unit {
    color: var(--muted);
    font-size: 0.83rem;
    font-weight: 600;
}

.metric-meta {
    margin: 0.75rem 0 0;
    color: #9aa5b5;
    font-size: 0.69rem;
}

.metric-meta .value-time {
    color: #78869b;
}

.detail-hero {
    align-items: center;
}

.hero-icon {
    display: inline-grid;
    width: 25px;
    height: 25px;
    place-items: center;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.85rem;
    letter-spacing: 0;
}

.hero-icon.system {
    background: var(--green-soft);
    color: var(--green);
}

.hero-count {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    border: 1px solid #e5eaff;
    border-radius: 14px;
    background: #f0f2ff;
    color: #6878df;
}

.hero-count strong {
    font-size: 1.7rem;
    font-weight: 750;
    letter-spacing: -0.05em;
    line-height: 1;
}

.hero-count span {
    max-width: 70px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.25;
}

.system-count {
    border-color: #d9f0e9;
    background: #eaf8f3;
    color: #139d7d;
}

.range-panel {
    margin-bottom: 1.4rem;
    padding: 1.35rem 1.5rem 1.5rem;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.range-heading {
    margin-bottom: 1rem;
}

.range-heading h2 {
    font-size: 1rem;
}

.range-hint {
    color: var(--muted);
    font-size: 0.76rem;
}

.range-hint i {
    margin-right: 0.25rem;
}

.time-range-buttons {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.6rem;
}

.time-btn {
    display: flex;
    min-height: 62px;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 0.15rem;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-muted);
    color: var(--ink);
    text-align: left;
    transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.time-btn strong {
    font-size: 0.9rem;
    font-weight: 700;
}

.time-btn span {
    color: var(--muted);
    font-size: 0.68rem;
}

.time-btn:hover {
    transform: translateY(-1px);
    border-color: #c9d0ff;
}

.time-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    box-shadow: 0 6px 14px rgba(82, 103, 232, 0.18);
}

.time-btn.active span {
    color: rgba(255, 255, 255, 0.78);
}

.time-btn:focus-visible,
.btn:focus-visible,
.section-link:focus-visible {
    outline: 3px solid rgba(82, 103, 232, 0.35);
    outline-offset: 3px;
}

.chart-grid {
    margin-top: 0;
}

.chart-card {
    overflow: hidden;
    padding: 1.15rem 1.35rem 1.25rem;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.chart-card-header {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    min-width: 0;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
}

.chart-card-header > div {
    min-width: 0;
}

.chart-card-header h2 {
    overflow: hidden;
    margin: 0 0 0.2rem;
    color: var(--ink);
    font-size: 0.93rem;
    font-weight: 680;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-card-header p {
    overflow: hidden;
    margin: 0;
    color: #9aa5b5;
    font-size: 0.67rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-card-header p span {
    padding: 0 0.2rem;
}

.chart-unit {
    margin-left: auto;
    padding: 0.28rem 0.52rem;
    border-radius: 8px;
    background: var(--surface-muted);
    color: #748197;
    font-size: 0.7rem;
    font-weight: 650;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 270px;
    padding-top: 0.85rem;
}

.chart-message {
    position: absolute;
    inset: 0.85rem 0 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    border-radius: 10px;
    background: rgba(248, 250, 252, 0.94);
    color: #9a5b32;
    font-size: 0.82rem;
    text-align: center;
}

.app-footer {
    padding: 1.35rem 0;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.55);
    color: #8a96a8;
    font-size: 0.72rem;
}

.footer-separator {
    padding: 0 0.25rem;
    color: #c0c7d2;
}

.footer-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 0.3rem;
    vertical-align: 1px;
    box-shadow: none;
}

#refreshBtn:disabled .bi-arrow-clockwise {
    animation: spin 0.7s linear infinite;
}

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

[data-bs-theme="dark"] {
    color-scheme: dark;
    --page-bg: #111827;
    --surface: #1b2638;
    --surface-muted: #202d42;
    --ink: #edf2fb;
    --muted: #a2aec1;
    --line: #2a384e;
    --accent: #8b9aff;
    --accent-soft: #293451;
    --green: #55d4b1;
    --green-soft: #1c3b3b;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.15);
    background-color: var(--page-bg);
}

[data-bs-theme="dark"] .page-hero h1,
[data-bs-theme="dark"] .section-heading h2,
[data-bs-theme="dark"] .range-heading h2,
[data-bs-theme="dark"] .metric-value,
[data-bs-theme="dark"] .chart-card-header h2,
[data-bs-theme="dark"] .hero-update strong {
    color: var(--ink);
}

[data-bs-theme="dark"] .hero-update,
[data-bs-theme="dark"] .app-footer {
    background: rgba(27, 38, 56, 0.82);
}

[data-bs-theme="dark"] .data-alert {
    border-color: #62502f;
    background: #342d20;
    color: #f0ca7d;
}

[data-bs-theme="dark"] .chart-message {
    background: rgba(27, 38, 56, 0.94);
    color: #f0b28e;
}

[data-bs-theme="dark"] .metric-card {
    border-color: var(--line);
}

[data-bs-theme="dark"] .metric-card h3,
[data-bs-theme="dark"] .metric-meta .value-time,
[data-bs-theme="dark"] .chart-unit {
    color: var(--muted);
}

[data-bs-theme="dark"] .hero-count {
    border-color: #353c61;
    background: #252d4a;
    color: #a7b2ff;
}

[data-bs-theme="dark"] .system-count {
    border-color: #285047;
    background: #1c3b3b;
    color: #55d4b1;
}

[data-bs-theme="dark"] .time-btn.active {
    color: #fff;
}

@media (max-width: 991.98px) {
    .navbar-actions {
        margin-top: 0.8rem;
        padding-bottom: 0.4rem;
    }
}

@media (max-width: 767.98px) {
    .app-main {
        padding-top: 2rem;
        padding-bottom: 2.8rem;
    }

    .page-hero {
        align-items: flex-start;
        margin-bottom: 2rem;
    }

    .hero-update {
        min-width: 0;
        padding: 0.65rem;
    }

    .hero-update-icon {
        width: 34px;
        height: 34px;
        flex-basis: 34px;
    }

    .hero-update small {
        font-size: 0.62rem;
    }

    .hero-update strong {
        font-size: 0.76rem;
    }

    .range-panel {
        padding: 1.1rem;
    }

    .range-hint {
        display: none;
    }

    .time-range-buttons {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .time-btn {
        min-height: 55px;
        align-items: center;
        padding: 0.5rem 0.3rem;
    }

    .chart-container {
        height: 230px;
    }
}

@media (max-width: 480px) {
    .page-hero {
        flex-direction: column;
        gap: 1rem;
    }

    .hero-update {
        align-self: stretch;
    }

    .section-heading h2 {
        font-size: 1.15rem;
    }

    .section-link {
        font-size: 0.76rem;
    }

    .metric-card {
        min-height: 175px;
        padding: 1rem;
    }

    .metric-topline {
        margin-bottom: 0.9rem;
    }

    .metric-value {
        font-size: 1.65rem;
    }

    .chart-card {
        padding: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
