:root {
    color-scheme: dark;
    --bg: #0b1020;
    --bg-top: #172554;
    --panel: rgba(17, 24, 39, 0.78);
    --panel-border: rgba(148, 163, 184, 0.16);
    --text: #e5eefb;
    --muted: #94a3b8;
    --accent: #60a5fa;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #e2e8f0;
    --bg-top: #bfdbfe;
    --panel: rgba(255, 255, 255, 0.82);
    --panel-border: rgba(148, 163, 184, 0.28);
    --text: #0f172a;
    --muted: #475569;
    --accent: #2563eb;
    --success: #15803d;
    --danger: #dc2626;
    --warning: #d97706;
    --shadow: 0 20px 40px rgba(15, 23, 42, 0.12);
}

:root[data-theme="light"] .badge-muted {
    background: rgba(148, 163, 184, .18);
    color: #475569;
}

:root[data-theme="light"] .badge-health-good {
    background: rgba(34, 197, 94, .16);
    color: #15803d;
}

:root[data-theme="light"] .badge-health-warning {
    background: rgba(245, 158, 11, .18);
    color: #b45309;
}

:root[data-theme="light"] .badge-health-danger {
    background: rgba(239, 68, 68, .16);
    color: #b91c1c;
}

:root[data-theme="light"] .badge-health-neutral {
    background: rgba(148, 163, 184, .16);
    color: #475569;
}

:root[data-theme="light"] .action-button.secondary {
    background: rgba(245, 158, 11, .16);
    color: #92400e;
    border: 1px solid rgba(217, 119, 6, .28);
}

:root[data-theme="light"] .action-button.danger {
    background: rgba(239, 68, 68, .14);
    color: #b91c1c;
    border: 1px solid rgba(220, 38, 38, .22);
}

:root[data-theme="light"] .action-button.ghost {
    background: rgba(148, 163, 184, .14);
    color: #334155;
    border: 1px solid rgba(148, 163, 184, .3);
}

:root[data-theme="light"] .source-badge.source-env {
    color: #1d4ed8;
    border-color: rgba(37, 99, 235, .22);
}

:root[data-theme="light"] .source-badge.source-yaml {
    color: #15803d;
    border-color: rgba(21, 128, 61, .22);
}

:root[data-theme="light"] .source-badge.source-both {
    color: #7e22ce;
    border-color: rgba(126, 34, 206, .22);
}

:root[data-theme="light"] .source-badge.source-unknown {
    color: #475569;
    border-color: rgba(100, 116, 139, .24);
}

:root[data-theme="light"] .monitor-state.down,
:root[data-theme="light"] .incident-status.open {
    color: #b91c1c;
}

:root[data-theme="light"] .field-group input,
:root[data-theme="light"] .field-group select {
    background: rgba(255, 255, 255, .88);
    color: #0f172a;
}

:root[data-theme="light"] .empty-state {
    background: rgba(255, 255, 255, .65);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, system-ui, sans-serif;
    background: radial-gradient(circle at top, var(--bg-top), var(--bg) 50%);
    color: var(--text);
}

.shell {
    width: min(1200px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2rem 0 3rem;
}
.shell-login {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hero, .panel, .stat-card, .monitor-card {
    backdrop-filter: blur(20px);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow);
}

.tab-strip {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.tab-button {
    border: 1px solid var(--panel-border);
    background: var(--panel);
    color: var(--text);
    border-radius: 999px;
    padding: .8rem 1.15rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease;
}

.tab-button:hover {
    transform: translateY(-1px);
}

.tab-button.active {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: white;
    border-color: transparent;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.tab-panel-stack {
    display: grid;
    gap: 1rem;
}

.overview-grid {
    align-items: start;
}

.hero {
    border-radius: 24px;
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.25rem;
}
.hero-login {
    max-width: 680px;
    margin: 0 auto 1.25rem;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--accent);
    margin: 0 0 .5rem;
    font-size: .8rem;
}

.hero h1 { margin: 0; font-size: clamp(2rem, 3vw, 3rem); }
.subtitle { color: var(--muted); margin: .5rem 0 0; }
.hero-badges { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: flex-end; }
.hero-actions {
    display: flex;
    gap: .75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 1rem;
}
.login-meta {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}
.action-status {
    color: var(--muted);
    font-size: .95rem;
}
.action-status.error {
    color: #fda4af;
}
.badge {
    border-radius: 999px;
    padding: .6rem .9rem;
    background: rgba(96, 165, 250, .15);
    color: var(--accent);
    font-size: .9rem;
}
.badge-muted { background: rgba(148, 163, 184, .12); color: var(--muted); }
.badge-health {
    font-weight: 700;
}
.badge-health-good {
    background: rgba(34, 197, 94, .16);
    color: #86efac;
}
.badge-health-warning {
    background: rgba(245, 158, 11, .16);
    color: #fcd34d;
}
.badge-health-danger {
    background: rgba(239, 68, 68, .16);
    color: #fda4af;
    animation: health-alert-pulse 1.8s ease-in-out infinite;
}
.badge-health-neutral {
    background: rgba(148, 163, 184, .12);
    color: #cbd5e1;
}

@keyframes health-alert-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
        transform: translateZ(0);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.14);
        transform: translateY(-1px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .badge-health-danger {
        animation: none;
    }
}

.action-button {
    border: none;
    border-radius: 999px;
    padding: .75rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform .15s ease, opacity .15s ease, background .15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.action-button:hover:not(:disabled) {
    transform: translateY(-1px);
}
.action-button:disabled {
    opacity: .65;
    cursor: wait;
}
.action-button.primary {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: white;
}
.action-button.secondary {
    background: rgba(245, 158, 11, .14);
    color: #fcd34d;
    border: 1px solid rgba(245, 158, 11, .35);
}
.action-button.danger {
    background: rgba(239, 68, 68, .14);
    color: #fda4af;
    border: 1px solid rgba(239, 68, 68, .35);
}
.action-button.ghost {
    background: rgba(148, 163, 184, .12);
    color: #e2e8f0;
    border: 1px solid rgba(148, 163, 184, .2);
}

.stats-grid, .panel-grid, .cards-grid, .incident-list {
    display: grid;
    gap: 1rem;
}
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 1rem; }
.panel-grid { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); margin-bottom: 1rem; }
.cards-grid, .incident-list { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.legend-panel { margin-bottom: 1rem; }
.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}
.legend-group {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.legend-title {
    color: var(--muted);
    font-size: .92rem;
    font-weight: 600;
}
.legend-items {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    align-items: center;
}

.stat-card, .panel, .monitor-card, .incident-card { border-radius: 20px; padding: 1.1rem 1.2rem; }
.stat-card span, .panel-header p, .panel-title { color: var(--muted); }
.stat-card strong { display: block; margin-top: .35rem; font-size: 2rem; }
.stat-card.success strong { color: var(--success); }
.stat-card.danger strong { color: var(--danger); }
.stat-card.warning strong { color: var(--warning); }

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}
.panel-header h2 { margin: 0; }
.panel-header p { margin: .35rem 0 0; }
.panel-title { margin-bottom: .8rem; font-weight: 600; }
.panel-description { margin: 0 0 1rem; color: var(--muted); }
.login-panel {
    max-width: 520px;
    width: 100%;
    margin: 0 auto;
}
.login-form {
    display: grid;
    gap: 1rem;
}
.login-error {
    margin: 0 0 1rem;
    color: #fda4af;
    font-weight: 600;
}

.inline-form {
    display: flex;
    gap: 1rem;
    align-items: end;
    flex-wrap: wrap;
}

.inline-form + .inline-form {
    margin-top: 1rem;
}

.incident-filters {
    display: flex;
    gap: 1rem;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    min-width: 180px;
}

.field-group.compact {
    margin-top: 1rem;
    max-width: 280px;
}

.field-group.grow {
    flex: 1 1 260px;
}

.field-group.small {
    flex: 0 0 120px;
}

.field-group label {
    color: var(--muted);
    font-size: .92rem;
}

.field-group input,
.field-group select {
    border: 1px solid rgba(148, 163, 184, .18);
    background: rgba(15, 23, 42, .65);
    color: var(--text);
    border-radius: 14px;
    padding: .8rem .95rem;
    font: inherit;
}

.field-group input:focus,
.field-group select:focus {
    outline: 2px solid rgba(96, 165, 250, .4);
    border-color: rgba(96, 165, 250, .5);
}

.multiselect-filter {
    position: relative;
}

.multiselect-filter-button {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, .18);
    background: rgba(15, 23, 42, .65);
    color: var(--text);
    border-radius: 14px;
    padding: .8rem .95rem;
    font: inherit;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    cursor: pointer;
}

.multiselect-filter-button::after {
    content: '▾';
    color: var(--muted);
    font-size: .9rem;
}

.multiselect-filter.open .multiselect-filter-button {
    outline: 2px solid rgba(96, 165, 250, .4);
    border-color: rgba(96, 165, 250, .5);
}

.multiselect-filter-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: min(280px, calc(100vw - 1rem));
    min-width: 220px;
    padding: .7rem;
    border-radius: 16px;
    border: 1px solid var(--panel-border);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-14px) scale(.94);
    filter: blur(8px);
    transform-origin: top left;
    transition: opacity .24s ease-out, transform .24s ease-out, filter .24s ease-out, visibility .24s ease;
    will-change: opacity, transform, filter;
}

.multiselect-filter-panel.open {
    display: grid;
    gap: .45rem;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    filter: blur(0);
    animation: multiselect-spring-in .42s cubic-bezier(.18, .89, .32, 1.28);
}

@keyframes multiselect-spring-in {
    0% {
        opacity: 0;
        transform: translateY(-18px) scale(.9);
        filter: blur(10px);
    }
    55% {
        opacity: 1;
        transform: translateY(4px) scale(1.03);
        filter: blur(0);
    }
    75% {
        transform: translateY(-2px) scale(.992);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .multiselect-filter-panel {
        transition: none;
    }

    .multiselect-filter-panel.open {
        animation: none;
    }
}

.multiselect-option {
    display: flex;
    align-items: center;
    gap: .6rem;
    color: var(--text);
    font-size: .95rem;
}

.multiselect-option input {
    accent-color: #3b82f6;
}

:root[data-theme="light"] .multiselect-filter-button {
    background: rgba(255, 255, 255, .88);
    color: #0f172a;
}

.config-editor {
    min-height: 320px;
    width: 100%;
    resize: vertical;
    border: 1px solid rgba(148, 163, 184, .18);
    background: rgba(15, 23, 42, .65);
    color: var(--text);
    border-radius: 16px;
    padding: 1rem;
    font: 500 .92rem/1.5 Consolas, "Cascadia Code", monospace;
}

.config-editor:focus {
    outline: 2px solid rgba(96, 165, 250, .4);
    border-color: rgba(96, 165, 250, .5);
}

:root[data-theme="light"] .config-editor {
    background: rgba(255, 255, 255, .88);
    color: #0f172a;
}

.hash-output {
    min-height: 120px;
}

.field-hint {
    color: var(--muted);
    font-size: .88rem;
    line-height: 1.4;
}

.meta-list, .monitor-meta, .incident-meta {
    margin: 0;
    display: grid;
    gap: .7rem;
}
.meta-list div, .monitor-meta div, .incident-meta div {
    display: grid;
    grid-template-columns: minmax(110px, 140px) 1fr;
    gap: .75rem;
}
.meta-list dt, .monitor-meta dt, .incident-meta dt { color: var(--muted); }
.meta-list dd, .monitor-meta dd, .incident-meta dd { margin: 0; word-break: break-word; }

.monitor-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}
.incident-card {
    backdrop-filter: blur(20px);
    background: var(--panel);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow);
}
.incident-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}
.monitor-actions {
    margin-bottom: 1rem;
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}
.monitor-type, .incident-type {
    display: inline-flex;
    padding: .25rem .55rem;
    border-radius: 999px;
    background: rgba(96, 165, 250, .15);
    color: var(--accent);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.monitor-name, .incident-name { margin: .6rem 0 0; font-size: 1.05rem; }
.monitor-state {
    padding: .4rem .8rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: .85rem;
}
.incident-status {
    padding: .4rem .8rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: .85rem;
}
.monitor-state.up { background: rgba(34, 197, 94, .16); color: var(--success); }
.monitor-state.down { background: rgba(239, 68, 68, .16); color: #fda4af; }
.monitor-state.snoozed { box-shadow: inset 0 0 0 1px rgba(245, 158, 11, .4); }
.incident-status.open { background: rgba(239, 68, 68, .16); color: #fda4af; }
.incident-status.resolved { background: rgba(34, 197, 94, .16); color: var(--success); }
.source-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .3rem .65rem;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .02em;
    border: 1px solid transparent;
}
.source-badge.source-env {
    background: rgba(96, 165, 250, .14);
    color: #93c5fd;
    border-color: rgba(96, 165, 250, .3);
}
.source-badge.source-yaml {
    background: rgba(34, 197, 94, .14);
    color: #86efac;
    border-color: rgba(34, 197, 94, .3);
}
.source-badge.source-both {
    background: rgba(168, 85, 247, .16);
    color: #d8b4fe;
    border-color: rgba(168, 85, 247, .32);
}
.source-badge.source-unknown {
    background: rgba(148, 163, 184, .14);
    color: #cbd5e1;
    border-color: rgba(148, 163, 184, .26);
}
.empty-state {
    padding: 1rem;
    border-radius: 16px;
    border: 1px dashed var(--panel-border);
    color: var(--muted);
    background: rgba(15, 23, 42, .45);
}

@media (max-width: 700px) {
    .hero { flex-direction: column; }
    .hero-badges { justify-content: flex-start; }
    .meta-list div, .monitor-meta div, .incident-meta div { grid-template-columns: 1fr; gap: .2rem; }
    .inline-form, .incident-filters { align-items: stretch; }
    .inline-form .action-button { width: 100%; }
    .tab-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tab-button { justify-content: center; }
}
