/* ---------------- rolagem de mensagens ---------------- */
#message-scroller { flex: 1; min-height: 0; overflow-y: auto; overflow-anchor: none; }
/* min-height mantem o palco de voz preenchendo a area; sem justify-content
   o conteudo comeca no topo, em vez de ficar colado no rodape */
#message-list { display: flex; flex-direction: column; min-height: 100%; padding-bottom: 24px; }

.load-more { padding: 16px; text-align: center; }
.load-more button { color: var(--link); font-size: 14px; }

/* ---------------- cabecalho do canal ---------------- */
.channel-intro { padding: 16px 16px 8px; }
.channel-intro .badge-icon {
  width: 68px; height: 68px; border-radius: 50%;
  background: var(--input); display: grid; place-items: center;
  color: var(--text-bright); margin-bottom: 8px;
}
.channel-intro h2 { font-size: 32px; font-weight: 700; color: var(--text-bright); margin-bottom: 8px; }
.channel-intro p { color: var(--text-muted); font-size: 16px; }

.day-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 16px 16px 8px;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
}
.day-divider::before, .day-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--divider);
}

/* ---------------- mensagem ---------------- */
.message {
  position: relative;
  padding: 2px 48px 2px 72px;
  min-height: 22px;
}
.message:hover { background: rgba(2, 2, 2, 0.06); }
:root[data-theme="light"] .message:hover { background: rgba(6, 6, 7, 0.03); }
.message.first { margin-top: 17px; padding-top: 2px; }
.message.mentioned { background: var(--mention-bg); box-shadow: inset 2px 0 0 var(--mention-border); }
.message.mentioned:hover { background: rgba(88, 101, 242, 0.24); }
.message.sending { opacity: 0.55; }
.message.failed .message-content { color: var(--red); }

.message .avatar-wrap { position: absolute; left: 16px; top: 2px; }
.message .avatar-clicavel { cursor: pointer; }
.message .msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.message .author {
  font-size: 16px; font-weight: 600; color: var(--text-bright);
  cursor: pointer;
}
.message .author:hover { text-decoration: underline; }
.message .owner-tag {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  background: var(--brand); color: #fff;
  padding: 1px 5px; border-radius: 3px; align-self: center;
}
.message .timestamp { font-size: 12px; color: var(--text-faint); }
.message .edited { font-size: 10px; color: var(--text-faint); margin-left: 4px; }

.message .gutter-time {
  position: absolute;
  left: 0; width: 72px;
  padding-right: 8px;
  text-align: right;
  font-size: 11px; color: var(--text-faint);
  opacity: 0; line-height: 22px;
}
.message:hover .gutter-time { opacity: 1; }

.message-content {
  font-size: 16px;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* ---------------- resposta ---------------- */
.reply-preview {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--text-muted);
  margin-bottom: 4px; cursor: pointer;
  position: relative;
}
.reply-preview::before {
  content: "";
  position: absolute;
  left: -40px; top: 10px;
  width: 36px; height: 10px;
  border-left: 2px solid var(--divider);
  border-top: 2px solid var(--divider);
  border-top-left-radius: 6px;
}
.reply-preview .avatar { width: 16px; height: 16px; font-size: 9px; }
.reply-preview .who { font-weight: 500; color: var(--text-bright); }
.reply-preview .snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview:hover .snippet { color: var(--text); }

.message.highlight { animation: flash 2s ease; }
@keyframes flash {
  0%, 40% { background: rgba(88, 101, 242, 0.28); }
  100% { background: transparent; }
}

/* ---------------- markdown ---------------- */
.message-content strong { font-weight: 700; }
.message-content em { font-style: italic; }
.message-content u { text-decoration: underline; }
.message-content s { text-decoration: line-through; }
.message-content code.inline {
  background: var(--input-alt); border-radius: 3px;
  padding: 1px 4px; font-family: var(--mono); font-size: 85%;
}
.message-content pre {
  background: var(--input-alt);
  border: 1px solid var(--divider);
  border-radius: 4px;
  padding: 8px;
  margin: 4px 0;
  overflow-x: auto;
  max-width: 100%;
}
.message-content pre code { font-family: var(--mono); font-size: 13px; color: var(--text); white-space: pre; }
.message-content blockquote {
  border-left: 4px solid var(--divider);
  padding-left: 12px; margin: 2px 0;
}
.message-content .mention {
  background: var(--mention-bg); color: #c9cdfb;
  border-radius: 3px; padding: 0 2px; font-weight: 500; cursor: pointer;
}
.message-content .mention:hover { background: var(--brand); color: #fff; }
.message-content .mention.me { background: rgba(88, 101, 242, 0.3); }
.message-content .spoiler {
  background: var(--input-alt); border-radius: 3px;
  color: transparent; cursor: pointer;
}
.message-content .spoiler.revealed { background: var(--hover); color: inherit; }
.message-content .emoji-lg { font-size: 40px; line-height: 1.2; }

/* ---------------- anexos ---------------- */
.attachments { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.attachment-img {
  max-width: 400px; max-height: 320px;
  border-radius: 4px; cursor: pointer;
  width: auto; object-fit: contain;
}
.attachment-file {
  display: flex; align-items: center; gap: 12px;
  background: var(--input-alt);
  border: 1px solid var(--divider);
  border-radius: 4px;
  padding: 10px 12px;
  max-width: 420px;
}
.attachment-file .info { min-width: 0; }
.attachment-file .fname { color: var(--link); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-file .fsize { font-size: 12px; color: var(--text-muted); }
.attachment-video, .attachment-audio { max-width: 420px; border-radius: 4px; }

/* ---------------- reacoes ---------------- */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  display: flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 6px;
  border-radius: 8px;
  background: var(--hover);
  border: 1px solid transparent;
  font-size: 14px; color: var(--text-muted);
}
.reaction:hover { border-color: var(--text-faint); }
.reaction.mine { background: var(--mention-bg); border-color: var(--brand); color: #c9cdfb; }
.reaction .count { font-size: 13px; font-weight: 600; }
.reaction.add { color: var(--text-muted); opacity: 0; }
.message:hover .reaction.add { opacity: 1; }

/* ---------------- acoes rapidas ---------------- */
.msg-actions {
  position: absolute;
  top: -16px; right: 16px;
  display: none;
  background: var(--chat);
  border: 1px solid var(--divider);
  border-radius: 4px;
  box-shadow: var(--shadow-high);
  overflow: hidden;
}
.message:hover .msg-actions { display: flex; }
.msg-actions button {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  color: var(--text-muted);
}
.msg-actions button:hover { background: var(--hover); color: var(--text-bright); }
.msg-actions button.danger:hover { color: var(--red); }

/* ---------------- edicao inline ---------------- */
.edit-box { margin: 4px 0; }
.edit-box textarea {
  width: 100%;
  background: var(--input-alt);
  border: 0; border-radius: 8px;
  padding: 10px;
  color: var(--text);
  resize: none;
  font-size: 16px;
  line-height: 1.375;
  outline: none;
}
.edit-box .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.edit-box .hint b { color: var(--link); cursor: pointer; font-weight: 400; }

/* ---------------- area do compositor ---------------- */
#composer-area { padding: 0 16px 24px; flex: 0 0 auto; }

#reply-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--input-alt);
  border-radius: 8px 8px 0 0;
  padding: 8px 16px;
  font-size: 13px; color: var(--text-muted);
  border-bottom: 1px solid var(--chat);
}
#reply-bar .who { color: var(--text-bright); font-weight: 600; }
#reply-bar .close { margin-left: auto; color: var(--text-muted); }
#reply-bar .close:hover { color: var(--text-bright); }

#pending-files { display: flex; gap: 8px; flex-wrap: wrap; background: var(--input); border-radius: 8px 8px 0 0; padding: 12px; border-bottom: 1px solid var(--divider); }
.pending-file {
  position: relative;
  width: 108px; height: 108px;
  background: var(--input-alt);
  border-radius: 4px;
  padding: 8px;
  display: flex; flex-direction: column; justify-content: flex-end;
  overflow: hidden;
}
.pending-file img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pending-file .fname {
  position: relative; z-index: 1;
  font-size: 11px; color: var(--text-bright);
  background: rgba(0, 0, 0, 0.6); border-radius: 3px; padding: 2px 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pending-file .remove {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 24px; height: 24px; border-radius: 4px;
  background: var(--modal); color: var(--red);
  display: grid; place-items: center;
}

#composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--input);
  border-radius: 8px;
  padding: 0 16px 0 0;
  position: relative;
}
#composer.stacked { border-radius: 0 0 8px 8px; }
#composer.disabled { opacity: 0.5; pointer-events: none; }

#composer .attach-btn {
  width: 40px; height: 44px;
  flex: 0 0 40px;
  display: grid; place-items: center;
  color: var(--text-muted);
  margin-left: 8px;
}
#composer .attach-btn:hover { color: var(--text-bright); }

#composer-input {
  flex: 1;
  background: none;
  border: 0;
  outline: none;
  resize: none;
  color: var(--text);
  font-size: 16px;
  line-height: 1.375;
  padding: 11px 0;
  max-height: 340px;
  min-height: 44px;
  overflow-y: auto;
}
#composer-input::placeholder { color: var(--text-faint); }

#composer .tool-btn {
  width: 36px; height: 44px;
  display: grid; place-items: center;
  color: var(--text-muted);
  flex: 0 0 36px;
}
#composer .tool-btn:hover { color: var(--text-bright); }
#composer .char-count { font-size: 12px; color: var(--text-muted); align-self: center; padding-left: 4px; }
#composer .char-count.over { color: var(--red); font-weight: 600; }

#typing-bar {
  height: 24px;
  font-size: 13px;
  color: var(--text);
  padding: 0 4px;
  display: flex; align-items: center; gap: 6px;
  margin-top: -20px;
}
#typing-bar .dots { display: inline-flex; gap: 2px; }
#typing-bar .dots i {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.4s infinite ease-in-out;
}
#typing-bar .dots i:nth-child(2) { animation-delay: 0.2s; }
#typing-bar .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------------- autocomplete ---------------- */
#autocomplete {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--modal-alt);
  border-radius: 8px;
  box-shadow: var(--shadow-high);
  overflow: hidden;
  max-height: 260px;
  overflow-y: auto;
  z-index: 30;
}
#autocomplete .ac-head {
  padding: 8px 12px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; color: var(--text-muted);
  border-bottom: 1px solid var(--divider);
}
.ac-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; cursor: pointer; font-size: 15px;
}
.ac-item.active { background: var(--hover); }
.ac-item .sub { color: var(--text-muted); font-size: 13px; margin-left: auto; }

/* ---------------- estado vazio / voz ---------------- */
.empty-state {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; text-align: center; padding: 40px;
  color: var(--text-muted);
}
.empty-state h2 { font-size: 24px; font-weight: 700; color: var(--text-bright); }
.empty-state p { max-width: 420px; }

.voice-stage {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 24px; background: var(--input-alt); padding: 40px;
}
.voice-tiles { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; }
.voice-tile {
  width: 200px; min-height: 140px; height: auto;
  padding: 20px 8px 16px;
  background: var(--sidebar);
  border-radius: 8px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  border: 2px solid transparent;
}
/* com o teto de 1,6x, a moldura ainda passa uns 24px alem do avatar grande
   (80px); sem essa folga embaixo, ela ficava por cima do nome e do ping */
.voice-tile .avatar-wrap.com-moldura { margin-bottom: 16px; }
.voice-tile.speaking { border-color: var(--green); }
.voice-tile .name { font-size: 14px; font-weight: 600; color: var(--text-bright); }
.voice-tile .muted-badge { font-size: 12px; color: var(--red); }
.voice-actions { display: flex; gap: 12px; }
.voice-actions button {
  height: 44px; padding: 0 20px; border-radius: 22px;
  background: var(--input); color: var(--text-bright);
  font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.voice-actions button:hover { background: var(--hover); }
.voice-actions button.on { background: var(--text-bright); color: var(--rail); }
.voice-actions button.leave { background: var(--danger); color: #fff; }
.voice-actions button.leave:hover { background: var(--danger-hover); }
.voice-actions button.join { background: var(--green); color: #fff; }

/* ---------------- palco de voz ---------------- */
.voice-stage .stage-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 20px; font-weight: 700; color: var(--text-bright);
}
.voice-stage .stage-hint { color: var(--text-muted); font-size: 15px; text-align: center; }

.voice-stage.with-stream {
  justify-content: flex-start;
  padding: 16px;
  gap: 12px;
}

/* ---------------- tela compartilhada ---------------- */
.stream-stage {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 220px;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stream-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.stream-video.ready { opacity: 1; }
.stream-video:fullscreen { object-fit: contain; background: #000; }

.stream-loading {
  position: absolute;
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}
.stream-video.ready + .stream-loading { display: none; }

.stream-bar {
  position: absolute;
  left: 12px; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: blur(4px);
}
.stream-bar .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red);
  flex: 0 0 8px;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }
.stream-bar .stream-btn {
  margin-left: auto;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 4px;
  color: #fff;
}
.stream-bar .stream-btn:hover { background: rgba(255, 255, 255, 0.18); }

.stream-switcher { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.switch-btn {
  display: flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  border-radius: 15px;
  background: var(--sidebar);
  color: var(--text-muted);
  font-size: 13px; font-weight: 500;
}
.switch-btn:hover { color: var(--text-bright); }
.switch-btn.active { background: var(--brand); color: #fff; }

/* ---------------- participantes ---------------- */
.voice-stage.with-stream .voice-tiles { gap: 8px; }
.voice-stage.with-stream .voice-tile {
  width: 132px; height: 96px;
  gap: 4px;
}
.voice-stage.with-stream .voice-tile .avatar.xl { width: 48px; height: 48px; font-size: 18px; }

.voice-tile .tile-flags { display: flex; align-items: center; gap: 6px; }
.voice-tile .muted-badge { color: var(--red); display: inline-flex; }
.stream-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 6px; border-radius: 8px;
  background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
}

.voice-actions button.sharing { background: var(--red); color: #fff; }
.voice-actions button.sharing:hover { background: var(--danger-hover); }

.voice-member .live-icon { margin-left: auto; color: var(--red); display: inline-flex; }
.voice-member .live-icon + .mute-icon { margin-left: 0; }

@media (max-width: 900px) {
  .voice-stage.with-stream .voice-tiles { display: none; }
}

/* participante clicavel: abre o controle de volume individual */
.voice-tile[data-user] { cursor: pointer; position: relative; }
.voice-tile[data-user]::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow 0.15s ease;
  pointer-events: none;
}
.voice-tile[data-user]:hover::after { box-shadow: inset 0 0 0 2px var(--brand); }
.voice-tile .dica-volume {
  position: absolute; top: 6px; right: 8px;
  font-size: 10px; color: var(--text-muted);
  opacity: 0; transition: opacity 0.15s ease;
}
.voice-tile[data-user]:hover .dica-volume { opacity: 1; }

/* silenciado por administrador: nao e o mudo comum */
.voice-tile .muted-badge.servidor { color: var(--brand-soft); }

/* ---- transmissao pausada (janela minimizada ou coberta) ---- */
.stream-pausada {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(0, 0, 0, .72);
  color: var(--text-bright);
  text-align: center;
  z-index: 2;
}
.stream-stage.pausada .stream-pausada { display: flex; }
.stream-pausada small { color: var(--text-muted); }
.palco-slot:empty { display: none; }
.stream-switcher:empty { display: none; }
