:root {
  --bg: #090d16;
  --bg-elev: #111827;
  --bg-card: #151e2e;
  --bg-hover: #1e293b;
  --border: #263349;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #10b981;
  --accent-dim: rgba(16, 185, 129, 0.14);
  --sky: #38bdf8;
  --sky-dim: rgba(56, 189, 248, 0.14);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.14);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* Auth / Setup Screen */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: radial-gradient(circle at top right, rgba(16, 185, 129, 0.12), transparent 45%),
              radial-gradient(circle at bottom left, rgba(56, 189, 248, 0.1), transparent 45%),
              var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.brand-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #10b981, #0ea5e9);
  display: grid; place-items: center; color: #052e16; font-weight: 800;
}
.brand-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
.auth-sub { color: var(--text-muted); margin: 0 0 1.5rem; font-size: 0.92rem; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.25rem 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}
.nav-list { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  font-weight: 500;
  transition: all 0.15s ease;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.vps-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.vps-pill strong { color: var(--text); display: block; margin-bottom: 0.15rem; }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 58px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-title { font-size: 1.05rem; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 0.65rem; }

.mobile-menu-btn {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
}

.content { padding: 1.25rem; max-width: 1360px; width: 100%; margin: 0 auto; }

/* Cards & Grid */
.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.card-title { font-weight: 600; font-size: 0.98rem; margin: 0; }
.muted { color: var(--text-muted); font-size: 0.84rem; }

.stat-value { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.02em; margin: 0.2rem 0; }
.progress-track {
  height: 7px; background: #0f172a; border-radius: 999px; overflow: hidden; margin-top: 0.6rem;
}
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s ease; }
.progress-fill.warn { background: var(--amber); }
.progress-fill.crit { background: var(--danger); }

/* Badges & Buttons */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  border: 1px solid transparent;
}
.badge-ok { background: var(--accent-dim); color: #34d399; border-color: rgba(16,185,129,0.3); }
.badge-info { background: var(--sky-dim); color: #38bdf8; border-color: rgba(56,189,248,0.3); }
.badge-warn { background: var(--amber-dim); color: #fbbf24; border-color: rgba(245,158,11,0.3); }
.badge-err { background: var(--danger-dim); color: #f87171; border-color: rgba(239,68,68,0.3); }
.badge-muted { background: #1e293b; color: var(--text-muted); border-color: var(--border); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.48rem 0.88rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-hover);
  color: var(--text); cursor: pointer; font-weight: 500; font-size: 0.85rem;
  transition: all 0.15s ease;
}
.btn:hover { background: #293548; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #052e16; font-weight: 600; }
.btn-primary:hover { background: #34d399; }
.btn-sky { background: var(--sky-dim); border-color: rgba(56,189,248,0.4); color: #38bdf8; }
.btn-danger { background: var(--danger-dim); border-color: rgba(239,68,68,0.35); color: #f87171; }
.btn-sm { padding: 0.32rem 0.6rem; font-size: 0.78rem; border-radius: 7px; }

.btn-group { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* Forms */
.field { margin-bottom: 0.85rem; }
.field label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.32rem; font-weight: 500; }
.input, .select, .textarea {
  width: 100%; background: #0c1220; border: 1px solid var(--border);
  border-radius: 8px; padding: 0.52rem 0.72rem; outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--sky); }
.textarea { font-family: var(--mono); font-size: 0.82rem; resize: vertical; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { text-align: left; padding: 0.65rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
code.mono { font-family: var(--mono); font-size: 0.8rem; background: #0c1220; padding: 0.15rem 0.4rem; border-radius: 5px; border: 1px solid var(--border); }

/* Terminal / Logs */
.terminal {
  background: #05080f;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  font-family: var(--mono);
  font-size: 0.79rem;
  line-height: 1.5;
  height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-line-stderr { color: #f87171; }
.log-line-system { color: #38bdf8; }
.log-line-stdout { color: #d1fae5; }

/* Alerts */
.alert {
  padding: 0.75rem 1rem; border-radius: 10px; margin-bottom: 1rem;
  border: 1px solid; font-size: 0.86rem;
}
.alert-warn { background: var(--amber-dim); border-color: rgba(245,158,11,0.4); color: #fde68a; }
.alert-info { background: var(--sky-dim); border-color: rgba(56,189,248,0.4); color: #bae6fd; }
.alert-err { background: var(--danger-dim); border-color: rgba(239,68,68,0.4); color: #fecaca; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.68);
  display: grid; place-items: center; padding: 1rem; z-index: 50;
}
.modal {
  width: 100%; max-width: 620px; max-height: 90vh; overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.25rem;
}

/* Toast */
.toast-wrap {
  position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 60;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
  background: #1e293b; border: 1px solid var(--border); color: var(--text);
  padding: 0.65rem 1rem; border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  font-size: 0.86rem;
}
.toast.ok { border-color: var(--accent); }
.toast.err { border-color: var(--danger); }

/* Sparkline */
.spark-wrap { width: 100%; height: 120px; }
.spark-wrap svg { width: 100%; height: 100%; display: block; }

/* Responsive */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: inline-flex; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
