:root, [data-theme="dark"] {
    --bg: #0b0f17;
    --bg-card: #141b2d;
    --bg-card-hover: #1a2340;
    --text: #e8edf7;
    --text-muted: #8b9bbf;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.35);
    --success: #22c55e;
    --warning: #f59e0b;
    --critical: #ef4444;
    --border: rgba(255,255,255,0.08);
    --shadow: 0 8px 32px rgba(0,0,0,0.4);
    --chart-grid: rgba(255,255,255,0.06);
}

[data-theme="light"] {
    --bg: #f0f4fa;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --text: #1e293b;
    --text-muted: #64748b;
    --accent: #4f46e5;
    --accent-glow: rgba(79, 70, 229, 0.2);
    --border: rgba(0,0,0,0.08);
    --shadow: 0 8px 32px rgba(0,0,0,0.08);
    --chart-grid: rgba(0,0,0,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

/* Splash */
.splash {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: linear-gradient(135deg, #0b0f17 0%, #1a1040 50%, #0b0f17 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.6s ease, visibility 0.6s;
}

.splash.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash-inner {
    text-align: center;
    position: relative;
}

.splash-ring {
    position: absolute;
    width: 200px;
    height: 200px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    animation: pulse-ring 2s ease-out infinite;
    opacity: 0.6;
}

.splash-ring-2 {
    width: 260px;
    height: 260px;
    animation-delay: 0.5s;
    border-color: rgba(99,102,241,0.4);
}

@keyframes pulse-ring {
    0% { transform: translate(-50%, -60%) scale(0.8); opacity: 0.8; }
    100% { transform: translate(-50%, -60%) scale(1.3); opacity: 0; }
}

.splash-icon {
    font-size: 4rem;
    animation: float 2s ease-in-out infinite;
    margin-bottom: 1rem;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

.splash-text {
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    font-weight: 700;
    background: linear-gradient(90deg, #fff, #a5b4fc, #fff);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 2s linear infinite;
}

.splash-sub {
    display: block;
    font-size: 0.55em;
    font-weight: 500;
    margin-top: 0.3em;
    opacity: 0.85;
}

@keyframes shimmer {
    0% { background-position: 0% center; }
    100% { background-position: 200% center; }
}

.splash-bar {
    width: 200px;
    height: 3px;
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
    margin: 1.5rem auto 0;
    overflow: hidden;
}

.splash-bar-fill {
    height: 100%;
    background: var(--accent);
    animation: load-bar 2s ease forwards;
}

@keyframes load-bar {
    from { width: 0; }
    to { width: 100%; }
}

/* Header */
.header {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 100;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.logo { font-size: 2rem; line-height: 1; }
.header h1 { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.subtitle { font-size: 0.75rem; color: var(--text-muted); }

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.btn-theme {
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    border-radius: 12px;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover { filter: brightness(1.1); }

.btn-ghost {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
}

/* Main */
.main { padding: 1rem 1.5rem 4rem; max-width: 1400px; margin: 0 auto; }

.status-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.status-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.875rem;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: default;
}

.status-card-clickable {
    cursor: pointer;
}

.status-card-clickable:active {
    transform: scale(0.98);
}

.status-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.status-card .label { font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.status-card .value { font-size: 1.1rem; font-weight: 600; }

.status-card.alert-active {
    background: color-mix(in srgb, var(--critical) 18%, var(--bg-card));
    border-color: var(--critical);
    box-shadow: 0 0 16px rgba(239,68,68,0.25);
}

.status-card.alert-warning {
    background: color-mix(in srgb, var(--warning) 18%, var(--bg-card));
    border-color: var(--warning);
    box-shadow: 0 0 16px rgba(245,158,11,0.2);
}

.status-card.alert-pulse {
    animation: alertPulse 0.6s ease-in-out 3;
}

@keyframes alertPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239,68,68,0.5); }
    50% { transform: scale(1.04); box-shadow: 0 0 24px 4px rgba(239,68,68,0.45); }
}

.btn-warn {
    background: color-mix(in srgb, var(--warning) 25%, var(--bg-card));
    color: var(--text);
    border: 1px solid var(--warning);
}

.btn-warn:hover { filter: brightness(1.08); }

.chart-period-bar {
    position: sticky;
    z-index: 90;
    margin: 0 0 1rem;
    padding: 0.65rem 0;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.chart-period-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chart-period-btn {
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chart-period-btn:hover {
    border-color: var(--accent);
}

.chart-period-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
    gap: 1rem;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1rem;
    box-shadow: var(--shadow);
    animation: fadeIn 0.4s ease;
}

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

.chart-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.chart-box { width: 100%; height: 260px; }

.footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.footer a { color: var(--accent); text-decoration: none; }

/* Toast */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(360px, calc(100vw - 2rem));
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 12px;
    padding: 0.875rem 1rem;
    box-shadow: var(--shadow);
    animation: slideIn 0.35s ease;
}

.toast.critical { border-left-color: var(--critical); }
.toast.warning { border-left-color: var(--warning); }

.toast-title { font-weight: 600; font-size: 0.875rem; margin-bottom: 0.25rem; }
.toast-body { font-size: 0.8rem; color: var(--text-muted); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(920px, 100%);
    max-height: min(90vh, 720px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 1rem 1rem 0.75rem;
    animation: fadeIn 0.25s ease;
}

.modal-close {
    position: absolute;
    top: 0.65rem;
    right: 0.75rem;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    padding-right: 2.5rem;
}

.modal-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0.25rem 0 0.75rem;
}

.modal-chart {
    width: 100%;
    height: min(52vh, 420px);
}

body.modal-open { overflow: hidden; }

@media (max-width: 640px) {
    .header { padding: 0.75rem 1rem; gap: 0.5rem; }
    .main { padding: 0.75rem 1rem 3rem; }
    .chart-period-inner { gap: 0.4rem; }
    .chart-period-btn { font-size: 0.72rem; padding: 0.4rem 0.65rem; }
    .chart-box { height: 220px; touch-action: pan-y; }
    .modal-chart { touch-action: pan-y; }
    .chart-box canvas,
    .modal-chart canvas {
        cursor: default !important;
    }
    .status-cards { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }

    .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .header-actions .btn,
    .header-actions a.btn {
        width: 100%;
        min-height: 2.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        font-size: 0.78rem;
        line-height: 1.2;
        padding: 0.5rem 0.4rem;
        border-radius: 14px;
    }
}

@media (min-width: 641px) {
    .header-actions .btn,
    .header-actions a.btn {
        flex: 0 0 auto;
    }
}
