:root {
    --bg: #0a0e1a;
    --bg-2: #0d1426;
    --panel: #111a30;
    --panel-2: #0f1830;
    --border: #1e2a44;
    --border-soft: #182238;
    --text: #e6ecf7;
    --muted: #8a97b0;
    --accent: #3b82f6;
    --accent-2: #2563eb;
    --accent-soft: rgba(59, 130, 246, .15);
    --green: #22c55e;
    --green-soft: rgba(34, 197, 94, .15);
    --orange: #f59e0b;
    --orange-soft: rgba(245, 158, 11, .15);
    --red: #ef4444;
    --red-soft: rgba(239, 68, 68, .15);
    --radius: 14px;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: radial-gradient(1200px 600px at 80% -10%, #11203f 0%, var(--bg) 55%);
    color: var(--text);
    font-family: "Segoe UI", Inter, system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.right { text-align: right; }
.ok { color: var(--green); }

/* ---------- LOGIN ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px;
}
.login-card {
    width: 100%; max-width: 380px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border);
    border-radius: 18px; padding: 28px;
    box-shadow: var(--shadow);
}
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand-logo { font-size: 28px; }
.brand-name { font-weight: 700; font-size: 18px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.login-form h1 { font-size: 20px; margin: 0 0 16px; }
.login-form label, .modal-body label { display: block; margin-bottom: 14px; }
.login-form label span, .modal-body label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
input {
    width: 100%; padding: 11px 12px;
    background: var(--bg-2); border: 1px solid var(--border);
    border-radius: 10px; color: var(--text); font-size: 14px; outline: none;
    transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-foot { text-align: center; color: var(--muted); font-size: 11px; margin-top: 18px; }

.btn-primary {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
    color: #fff; border: none; border-radius: 10px;
    padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
    transition: filter .15s, transform .05s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-block { width: 100%; padding: 12px; margin-top: 6px; }

.alert-error {
    background: var(--red-soft); border: 1px solid rgba(239, 68, 68, .4);
    color: #fecaca; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: 13px;
}

/* ---------- APP SHELL ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px; flex-shrink: 0;
    background: linear-gradient(180deg, #0c1426 0%, #0a1020 100%);
    border-right: 1px solid var(--border-soft);
    display: flex; flex-direction: column; padding: 18px 14px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.sidebar-brand .brand-logo { font-size: 22px; }
.sidebar-brand .brand-name { font-weight: 700; font-size: 16px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 10px; color: var(--muted);
    cursor: pointer; font-weight: 500; user-select: none;
    border-left: 3px solid transparent; transition: background .15s, color .15s;
}
.nav-item .ic { font-size: 14px; width: 16px; text-align: center; }
.nav-item:hover { background: rgba(255, 255, 255, .03); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #fff; border-left-color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid var(--border-soft); }
.dot-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot-on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot-off { background: var(--red); box-shadow: 0 0 8px var(--red); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 62px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
    padding: 0 26px; border-bottom: 1px solid var(--border-soft);
    background: rgba(10, 14, 26, .6); backdrop-filter: blur(6px);
}
.topbar-title { font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip {
    background: var(--panel); border: 1px solid var(--border);
    padding: 6px 12px; border-radius: 20px; font-size: 13px;
}
.btn-ghost {
    background: var(--panel); border: 1px solid var(--border); color: var(--text);
    width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 15px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent); }

.view { padding: 24px 26px; }

/* ---------- STAT CARDS ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat-card {
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px 16px;
    box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat-card::after {
    content: ""; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px;
    background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
}
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: .5px; }
.stat-value .unit { font-size: 16px; color: var(--muted); margin-left: 3px; font-weight: 600; }
.stat-foot { font-size: 12px; margin-top: 4px; }

.chart-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 22px; }
.chart-box { padding: 14px 16px 16px; height: 240px; position: relative; }
@media (max-width: 980px) { .chart-grid { grid-template-columns: 1fr; } }

.bar { height: 6px; border-radius: 4px; background: var(--border); overflow: hidden; margin-top: 5px; min-width: 60px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.bar.warn > span { background: linear-gradient(90deg, var(--orange), #d97706); }
.bar.hot > span { background: linear-gradient(90deg, var(--red), #dc2626); }

/* ---------- SETTINGS / SWITCH ---------- */
.settings-body { padding: 18px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.setting-title { font-weight: 600; margin-bottom: 3px; }
.setting-status { margin-top: 12px; }
code { background: var(--bg-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; font-size: 12px; }
.switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 26px; cursor: pointer; transition: background .2s; }
.slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; }
.switch input:checked + .slider { background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ---------- CARD / TABLE ---------- */
.card {
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 22px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border-soft); }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.link { color: var(--accent); cursor: pointer; font-size: 13px; text-decoration: none; }
.link:hover { text-decoration: underline; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
    color: var(--muted); font-weight: 600; padding: 12px 18px; border-bottom: 1px solid var(--border-soft);
}
.data-table td { padding: 13px 18px; border-bottom: 1px solid var(--border-soft); font-size: 13px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255, 255, 255, .02); }
.mono { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; color: var(--muted); }

/* status pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-run { background: var(--green-soft); color: var(--green); }
.pill-stop { background: var(--red-soft); color: #fca5a5; }
.pill-other { background: var(--orange-soft); color: var(--orange); }

/* row actions */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.act {
    border: 1px solid var(--border); background: var(--bg-2); color: var(--text);
    border-radius: 8px; padding: 5px 9px; font-size: 12px; cursor: pointer; transition: all .12s;
}
.act:hover { border-color: var(--accent); background: var(--accent-soft); }
.act-danger:hover { border-color: var(--red); background: var(--red-soft); color: #fca5a5; }

/* ---------- MODAL ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(4, 7, 14, .68);
    display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
    backdrop-filter: blur(3px);
}
.modal {
    width: 100%; max-width: 440px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
}
.modal-lg { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; max-height: 65vh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border-soft); }
.logs {
    background: #05080f; border: 1px solid var(--border); border-radius: 10px; padding: 14px;
    font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; line-height: 1.5;
    white-space: pre-wrap; word-break: break-word; color: #cbd5e1; margin: 0; max-height: 56vh; overflow: auto;
}

/* ---------- TOASTS ---------- */
.toast-wrap { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast {
    background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
    padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; min-width: 220px;
    animation: slideIn .2s ease;
}
.toast-ok { border-left-color: var(--green); }
.toast-err { border-left-color: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

@media (max-width: 820px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .sidebar { width: 64px; }
    .sidebar-brand .brand-name, .nav-item span:not(.ic), .sidebar-foot { display: none; }
}
