:root {
  color-scheme: dark;
  --bg: #070b12;
  --bg-soft: #0d1320;
  --card: rgba(18, 26, 41, 0.82);
  --card-border: rgba(255, 255, 255, 0.07);
  --text: #eef3fb;
  --muted: #8b98ad;
  --accent: #4f8cff;
  --accent-2: #22d3b6;
  --danger: #ff6b81;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60rem 40rem at 15% -10%, rgba(79, 140, 255, 0.16), transparent 60%),
    radial-gradient(50rem 30rem at 95% 0%, rgba(34, 211, 182, 0.1), transparent 55%);
  pointer-events: none;
  z-index: 0;
}

.screen { position: relative; z-index: 1; }

/* ---------- marca ---------- */

.brand { display: flex; align-items: center; gap: 14px; }
.brand.hero { margin-bottom: 26px; }
.brand h1 { font-size: 30px; margin: 0; letter-spacing: -0.5px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.brand.small span { font-weight: 600; letter-spacing: 0.2px; }

/* Logo oficial (mesmo ícone do app desktop). */
.logo-img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: block;
  flex: none;
}
.brand.small .logo-img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 22px;
  color: #06101f;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 30px rgba(79, 140, 255, 0.35);
}

/* ---------- auth ---------- */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 32px 20px;
}

.auth-card { width: min(420px, 100%); }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 11px;
  padding: 4px;
  margin-bottom: 20px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active { background: rgba(255, 255, 255, 0.09); color: var(--text); }

form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

input {
  width: 100%;
  margin-top: 7px;
  padding: 12px 13px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(6, 10, 18, 0.65);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

button { font: inherit; }

.primary {
  border: 0;
  border-radius: 10px;
  padding: 11px 18px;
  font-weight: 700;
  color: #06101f;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
}

.primary:hover { transform: translateY(-1px); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.wide { width: 100%; }

.ghost {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
}

.ghost:hover { background: rgba(255, 255, 255, 0.08); }

.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 14px 0 0; }
.error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- dashboard ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  background: rgba(7, 11, 18, 0.7);
  z-index: 5;
}

.top-actions { display: flex; align-items: center; gap: 14px; }
.user-email { color: var(--muted); font-size: 13.5px; }

a.download-app {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-size: 13px;
}

.auth-download { margin-top: 18px; }
.auth-download a { color: var(--accent); text-decoration: none; }
.auth-download a:hover { text-decoration: underline; }

main { max-width: 1180px; margin: 0 auto; padding: 34px 28px 60px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 26px;
}

.page-head h2 { margin: 0; font-size: 26px; letter-spacing: -0.4px; }
.page-head .muted { margin: 6px 0 0; font-size: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 16px;
}

.machine {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s, transform 0.15s;
}

.machine:hover { border-color: rgba(79, 140, 255, 0.35); transform: translateY(-2px); }
.machine.off { opacity: 0.78; }

.machine-top { display: flex; align-items: center; justify-content: space-between; }

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.machine.on .status { color: var(--accent-2); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4a5568;
}

.machine.on .dot {
  background: var(--accent-2);
  box-shadow: 0 0 10px rgba(34, 211, 182, 0.8);
}

.os { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.machine h3 { margin: 4px 0 0; font-size: 17px; letter-spacing: -0.2px; }

.machine-id {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 14px;
  color: #b9c7dd;
  letter-spacing: 0.5px;
}

.machine-meta { font-size: 12px; color: var(--muted); }
.machine .primary { margin-top: 6px; }

/* Conectar ocupa a linha toda; Renomear e Remover dividem a de baixo. */
.machine-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.machine-actions > * { min-width: 0; margin-top: 0; }
.machine-actions .primary { grid-column: 1 / -1; }
.machine-actions .rename,
.machine-actions .remove { padding: 8px 10px; font-size: 13px; }
.machine-actions .remove { color: var(--muted); }
.machine-actions .remove:hover { color: var(--danger); border-color: rgba(255, 107, 129, 0.35); }

.web-open {
  align-self: flex-start;
  margin-top: -2px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.18);
  padding-bottom: 1px;
}

.web-open:hover { color: var(--accent); border-color: rgba(79, 140, 255, 0.5); }

.empty {
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.015);
}

.empty-icon { font-size: 40px; margin-bottom: 8px; }
.empty h3 { margin: 0 0 8px; }
.empty p { margin: 0 auto; max-width: 480px; color: var(--muted); line-height: 1.55; }
.footer-hint { text-align: center; margin-top: 26px; }

/* ---------- dialog ---------- */

dialog {
  border: 1px solid var(--card-border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: var(--radius);
  padding: 22px;
  width: min(430px, calc(100vw - 32px));
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6);
}

dialog::backdrop { background: rgba(2, 5, 10, 0.7); backdrop-filter: blur(3px); }

.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h3 { margin: 0; }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
}

.code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 10px;
  padding: 14px 18px;
  border-radius: 12px;
  background: rgba(79, 140, 255, 0.08);
  border: 1px solid rgba(79, 140, 255, 0.22);
}

#pair-code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 3px;
}

/* ---------- sessão remota ---------- */

.session-body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.session-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(7, 11, 18, 0.88);
  backdrop-filter: blur(10px);
}

.session-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
}

.session-actions { display: flex; gap: 8px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-2);
  background: rgba(34, 211, 182, 0.12);
}

.pill.off {
  color: var(--danger);
  background: rgba(255, 107, 129, 0.12);
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  line-height: 0;
}

#remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  border-radius: 10px;
  pointer-events: none;
  z-index: 1;
}

.overlay {
  z-index: 2;
}

canvas#screen {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  background: #000;
  border-radius: 10px;
  outline: none;
  cursor: crosshair;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  line-height: 1.5;
  background: rgba(5, 8, 14, 0.84);
  border-radius: 10px;
  backdrop-filter: blur(2px);
}

.overlay[hidden] { display: none; }

/* Em tela cheia o vídeo ocupa a tela inteira; Esc sai. */
:fullscreen .session-bar { display: none; }
:fullscreen .stage { padding: 0; }

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(560px, calc(100vw - 32px));
  padding: 13px 18px;
  border-radius: 12px;
  background: #16202f;
  border: 1px solid rgba(79, 140, 255, 0.35);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  font-size: 13.5px;
  line-height: 1.45;
}

@media (max-width: 640px) {
  .topbar { padding: 14px 16px; }
  main { padding: 24px 16px 48px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .primary { width: 100%; }
  .user-email { display: none; }
  .brand.hero { flex-direction: column; align-items: flex-start; }
  #pair-code { font-size: 22px; }
}


/* Diagnóstico do vídeo: painel recolhível no canto inferior direito.
   Recolhido por padrão, então não cobre a tela remota nem rouba cliques do
   mouse que o usuário está controlando. */
.rtc-panel {
  position: fixed;
  right: 10px;
  bottom: 48px;
  width: 360px;
  max-width: calc(100vw - 20px);
  z-index: 40;
  font: 11px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.rtc-panel > summary {
  cursor: pointer;
  list-style: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(8, 12, 20, 0.9);
  color: #9fe8c8;
  border: 1px solid rgba(120, 200, 170, 0.25);
  user-select: none;
}

.rtc-panel[open] > summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.rtc-panel-bar {
  display: flex;
  justify-content: flex-end;
  padding: 4px 8px 0;
  background: rgba(8, 12, 20, 0.94);
}

.rtc-log-body {
  margin: 0;
  max-height: 220px;
  overflow: auto;
  padding: 6px 10px 10px;
  border-radius: 0 0 8px 8px;
  background: rgba(8, 12, 20, 0.94);
  color: #9fe8c8;
  white-space: pre-wrap;
  user-select: text;
  cursor: text;
}
