:root {
    --bg: #0b1120;
    --bg-elev: #111827;
    --bg-card: #162033;
    --border: #24324a;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #38bdf8;
    --radius: 10px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

code, pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12.5px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

/* Login Screen */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(circle at top right, #172554 0%, #0b1120 55%);
}

.login-card {
    width: 100%;
    max-width: 410px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 32px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.brand-badge {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.shield-icon {
    font-size: 36px;
    background: rgba(59, 130, 246, 0.14);
    border: 1px solid rgba(59, 130, 246, 0.35);
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-badge h1 { font-size: 20px; letter-spacing: 0.6px; }
.brand-badge p { color: var(--muted); font-size: 12px; margin-top: 2px; }

.login-footer {
    margin-top: 22px;
    text-align: center;
    font-size: 11.5px;
    color: var(--muted);
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

/* App Shell */
#app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
}

.logo-row { display: flex; align-items: center; gap: 10px; }
.shield-sm {
    font-size: 22px;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}
.logo-title { font-weight: 700; font-size: 15px; letter-spacing: 0.5px; }
.logo-sub { font-size: 11px; color: var(--muted); }

.nav-menu {
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-item {
    background: transparent;
    border: none;
    color: var(--muted);
    text-align: left;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.nav-item.active { background: rgba(59, 130, 246, 0.16); color: #93c5fd; font-weight: 600; }

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.server-pill {
    font-size: 11.5px;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 7px;
    word-break: break-word;
}

.main {
    flex: 1;
    padding: 24px 28px;
    min-width: 0;
}

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

.topbar h2 { font-size: 20px; font-weight: 700; }
.subtitle { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* Health Banner */
.health-banner {
    border-radius: var(--radius);
    padding: 18px 22px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    border: 1px solid var(--border);
}

.health-banner.healthy {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.14), rgba(16, 185, 129, 0.04));
    border-color: rgba(16, 185, 129, 0.35);
}

.health-banner.warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.16), rgba(245, 158, 11, 0.04));
    border-color: rgba(245, 158, 11, 0.4);
}

.health-banner.critical {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.18), rgba(239, 68, 68, 0.05));
    border-color: rgba(239, 68, 68, 0.45);
}

.health-title { font-size: 17px; font-weight: 700; }
.health-desc { font-size: 13px; color: var(--muted); margin-top: 3px; }
.health-meta { font-size: 12.5px; color: var(--text); text-align: right; }

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.kpi-val { font-size: 28px; font-weight: 700; margin: 6px 0 4px; }
.kpi-sub { font-size: 12px; color: var(--muted); }

/* Cards & Grids */
.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.col-stack { display: flex; flex-direction: column; gap: 18px; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.card-head h3 { font-size: 15px; font-weight: 600; }

/* Tables */
.table-wrap { overflow-x: auto; }
.tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.tbl th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--muted);
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.tbl td {
    padding: 10px 10px;
    border-bottom: 1px solid rgba(36, 50, 74, 0.55);
    vertical-align: middle;
}
.tbl tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* Badges & Pills */
.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.pill-success { background: rgba(16, 185, 129, 0.16); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.pill-danger { background: rgba(239, 68, 68, 0.18); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.35); }
.pill-warning { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.35); }
.pill-info { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.3); }
.pill-muted { background: rgba(148, 163, 184, 0.14); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.25); }

/* Buttons */
.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: #93c5fd; }
.btn-danger { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.3); }
.btn-success { background: rgba(16, 185, 129, 0.18); border-color: rgba(16, 185, 129, 0.4); color: #6ee7b7; }
.btn-success:hover:not(:disabled) { background: rgba(16, 185, 129, 0.3); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 4px 8px; font-size: 11.5px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #cbd5e1; }
.field input[type="text"],
.field input[type="password"],
.field select,
.input-sm {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
}
.input-sm { width: auto; padding: 6px 10px; font-size: 12.5px; }
.field input:focus, .field select:focus, .input-sm:focus {
    outline: none;
    border-color: var(--primary);
}
.hint { display: block; margin-top: 4px; font-size: 11.5px; color: var(--muted); }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; }

.divider {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #93c5fd;
    font-weight: 700;
    margin: 18px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    margin-bottom: 10px;
    user-select: none;
}
.toggle input { accent-color: var(--primary); width: 15px; height: 15px; }
.checkbox-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; margin-bottom: 10px; }

.alert-box {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-danger { background: rgba(239, 68, 68, 0.16); border: 1px solid rgba(239, 68, 68, 0.4); color: #fecaca; }

/* Tabs */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Alert Cards */
.alerts-container { display: flex; flex-direction: column; gap: 12px; }
.alert-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 4px solid var(--info);
    border-radius: 8px;
    padding: 14px 16px;
}
.alert-item.sev-CRITICAL { border-left-color: var(--danger); }
.alert-item.sev-HIGH { border-left-color: var(--warning); }
.alert-item.sev-MEDIUM { border-left-color: var(--info); }

.alert-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.alert-title { font-weight: 600; font-size: 13.5px; margin-top: 6px; }
.alert-path { font-family: monospace; font-size: 12px; color: #93c5fd; margin-top: 4px; word-break: break-all; }
.alert-details { font-size: 12px; color: var(--muted); white-space: pre-wrap; margin-top: 8px; }
.alert-actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

.code-box, .log-box {
    background: #070b14;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    font-size: 12px;
    color: #cbd5e1;
    overflow-x: auto;
    max-height: 360px;
    white-space: pre-wrap;
    word-break: break-all;
}

.code-copy-box {
    margin-top: 10px;
    background: #070b14;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.code-copy-box code { font-size: 12px; color: #7dd3fc; word-break: break-all; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 28px 14px;
    color: var(--muted);
    font-size: 13px;
}

/* Toast */
#toast-container {
    position: fixed;
    top: 18px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 11px 16px;
    border-radius: 9px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    font-size: 13px;
    max-width: 360px;
}
.toast.ok { border-left: 4px solid var(--success); }
.toast.err { border-left: 4px solid var(--danger); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.7); }
.modal-card {
    position: relative;
    z-index: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 100%;
    max-width: 720px;
    padding: 18px 20px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
    #app { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
    .nav-menu { flex-direction: row; flex-wrap: wrap; }
    .main { padding: 16px; }
    .checkbox-grid { grid-template-columns: 1fr; }
}
