/* ==========================================================================
   Voice Chat — interface no padrão visual do Discord
   ========================================================================== */

:root {
  /* Paleta escura */
  --bg-darkest:  #1e1f22;   /* fundo do app / lobby */
  --bg-sidebar:  #2b2d31;   /* coluna da esquerda */
  --bg-main:     #313338;   /* área central */
  --bg-panel:    #232428;   /* painel do usuário (rodapé da sidebar) */
  --bg-hover:    #35373c;
  --bg-active:   #404249;
  --bg-input:    #1e1f22;

  --brand:       #5865f2;   /* blurple */
  --brand-hover: #4752c4;
  --green:       #23a559;
  --red:         #da373c;
  --yellow:      #f0b132;

  --text:        #f2f3f5;
  --text-2:      #b5bac1;
  --text-3:      #949ba4;
  --border:      #3f4147;

  --font: "gg sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg-darkest);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.screen { height: 100vh; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ==========================================================================
   LOBBY
   ========================================================================== */
#lobby {
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg-darkest);
}

.lobby-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-main);
  border-radius: 5px;
  padding: 32px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
}

.lobby-head { text-align: center; margin-bottom: 20px; }
.lobby-head h1 { margin: 0 0 8px; font-size: 24px; font-weight: 600; }
.lobby-head p { margin: 0; color: var(--text-2); font-size: 16px; }

.field { display: block; margin-bottom: 20px; }

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text-2);
}
.field-label em { font-style: normal; font-weight: 400; text-transform: none; color: var(--text-3); }

.field-row { display: flex; gap: 8px; }
.field-row input { flex: 1; min-width: 0; }

input, select {
  width: 100%;
  padding: 10px;
  border-radius: 3px;
  border: 1px solid var(--bg-darkest);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus { border-color: var(--brand); }
input::placeholder { color: #5c5f66; }

.btn-primary {
  width: 100%;
  padding: 11px;
  margin-top: 4px;
  border-radius: 3px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  transition: background .15s;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }

.btn-secondary {
  padding: 10px 14px;
  border-radius: 3px;
  background: var(--bg-active);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s;
}
.btn-secondary:hover { background: #4e5058; }

.alert {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 4px;
  background: rgba(218, 55, 60, .1);
  border: 1px solid rgba(218, 55, 60, .35);
  color: #f5a3a5;
  font-size: 14px;
}

.lobby-foot {
  margin: 18px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-3);
}
.lobby-foot b { color: var(--text-2); }

/* ==========================================================================
   APP — layout
   ========================================================================== */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  /* minmax(0, 1fr) é essencial: sem isso a linha da grade cresce até o
     tamanho do conteúdo. Se a barra lateral ficasse mais alta que a janela,
     a interface inteira passava da tela — e como o body tem overflow:hidden,
     o rodapé e a parte de baixo da transmissão sumiam sem rolagem possível. */
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  background: var(--bg-main);
}

/* ---------------------------- SIDEBAR ---------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  min-height: 0;
}

.server-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 48px;
  padding: 0 10px 0 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .2);
  font-weight: 600;
  font-size: 15px;
}
.server-head > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn-sm {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  color: var(--text-3);
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.icon-btn-sm:hover { background: var(--bg-hover); color: var(--text); }

.channels { flex: 1; overflow-y: auto; padding: 16px 8px 8px; min-height: 0; }

.channel-label {
  padding: 0 8px 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text-3);
}

.channel {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--text-3);
  font-size: 15px;
}
.channel.active { background: var(--bg-active); color: var(--text); }
.channel-ico { flex-shrink: 0; opacity: .8; }
.channel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  background: rgba(0, 0, 0, .25);
  padding: 1px 7px;
  border-radius: 8px;
}

/* --- lista de participantes (aninhada sob o canal, como no Discord) --- */
.participants { padding: 2px 0 0 16px; }

.participant {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: default;
  transition: background .12s;
}
.participant:hover { background: var(--bg-hover); }

.avatar-wrap { position: relative; flex-shrink: 0; line-height: 0; }

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  /* o anel verde de "falando" entra aqui */
  box-shadow: 0 0 0 0 rgba(35, 165, 89, 0);
  transition: box-shadow .1s ease-out;
}

/* Falando: anel verde, igual ao Discord */
.participant.speaking .avatar { box-shadow: 0 0 0 2px var(--green); }

.p-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.participant:hover .p-name { color: var(--text-2); }
.participant.speaking .p-name { color: var(--text); }

.p-icons { display: flex; gap: 4px; flex-shrink: 0; color: var(--text-3); line-height: 0; }
.p-icons svg { display: block; }
.p-icons .muted { color: var(--red); }
.p-icons .sharing { color: var(--green); }

/* qualidade de conexão ruim */
.participant[data-quality="poor"] .p-name::after,
.participant[data-quality="lost"] .p-name::after { content: " ⚠"; color: var(--yellow); }

/* ---------------------------- PAINEL DO USUÁRIO ---------------------------- */
.user-panel {
  flex-shrink: 0;
  background: var(--bg-panel);
  padding: 8px;
}

.user-info { display: flex; align-items: center; gap: 8px; padding: 4px 2px 6px; }

.user-info .avatar { width: 32px; height: 32px; font-size: 13px; }

.presence {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  border: 3px solid var(--bg-panel);
  box-sizing: content-box;
}

.user-text { min-width: 0; flex: 1; }

.user-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-3);
}

.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.conn-dot[data-state="connected"]    { background: var(--green); }
.conn-dot[data-state="reconnecting"] { background: var(--yellow); animation: blink 1s infinite; }
.conn-dot[data-state="offline"]      { background: var(--red); }
@keyframes blink { 50% { opacity: .25; } }

.user-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }

/* ---- volume geral ---- */
.volume { display: flex; align-items: center; gap: 8px; padding: 10px 4px 2px; }
.volume-ico { color: var(--text-3); line-height: 0; flex-shrink: 0; }

.volume input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-active);
  outline: none;
  cursor: pointer;
  padding: 0;
  border: none;
}
.volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-2);
  cursor: pointer;
}
.volume input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: var(--text-2);
  cursor: pointer;
}
.volume:hover input[type="range"]::-webkit-slider-thumb { background: var(--text); }

/* Surdo: o controle de volume perde o sentido, então some visualmente. */
.deafened .volume { opacity: .35; pointer-events: none; }

.icon-btn {
  display: grid;
  place-items: center;
  height: 34px;
  border-radius: 4px;
  color: var(--text-2);
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn .ico { display: block; line-height: 0; }
.icon-btn .lbl { display: none; }          /* rótulo só para leitores de tela */

.icon-btn.active { background: var(--brand); color: #fff; }
.icon-btn.muted  { background: rgba(218, 55, 60, .12); color: var(--red); }
.icon-btn.ptt    { background: var(--green); color: #fff; }
.icon-btn.danger:hover { background: var(--red); color: #fff; }

/* ---------------------------- ÁREA PRINCIPAL ---------------------------- */
/* min-height:0 permite que o palco encolha em vez de empurrar o layout. */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .2);
}
.topbar-ico { color: var(--text-3); flex-shrink: 0; }
.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.topbar-hint { font-size: 13px; color: var(--text-3); }

kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-darkest);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  font-family: inherit;
  font-size: 11px;
  color: var(--text-2);
}

/* min-height:0 é o que permite o filho encolher dentro do flex —
   sem isso o palco cresce além da janela e a tela transmitida fica cortada. */
.stage { flex: 1; padding: 16px; overflow-y: auto; min-height: 0; display: flex; }

.stage-empty {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  color: var(--text-3);
}
.stage-empty-art {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--bg-sidebar);
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  color: var(--text-3);
}
.stage-empty h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; color: var(--text-2); }
.stage-empty p { margin: 0; font-size: 14px; }

.screens {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 12px;
  align-content: start;
}

.screen-wrapper {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 2px solid transparent;
  transition: border-color .12s;
  min-height: 0;
}
.screen-wrapper:hover { border-color: var(--brand); }

/* ---------------------------------------------------------------------------
   UMA transmissão só: o quadro ocupa exatamente a área disponível, sem
   proporção fixa. É isto que conserta o corte — com `aspect-ratio: 16/9`
   numa janela larga e baixa, o quadro ficava mais alto que a área visível
   e a parte de baixo sumia atrás da rolagem.
   --------------------------------------------------------------------------- */
.screens.solo { grid-template-columns: 1fr; align-content: stretch; }
.screens.solo .screen-wrapper { aspect-ratio: auto; height: 100%; }

.screen-wrapper video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  /* contain = mostra a tela inteira (padrão). O botão "Preencher" troca
     para cover, que ocupa tudo cortando as bordas. */
  object-fit: contain;
}
.screens.fill .screen-wrapper video { object-fit: cover; }

/* ---- controles de exibição na barra do topo ---- */
.view-controls { display: flex; align-items: center; gap: 4px; margin-left: auto; }

.pill {
  padding: 5px 11px;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, color .12s;
}
.pill:hover { background: var(--bg-hover); color: var(--text); }
.pill.active { background: var(--bg-active); color: var(--text); }
.pill.icon-only { display: grid; place-items: center; width: 30px; padding: 0; height: 28px; }

.screen-caption {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .75);
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
}
.screen-caption::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
}

/* ---------------------------- TOAST ---------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 16px rgba(0, 0, 0, .24);
  font-size: 14px;
  z-index: 60;
}

/* ---------------------------- MODAL ---------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .8);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 24px;
}

.modal-card {
  width: 100%;
  max-width: 780px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  border-radius: 5px;
  padding: 24px;
}
.modal-card h3 { margin: 0; font-size: 20px; font-weight: 600; }
.modal-sub { margin: 6px 0 18px; font-size: 14px; color: var(--text-2); }

.picker-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.picker-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--bg-sidebar);
  border: 2px solid transparent;
  border-radius: 6px;
  color: var(--text-2);
  text-align: left;
  transition: border-color .12s, background .12s;
}
.picker-item:hover { border-color: var(--brand); background: var(--bg-hover); color: var(--text); }
.picker-item img { width: 100%; aspect-ratio: 16/9; object-fit: contain; background: #000; border-radius: 4px; }
.picker-item span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.modal-actions { display: flex; justify-content: flex-end; margin-top: 18px; }

/* ---------------------------- RESPONSIVO ---------------------------- */
@media (max-width: 780px) {
  .app { grid-template-columns: 190px 1fr; }
  .topbar-sep, .topbar-hint { display: none; }
}

/* ---------------------------- SCROLLBAR ---------------------------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-darkest); border-radius: 4px; }
.sidebar ::-webkit-scrollbar-thumb { background: #1a1b1e; }
