:root {
    --bg: #0b0f19;
    --bg-soft: #111827;
    --panel: rgba(17, 24, 39, 0.72);
    --panel-border: rgba(148, 163, 184, 0.14);
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --text-faint: #64748b;
    --green: #22c55e;
    --green-glow: rgba(34, 197, 94, 0.35);
    --yellow: #f59e0b;
    --yellow-glow: rgba(245, 158, 11, 0.3);
    --red: #ef4444;
    --red-glow: rgba(239, 68, 68, 0.35);
    --blue: #38bdf8;
    --radius: 16px;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: radial-gradient(1200px 600px at 80% -10%, rgba(56, 189, 248, 0.08), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(34, 197, 94, 0.06), transparent 55%),
        var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.bg-decor {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(148, 163, 184, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.035) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: radial-gradient(ellipse 80% 60% at 50% 20%, black, transparent 80%);
    z-index: 0;
}

.wrap {
    position: relative;
    z-index: 1;
    max-width: 1080px;
    margin: 0 auto;
    padding: 40px 24px 64px;
}

/* ── Header ─────────────────────────────── */

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand h1 {
    margin: 0;
    font-size: 21px;
    line-height: 1.1;
    letter-spacing: -0.01em;
}

.history-link {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.08);
    color: var(--blue);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.history-link:hover {
    background: rgba(56, 189, 248, 0.16);
    border-color: rgba(56, 189, 248, 0.55);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.08);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover {
    background: rgba(148, 163, 184, 0.18);
    border-color: rgba(148, 163, 184, 0.45);
    color: var(--text);
}

.subtitle {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

/* ── Badges / pills ─────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: currentColor;
}

.badge.operational {
    color: var(--green);
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.25);
    box-shadow: 0 0 24px var(--green-glow);
}

.badge.degraded {
    color: var(--yellow);
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.25);
    box-shadow: 0 0 24px var(--yellow-glow);
}

.badge.down {
    color: var(--red);
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.25);
    box-shadow: 0 0 24px var(--red-glow);
}

.badge.inactive {
    color: var(--text-faint);
    background: rgba(100, 116, 139, 0.12);
    border-color: rgba(100, 116, 139, 0.2);
}

.badge.loading {
    color: var(--blue);
    background: rgba(56, 189, 248, 0.08);
    border-color: rgba(56, 189, 248, 0.2);
}

.badge.coming-soon {
    color: var(--blue);
    background: rgba(56, 189, 248, 0.08);
    border-color: rgba(56, 189, 248, 0.25);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.15);
}

.badge.loading::before {
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.8); }
}

/* ── Announcement banner ────────────────── */

.banner {
    margin-bottom: 20px;
    padding: 14px 18px;
    border-radius: 12px;
    border: 1px solid;
    font-size: 14px;
    line-height: 1.45;
    backdrop-filter: blur(12px);
}

.banner strong {
    margin-right: 4px;
}

.banner.info {
    color: var(--blue);
    background: rgba(56, 189, 248, 0.08);
    border-color: rgba(56, 189, 248, 0.25);
}

.banner.warning {
    color: var(--yellow);
    background: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.25);
}

.banner.critical {
    color: var(--red);
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.25);
}

.banner.maintenance {
    color: var(--text);
    background: rgba(148, 163, 184, 0.1);
    border-color: rgba(148, 163, 184, 0.3);
}

/* ── Region map ─────────────────────────── */

.map-section {
    margin-bottom: 28px;
}

.region-map {
    height: 400px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-soft);
    box-shadow: var(--shadow);
    z-index: 0;
}

.region-map .leaflet-popup-content {
    font-size: 13px;
}

/* ── Summary cards ──────────────────────── */

.summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 16px 18px;
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow);
}

.stat-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-faint);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ── Server cards ───────────────────────── */

.servers {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.server-card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 20px;
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.server-card:hover {
    transform: translateY(-2px);
}

.server-card.down {
    border-color: rgba(239, 68, 68, 0.35);
}

.server-card.degraded {
    border-color: rgba(245, 158, 11, 0.35);
}

.server-card.coming-soon {
    border-style: dashed;
    border-color: rgba(56, 189, 248, 0.35);
    background: rgba(17, 24, 39, 0.45);
}

.coming-soon-note {
    padding: 10px 0 4px;
    font-size: 13px;
    color: var(--text-muted);
}

.server-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.server-title {
    min-width: 0;
}

.server-name {
    display: block;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.server-region {
    display: block;
    margin-top: 3px;
    font-size: 12px;
    color: var(--text-muted);
}

.services {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
}

.service {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    min-width: 0;
}

.service .dot {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
}

.service .dot.operational {
    background: var(--green);
    box-shadow: 0 0 10px var(--green-glow);
}

.service .dot.degraded {
    background: var(--yellow);
    box-shadow: 0 0 10px var(--yellow-glow);
}

.service .dot.down {
    background: var(--red);
    box-shadow: 0 0 10px var(--red-glow);
}

.service .dot.inactive {
    background: var(--text-faint);
}

.service .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.service .detail {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-faint);
    white-space: nowrap;
}

/* ── Status bars (per server, 15-min) ───── */

.server-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0;
    height: 36px;
    padding: 6px 8px;
    background: rgba(2, 6, 23, 0.35);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 10px;
    overflow: visible;
}

.server-bars .status-bar {
    position: relative;
    flex: 0 0 3px;
    width: 3px;
    min-width: 0;
}

.server-bars .status-bar::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #0b0f19;
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-family: var(--font-mono);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.server-bars .status-bar:hover::after {
    opacity: 1;
}

.status-bar {
    border-radius: 2px 2px 0 0;
    transition: height 0.3s ease, background 0.3s ease;
}

.status-bar.operational {
    height: 100%;
    background: linear-gradient(180deg, #4ade80, #16a34a);
    box-shadow: 0 0 14px var(--green-glow);
}

.status-bar.degraded {
    height: 55%;
    background: linear-gradient(180deg, #fbbf24, #d97706);
    box-shadow: 0 0 14px var(--yellow-glow);
}

.status-bar.maintenance {
    height: 70%;
    background: linear-gradient(180deg, #60a5fa, #2563eb);
    box-shadow: 0 0 14px rgba(59, 130, 246, 0.5);
}

.status-bar.down {
    height: 22%;
    background: linear-gradient(180deg, #f87171, #dc2626);
    box-shadow: 0 0 14px var(--red-glow);
}

.status-bar.unknown {
    height: 30%;
    background: rgba(100, 116, 139, 0.28);
    box-shadow: none;
}

.status-bar.loading {
    height: 40%;
    background: linear-gradient(180deg, #38bdf8, #0284c7);
    animation: pulse 1.2s ease-in-out infinite;
}

/* ── History range tabs (24h / 30d) ──────── */

.history-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-bars {
    min-width: 0;
}

.server-bars.range-30d {
    justify-content: flex-start;
    gap: 4px;
}

.server-bars.range-30d .status-bar {
    flex: 1 1 0;
    width: auto;
    min-width: 2px;
    max-width: none;
}

.history-tabs {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px;
    background: rgba(2, 6, 23, 0.35);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 10px;
    align-self: flex-start;
}

.history-tab {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}

.history-tab:hover {
    color: var(--text);
    background: rgba(148, 163, 184, 0.12);
}

.history-tab.active {
    color: var(--text);
    background: rgba(56, 189, 248, 0.18);
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.3);
}

[data-theme="light"] .history-tabs {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(15, 23, 42, 0.1);
}

[data-theme="light"] .history-tab:hover {
    background: rgba(15, 23, 42, 0.06);
}

[data-theme="light"] .history-tab.active {
    background: rgba(56, 189, 248, 0.14);
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.45);
}

.server-foot {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
    font-size: 11px;
    color: var(--text-faint);
}

/* ── Incident history page ──────────────── */

.section-title {
    margin: 0 0 14px;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.deployments {
    display: grid;
    gap: 14px;
    margin-bottom: 36px;
}

.incidents {
    display: grid;
    gap: 14px;
}

.incident {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 18px 20px;
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow);
}

.incident.down {
    border-color: rgba(239, 68, 68, 0.35);
}

.incident.degraded {
    border-color: rgba(245, 158, 11, 0.35);
}

.incident.deployment {
    border-color: rgba(34, 197, 94, 0.3);
}

.incident-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.incident-server {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.incident-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    font-size: 12px;
    color: var(--text-muted);
}

.incident-meta b {
    color: var(--text);
    font-weight: 700;
}

.empty-state {
    grid-column: 1 / -1;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow);
}

.empty-state strong {
    color: var(--text);
}

.foot a {
    color: var(--blue);
    text-decoration: none;
}

.foot a:hover {
    text-decoration: underline;
}

.map-credit {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-faint);
}

/* ── Loading / error ────────────────────── */

.loading-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 56px 20px;
    color: var(--text-muted);
}

.spinner {
    width: 34px;
    height: 34px;
    margin: 0 auto 16px;
    border: 3px solid rgba(148, 163, 184, 0.2);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

.error-state {
    grid-column: 1 / -1;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
    color: var(--red);
}

.error-state p {
    margin: 6px 0;
}

/* ── Footer ─────────────────────────────── */

.foot {
    margin-top: 36px;
    text-align: center;
    color: var(--text-faint);
    font-size: 12px;
}

.foot code {
    font-family: var(--font-mono);
    background: rgba(148, 163, 184, 0.1);
    padding: 2px 6px;
    border-radius: 6px;
}

/* ── Responsive ─────────────────────────── */

@media (max-width: 760px) {
    .summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .servers {
        grid-template-columns: 1fr;
    }

    .wrap {
        padding: 24px 16px 48px;
    }
}

/* ── Light theme ─────────────────────────── */

[data-theme="light"] {
    --bg: #f1f5f9;
    --bg-soft: #ffffff;
    --panel: rgba(255, 255, 255, 0.78);
    --panel-border: rgba(15, 23, 42, 0.1);
    --text: #0f172a;
    --text-muted: #475569;
    --text-faint: #64748b;
    --green-glow: rgba(34, 197, 94, 0.22);
    --yellow-glow: rgba(245, 158, 11, 0.2);
    --red-glow: rgba(239, 68, 68, 0.22);
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

[data-theme="light"] body {
    background: radial-gradient(1200px 600px at 80% -10%, rgba(56, 189, 248, 0.1), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(34, 197, 94, 0.08), transparent 55%),
        var(--bg);
}

[data-theme="light"] .theme-toggle {
    background: rgba(15, 23, 42, 0.05);
    border-color: rgba(15, 23, 42, 0.15);
}

[data-theme="light"] .theme-toggle:hover {
    background: rgba(15, 23, 42, 0.1);
    border-color: rgba(15, 23, 42, 0.3);
    color: var(--text);
}

[data-theme="light"] .server-bars {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(15, 23, 42, 0.1);
}

[data-theme="light"] .server-bars .status-bar::after {
    background: #ffffff;
    border-color: rgba(15, 23, 42, 0.15);
    color: #0f172a;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

[data-theme="light"] .server-card.coming-soon {
    background: rgba(255, 255, 255, 0.55);
}
