:root {
  color-scheme: light;
  --bg-canvas: var(--marca-canvas, #F0F6F6);
  --bg-surface: var(--marca-superficie, #ffffff);
  --bg-surface-elevated: #f1f5f9;
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-primary: var(--marca-texto, #0f172a);
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-primary: var(--marca-primaria, #00767D);
  --accent-primary-hover: var(--marca-hover, #005b60);
  --accent-primary-fg: var(--marca-contraste, #ffffff);
  --state-success: #16a34a;
  --state-success-soft: rgba(22, 163, 74, 0.1);
  --state-warning: #d97706;
  --state-warning-soft: rgba(217, 119, 6, 0.1);
  --state-danger: #dc2626;
  --state-danger-soft: rgba(220, 38, 38, 0.1);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-size-micro: 0.75rem;
  --font-size-body: 1rem;
  --font-size-section: clamp(1.25rem, 2vw, 1.75rem);
  --font-size-position: clamp(3.5rem, 15vw, 6rem);

  --space-1: 2px;
  --space-2: 4px;
  --space-3: 8px;
  --space-4: 12px;
  --space-5: 16px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --radius-round: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06), 0 12px 28px rgba(15, 23, 42, 0.06);
  --shadow-focus: 0 0 0 4px rgba(15, 23, 42, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-size: var(--font-size-body);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: 0.46; }
a { color: inherit; text-decoration: none; }
img, svg, video, iframe { display: block; max-width: 100%; }
/* Nomes, e-mails e URLs longos quebram em vez de empurrar a tela para o lado. */
h1, h2, h3, p, li, dd, dt, label, summary { overflow-wrap: anywhere; }

:focus-visible {
  outline: 3px solid var(--text-primary);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 1120px);
  margin-inline: auto;
  padding: var(--space-5) var(--space-5) calc(var(--space-6) + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: calc(68px + var(--safe-top));
  padding: var(--safe-top) max(var(--space-5), calc((100vw - 1120px) / 2 + var(--space-5))) 0;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.brand-lockup { display: flex; align-items: center; gap: var(--space-4); min-width: 0; }
.brand-copy { min-width: 0; }
.brand-mark {
  display: grid;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: var(--accent-primary);
  color: var(--accent-primary-fg);
}
.brand-name {
  margin: 0;
  overflow: hidden;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 750;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.015em;
}
.brand-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: var(--font-size-micro);
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--state-success);
  box-shadow: 0 0 0 3px var(--state-success-soft);
}
.status-dot.paused { background: var(--state-warning); box-shadow: 0 0 0 3px var(--state-warning-soft); }

.card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
}

.button {
  display: inline-flex;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 0 20px;
  border: 1px solid var(--accent-primary);
  border-radius: 13px;
  background: var(--accent-primary);
  color: var(--accent-primary-fg);
  font-size: 0.95rem;
  font-weight: 750;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
}
.button:active { transform: translateY(0); }
.button.secondary { border-color: var(--border-strong); background: var(--bg-surface); color: var(--text-primary); }
.button.danger { border-color: var(--state-danger); background: var(--state-danger); color: #fff; }
.button.full { width: 100%; }
.button.compact { min-height: 44px; padding-inline: 14px; font-size: 0.85rem; }

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: background-color 180ms ease, border-color 180ms ease;
}
.danger-soft { border-color: rgba(220, 38, 38, 0.28); background: var(--state-danger-soft); color: var(--state-danger); }

.badge, .pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: 6px;
  padding: 0 11px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-round);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  font-size: var(--font-size-micro);
  font-weight: 750;
  letter-spacing: 0.02em;
}
.badge.is-success, .pill.success { border-color: rgba(22, 163, 74, 0.3); background: var(--state-success-soft); color: var(--text-primary); }
.badge.is-warning, .pill.warning { border-color: rgba(217, 119, 6, 0.3); background: var(--state-warning-soft); color: var(--text-primary); }
.badge.is-danger, .pill.danger { border-color: rgba(220, 38, 38, 0.3); background: var(--state-danger-soft); color: var(--text-primary); }

.field { display: grid; gap: var(--space-3); }
.field label { color: var(--text-primary); font-size: 0.875rem; font-weight: 700; }
.input, .textarea {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  outline: none;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.textarea { min-height: 104px; padding-block: 13px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .textarea:focus { border-color: var(--accent-primary); box-shadow: var(--shadow-focus); }
.input-error { border-color: var(--state-danger) !important; box-shadow: 0 0 0 4px var(--state-danger-soft) !important; }

.section-title {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--font-size-section);
  font-weight: 850;
  line-height: 1.15;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.section-copy { margin: 10px 0 0; color: var(--text-secondary); font-size: 0.98rem; line-height: 1.6; }
.eyebrow { margin: 0; color: var(--text-secondary); font-size: var(--font-size-micro); font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.stack { display: grid; gap: var(--space-5); }
.muted-link { display: inline-flex; min-height: 44px; align-items: center; padding: 0 var(--space-3); background: transparent; color: var(--text-secondary); font-size: 0.9rem; font-weight: 650; text-decoration: underline; text-underline-offset: 4px; }
.inline-link { color: var(--text-primary); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

/* Hover somente com mouse: no toque o efeito ficaria preso depois do clique. */
@media (hover: hover) {
  .button:hover { border-color: var(--accent-primary-hover); background: var(--accent-primary-hover); transform: translateY(-1px); }
  .button.secondary:hover { background: var(--bg-surface-elevated); }
  .icon-button:hover { border-color: var(--border-strong); background: var(--bg-surface-elevated); }
  .muted-link:hover { color: var(--text-primary); }
}

.flash-message { width: min(calc(100% - 32px), 1088px); margin: var(--space-4) auto 0; padding: var(--space-4) var(--space-5); border: 1px solid var(--border-subtle); border-left: 4px solid var(--accent-primary); border-radius: var(--radius-sm); background: var(--bg-surface); color: var(--text-primary); font-weight: 650; box-shadow: var(--shadow-sm); }

/* Lista da fila compartilhada por status, painel (antes do JS) e TV. */
.queue-list-card { padding: 20px; }
.queue-list { display: grid; gap: 8px; }
.queue-row { display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 12px; align-items: center; min-height: 62px; padding: 8px 12px; border: 1px solid var(--border-subtle); border-radius: 12px; background: var(--bg-surface); }
.queue-row.current { border-color: rgba(22, 163, 74, 0.35); background: var(--state-success-soft); }
.queue-row.me { border-color: var(--text-primary); border-width: 2px; background: var(--bg-surface-elevated); }
.queue-index { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 10px; background: var(--bg-surface-elevated); color: var(--text-primary); font-family: var(--font-mono); font-size: 0.84rem; font-weight: 850; }
.queue-row.current .queue-index { background: var(--state-success); color: #fff; }
.queue-row.me .queue-index { background: var(--text-primary); color: var(--bg-surface); }
.queue-person { min-width: 0; }
.queue-person strong { display: block; overflow: hidden; color: var(--text-primary); font-size: 0.92rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.queue-person span { display: block; margin-top: 2px; color: var(--text-secondary); font-size: 0.75rem; }

.empty-state { display: none; padding: var(--space-7); text-align: center; }
.empty-state.is-active { display: grid; justify-items: center; gap: var(--space-5); }
.empty-state .section-copy { max-width: 520px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: var(--space-5) var(--space-5) calc(var(--space-5) + var(--safe-bottom));
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(5px);
}
.modal-backdrop.is-open { display: flex; }
.modal {
  width: min(100%, 460px);
  /* Com o teclado aberto o modal rola por dentro em vez de ser cortado. */
  max-height: calc(100vh - 32px - var(--safe-bottom));
  max-height: calc(100dvh - 32px - var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: 0 24px 64px rgba(2, 6, 23, 0.24);
  animation: modal-in 180ms ease-out;
}
.modal h2 { margin: 0; font-size: 1.3rem; letter-spacing: -0.02em; }
.modal p { margin: 8px 0 20px; color: var(--text-secondary); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
@media (max-width: 420px) { .modal-actions { grid-template-columns: 1fr; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px); } }

.toast {
  position: fixed;
  right: var(--space-5);
  bottom: calc(var(--space-5) + var(--safe-bottom));
  z-index: 130;
  width: min(calc(100vw - 32px), 380px);
  padding: 14px 18px;
  border: 1px solid #334155;
  border-radius: 13px;
  background: #0f172a;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 650;
  box-shadow: 0 18px 48px rgba(2, 6, 23, 0.26);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

.lucide-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Pareamento da TV: código legível de longe e sem estourar telas pequenas. */
.pairing-shell { display: grid; min-height: 100vh; min-height: 100dvh; place-items: center; }
.pairing-card { display: grid; justify-items: center; gap: var(--space-3); width: min(100%, 760px); padding: clamp(24px, 6vw, 48px); text-align: center; }
.pairing-card h1 { margin: 0; }
.pairing-card p { margin: 0; color: var(--text-secondary); }
.pairing-code { display: block; color: var(--marca-primaria); font: 800 clamp(2.5rem, 13vw, 7rem) var(--font-mono); letter-spacing: 0.12em; }

@media (min-width: 768px) {
  .app-shell { padding: var(--space-7) var(--space-6) calc(var(--space-7) + var(--safe-bottom)); }
  .modal-backdrop { align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

.brand-logo { width: 44px; height: 44px; flex: 0 0 44px; object-fit: contain; border-radius: 10px; }
.form-error { color: var(--state-danger); }
