:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --accent: #06b6d4;
  --accent-light: #ecfeff;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --priority-color: #e11d48;
  --priority-bg: #ffe4e6;
  --success: #10b981;
  --success-bg: #d1fae5;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.04);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

[data-theme="dark"] {
  --bg-main: #090d16;
  --bg-card: #131b2e;
  --bg-sidebar: #0f172a;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #1e293b;
  --primary-light: rgba(2, 132, 199, 0.15);
  --accent-light: rgba(6, 182, 212, 0.15);
  --priority-bg: rgba(225, 29, 72, 0.2);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========================================================
   NAVBAR & HEADER (CONTROLE E ADMIN)
======================================================== */
.navbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  height: 38px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.brand-icon-default {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #ffffff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-tagline {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: none;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.clinic-selector-select {
  padding: 0.45rem 0.85rem;
  min-width: 150px;
  max-width: 260px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.18s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast, #ffffff);
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: var(--primary-contrast, #ffffff);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--primary-glow, rgba(2, 132, 199, 0.3));
}

.btn-secondary {
  background: var(--bg-sidebar);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-tv {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.25);
}

.btn-tv:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-danger {
  background: #ef4444;
  color: #ffffff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-success {
  background: #059669;
  color: #ffffff;
}

.btn-success:hover {
  background: #047857;
}

/* ========================================================
   MAIN LAYOUT (RECEPTION & DOCTORS)
======================================================== */
.main-container {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1480px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}

@media (max-width: 1080px) {
  .main-container {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.45rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 1.02rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input-lg {
  font-size: 1.35rem;
  font-weight: 600;
  padding: 0.9rem 1.2rem;
}

/* Room Grid Selection */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.85rem;
  margin-top: 0.5rem;
}

.room-btn {
  background: var(--bg-sidebar);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.9rem 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  user-select: none;
  min-height: 80px;
}

.room-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
}

.room-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 2px var(--primary);
}

.room-icon-svg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--primary);
}

.room-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  text-transform: none;
}

.room-category {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: none;
}

/* Priority Toggle */
.priority-toggle {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem 1.2rem;
  background: var(--bg-sidebar);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-color);
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
}

.priority-toggle.active {
  background: var(--priority-bg);
  border-color: var(--priority-color);
  color: var(--priority-color);
}

.priority-toggle input {
  display: none;
}

.priority-label {
  font-weight: 700;
  font-size: 0.95rem;
}

/* Big Call Button */
.btn-call-big {
  width: 100%;
  padding: 1.15rem;
  font-size: 1.3rem;
  font-weight: 800;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), #0284c7);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  box-shadow: 0 10px 20px rgba(2, 132, 199, 0.25);
  transition: all 0.2s ease;
}

.btn-call-big:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 25px rgba(2, 132, 199, 0.35);
}

/* Doctor Pinned Room Banner */
.doctor-room-bar {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
}

.doctor-room-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.doctor-room-title {
  font-size: 1.5rem;
  font-weight: 800;
  text-transform: none;
}

.doctor-room-subtitle {
  font-size: 0.9rem;
  opacity: 0.9;
  text-transform: none;
}

/* Queue List */
.queue-table {
  width: 100%;
  border-collapse: collapse;
}

.queue-table th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.75rem 0.85rem;
  border-bottom: 1.5px solid var(--border-color);
}

.queue-table td {
  padding: 0.85rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.95rem;
}

.queue-row:hover {
  background: var(--bg-sidebar);
}

.badge-priority {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--priority-bg);
  color: var(--priority-color);
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* History Sidebar */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 420px;
  overflow-y: auto;
}

.history-item {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s ease;
}

.history-item:hover {
  border-color: var(--primary);
  background: var(--bg-card);
}

.history-item.priority {
  border-left: 4px solid var(--priority-color);
}

.history-patient {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-main);
  text-transform: none;
}

.history-details {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  text-transform: none;
}

.history-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--border-color);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
}

.btn-recall {
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
}

.btn-recall:hover {
  background: var(--primary);
  color: #fff;
}

/* ==========================================================================
   TV PANEL STYLES (TOTALMENTE RESPONSIVO E AUTO-ADAPTÁVEL A QUALQUER TELA)
   Suporte a 720p, 1080p, 1440p, 4K, 8K, Ultrawide e Totens Verticais
========================================================================== */
.tv-body {
  background: #090e1a;
  color: #f8fafc;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  user-select: none;
  position: relative;
  font-size: clamp(13px, 1vmin + 6px, 26px);
}

/* Header Auto-Adaptável */
.tv-header {
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1.5px solid rgba(255, 255, 255, 0.1);
  padding: clamp(0.5rem, 1.2vh, 1.6rem) clamp(1rem, 2.5vw, 3.5rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  min-height: clamp(55px, 8.5vh, 110px);
  z-index: 10;
}

.tv-brand {
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 1.5vw, 1.8rem);
  min-width: 0;
}

.tv-logo {
  height: clamp(35px, 5.5vh, 75px);
  width: auto;
  max-width: clamp(140px, 18vw, 300px);
  object-fit: contain;
}

.tv-title {
  font-size: clamp(1.15rem, 2.2vw, 2.8rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
  text-transform: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-clock-container {
  text-align: right;
  flex-shrink: 0;
}

.tv-clock {
  font-size: clamp(1.6rem, 2.8vw, 3.8rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--primary, #38bdf8);
  line-height: 1;
}

.tv-date {
  font-size: clamp(0.75rem, 1vw, 1.3rem);
  color: #94a3b8;
  margin-top: clamp(2px, 0.4vh, 6px);
  text-transform: none;
}

/* Grid Principal da TV (Auto-dimensionado em altura e largura) */
.tv-main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr clamp(260px, 26vw, 480px);
  gap: clamp(0.8rem, 1.6vw, 2.5rem);
  padding: clamp(0.8rem, 1.6vw, 2.5rem);
  min-height: 0; /* Impede overflow vertical */
  height: calc(100vh - clamp(55px, 8.5vh, 110px));
  height: calc(100dvh - clamp(55px, 8.5vh, 110px));
  position: relative;
  overflow: hidden;
}

/* Mídia / Propaganda em Espera */
.tv-media-container {
  background: linear-gradient(145deg, #131d31, #0d1527);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: clamp(12px, 1.8vw, 28px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  height: 100%;
  width: 100%;
  min-height: 0;
}

.tv-media-content {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #000;
}

/* Enquadramento Original e Completo para Vídeos (YouTube / Vimeo / Google Drive) */
.tv-media-iframe-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  border-radius: inherit;
  background: #000;
}

/* Caixa com Proporção 16:9 Original do Vídeo e Máscara Limpa de Ícones */
.tv-media-iframe-crop {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border-radius: 4px;
}

.tv-media-iframe-crop iframe,
.tv-media-iframe-crop #tvYoutubePlayer {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 114%;
  transform: translate(-50%, -50%);
  border: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
}

.tv-media-iframe-crop iframe.loaded,
.tv-media-iframe-crop #tvYoutubePlayer.loaded {
  opacity: 1;
}

.video-compress-bar-container {
  margin-top: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.85rem;
}

.video-compress-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.4rem;
}

.video-compress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.tv-media-overlay-text {
  position: absolute;
  bottom: 0;
  inset-inline: 0;
  background: linear-gradient(to top, rgba(9, 14, 26, 0.96) 20%, transparent 100%);
  padding: clamp(1rem, 2.5vw, 3rem);
  text-align: left;
}

.tv-media-title {
  font-size: clamp(1.4rem, 2.4vw, 3.2rem);
  font-weight: 800;
  color: #ffffff;
  margin-bottom: clamp(0.25rem, 0.5vh, 0.8rem);
  text-transform: none;
}

.tv-media-subtitle {
  font-size: clamp(0.95rem, 1.3vw, 1.8rem);
  color: #cbd5e1;
  max-width: 900px;
  text-transform: none;
  line-height: 1.35;
}

/* Barra Lateral da TV (Últimas Chamadas) */
.tv-sidebar {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: clamp(12px, 1.8vw, 28px);
  padding: clamp(0.8rem, 1.4vw, 2rem);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.tv-sidebar-title {
  font-size: clamp(0.95rem, 1.3vw, 1.7rem);
  font-weight: 800;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: clamp(0.5rem, 1vh, 1rem);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: clamp(0.5rem, 1vh, 1rem);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.tv-history-list {
  display: flex;
  flex-direction: column;
  gap: clamp(0.45rem, 0.9vh, 0.85rem);
  overflow: hidden !important;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
  flex: 1;
  min-height: 0;
  justify-content: flex-start;
}

.tv-history-list::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

.tv-history-card {
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: clamp(8px, 1vw, 16px);
  padding: clamp(0.6rem, 1vh, 1.1rem) clamp(0.8rem, 1.2vw, 1.4rem);
  border-left: clamp(4px, 0.5vw, 8px) solid var(--primary, #38bdf8);
  flex-shrink: 0;
}

.tv-history-card.priority {
  border-left-color: #f43f5e;
}

.tv-history-name {
  font-size: clamp(1.05rem, 1.4vw, 1.8rem);
  font-weight: 700;
  color: #ffffff;
  text-transform: none;
}

.tv-history-room {
  font-size: clamp(0.85rem, 1.15vw, 1.4rem);
  color: var(--primary, #38bdf8);
  font-weight: 700;
  margin-top: 0.25rem;
  text-transform: none;
}

/* ==========================================================================
   FULL-SCREEN CALL TAKEOVER AUTO-ADAPTÁVEL (TELA CHEIA DINÂMICA)
========================================================================== */
.tv-call-takeover {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  background: radial-gradient(circle at center, var(--tv-radial-glow, #1e293b) 0%, #090e1a 100%) !important;
  z-index: 999999 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  padding: clamp(1.5rem, 4vmin, 5rem) !important;
  text-align: center !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.95);
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.35s;
  overflow: hidden;
}

.tv-call-takeover.active {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
  transform: scale(1) !important;
}

.tv-takeover-badge {
  display: inline-flex;
  align-items: center;
  gap: clamp(0.4rem, 0.8vw, 1rem);
  background: var(--primary-light, rgba(56, 189, 248, 0.18));
  color: #ffffff;
  border: clamp(1.5px, 0.25vw, 3px) solid var(--primary, rgba(56, 189, 248, 0.5));
  padding: clamp(0.4rem, 1vh, 1.1rem) clamp(1.2rem, 2.5vw, 3rem);
  border-radius: 9999px;
  font-size: clamp(0.9rem, 1.6vw, 2.2rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: clamp(1rem, 3vh, 3.5rem);
  flex-shrink: 0;
}

.tv-takeover-badge.priority {
  background: rgba(244, 63, 94, 0.25);
  color: #ffffff;
  border-color: #f43f5e;
}

.tv-takeover-patient {
  font-size: clamp(2.4rem, 6.5vw, 6.8rem);
  font-weight: 900;
  line-height: 1.12;
  color: #ffffff;
  margin-bottom: clamp(1rem, 3vh, 3.5rem);
  text-shadow: 0 10px 40px rgba(0,0,0,0.6);
  word-break: break-word;
  max-width: min(92vw, 1600px);
  text-transform: none;
  animation: pulse-takeover 2s infinite ease-in-out;
  flex-shrink: 1;
}

@keyframes pulse-takeover {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.tv-takeover-room-box {
  background: rgba(255, 255, 255, 0.06);
  border: clamp(2.5px, 0.35vw, 5px) solid var(--primary, #38bdf8);
  border-radius: clamp(12px, 2vw, 30px);
  padding: clamp(1rem, 2.2vh, 3rem) clamp(2rem, 4.5vw, 6rem);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.25rem, 0.6vh, 0.8rem);
  box-shadow: 0 0 clamp(30px, 5vw, 90px) var(--primary-glow, rgba(56, 189, 248, 0.35));
  max-width: min(92vw, 1400px);
  flex-shrink: 0;
}

.tv-takeover-room-box.priority {
  border-color: #f43f5e;
  box-shadow: 0 0 clamp(30px, 5vw, 90px) rgba(244, 63, 94, 0.45);
}

.tv-takeover-room-name {
  font-size: clamp(1.8rem, 4.2vw, 5rem);
  font-weight: 900;
  color: var(--primary, #38bdf8);
  text-transform: none;
}

.tv-takeover-room-box.priority .tv-takeover-room-name {
  color: #ffffff;
}

.tv-takeover-prof-name {
  font-size: clamp(0.95rem, 1.6vw, 2.2rem);
  color: #ffffff;
  text-transform: none;
}

/* ==========================================================================
   ADAPTAÇÃO AUTOMÁTICA PARA TELAS VERTICAIS / TOTENS (9:16 ou 3:4)
========================================================================== */
@media (max-aspect-ratio: 1/1) {
  .tv-main-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 52% 48%;
    gap: 1rem;
    padding: 1rem;
  }

  .tv-media-overlay-text {
    padding: 1.25rem;
  }

  .tv-takeover-patient {
    font-size: clamp(2.2rem, 8vw, 5.5rem);
  }

  .tv-takeover-room-name {
    font-size: clamp(1.6rem, 6vw, 4rem);
  }
}

/* Audio Unlock Overlay & Universal Modals */
.audio-unlock-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  text-align: center;
  padding: 2rem;
}

.audio-unlock-overlay[style*="display: none"],
.audio-unlock-overlay[style*="display:none"],
.audio-unlock-overlay.hidden {
  display: none !important;
  pointer-events: none !important;
}

.audio-unlock-btn {
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  color: #ffffff;
  border: none;
  font-size: clamp(1.1rem, 1.8vw, 1.8rem);
  font-weight: 800;
  padding: clamp(0.8rem, 1.5vh, 1.5rem) clamp(1.8rem, 3vw, 3.5rem);
  border-radius: var(--radius-xl);
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(6, 182, 212, 0.4);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.audio-unlock-btn:hover {
  transform: scale(1.05);
}

/* ========================================================
   ADMIN & CUSTOMIZATION PANEL
======================================================== */
.admin-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  max-width: 1440px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  width: 100%;
}

@media (max-width: 860px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

.admin-nav {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: fit-content;
}

.admin-nav-item {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.15s;
}

.admin-nav-item:hover {
  background: var(--bg-sidebar);
  color: var(--text-main);
}

.admin-nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.color-picker-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.color-input {
  width: 50px;
  height: 45px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  cursor: pointer;
  padding: 2px;
}

/* Rodapé Discreto VoxScreen */
.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 100%;
  margin-top: auto;
  user-select: none;
}

.app-footer a {
  color: #94a3b8;
  font-weight: 700;
  text-decoration: none;
  transition: color 0.2s ease;
}

.app-footer a:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* Selo VoxScreen no canto inferior direito da TV */
.tv-watermark {
  position: fixed;
  bottom: clamp(0.75rem, 1.8vh, 1.5rem);
  right: clamp(1rem, 2vw, 2rem);
  font-size: clamp(0.85rem, 1.1vw, 1.15rem);
  font-weight: 800;
  color: #f1f5f9;
  letter-spacing: 0.6px;
  z-index: 99999 !important;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(15, 23, 42, 0.85);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1.5px solid rgba(56, 189, 248, 0.35);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
  user-select: none;
}

.tv-watermark .tv-bolt {
  color: #38bdf8;
  font-size: 1.25em;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.75));
}

/* ========================================================
   THEME PRESETS & BRANDING ENGINE STYLES
======================================================== */
.theme-presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.85rem;
  margin-top: 0.75rem;
}

.theme-preset-card {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.theme-preset-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.theme-preset-card.active {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary), 0 4px 12px var(--primary-glow, rgba(2, 132, 199, 0.2));
}

.theme-preset-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.theme-preset-name {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--text-main);
}

.theme-preset-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--bg-sidebar);
  color: var(--text-muted);
  font-weight: 700;
}

.theme-color-dots {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.theme-color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.theme-preview-box {
  background: #090e1a;
  border: 1.5px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  color: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
  overflow: hidden;
}

/* ========================================================
   ÁREA PROFISSIONAL & MOBILE RESPONSIVE ENGINE (iOS & ANDROID)
======================================================== */

/* Suporte a Safe Area (iPhone notch / Android gesture bar) */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

/* Breakpoint 1: Tablets e Telas Médias (<= 960px) */
@media (max-width: 960px) {
  .navbar {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .nav-actions {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 3px;
    justify-content: flex-start;
  }

  .nav-actions::-webkit-scrollbar {
    display: none;
  }

  .nav-actions .btn {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 0.85rem;
    padding: 0.5rem 0.85rem;
  }

  .clinic-selector-select {
    flex-shrink: 0;
    font-size: 0.85rem;
  }

  .main-container {
    padding: 1rem;
    gap: 1rem;
    grid-template-columns: 1fr;
  }

  .card {
    padding: 1.2rem;
    margin-bottom: 1rem;
  }
}

/* Breakpoint 2: Smartphones iOS e Android (<= 640px) */
@media (max-width: 640px) {
  .brand-container {
    gap: 0.6rem;
  }

  .brand-icon-default {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .brand-tagline {
    font-size: 0.75rem;
  }

  /* Doctor Room Bar: Empilhamento vertical ergonômico */
  .doctor-room-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    padding: 1rem;
    text-align: left;
  }

  .doctor-room-info {
    width: 100%;
  }

  .doctor-room-title {
    font-size: 1.25rem;
    line-height: 1.2;
  }

  .doctor-room-subtitle {
    font-size: 0.82rem;
  }

  #btnChangeRoom {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    min-height: 44px;
  }

  /* Próximo da Fila no Mobile */
  #nextPatientBox {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    padding: 1rem;
    text-align: left;
  }

  #nextPatientName {
    font-size: 1.15rem;
    word-break: break-word;
    line-height: 1.3;
  }

  #btnCallNext {
    width: 100%;
    justify-content: center;
    padding: 0.9rem;
    font-size: 1.05rem;
    min-height: 48px;
  }

  /* Fila de Pacientes: Transformação em Cards Verticais para Celular */
  .queue-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .queue-table thead {
    display: none;
  }

  .queue-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    width: 100%;
  }

  .queue-row {
    background: var(--bg-sidebar);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    box-shadow: var(--shadow-sm);
  }

  .queue-row td {
    padding: 0 !important;
    border: none !important;
  }

  /* Horário */
  .queue-row td:nth-child(1) {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
  }

  /* Nome do Paciente */
  .queue-row td:nth-child(2) {
    flex: 1 1 auto;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--text-main);
    word-break: break-word;
    min-width: 120px;
  }

  /* Local Destino / Profissional */
  .queue-row td:nth-child(3) {
    font-size: 0.82rem;
    color: var(--text-muted);
  }

  /* Tag Preferencial/Normal */
  .queue-row td:nth-child(4) {
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }

  /* Botões de Ação da Linha */
  .queue-row td:last-child {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
  }

  .btn-call-row {
    padding: 0.6rem 1rem !important;
    font-size: 0.88rem !important;
    font-weight: 700 !important;
    border-radius: var(--radius-sm) !important;
    min-height: 38px;
  }

  /* Botão Principal de Chamada Manual */
  .btn-call-big {
    padding: 1.05rem;
    font-size: 1.15rem;
    min-height: 52px;
  }

  .btn-call-big:active {
    transform: scale(0.98);
  }

  .form-input-lg {
    font-size: 1.1rem;
    padding: 0.8rem 1rem;
  }

  /* Previne zoom incômodo automático no Safari iOS */
  .form-input, .form-select, .form-textarea, select, input {
    font-size: 16px !important;
  }

  /* Modal de Troca de Sala / Consultório no Celular */
  #roomSelectModal > div,
  .audio-unlock-overlay > div {
    width: 95% !important;
    max-width: 95% !important;
    padding: 1.25rem !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg) !important;
  }

  #modalRoomsGrid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
    gap: 0.6rem !important;
  }

  .room-btn {
    min-height: 65px;
    padding: 0.6rem 0.5rem;
  }

  #btnSaveActiveRoom {
    width: 100%;
    padding: 0.85rem;
    font-size: 1rem;
    justify-content: center;
    min-height: 46px;
  }

  /* Histórico no Mobile */
  .history-item {
    padding: 0.75rem;
    gap: 0.5rem;
  }

  .history-patient {
    font-size: 0.95rem;
  }

  /* ========================================================
     PAINEL DE RECEPÇÃO & TRIAGEM NO MOBILE (INDEX.HTML)
  ======================================================== */
  #receptionForm .form-group[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  #receptionForm div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  #roomsContainer {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
    gap: 0.6rem !important;
  }

  #btnAddToQueue, #btnDirectCall {
    width: 100% !important;
    padding: 0.9rem !important;
    font-size: 1rem !important;
    min-height: 48px;
    justify-content: center;
  }

  .card-header {
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  #queueFilterSection {
    padding: 0.65rem 0.75rem !important;
  }

  #queueFilterPills {
    gap: 0.35rem !important;
  }

  /* ========================================================
     PAINEL DE CONFIGURAÇÕES NO MOBILE (ADMIN.HTML)
  ======================================================== */
  .admin-grid {
    padding: 0 0.75rem !important;
    margin: 1rem auto !important;
    gap: 1rem !important;
  }

  .admin-nav {
    flex-direction: row !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    padding: 0.5rem !important;
    gap: 0.4rem !important;
    width: 100% !important;
    border-radius: var(--radius-md) !important;
  }

  .admin-nav::-webkit-scrollbar {
    display: none !important;
  }

  .admin-nav-item {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 0.55rem 0.85rem !important;
    font-size: 0.84rem !important;
    gap: 0.45rem !important;
  }

  #adminClinicHeaderCard {
    padding: 1rem !important;
  }

  #adminClinicSelectWrapper {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  #adminClinicSelectTop {
    width: 100% !important;
    min-width: 100% !important;
  }

  .theme-presets-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 0.6rem !important;
  }

  .theme-preset-card {
    padding: 0.7rem !important;
  }

  .theme-preset-name {
    font-size: 0.82rem !important;
  }

  .theme-preview-box {
    padding: 0.85rem !important;
  }

  /* Tabelas do Admin com rolagem touch fluida */
  table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Mídia & Propaganda no Admin */
  #mediaPreviewImg, #mediaVideoPreview {
    max-width: 100% !important;
    height: auto !important;
  }
}

/* Telas Pequeníssimas (<= 360px - iPhone SE 1st gen, relógios/telas compactas) */
@media (max-width: 360px) {
  .brand-title {
    font-size: 0.95rem;
  }
  .btn {
    font-size: 0.8rem;
    padding: 0.45rem 0.7rem;
  }
}




