:root {
  --bg: #0b1120;
  --bg-elev: #111827;
  --bg-card: #162033;
  --bg-subtle: #1e293b;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top right, #172554 0%, var(--bg) 42%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(148, 163, 184, 0.14);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

.hidden { display: none !important; }

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.95rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--bg-subtle);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.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-secondary { background: var(--bg-subtle); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: #273549; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); background: rgba(255,255,255,0.04); }
.btn-danger { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.45); color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.28); color: #fff; }
.btn-sm { padding: 0.36rem 0.65rem; font-size: 0.8rem; border-radius: 8px; }
.btn-block { width: 100%; padding: 0.72rem 1rem; font-size: 0.95rem; }

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }

/* Brand */
.brand-mark { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1.4rem; }
.brand-mark h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.02em; }
.subtitle { margin: 0.2rem 0 0; font-size: 0.86rem; color: var(--text-muted); }
.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.03em;
  color: #fff;
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.35);
  flex-shrink: 0;
}
.brand-logo.sm { width: 36px; height: 36px; font-size: 0.88rem; border-radius: 10px; }

/* Login */
.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(22, 32, 51, 0.92);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.8rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

/* Forms */
.form-stack { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.86rem; color: var(--text-muted); }
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.68rem 0.85rem;
  color: var(--text);
  font-size: 0.94rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.22);
}
.field-hint { margin: 0; font-size: 0.8rem; line-height: 1.5; color: var(--text-muted); }
.form-error { margin: 0; font-size: 0.84rem; color: #fca5a5; }
.alert {
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  line-height: 1.45;
  margin-bottom: 1rem;
}
.alert-warn {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
}

/* Dashboard Layout */
.dashboard-shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(0.85rem, env(safe-area-inset-top)) 1.25rem 0.85rem;
  background: rgba(11, 17, 32, 0.85);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar-title { margin: 0; font-size: 1.05rem; letter-spacing: -0.01em; }
.topbar-sub { margin: 0.1rem 0 0; font-size: 0.76rem; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }

.main-content {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem max(2.5rem, env(safe-area-inset-bottom));
}

/* Summary Strip */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.summary-item {
  background: rgba(22, 32, 51, 0.75);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.summary-label { font-size: 0.76rem; color: var(--text-muted); }
.summary-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-err { color: var(--err); }

/* Empty State */
.empty-state {
  background: rgba(22, 32, 51, 0.7);
  border: 1px dashed var(--border-strong);
  border-radius: 18px;
  padding: 3rem 1.5rem;
  text-align: center;
  max-width: 520px;
  margin: 2rem auto;
}
.empty-icon { font-size: 2rem; color: var(--primary); margin-bottom: 0.6rem; }
.empty-state h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
.empty-state p { margin: 0 0 1.25rem; font-size: 0.88rem; color: var(--text-muted); line-height: 1.6; }

/* Server Cards Grid */
.servers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1rem;
}

.server-card {
  background: rgba(22, 32, 51, 0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  transition: border-color 0.15s ease;
}
.server-card:hover { border-color: var(--border-strong); }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.card-title-wrap { min-width: 0; }
.card-name { margin: 0; font-size: 1.05rem; font-weight: 700; word-break: break-word; }
.card-meta {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.ip-copy {
  border: none;
  background: rgba(59, 130, 246, 0.14);
  color: #93c5fd;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
}
.ip-copy:hover { background: rgba(59, 130, 246, 0.25); }

/* Status Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  flex-shrink: 0;
}
.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.badge-online { background: rgba(34, 197, 94, 0.14); color: #4ade80; }
.badge-offline { background: rgba(245, 158, 11, 0.14); color: #fbbf24; }
.badge-disabled { background: rgba(148, 163, 184, 0.16); color: #cbd5e1; }
.badge-error { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-loading { background: rgba(59, 130, 246, 0.14); color: #93c5fd; }

/* Spec Tags */
.spec-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.spec-pill {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
}

/* Usage Bars */
.metrics-stack { display: flex; flex-direction: column; gap: 0.65rem; }
.metric-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  margin-bottom: 0.28rem;
}
.metric-label { color: var(--text-muted); font-weight: 500; }
.metric-val { color: var(--text); font-variant-numeric: tabular-nums; }
.bar-track {
  height: 7px;
  background: rgba(15, 23, 42, 0.85);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  transition: width 0.35s ease;
}
.bar-fill.warn { background: linear-gradient(90deg, #d97706, #fbbf24); }
.bar-fill.danger { background: linear-gradient(90deg, #dc2626, #f87171); }

.card-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  font-size: 0.82rem;
  padding: 0.65rem 0.75rem;
  border-radius: 9px;
  line-height: 1.45;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.card-foot-meta { font-size: 0.72rem; color: var(--text-muted); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 1.35rem;
  box-shadow: var(--shadow);
}
.modal-sm { max-width: 380px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 0.5rem;
}
.confirm-text { margin: 0 0 1.25rem; font-size: 0.9rem; color: var(--text-muted); line-height: 1.55; }

/* Toast */
.toast-container {
  position: fixed;
  right: 1rem;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(340px, calc(100vw - 2rem));
}
.toast {
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.7rem 0.95rem;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}
.toast-err { border-color: rgba(239, 68, 68, 0.55); color: #fecaca; }
.toast-ok { border-color: rgba(34, 197, 94, 0.5); color: #bbf7d0; }

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .topbar-actions { justify-content: flex-start; }
  .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .servers-grid { grid-template-columns: 1fr; }
}
