:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #22c55e;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(15, 23, 42, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.brand-name {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.2px;
}

.brand-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.topbar-actions, .user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}

#userEmail {
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.center-stage {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.dashboard {
  max-width: 860px;
  margin: 28px auto;
  padding: 0 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.18);
  color: #60a5fa;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 10px;
}

h1, h2, h3 {
  margin: 0 0 8px 0;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 18px 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

input:focus, select:focus {
  border-color: #38bdf8;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.btn-danger {
  background: rgba(220, 38, 38, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(220, 38, 38, 0.45);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.device-selector-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.select-wrap {
  flex: 1 1 240px;
}

.presence-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.presence-pill .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #64748b;
}

.presence-pill.online .dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.stat-val {
  font-size: 0.88rem;
  word-break: break-word;
}

.config-drawer {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.config-drawer summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}

.drawer-body {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.drawer-body .field {
  flex: 1 1 260px;
}

.error-text {
  color: #fca5a5;
  font-size: 0.85rem;
  margin: 4px 0 0 0;
}

.info-text {
  color: #93c5fd;
  font-size: 0.86rem;
  margin: 12px 0 0 0;
}

/* Session Viewport */
.session-view {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.viewport-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.session-overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.floating-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(15, 23, 42, 0.92);
  border-top: 1px solid var(--border);
}

.tool-group {
  display: inline-flex;
  gap: 6px;
}

.tool-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.tool-danger {
  background: rgba(220, 38, 38, 0.25);
  border-color: rgba(220, 38, 38, 0.5);
  color: #fecaca;
}

.hidden-input {
  position: fixed;
  left: -9999px;
  top: 0;
  opacity: 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 400px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 600px) {
  #userEmail {
    display: none;
  }
  .card {
    padding: 18px;
  }
}
