:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #0f1620;
  --line: rgba(255,255,255,0.07);
  --line-strong: rgba(255,255,255,0.12);
  --text: #e5edf7;
  --muted: #8291a6;
  --brand: #3b82f6;
  --brand-2: #8b5cf6;
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #22c55e;
  --shadow: 0 10px 30px rgba(0,0,0,0.32);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(59,130,246,0.14), transparent 28rem),
    radial-gradient(circle at bottom right, rgba(139,92,246,0.10), transparent 30rem),
    var(--bg);
  font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 246px;
  background: rgba(10,15,22,0.92);
  border-right: 1px solid var(--line);
  color: #fff;
  padding: 22px 16px;
  backdrop-filter: blur(16px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 30px;
}
.brand-mark, .login-mark {
  width: 13px;
  height: 28px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--brand), var(--brand-2));
  box-shadow: 0 0 24px rgba(59,130,246,0.42);
}
.sidebar nav { display: grid; gap: 8px; }
.sidebar a {
  color: #c8d2df;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 12px;
}
.sidebar a:hover { background: #1e293b; color: #fff; }
.sidebar-foot {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.logout { border: 1px solid var(--line); }

.main {
  margin-left: 246px;
  padding: 30px;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 22px;
}
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 30px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
.page-head p, .muted { color: var(--muted); }
.ghost-link {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 10px 12px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metric, .panel, .device-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.015)), var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.metric { padding: 18px; border-left: 3px solid var(--brand); }
.metric span { color: var(--muted); display: block; margin-bottom: 8px; }
.metric strong { font-size: 32px; line-height: 1; }
.metric small { display: block; color: var(--muted); margin-top: 8px; }
.metric-ok { border-left-color: var(--ok); }
.metric-warn { border-left-color: var(--warn); }
.metric-danger { border-left-color: var(--danger); }
.panel { padding: 18px; margin-bottom: 18px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.panel-head span {
  min-width: 30px;
  text-align: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: #1e293b;
  color: #dbeafe;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.device-card {
  padding: 16px;
  display: grid;
  gap: 14px;
  border-left: 3px solid #475569;
  cursor: context-menu;
}
.status-border-online { border-left-color: var(--ok); }
.status-border-degraded { border-left-color: var(--warn); }
.status-border-offline { border-left-color: var(--danger); }
.card-top, .card-bottom {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.card-top p, .card-bottom small {
  margin: 6px 0 0;
  color: var(--muted);
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.card-meta span {
  padding: 5px 8px;
  border-radius: 999px;
  background: #0b1220;
  color: #aab8c9;
  border: 1px solid var(--line);
  font-size: 12px;
}

.split {
  display: grid;
  grid-template-columns: minmax(310px, 380px) 1fr;
  gap: 18px;
  align-items: start;
}
.form { display: grid; gap: 12px; }
.dense-form { position: sticky; top: 22px; }
.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.form-actions button { flex: 1; }
label { display: grid; gap: 6px; font-size: 13px; color: #aab8c9; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: #0b1220;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(59,130,246,0.72);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
textarea { min-height: 96px; resize: vertical; }
button {
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}
button:hover { filter: brightness(1.08); }
.icon-button { padding: 8px 10px; }
.danger-button {
  background: transparent;
  color: #fecaca;
  border: 1px solid rgba(239,68,68,0.38);
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; }
td small { display: block; color: var(--muted); margin-top: 4px; }
code {
  color: #bfdbfe;
  background: #0b1220;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 6px;
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
tr[data-device-target] { cursor: context-menu; }
.status {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: #1e293b;
  color: #cbd5e1;
}
.status.online { background: rgba(34,197,94,0.12); color: #86efac; }
.status.offline { background: rgba(239,68,68,0.12); color: #fca5a5; }
.status.degraded { background: rgba(245,158,11,0.12); color: #fcd34d; }
.alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.alert-list li {
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b1220;
}
.alert-list strong { color: #fca5a5; }
.alert-list span { color: #bfdbfe; }
.alert-list p { margin: 0; color: var(--muted); }
.flash { padding: 10px; border-radius: 12px; margin-bottom: 10px; background: #1e293b; }
.login-page {
  display: grid;
  place-items: center;
  padding: 18px;
}
.login-box {
  width: min(390px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  padding: 26px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.015)), var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.login-mark { width: 40px; height: 6px; }
.login-error { color: #fca5a5; margin: 0; }

.ctx-menu {
  position: fixed;
  z-index: 80;
  min-width: 220px;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(15,22,32,0.98);
  box-shadow: 0 18px 45px rgba(0,0,0,0.42);
  backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}
.ctx-menu.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.ctx-header {
  display: grid;
  gap: 2px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.ctx-header strong { font-size: 13px; }
.ctx-header span {
  color: var(--muted);
  font-size: 12px;
}
.ctx-item {
  width: 100%;
  display: block;
  text-align: left;
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  background: transparent;
}
.ctx-item:hover {
  background: #1e293b;
  filter: none;
}
.ctx-item.danger { color: #fecaca; }

.modal-lite {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(3,7,18,0.58);
}
.modal-lite.active { display: flex; }
.modal-card {
  width: min(560px, 100%);
  max-height: min(680px, calc(100vh - 40px));
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.modal-head p {
  margin: 5px 0 0;
  color: var(--muted);
}
.ghost-icon {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--text);
}
.service-list {
  display: grid;
  gap: 8px;
}
.service-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b1220;
}
.service-row span {
  color: #bfdbfe;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}
.service-row em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}
.toast-wrap {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: grid;
  gap: 8px;
}
.toast {
  min-width: 190px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--brand);
  border-radius: 12px;
  background: rgba(15,22,32,0.98);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}
.toast.success { border-left-color: var(--ok); }
.toast.danger { border-left-color: var(--danger); }

@media (max-width: 900px) {
  .sidebar { position: static; width: auto; }
  .sidebar-foot { position: static; margin-top: 16px; }
  .main { margin-left: 0; padding: 16px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .metrics-grid, .split { grid-template-columns: 1fr; }
  .dense-form { position: static; }
}
