:root {
  --bg: #0f1117;
  --panel: #181b24;
  --panel-2: #1f2330;
  --border: #2a2f3d;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-hover: #3a78f0;
  --danger: #ef4f6b;
  --ok: #36c98b;
  --warn: #e8b54a;
  --radius: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.hidden { display: none !important; }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar .brand { font-weight: 700; letter-spacing: 0.3px; }
.topbar .brand span { color: var(--accent); }
.topbar .right { display: flex; align-items: center; gap: 1rem; }
.topbar .user { color: var(--muted); font-size: 0.9rem; }

/* ---- Buttons ---- */
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
button:hover { background: #262b3a; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: rgba(239, 79, 107, 0.12); }
button.ghost { background: transparent; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.login-card h1 span { color: var(--accent); }
.login-card p.sub { margin: 0 0 1.5rem; color: var(--muted); font-size: 0.9rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.field input {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.7rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.field input:focus { outline: none; border-color: var(--accent); }
.error-msg { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; margin: 0.25rem 0 0.75rem; }

/* ---- Dashboard ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.section-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 1.5rem 0 0.75rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.card .title { font-weight: 600; font-size: 1.05rem; }
.card .meta { color: var(--muted); font-size: 0.82rem; line-height: 1.5; }
.card .actions { display: flex; gap: 0.5rem; margin-top: auto; flex-wrap: wrap; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.ready { color: var(--ok); border-color: rgba(54, 201, 139, 0.4); }
.badge.provisioning { color: var(--warn); border-color: rgba(232, 181, 74, 0.4); }
.badge.error { color: var(--danger); border-color: rgba(239, 79, 107, 0.4); }
.badge.connected { color: var(--accent); border-color: rgba(79, 140, 255, 0.4); }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { color: var(--muted); font-size: 0.9rem; padding: 1rem 0; }

/* ---- Console page ---- */
.console-body { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.console-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 1rem; background: var(--panel); border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.console-bar .status { color: var(--muted); font-size: 0.85rem; }
#screen { flex: 1 1 auto; background: #000; overflow: hidden; }
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(15, 17, 23, 0.85); color: var(--text); text-align: center; z-index: 10;
}
.overlay .box { max-width: 420px; padding: 2rem; }
.overlay h2 { margin: 0.5rem 0; }
.overlay p { color: var(--muted); }

/* ============================ noVNC control panel ============================ */
/* The #screen sits in a positioned wrapper so the panel can fling out over it. */
.console-stage { flex: 1 1 auto; position: relative; overflow: hidden; }
.console-stage > #screen { position: absolute; inset: 0; }

/* Slim handle clinging to the left edge; click/hover flings the panel out. */
#panel-handle {
  position: absolute; top: 50%; left: 0; transform: translateY(-50%);
  z-index: 6; width: 22px; height: 84px; padding: 0;
  display: grid; place-items: center; cursor: pointer;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  transition: left 0.22s ease, color 0.15s ease;
}
#panel-handle:hover { color: var(--text); }
#panel-handle .chev { font-size: 0.9rem; line-height: 1; }

/* The fling-out panel itself. Translated off-screen until .open. */
#panel {
  position: absolute; top: 0; left: 0; bottom: 0; z-index: 7;
  width: 300px; max-width: 86vw;
  display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  overflow-y: auto;
}
#panel.open { transform: translateX(0); }
/* When open, push the handle to the panel's edge and flip the chevron. */
.console-stage.panel-open #panel-handle { left: 300px; max-width: 86vw; }
@media (max-width: 360px) { .console-stage.panel-open #panel-handle { left: 86vw; } }

#panel header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
}
#panel header .title { font-weight: 600; }
#panel header .title span { color: var(--accent); }

.panel-section { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.panel-section > h3 {
  margin: 0 0 0.6rem; font-size: 0.72rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.panel-section .row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.panel-section .row:last-child { margin-bottom: 0; }
.panel-section .row label { flex: 1 1 auto; font-size: 0.85rem; }
.panel-section .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.panel-section button { width: 100%; }
.panel-section input[type="range"] { flex: 1 1 auto; accent-color: var(--accent); }
.panel-section input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.panel-section .val { width: 1.6rem; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.panel-section textarea {
  width: 100%; min-height: 64px; resize: vertical; margin-top: 0.25rem;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.4rem 0.5rem; font: inherit; font-size: 0.8rem;
}
.panel-section .hint { font-size: 0.72rem; color: var(--muted); margin: 0.15rem 0 0; }
.panel-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.panel-status-dot.ok { background: var(--ok); }
.panel-status-dot.warn { background: var(--warn); }
.panel-status-dot.bad { background: var(--danger); }
