/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ---------- Trilho de servidores ---------- */
#server-rail {
  width: var(--rail-width);
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow-y: auto;
  flex-shrink: 0;
  min-height: 0; /* rolagem da tarja quando há muitos servidores */
}

.server-home, .server-icon, .server-add {
  width: calc(48px * var(--ui-scale));
  height: calc(48px * var(--ui-scale));
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(20px * var(--font-scale));
  cursor: pointer;
  color: #fff;
  background: var(--bg-primary);
  transition: border-radius 0.2s, background 0.2s;
  position: relative;
  flex-shrink: 0;
}

.server-home {
  background: var(--blurple);
  font-size: calc(18px * var(--font-scale));
}

.server-home img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}

.server-icon {
  font-size: calc(15px * var(--font-scale));
  font-weight: 700;
  text-transform: uppercase;
  overflow: hidden;
}

.server-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.server-icon:hover, .server-home:hover, .server-add:hover {
  border-radius: 16px;
}

.server-add {
  background: var(--bg-primary);
  color: var(--green);
  font-size: calc(22px * var(--font-scale));
  font-weight: 400;
}

.server-add:hover { background: var(--green); color: #fff; }

.server-icon.active::before,
.server-home.active::before {
  content: '';
  position: absolute;
  left: -12px;
  width: 4px;
  height: 40px;
  background: #fff;
  border-radius: 4px;
}

.server-rail-divider {
  width: 32px;
  height: 2px;
  background: var(--bg-rail);
  border-radius: 2px;
}

/* ---------- Sidebar de canais ---------- */
#channel-sidebar {
  position: relative;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* Alça para arrastar a sidebar de canais (chats) horizontalmente */
#channel-sidebar-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  z-index: 15;
  touch-action: none;
}
#channel-sidebar-resizer:hover {
  background: rgba(88, 101, 242, 0.15);
}
body.resizing-channels {
  cursor: ew-resize;
  user-select: none;
}

#server-header {
  height: 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  font-weight: 600;
  font-size: calc(15px * var(--font-scale));
  flex-shrink: 0;
}

#server-header:hover { background: var(--bg-hover); }

#server-chevron { color: var(--text-muted); font-size: calc(14px * var(--font-scale)); }

/* Banner do servidor (abaixo do nome no menu de chats) — proporção 4:2 (2:1) */
#server-banner {
  width: 100%;
  aspect-ratio: 4 / 2;
  overflow: hidden;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  /* Fundo transparente: um banner com imagem TRANSPARENTE mostra o que está ATRÁS
     (o fundo do servidor, quando houver) em vez de um fundo sólido "sem foto". */
  background: transparent;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
#server-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#channel-scroll {
  flex: 1;
  min-height: 0; /* rolagem da lista quando há muitos canais */
  overflow-y: auto;
  padding: 12px 8px;
}

.channel-group-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px;
  margin-top: 8px;
  text-transform: uppercase;
}

.channel-add {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: calc(14px * var(--font-scale));
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 4px;
}

.channel-add:hover { color: var(--text-normal); background: var(--bg-hover); }

.channel-action {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: calc(13px * var(--font-scale));
  line-height: 1;
  opacity: 0;
  flex-shrink: 0;
  border-radius: 4px;
}

.channel:hover .channel-action { opacity: 1; }
.channel-action:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

/* ---------- Mensagens diretas ---------- */
.dm-channel .dm-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.dm-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* Bolinha de status (online/ausente/não perturbe) no avatar da lista de DMs do Início.
   O anel da bolinha acompanha o FUNDO do item (normal, hover e ativo). */
.dm-avatar-wrap { display: flex; }
.dm-channel .status-dot { border-color: var(--bg-secondary); }
.dm-channel:hover .status-dot { border-color: var(--bg-hover); }
.dm-channel.active .status-dot { border-color: var(--bg-active); }

.dm-channel .channel-name {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  line-height: 1.25;
}
.dm-channel .channel-name-text {
  font-size: calc(13px * var(--font-scale));
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dm-channel .channel-name-sub {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
  font-size: calc(11px * var(--font-scale));
  color: var(--text-muted);
}
.dm-channel .channel-name-sub .dm-tag {
  color: var(--text-muted);
  font-size: calc(10px * var(--font-scale));
  font-weight: 500;
  margin-left: 0;
  flex-shrink: 0;
}
.dm-channel .channel-name-sub .dm-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* DM de NÃO-amigo: aparece na lista, mas opaca (não notifica por padrão) */
.dm-channel.dm-opaque {
  opacity: 0.55;
}
.dm-channel.dm-opaque:hover {
  opacity: 0.95;
}

.dm-actions {
  display: flex;
  gap: 2px;
  align-items: center;
}

.dm-group-label {
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 6px 8px 2px;
  text-transform: uppercase;
}

/* Linha de solicitação de amizade */
.friend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  text-align: left;
}

.friend-name {
  flex: 1;
  font-size: calc(14px * var(--font-scale));
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.friend-action {
  padding: 6px 12px;
  font-size: calc(13px * var(--font-scale));
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

/* Menu de ações do canal */
.channel-menu {
  position: fixed;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px;
  min-width: 190px;
  z-index: 250;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.channel-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: calc(14px * var(--font-scale));
  color: var(--text-normal);
  cursor: pointer;
  user-select: none;
}

.channel-menu-item:hover { background: var(--blurple); color: #fff; }
.channel-menu-item.danger:hover { background: var(--red); color: #fff; }

.channel {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  margin: 1px 0;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: calc(15px * var(--font-scale));
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
}

.channel:hover { background: var(--bg-hover); color: var(--text-normal); }

.channel.active {
  background: var(--bg-active);
  color: #fff;
}

.channel-icon { font-size: calc(18px * var(--font-scale)); width: 20px; text-align: center; flex-shrink: 0; }
.channel-name { overflow: hidden; text-overflow: ellipsis; flex: 1; }

.voice-channel .voice-state {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red); /* offline/inacessível até confirmar que o TURN responde */
  flex-shrink: 0;
  transition: background 0.2s;
}

.voice-channel .voice-state.turn-on { background: var(--green); }

.voice-channel .voice-state.turn-on.connected {
  background: var(--green-bright);
  box-shadow: 0 0 8px var(--green-bright);
}

/* Canal de voz vira coluna: linha do topo + usuários presentes na call */
.voice-channel {
  flex-direction: column;
  align-items: stretch;
  white-space: normal;
}

.voice-channel .channel-top {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.voice-channel-members {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  padding: 4px 0 0 2px;
}

.voice-channel-member {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: calc(11px * var(--font-scale));
  color: var(--text-normal);
  max-width: 100%;
  overflow: hidden;
}

.voice-channel-member .avatar {
  width: 16px;
  height: 16px;
  font-size: calc(8px * var(--font-scale));
  flex-shrink: 0;
}

.voice-channel-member-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.voice-channel-member-multi {
  color: var(--yellow);
  font-weight: 700;
  font-size: calc(10px * var(--font-scale));
  flex-shrink: 0;
}

.channel.voice-connected {
  background: rgba(35, 165, 90, 0.15);
  color: var(--green-bright);
}

/* ---------- Barra "call ativa" acima do perfil ---------- */
#active-call {
  border-top: 1px solid var(--bg-primary);
  padding: 6px 10px 8px;
  background: var(--bg-soft);
  flex-shrink: 0;
}
#active-call.hidden { display: none; }

.active-call-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.active-call-name {
  flex: 1;
  min-width: 0;
  font-size: calc(12px * var(--font-scale));
  font-weight: 700;
  color: var(--green-bright, #23a55a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Nome da call em vermelho quando a conexão caiu (RECONECTANDO) */
.active-call-name.reconnecting { color: var(--red); }

.active-call-leave {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: calc(16px * var(--font-scale));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s;
}
.active-call-leave:hover { filter: brightness(1.15); }
.active-call-leave .mi { font-size: calc(16px * var(--ui-scale)); }

.active-call-members {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 22px;
}

.active-call-avatar {
  position: relative;
  display: inline-flex;
}
.active-call-avatar .avatar {
  width: 22px;
  height: 22px;
  font-size: calc(11px * var(--font-scale));
}
/* Borda verde no avatar quando o usuário está falando (na barra "call ativa") */
.active-call-avatar.speaking .avatar {
  box-shadow: 0 0 0 3px var(--green);
  border-radius: 50%;
}

.active-call-count {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: var(--yellow, #f0b232);
  color: #000;
  font-size: calc(9px * var(--font-scale));
  font-weight: 700;
  line-height: 1;
  padding: 1px 3px;
  border-radius: 6px;
  border: 1px solid var(--bg-soft);
}

/* Overlays de estado (SEM fundo) na foto da barra "call ativa": mic cortado / fone cortado */
.active-call-avatar .active-call-state {
  position: absolute;
  bottom: -2px;
  font-size: calc(11px * var(--font-scale));
  line-height: 1;
  color: var(--red);
  text-shadow: 0 0 2px #000, 0 0 2px #000;
  pointer-events: none;
  z-index: 2;
}
.active-call-avatar .active-call-state .mi { font-size: calc(11px * var(--ui-scale)); }
.active-call-avatar .active-call-state.mic { left: -2px; }
.active-call-avatar .active-call-state.deaf { left: auto; right: -2px; }

/* Vermelho mais escuro = mute/deafen por ADMIN do servidor */
.active-call-avatar .active-call-state.admin { color: #a01215; }

/* ---------- Banner de chamada DM recebida ---------- */
#incoming-call {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-elevated, #1e1f22);
  border: 1px solid var(--blurple, #5865f2);
  border-radius: var(--radius, 10px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  max-width: calc(100vw - 24px);
  animation: incoming-call-pop 0.25s ease;
}
#incoming-call.hidden { display: none; }
@keyframes incoming-call-pop {
  from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.incoming-call-avatar {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--blurple, #5865f2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: incoming-call-pulse 1.2s ease-in-out infinite;
}
.incoming-call-avatar .mi { font-size: calc(22px * var(--ui-scale)); }
@keyframes incoming-call-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(88, 101, 242, 0.5); }
  50% { box-shadow: 0 0 0 10px rgba(88, 101, 242, 0); }
}
.incoming-call-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.incoming-call-name {
  font-size: calc(14px * var(--font-scale));
  font-weight: 700;
  color: var(--text-normal, #dbdee1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
.incoming-call-detail {
  font-size: calc(12px * var(--font-scale));
  color: var(--text-muted, #949ba4);
}
.incoming-call-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: calc(18px * var(--font-scale));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s;
}
.incoming-call-btn:hover { filter: brightness(1.15); }
.incoming-call-btn .mi { font-size: calc(20px * var(--ui-scale)); }
.incoming-call-btn.answer { background: var(--green, #23a55a); order: 3; }
.incoming-call-btn.decline { background: var(--red, #f23f43); order: 2; }

/* ---------- Painel do usuário ---------- */
#user-panel {
  position: relative;
  z-index: 1; /* acima do fogo do tema (z-index 0), abaixo de menus/modais */
  background: var(--bg-panel);
  padding: 8px;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: var(--radius);
}

.user-info:hover { background: var(--bg-hover); }

.avatar-wrap { position: relative; flex-shrink: 0; cursor: pointer; }

.avatar {
  width: calc(32px * var(--ui-scale));
  height: calc(32px * var(--ui-scale));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: calc(14px * var(--font-scale));
  color: #fff;
  background: var(--blurple);
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* Foto de perfil: a imagem preenche o círculo do avatar */
.avatar img, .dm-avatar img, .msg-avatar img, .call-part-thumb .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

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

.status-dot.offline { background: var(--text-muted); }
.status-dot.idle { background: var(--yellow); }
.status-dot.dnd { background: var(--red); }
.status-dot.invisible { background: var(--text-muted); }

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

#user-name {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.25;
  min-width: 0;
}
#user-name .user-name-line {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
}
#user-name .app-badge {
  margin-left: 0;
  font-size: calc(12px * var(--font-scale));
}
#user-name .user-name-text {
  font-weight: 600;
  font-size: calc(12px * var(--font-scale));
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#user-name .member-tag {
  color: var(--text-muted);
  font-size: calc(10px * var(--font-scale));
  font-weight: 500;
  margin-left: 0;
}

/* Linha do próprio convidado: emblema "temp" + id */
#user-name .user-tag-line {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
}
#user-name .user-tag-line .member-temp {
  margin-left: 0;
}

.user-controls {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.ctrl-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: calc(15px * var(--font-scale));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.ctrl-btn:hover { background: var(--bg-primary); color: var(--text-normal); }
.ctrl-btn.muted { background: var(--red); color: #fff; }
.ctrl-btn.logout:hover { background: var(--red); color: #fff; }

/* ----- Mensagem de status (Online, <msg> / Ausente, <msg>...) ----- */
#user-name .user-status-text {
  font-size: calc(10px * var(--font-scale));
  color: var(--text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-status-text {
  font-size: calc(11px * var(--font-scale));
  color: var(--text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
  padding-left: 1px;
}

/* ----- Menu de status (abre ao clicar no ponto de status / profile-status) ----- */
.status-menu {
  position: fixed;
  z-index: 3000;
  width: 280px;
  background: var(--bg-modal, var(--bg-primary));
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: calc(13px * var(--font-scale));
}
.status-menu-opts {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.status-menu-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-normal);
  cursor: pointer;
  text-align: left;
}
.status-menu-opt:hover { background: var(--bg-primary); }
.status-menu-opt.active { background: var(--accent-soft, rgba(88, 101, 242, 0.18)); }
.status-menu-opt .status-dot { position: static; border: none; width: 10px; height: 10px; }
.status-menu-input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input, var(--bg-primary));
  color: var(--text-normal);
  font-size: calc(13px * var(--font-scale));
}
.status-menu-dur { display: flex; flex-direction: column; gap: 4px; }
.status-menu-dur-label { font-size: calc(11px * var(--font-scale)); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.status-menu-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.status-menu-chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  font-size: calc(12px * var(--font-scale));
  cursor: pointer;
}
.status-menu-chip.active { background: var(--accent, #5865F2); border-color: var(--accent, #5865F2); color: #fff; }
.status-menu-actions { display: flex; gap: 6px; margin-top: 2px; }
.status-menu-save {
  flex: 1;
  padding: 7px;
  border: none;
  border-radius: 6px;
  background: var(--accent, #5865F2);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.status-menu-clear {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.status-menu-clear:hover { color: var(--red); border-color: var(--red); }

