:root {
    --bg: #090d16;
    --surface: #111827;
    --surface-2: #1a2335;
    --border: #243047;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --ok: #10b981;
    --warn: #f59e0b;
    --danger: #ef4444;
    --radius: 12px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top, #111b2e 0%, var(--bg) 60%);
    color: var(--text);
    min-height: 100vh;
}

.hidden { display: none !important; }

/* Auth */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.brand-header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 1.5rem;
}
.brand-header h1 { margin: 0; font-size: 1.3rem; }
.brand-header p { margin: 0.2rem 0 0; font-size: 0.85rem; color: var(--muted); }
.brand-logo {
    width: 44px;
    height: 44px;
    border-radius: 11px;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: #fff;
    flex-shrink: 0;
}
.brand-logo.small { width: 32px; height: 32px; font-size: 0.8rem; border-radius: 8px; }

.auth-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--bg);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 1.25rem;
    border: 1px solid var(--border);
}
.auth-tab {
    background: transparent;
    border: 0;
    color: var(--muted);
    padding: 0.5rem;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
}
.auth-tab.active { background: var(--surface-2); color: var(--text); }

.auth-form, .stack-form { display: flex; flex-direction: column; gap: 0.85rem; }
.auth-form label span { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
input, select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.65rem 0.8rem;
    border-radius: 9px;
    font-size: 0.9rem;
    outline: none;
}
input:focus, select:focus { border-color: var(--primary); }

.btn {
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 0.65rem 1rem;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: 0.15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-danger { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.35); color: #fca5a5; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

.form-error { color: #fca5a5; font-size: 0.84rem; margin: 0.85rem 0 0; }

/* App Shell */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.8rem 1.5rem;
    background: rgba(17, 24, 39, 0.88);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    flex-wrap: wrap;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.topbar-title { font-size: 1rem; }
.main-nav { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.nav-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    padding: 0.48rem 0.85rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.nav-btn.active { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.badge-pill {
    background: var(--danger);
    color: #fff;
    font-size: 0.72rem;
    padding: 1px 6px;
    border-radius: 999px;
}

.stream-badge {
    font-size: 0.75rem;
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    font-weight: 600;
    border: 1px solid var(--border);
}
.stream-badge.connected { background: rgba(16, 185, 129, 0.14); color: #34d399; border-color: rgba(16, 185, 129, 0.35); }
.stream-badge.disconnected { background: rgba(245, 158, 11, 0.14); color: #fbbf24; border-color: rgba(245, 158, 11, 0.35); }
.transport-select { width: auto; padding: 0.35rem 0.6rem; font-size: 0.8rem; }
.user-label { font-size: 0.82rem; color: var(--muted); }

.content-area { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }
.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.1rem;
}
.section-header h2 { margin: 0; font-size: 1.15rem; }
.section-header p { margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--muted); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem;
}

/* Devices Grid */
.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(370px, 1fr));
    gap: 1rem;
}
.device-card { display: flex; flex-direction: column; gap: 0.9rem; }
.device-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.device-title { font-weight: 700; font-size: 1.02rem; display: flex; align-items: center; gap: 0.5rem; }
.os-tag {
    font-size: 0.72rem;
    text-transform: uppercase;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
}
.status-dot {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
}
.status-dot::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
}
.status-dot.online { color: #34d399; }
.status-dot.online::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-dot.offline { color: #f87171; }
.status-dot.offline::before { background: var(--danger); }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.metric-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.65rem 0.75rem;
}
.metric-head { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.35rem; }
.metric-val { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.bar-track { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); transition: width 0.3s ease; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.crit { background: var(--danger); }

.sparkline { width: 100%; height: 34px; display: block; margin-top: 0.35rem; }
.meta-sub { font-size: 0.76rem; color: var(--muted); display: flex; justify-content: space-between; margin-top: 0.3rem; font-variant-numeric: tabular-nums; }

/* Forms & Lists */
.inline-form {
    display: grid;
    grid-template-columns: 1.2fr 1.2fr 0.8fr 1.6fr 0.6fr 0.6fr auto;
    gap: 0.6rem;
    margin-bottom: 1rem;
    align-items: center;
}
@media (max-width: 980px) {
    .inline-form { grid-template-columns: 1fr 1fr; }
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); }
.checkbox-row input { width: auto; }
.stack-list { display: flex; flex-direction: column; gap: 0.65rem; margin-top: 0.85rem; }
.list-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.85rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}
.pill { font-size: 0.73rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; }
.pill.up { background: rgba(16, 185, 129, 0.16); color: #34d399; }
.pill.down { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
.pill.pending { background: rgba(148, 163, 184, 0.16); color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86rem; }
.mt-1 { margin-top: 1rem; }
.empty-state { color: var(--muted); font-size: 0.88rem; padding: 1.5rem; text-align: center; border: 1px dashed var(--border); border-radius: 10px; }

.toast-container { position: fixed; bottom: 1.25rem; right: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 99; max-width: 360px; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--primary); padding: 0.8rem 1rem; border-radius: 10px; font-size: 0.84rem; box-shadow: 0 12px 30px rgba(0,0,0,0.45); }
.toast.critical { border-left-color: var(--danger); }
