:root {
  --bg: #0e1116;
  --bg-raised: #161b22;
  --bg-inset: #0b0e13;
  --border: #262c36;
  --border-soft: #1d222b;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #2f81f7;
  --accent-hover: #4894ff;
  --online: #3fb950;
  --starting: #d29922;
  --offline: #6e7681;
  --danger: #f85149;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 16px; }
.muted { color: var(--text-dim); font-size: 13px; margin: 2px 0 0; }
.error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: 0 0 38px;
  background: linear-gradient(135deg, var(--accent), #1f6feb);
  border-radius: 9px;
  font-weight: 700; font-size: 14px; letter-spacing: 0.5px; color: #fff;
}
.brand.small .brand-mark { width: 30px; height: 30px; flex-basis: 30px; font-size: 12px; }

/* ---------- Login ---------- */
.centered { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}
.login-card .brand { margin-bottom: 24px; }
.login-card label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 500; }

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 129, 247, 0.25);
}
input[type="checkbox"] { width: auto; }

/* ---------- Buttons ---------- */
.btn {
  padding: 8px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #1f2630; border-color: #3a4250; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: transparent; border-color: #5c2626; color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: rgba(248, 81, 73, 0.12); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 20px; padding: 10px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.host-stat { color: var(--text-dim); font-size: 12px; font-family: var(--mono); }
.user-chip {
  padding: 4px 10px; background: var(--bg-inset);
  border: 1px solid var(--border); border-radius: 20px; font-size: 12px;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 7px 14px; background: transparent; border: none;
  border-radius: 7px; color: var(--text-dim);
  font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.tab.active { color: var(--text); background: rgba(255,255,255,0.08); }
.tabs.sub { border-bottom: 1px solid var(--border); padding-bottom: 0; margin: 20px 0 0; gap: 2px; }
.tabs.sub .tab { border-radius: 7px 7px 0 0; margin-bottom: -1px; border-bottom: 2px solid transparent; }
.tabs.sub .tab.active { background: transparent; border-bottom-color: var(--accent); color: var(--text); }

/* ---------- Views ---------- */
.view { display: none; }
.view.active { display: grid; }
#view-servers.active { grid-template-columns: 300px 1fr; height: calc(100vh - 56px); }
#view-users.active, #view-audit.active { padding: 24px; justify-items: center; }

.sidebar {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg-raised);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; background: var(--bg-raised);
}
.server-list { padding: 8px; display: flex; flex-direction: column; gap: 4px; }

.server-card {
  padding: 11px 12px; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.server-card:hover { background: rgba(255,255,255,0.04); }
.server-card.selected { background: rgba(47,129,247,0.12); border-color: rgba(47,129,247,0.4); }
.server-card .row { display: flex; align-items: center; gap: 8px; }
.server-card .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-card .meta { color: var(--text-dim); font-size: 12px; margin-top: 3px; font-family: var(--mono); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; background: var(--offline); }
.dot.online { background: var(--online); box-shadow: 0 0 6px rgba(63,185,80,0.6); }
.dot.starting { background: var(--starting); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 4px; font-weight: 600;
  background: rgba(210,153,34,0.16); color: var(--starting);
}

/* ---------- Detail ---------- */
.detail { overflow-y: auto; padding: 24px; }
.empty { display: grid; place-items: center; height: 100%; color: var(--text-dim); }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.power { display: flex; gap: 8px; }

.statgrid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px; margin-top: 18px;
}
.stat {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.stat .label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat .value { font-size: 18px; font-weight: 600; margin-top: 4px; font-family: var(--mono); }

.pane { display: none; padding-top: 18px; }
.pane.active { display: block; }

.console {
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 14px; margin: 0;
  height: 46vh; min-height: 260px; overflow-y: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
  color: #c9d1d9;
}
.console-input { display: flex; gap: 0; }
.console-input input {
  border-radius: 0 0 0 var(--radius); border-top: none; font-family: var(--mono);
}
.console-input .btn { border-radius: 0 0 var(--radius) 0; border-left: none; }

/* ---------- Forms & panels ---------- */
.panel {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.panel.wide { width: 100%; max-width: 1000px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.field label { display: block; font-size: 12px; font-weight: 500; margin-bottom: 5px; color: var(--text-dim); }
.field .hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.form-actions { margin-top: 18px; display: flex; gap: 8px; align-items: center; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
td.actions { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
code.inline {
  font-family: var(--mono); font-size: 12px; background: var(--bg-inset);
  padding: 2px 6px; border-radius: 5px; border: 1px solid var(--border);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(1,4,9,0.75);
  display: grid; place-items: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px;
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 11px 15px; font-size: 13px;
  max-width: 380px; animation: slide-in 0.18s ease-out;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--online); }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }

@media (max-width: 860px) {
  #view-servers.active { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
  .topbar { gap: 12px; padding: 0 12px; }
  .host-stat { display: none; }
}
