﻿:root {
  color-scheme: dark;
  --bg: #090d16;
  --surface: #111827;
  --surface-elevated: #172033;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.flex-1 { flex: 1; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { border-color: rgba(255,255,255,0.28); background: #1e293b; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.sm { padding: 6px 12px; font-size: 12px; }
.btn.full { width: 100%; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04101d;
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); }
.keepalive-btn.active { background: rgba(34, 197, 94, 0.14); border-color: rgba(34, 197, 94, 0.45); color: #86efac; }
.btn.danger { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.45); color: #fecaca; }
.btn.danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.28); }

input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #0b1120;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--accent); }

/* View 1: Login */
.view-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(600px 300px at 50% 10%, rgba(56, 189, 248, 0.08), transparent),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}
.login-brand h1 { font-size: 18px; margin: 0 0 4px; font-weight: 600; }
.subtitle { margin: 0; font-size: 12px; color: var(--muted); }

.brand-mark {
  font-size: 26px !important;
  background: linear-gradient(135deg, #fde68a, #f59e0b) !important;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.brand-mark.sm { width: 32px; height: 32px; font-size: 18px !important; border-radius: 8px; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: #0b1120;
  border-radius: 10px;
  margin-bottom: 20px;
}
.tab {
  padding: 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.tab.active { background: var(--surface-elevated); color: var(--text); }

.auth-form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
.input-group { display: flex; gap: 8px; }
.form-error { margin-top: 12px; font-size: 13px; color: #f87171; min-height: 18px; }

.qr-info {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding-top: 6px;
  text-align: center;
}
.qr-img { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 10px; }
.qr-tip { font-size: 13px; color: var(--muted); }
.qr-link a { font-size: 12px; color: var(--accent); text-decoration: none; }
.qr-poll { font-size: 12px; color: var(--accent); }

/* View 2: Dashboard */
.view-dashboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(10px);
}
.dash-brand { display: flex; align-items: center; gap: 10px; }
.brand-title { font-weight: 600; font-size: 15px; }
.dash-user { display: flex; align-items: center; gap: 10px; }
.user-badge { font-size: 13px; color: var(--muted); padding-right: 4px; }

.dash-main {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 36px 24px;
}
.dash-section-head { margin-bottom: 24px; }
.dash-section-head h2 { margin: 0 0 6px; font-size: 22px; font-weight: 600; }

.pc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

.pc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: border-color 0.18s, transform 0.18s;
}
.pc-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }

.pc-card-top { display: flex; justify-content: space-between; align-items: center; }
.pc-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-pill.online { color: #86efac; background: rgba(34, 197, 94, 0.12); }
.status-pill.online .dot { background: var(--success); }
.status-pill.ready { color: #7dd3fc; background: rgba(56, 189, 248, 0.12); }
.status-pill.ready .dot { background: var(--accent); }
.status-pill.offline { color: #fca5a5; background: rgba(239, 68, 68, 0.12); }
.status-pill.offline .dot { background: var(--danger); }

.pc-name { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.pc-sub { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.pc-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag {
  font-size: 11px;
  color: var(--muted);
  background: #0b1120;
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
}
.pc-card-actions { display: flex; gap: 8px; margin-top: auto; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 48px; color: var(--muted); }
.empty-state.error { color: #f87171; }

/* View 3: Full-Viewport Desktop Stage */
.view-desktop {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  overflow: hidden;
  user-select: none;
}

.desktop-stage {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  position: relative;
  contain: layout paint;
}

.desktop-stage #spice-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  display: block;
  cursor: default;
}

.desktop-stage.scale-fill #spice-canvas { object-fit: fill; }

.desktop-stage.scale-native {
  overflow: auto;
  place-items: start;
}
.desktop-stage.scale-native #spice-canvas {
  position: static;
  width: auto;
  height: auto;
  object-fit: none;
}

.desktop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 13, 22, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 15;
}
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-text { font-size: 14px; color: var(--muted); }

/* Floating Glass HUD */
.desktop-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.hud-hover-zone {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 14px;
  pointer-events: auto;
}
.hud-bar {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  transform: translateY(-130%);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.desktop-hud:hover .hud-bar,
.desktop-hud.peek .hud-bar,
.desktop-hud.pinned .hud-bar {
  transform: translateY(0);
  opacity: 1;
}

.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; }
.hud-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.hud-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.hud-dot.connecting { background: var(--warning); }
.hud-dot.offline { background: var(--danger); }

.hud-vm-name { font-size: 13px; font-weight: 600; }
.hud-telemetry {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  contain: layout style;
}

.hud-btn {
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.hud-btn:hover { background: rgba(255, 255, 255, 0.14); }
.hud-btn.active { border-color: var(--accent); color: var(--accent); }
.hud-btn.danger { background: rgba(239, 68, 68, 0.22); border-color: rgba(239, 68, 68, 0.45); color: #fecaca; }
.hud-btn.danger:hover { background: rgba(239, 68, 68, 0.36); }

/* Diagnostics Drawer */
.diag-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 440px;
  max-width: 92vw;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(14px);
  border-left: 1px solid var(--border-strong);
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.diag-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
}
.diag-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: grid;
  gap: 10px;
  align-content: start;
}
.diag-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.diag-code {
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: #020617;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  gap: 12px;
}
.modal-card h3 { margin: 0; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 70;
  display: grid;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { border-color: rgba(34, 197, 94, 0.5); color: #86efac; }
.toast.toast-error { border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
