/* =====================================================================
 *  NK SCREEN - ESTILO
 *  ---------------------------------------------------------------------
 *  Tema escuro (padrao) e tema claro, no mesmo esquema do NK VISUAL:
 *  variaveis em :root e [data-theme="light"]. A paleta escura e a do
 *  Lotus Screenshare (abyss/painel/orquidea/sinal), re-tematizada.
 * ===================================================================== */

:root {
  /* Tema escuro (padrao) */
  --fundo: #07080b;
  --fundo-2: #10121a;
  --fundo-3: #151826;
  --painel: #10121a;
  --borda: #22273a;
  --borda-clara: #2c3350;
  --texto: #edeff5;
  --texto-fraco: #8891a6;
  --destaque: #2f9bff;
  --destaque-2: #7fd4ff;
  --perigo: #ff5266;
  --ok: #4fe7c4;
  --raio: 14px;
  --sombra: 0 1.5rem 4rem -1.5rem rgba(0, 0, 0, 0.72);
  --brilho: 0 0 0 1px color-mix(in srgb, var(--destaque) 16%, transparent), 0 0 32px -8px color-mix(in srgb, var(--destaque) 35%, transparent);
  --grad-destaque: linear-gradient(180deg, var(--destaque), var(--destaque-2));
  --cor-sobre-destaque: #0b0714;
}

/* Tema claro */
[data-theme="light"] {
  --fundo: #F8FAFC;
  --fundo-2: #F1F5F9;
  --fundo-3: #E2E8F0;
  --painel: #FFFFFF;
  --borda: #E2E8F0;
  --borda-clara: #CBD5E1;
  --texto: #0F172A;
  --texto-fraco: #64748B;
  --destaque: #06B6D4;
  --destaque-2: #10B981;
  --perigo: #EF4444;
  --ok: #16A34A;
  --sombra: 0 1.5rem 4rem -1.5rem rgba(15, 23, 42, 0.28);
  --brilho: 0 0 0 1px color-mix(in srgb, var(--destaque) 20%, transparent), 0 0 32px -8px color-mix(in srgb, var(--destaque) 30%, transparent);
  --grad-destaque: linear-gradient(180deg, var(--destaque), var(--destaque-2));
  --cor-sobre-destaque: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--fundo);
  color: var(--texto);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior: none;
}

.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* ===================== CABECALHO ===================== */

.cabecalho {
  min-height: 48px;
  flex: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: env(safe-area-inset-top) 12px 0;
  background: var(--fundo-2);
  border-bottom: 1px solid var(--borda);
}

.marca {
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--texto-fraco);
  font-weight: 300;
  white-space: nowrap;
}
.marca b { color: var(--destaque); font-weight: 700; letter-spacing: 2px; }

/* contexto da sala, no meio da barra */
.cabecalho-contexto {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.cabecalho-contexto[hidden] { display: none; }
.cabecalho-contexto .sala-participantes { overflow: hidden; text-overflow: ellipsis; }

.cabecalho-acoes { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* botao compacto da barra superior */
.btn-header {
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--fundo-3);
  border: 1px solid var(--borda);
  color: var(--texto);
}
.btn-header[hidden] { display: none; }

/* Botao de tema (lua/sol) - mesmo estilo do NK VISUAL */
.btn.tema {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  font-size: 16px;
  background: var(--fundo-3);
  border: 1px solid var(--borda-clara);
  color: var(--texto);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s ease;
}
.btn.tema:hover {
  background: var(--borda-clara);
  border-color: var(--destaque);
  transform: rotate(15deg);
}
.btn.tema:active { transform: rotate(-15deg) scale(.95); }
.btn.tema:focus-visible { outline: 2px solid var(--destaque); outline-offset: 2px; }
.btn.tema svg { width: 18px; height: 18px; display: block; }

/* alterna o desenho do botao conforme o tema (estilo NK STUDIO) */
#iconeTema svg { display: none; }
#iconeTema .tema-lua { display: block; }
html[data-theme="light"] #iconeTema .tema-lua { display: none; }
html[data-theme="light"] #iconeTema .tema-sol { display: block; }

/* ===================== AREA ===================== */

main {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.view { position: absolute; inset: 0; }
#view-home[hidden], #view-sala[hidden] { display: none; }

/* ===================== TELA INICIAL ===================== */

#view-home {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
  overflow: hidden;
}

/* aneis "ripple" ao fundo */
.ripple {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  overflow: hidden;
}
.ripple .anel {
  position: absolute;
  width: 36rem;
  height: 36rem;
  max-width: 140vw;
  max-height: 140vw;
  border-radius: 999px;
  border: 1px solid var(--borda-clara);
  animation: ripple-pulse 7s cubic-bezier(.22, .61, .36, 1) infinite;
}
.ripple .anel:nth-child(1) { animation-delay: 0s; }
.ripple .anel:nth-child(2) { animation-delay: 1.5s; }
.ripple .anel:nth-child(3) { animation-delay: 3s; }
.ripple .anel:nth-child(4) { animation-delay: 4.5s; }

@keyframes ripple-pulse {
  0%   { opacity: 0; transform: scale(.1); }
  8%   { opacity: .9; }
  70%  { border-color: var(--destaque); }
  100% { opacity: 0; transform: scale(1); }
}

.card {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px 24px;
  background: linear-gradient(180deg, var(--fundo-3), var(--painel));
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  animation: rise-in .7s cubic-bezier(.16, 1, .3, 1) both;
}
.card:focus-within { box-shadow: var(--sombra), var(--brilho); }

@keyframes rise-in {
  0%   { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}

.selo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--borda);
  background: color-mix(in srgb, var(--painel) 60%, transparent);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  letter-spacing: .2em;
  color: var(--texto-fraco);
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--destaque-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--destaque-2) 22%, transparent);
  flex: none;
}

.card h1 {
  margin: 2px 0 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.15;
}
.card .sub {
  margin: -6px 0 2px;
  color: var(--texto-fraco);
  font-size: 14px;
}

/* campos */
.campo {
  width: 100%;
  background: var(--fundo);
  border: 1px solid var(--borda);
  color: var(--texto);
  font: inherit;
  padding: 12px 14px;
  border-radius: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.campo::placeholder { color: var(--texto-fraco); }
.campo:hover { border-color: var(--borda-clara); }
.campo:focus { outline: none; border-color: var(--destaque); box-shadow: 0 0 0 3px color-mix(in srgb, var(--destaque) 22%, transparent); }

.campo-codigo {
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: .42em;
  text-transform: uppercase;
  text-align: center;
  font-size: 18px;
  padding-left: 14px;
}

.ou {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--texto-fraco);
  font-size: 12px;
  margin: 2px 0;
}
.ou::before, .ou::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--borda);
}

/* botoes */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  color: var(--texto);
  background: var(--fundo-3);
  border: 1px solid var(--borda-clara);
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .12s, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--borda-clara); }
.btn:active:not(:disabled) { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; display: block; }

.btn-destaque {
  background: var(--grad-destaque);
  border-color: transparent;
  color: var(--cor-sobre-destaque);
  box-shadow: 0 8px 24px -8px color-mix(in srgb, var(--destaque) 60%, transparent);
}
.btn-destaque:hover { box-shadow: 0 10px 28px -6px color-mix(in srgb, var(--destaque) 70%, transparent); }

.btn-largo { width: 100%; }

.erro {
  min-height: 18px;
  color: var(--perigo);
  font-size: 13px;
  text-align: center;
}

/* ===================== SALA ===================== */

#view-sala {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sala-participantes { color: var(--texto-fraco); font-size: 13px; white-space: nowrap; }

/* area principal da sala: grade + chat lado a lado */
.sala-main { flex: 1; min-height: 0; display: flex; }

/* ===================== CHAT ===================== */

.chat {
  width: 300px;
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--painel);
  border-left: 1px solid var(--borda);
}
.chat[hidden] { display: none; }

.chat-topo {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--fundo-2);
  border-bottom: 1px solid var(--borda);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--texto-fraco);
}
.painel-fechar {
  background: transparent; border: 0; color: var(--texto-fraco);
  cursor: pointer; padding: 0 4px; display: inline-flex; align-items: center;
}
.painel-fechar svg { width: 16px; height: 16px; display: block; }
.painel-fechar:hover { color: var(--texto); }

.chat-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
}
.chat-msg { animation: rise-in .2s ease both; }
.chat-msg .nome { font-weight: 700; margin-right: 4px; }
.chat-msg .texto { color: var(--texto); }
.chat-msg .hora { color: var(--texto-fraco); font-size: 10px; margin-left: 4px; opacity: .7; }
.chat-vazio { color: var(--texto-fraco); font-size: 12px; text-align: center; padding: 12px; }

/* lista de participantes acima do chat (max 50% da altura, rola) */
.chat-participantes {
  flex: none;
  max-height: 50%;
  overflow-y: auto;
  padding: 6px 10px;
  border-bottom: 1px solid var(--borda);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 12px;
}
.chat-participantes:empty { display: none; }
.chat-participantes .nick { display: inline-flex; align-items: center; gap: 4px; }
.chat-participantes .nick .ponto { width: 6px; height: 6px; border-radius: 50%; background: var(--destaque-2); flex: none; }

/* toggle "Mostrar atividade" */
.atividade-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; letter-spacing: 0; text-transform: none;
  color: var(--texto-fraco); cursor: pointer; white-space: nowrap;
}
.atividade-toggle input { accent-color: var(--destaque); margin: 0; }

/* esconde as mensagens de atividade quando o toggle esta desmarcado */
.chat.atividade-off .chat-atividade { display: none; }

.emot { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; }
.emot-svg { width: 100%; height: 100%; display: block; }

.chat-form {
  flex: none;
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--borda);
  background: var(--fundo-2);
}
.chat-form .campo { padding: 8px 10px; border-radius: 10px; }
.chat-form .btn { padding: 8px 12px; border-radius: 10px; }

.btn-emoji {
  width: 40px; height: 40px; flex: none; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-emoji svg { width: 18px; height: 18px; display: block; }

.emots-popup {
  position: fixed; z-index: 1100;
  width: 268px; max-height: 60vh; overflow-y: auto;
  background: var(--fundo-3); border: 1px solid var(--borda-clara);
  border-radius: var(--raio); box-shadow: var(--sombra); padding: 8px;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
}
.emots-popup[hidden] { display: none; }
.emots-item {
  aspect-ratio: 1;
  background: var(--fundo-2); border: 1px solid var(--borda);
  border-radius: 8px; cursor: pointer; padding: 3px;
  display: flex; align-items: center; justify-content: center;
}
.emots-item:hover { background: var(--fundo); border-color: var(--destaque); }
.emots-item .emot-svg { width: 100%; height: 100%; }

.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--fundo-3);
  border: 1px solid var(--borda);
  color: var(--texto);
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.mini-btn:hover { background: var(--borda-clara); }
.mini-btn svg { width: 14px; height: 14px; display: block; }

/* popup de temas (cores de destaque) */
.temas-popup {
  position: fixed;
  z-index: 1100;
  min-width: 190px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--fundo-3);
  border: 1px solid var(--borda-clara);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
  padding: 6px;
}
.temas-popup[hidden] { display: none; }
.temas-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--texto);
  font: inherit;
  text-align: left;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.temas-item:hover { background: var(--fundo-2); }
.temas-item.ativo { background: var(--fundo-2); }
.temas-swatch {
  width: 18px; height: 18px; flex: none;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.temas-item .temas-check { margin-left: auto; color: var(--destaque-2); font-weight: 700; }

/* grade de participantes */
#grade {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 10px;
  padding: 10px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  overflow: auto;
}

.tile {
  position: relative;
  min-height: 0;
  border-radius: var(--raio);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--borda);
}
.tile.local { border-color: color-mix(in srgb, var(--destaque) 55%, var(--borda)); }

.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
.tile-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-conic-gradient(var(--fundo-2) 0% 25%, var(--fundo-3) 0% 50%) 50% / 26px 26px;
}
.tile-placeholder[hidden] { display: none; }

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  color: var(--cor-sobre-destaque);
  background: var(--grad-destaque);
  box-shadow: var(--brilho);
}

.tile-rodape {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 8px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.65));
  pointer-events: none;
}
.tile-nome {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-selo {
  flex: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--cor-sobre-destaque);
  background: var(--grad-destaque);
  border-radius: 999px;
  padding: 2px 8px;
}
.tile-selo[hidden] { display: none; }

/* controles por participante (aparecem no hover / no foco) */
.tile-controles {
  position: absolute; top: 8px; right: 8px; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  opacity: 0; transition: opacity .15s;
}
.tile:hover .tile-controles, .tile.foco .tile-controles { opacity: 1; }
.tile-btn {
  width: 30px; height: 30px; padding: 0; border-radius: 8px;
  background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.tile-btn:hover { background: rgba(0, 0, 0, 0.75); }
.tile-btn svg { width: 15px; height: 15px; display: block; }
.tile-vol {
  display: flex; align-items: center; gap: 4px;
  background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px; padding: 2px 6px 2px 2px;
}
.tile-vol .tile-btn { background: transparent; border: 0; width: 26px; height: 26px; }
.tile-vol input[type="range"] { width: 64px; }
.tile.local .tile-vol { display: none; }

/* layout com foco (spotlight): um grande em cima, os outros em faixa */
#grade.com-foco {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  grid-template-rows: minmax(0, 1fr);
  grid-auto-rows: 120px;
}
#grade.com-foco .tile { height: 120px; }
#grade.com-foco .tile.foco { grid-column: 1 / -1; grid-row: 1; height: auto; }
.tile.foco { border-color: var(--destaque); box-shadow: var(--brilho); }

/* controles */
.sala-controles {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  background: var(--fundo-2);
  border-top: 1px solid var(--borda);
}

.control-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  color: var(--texto);
  background: var(--fundo-3);
  border: 1px solid var(--borda);
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.control-btn:hover { border-color: var(--borda-clara); }
.control-btn svg { width: 18px; height: 18px; display: block; }
.control-btn.ativo {
  background: var(--grad-destaque);
  border-color: transparent;
  color: var(--cor-sobre-destaque);
}
.control-btn-danger {
  color: var(--perigo);
  background: transparent;
  border-color: color-mix(in srgb, var(--perigo) 45%, transparent);
}
.control-btn-danger:hover {
  background: color-mix(in srgb, var(--perigo) 12%, transparent);
  border-color: var(--perigo);
}

/* aviso rapido dentro da sala */
.toast {
  position: absolute;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(90%, 460px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--fundo-3);
  border: 1px solid var(--borda-clara);
  color: var(--texto);
  font-size: 13px;
  box-shadow: var(--sombra);
  text-align: center;
}
.toast[hidden] { display: none; }

/* ===================== TELAS PEQUENAS ===================== */

@media (max-width: 640px) {
  .card { padding: 22px 18px; }
  .card h1 { font-size: 22px; }
  #grade {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }
  .sala-controles { gap: 8px; padding: 8px; }
  .control-btn { padding: 10px 12px; font-size: 13px; }
  .sala-participantes { display: none; }
  .btn-header .rotulo, #btn-copiar .rotulo, #btn-temas .rotulo { display: none; }
  .btn-header { padding: 7px 9px; }
  .cabecalho { gap: 6px; }
  .chat {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    z-index: 30;
    width: min(320px, 88vw);
    box-shadow: -10px 0 34px rgba(0, 0, 0, 0.5);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ripple .anel { animation: none; opacity: .4; }
  .card { animation: none; }
}