/* ---------------- telas ---------------- */
#auth-screen, #app-screen { position: fixed; inset: 0; }
#app-screen { display: flex; flex-direction: column; background: var(--rail); }
#app-corpo { flex: 1; display: flex; min-height: 0; }

/* ---------------- barra de servidores ---------------- */
#guild-rail {
  width: 72px;
  flex: 0 0 72px;
  background: var(--rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow-y: auto;
  scrollbar-width: none;
}
#guild-rail::-webkit-scrollbar { display: none; }

/*
 * O servidor aberto ganha um contorno solido da marca, afastado do icone pelo
 * fundo do trilho - visivel em qualquer icone, claro ou escuro, sem brilho.
 * O nao lido e um ponto na borda esquerda.
 */
.guild-pill {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: grid;
  place-items: center;
}
.guild-pill .guild-btn {
  transition: border-radius var(--t-abre) var(--curva-saida), background var(--t-toque) ease, box-shadow var(--t-toque) ease;
}
.guild-pill:not(.active):hover .guild-btn { border-radius: 12px; background: var(--input); }
.guild-pill.active .guild-btn {
  border-radius: 12px;
  box-shadow: 0 0 0 2px var(--rail), 0 0 0 4px var(--brand);
}

.guild-pill.unread:not(.active)::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  width: 4px;
  height: 8px;
  border-radius: 0 4px 4px 0;
  background: var(--text-bright);
  transform: translateY(-50%);
}

.guild-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--sidebar);
  color: var(--text-bright);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: var(--fs-ui);
  overflow: hidden;
}
.guild-btn img { width: 100%; height: 100%; object-fit: cover; }
.guild-btn.home { background: var(--input-alt); padding: 0; }
.guild-btn.home img { width: 100%; height: 100%; object-fit: cover; }
.guild-btn.action { background: var(--sidebar); color: var(--text-muted); font-size: 22px; font-weight: 400; }
.guild-pill:hover .guild-btn.action { background: var(--input); color: var(--text-bright); }

.rail-divider { width: 28px; height: 1px; background: var(--divider); flex: 0 0 1px; }

.guild-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 3px solid var(--rail);
  box-sizing: content-box;
}

/* ---------------- barra lateral ---------------- */
#sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#sidebar-header {
  height: 48px;
  flex: 0 0 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
  font-size: var(--fs-ui);
  color: var(--text-bright);
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
  z-index: 2;
  transition: background var(--t-toque) ease;
}
#sidebar-header:hover { background: var(--hover); }

#channel-list { flex: 1; min-height: 0; padding: 8px 8px 16px; }

/* categoria: rotulo de apoio, em caixa normal - quem manda na lista sao os canais */
.category {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 18px 6px 4px 2px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-faint);
  cursor: pointer;
}
.category:hover { color: var(--text-bright); }
.category .caret { transition: transform var(--t-abre) var(--curva-saida); flex: 0 0 12px; }
.category.collapsed .caret { transform: rotate(-90deg); }
.category .add-channel { margin-left: auto; opacity: 0; font-size: 18px; line-height: 1; }
.category:hover .add-channel, .category:focus-within .add-channel { opacity: 1; }
.category .add-channel:hover { color: var(--text-bright); }

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 8px 0 10px;
  margin: 1px 0;
  border-radius: var(--radius-row);
  color: var(--text-muted);
  font-size: var(--fs-ui);
  font-weight: 500;
  cursor: pointer;
  position: relative;
}
.channel-item { transition: background var(--t-toque) ease, color var(--t-toque) ease; }
.channel-item:hover { background: var(--hover); color: var(--text); }
.channel-item.active { background: var(--active); color: var(--text-bright); }
.channel-item.active .icon { color: var(--text-bright); }
.channel-item.unread { color: var(--text-bright); font-weight: 600; }
.channel-item.unread:not(.active)::before {
  content: "";
  position: absolute;
  left: -8px;
  width: 4px; height: 8px;
  border-radius: 0 4px 4px 0;
  background: var(--text-bright);
}
.channel-item .icon { flex: 0 0 18px; color: var(--text-faint); }
.channel-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-item .tools { display: flex; gap: 4px; opacity: 0; }
.channel-item:hover .tools, .channel-item.active .tools, .channel-item:focus-within .tools { opacity: 1; }
.channel-item .tools button:hover { color: var(--text-bright); }
.channel-item .badge {
  min-width: 16px; height: 16px; padding: 0 5px;
  border-radius: 8px; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
  font-variant-numeric: tabular-nums;
}

.voice-members { padding: 2px 0 6px 18px; }
.voice-member {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 8px; border-radius: var(--radius-row);
  font-size: var(--fs-sm); color: var(--text-muted);
}
.voice-member[data-user] { cursor: pointer; }
.voice-member:hover { background: var(--hover); color: var(--text-bright); }
.voice-member .avatar { width: 24px; height: 24px; }
/* com o teto de 1,6x, a moldura ainda passa uns 7px alem do avatar de 24px;
   sem isso ela ficava por cima do nome e do ping ao lado */
.voice-member .avatar-wrap.com-moldura { margin-right: 8px; }
.voice-member.speaking .avatar { box-shadow: 0 0 0 2px var(--green); }
.voice-member .mute-icon { margin-left: auto; color: var(--red); }

/* ---------------- painel do usuario ---------------- */
#user-panel {
  height: 52px;
  flex: 0 0 52px;
  background: var(--rail);
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
}
#user-panel .me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 4px; border-radius: var(--radius-row); cursor: pointer; }
#user-panel .me:hover { background: var(--hover); }
#user-panel .names { min-width: 0; line-height: 1.25; }
#user-panel .names .username { font-size: var(--fs-sm); font-weight: 600; color: var(--text-bright); }
#user-panel .names .sub { font-size: var(--fs-xs); color: var(--text-muted); }
#user-panel .panel-btn {
  width: 32px; height: 32px; border-radius: var(--radius);
  display: grid; place-items: center; color: var(--text-muted);
  transition: background var(--t-toque) ease, color var(--t-toque) ease;
}
#user-panel .panel-btn:hover { background: var(--hover); color: var(--text-bright); }
#user-panel .panel-btn.on { color: var(--red); background: rgba(239, 75, 79, 0.12); }

/* ---------------- painel de voz conectado ---------------- */
#voice-panel {
  background: var(--rail);
  border-top: 1px solid var(--divider);
  padding: 10px 10px 12px;
}
#voice-panel .status { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); font-weight: 600; color: var(--green); }
#voice-panel .channel { font-size: var(--fs-xs); color: var(--text-muted); padding-left: 23px; margin-top: 1px; }
#voice-panel .actions { display: flex; gap: 8px; margin-top: 10px; }
#voice-panel .actions button {
  flex: 1; height: 32px; border-radius: var(--radius); background: var(--input);
  color: var(--text-bright); font-size: var(--fs-sm); font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background var(--t-toque) ease;
}
#voice-panel .actions button:hover { background: var(--active); }
#voice-panel .actions button.leave { color: var(--red); background: rgba(239, 75, 79, 0.12); }
#voice-panel .actions button.leave:hover { background: rgba(239, 75, 79, 0.2); }

/* ---------------- conteudo ---------------- */
#content { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--chat); }

#chat-header {
  height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--divider);
  z-index: 2;
}
#chat-header .title { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text-bright); font-size: var(--fs-ui); }
#chat-header .title .icon { color: var(--text-faint); }
#chat-header .topic {
  border-left: 1px solid var(--divider);
  margin-left: 6px; padding-left: 12px;
  font-size: var(--fs-sm); color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 40vw;
}
#chat-header .spacer { flex: 1; }
#chat-header .header-btn {
  width: 32px; height: 32px; border-radius: var(--radius);
  display: grid; place-items: center; color: var(--text-muted);
  transition: background var(--t-toque) ease, color var(--t-toque) ease;
}
#chat-header .header-btn:hover { color: var(--text-bright); background: var(--hover); }
#chat-header .header-btn.on { color: var(--text-bright); background: var(--active); }

#header-search {
  width: 160px; height: 30px;
  background: var(--input);
  border: 1px solid transparent; border-radius: var(--radius);
  padding: 0 10px;
  font-size: var(--fs-sm);
  color: var(--text);
  transition: width var(--t-move) var(--curva-saida), border-color var(--t-toque) ease;
}
#header-search:focus { width: 240px; outline: none; border-color: var(--brand); }
#header-search::placeholder { color: var(--text-faint); }

#content-body { flex: 1; display: flex; min-height: 0; }

#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

/* ---------------- lista de membros ---------------- */
#members {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar);
  padding: 8px 8px 16px;
  min-height: 0;
  border-left: 1px solid var(--divider);
}
#members.collapsed { display: none; }
.members-group {
  font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-faint); padding: 18px 8px 6px;
}
/* a contagem fica no tom apagado mesmo quando o grupo tem a cor do cargo */
.members-group .contagem { color: var(--text-faint); font-weight: 500; margin-left: 2px; }
.member-row {
  display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 8px; border-radius: var(--radius-row); cursor: pointer;
}
.member-row { transition: background var(--t-toque) ease; }
.member-row:hover { background: var(--hover); }
.member-row.offline { opacity: 0.45; transition: opacity var(--t-toque) ease; }
.member-row.offline:hover { opacity: 0.75; }
.member-row .names { min-width: 0; line-height: 1.25; }
.member-row .display-name { font-size: var(--fs-ui); font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-row.owner .display-name { color: var(--owner); }
.member-row .sub { font-size: var(--fs-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- avatares ---------------- */
.avatar {
  width: 32px; height: 32px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
  color: #fff;
  overflow: hidden;
  position: relative;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }
.avatar.xl { width: 80px; height: 80px; font-size: 30px; }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }

/* inline-block garante que o span tenha caixa propria mesmo fora de um pai
   flex - sem isso, a moldura (position:absolute, largura em %) resolve o
   tamanho contra o container errado e "explode" (bug do banner de DM) */
.avatar-wrap { position: relative; display: inline-block; flex: 0 0 auto; }
.presence-dot {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 3px solid var(--sidebar);
  box-sizing: content-box;
}
.presence-dot.online { background: var(--green); }
.presence-dot.idle { background: var(--yellow); }
.presence-dot.dnd { background: var(--red); }
.presence-dot.offline { background: #80848e; }
/* o painel de baixo agora e mais escuro que a lateral: o furo tem que casar */
.presence-dot.on-panel { border-color: var(--rail); }
.presence-dot.on-chat { border-color: var(--chat); }
.presence-dot.on-modal { border-color: var(--modal); }
.presence-dot.on-card { border-color: var(--modal-alt); }

/* ---------------- responsivo ---------------- */
@media (max-width: 1024px) { #members { display: none; } }
@media (max-width: 720px) {
  #guild-rail { width: 60px; flex-basis: 60px; }
  #sidebar { width: 200px; flex-basis: 200px; }
  #chat-header .topic { display: none; }
  #header-search { display: none; }
}

/* marca de cargo na lista de membros */
.marca-cargo {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px; font-weight: 600;
  line-height: 16px;
  vertical-align: middle;
}
.marca-cargo.dono { background: rgba(233, 168, 58, 0.14); color: var(--owner); }
.marca-cargo.admin { background: rgba(149, 69, 243, 0.16); color: var(--brand-soft); }
.voice-member .mute-icon { margin-left: auto; }

/* ---- arrastar alguem de um canal de voz para outro ---- */
.voice-member.movivel { cursor: grab; }
.voice-member.movivel:active { cursor: grabbing; }
.voice-member.arrastando { opacity: .4; }

/* enquanto arrasta, os canais de voz se anunciam como destino */
body.movendo-alguem .channel-item[data-type="voice"] {
  outline: 1px dashed var(--divider);
  outline-offset: -2px;
  border-radius: 4px;
}
body.movendo-alguem .channel-item.alvo-de-mover {
  outline: 2px solid var(--brand);
  background: var(--hover);
  color: var(--text-bright);
}
body.movendo-alguem .channel-item.alvo-de-mover .icon { color: var(--brand); }

/* ---- ping de quem esta na chamada ---- */
.ping {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  padding: 1px 5px;
  border-radius: 8px;
  background: var(--input);
  white-space: nowrap;
  flex: none;
}
.ping.bom { color: var(--green); }
.ping.medio { color: var(--yellow); }
.ping.ruim { color: var(--red); }
.voice-tile .ping { margin-top: 2px; }

/* ---- escolha de microfone e saida de som ---- */
.campo-aparelho {
  flex: none;
  max-width: 260px;
  background: var(--input);
  color: var(--text-bright);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 7px 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.campo-aparelho:disabled { opacity: .5; cursor: not-allowed; }

/* ---- espiada na transmissao ---- */
.previa-tela {
  padding: 0;
  overflow: hidden;
  width: 280px;
  cursor: pointer;
}
.previa-tela .cabeca {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-bright);
}
.previa-tela .ponto {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
  flex: none;
}
.previa-tela video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  object-fit: contain;
}
.previa-tela .sem-previa,
.previa-tela .rodape {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ---- moldura de perfil ---- */
.avatar-wrap.com-moldura { overflow: visible; }
.avatar-wrap .moldura {
  position: absolute;
  left: 50%;
  top: 50%;
  /*
   * O furo da moldura tem que casar com o diametro do avatar - mas os furos
   * medidos vao de 0,46 a 0,74, e no furo mais estreito isso amplia o avatar
   * em mais de 2x. Sem um teto, essa ampliacao passava por cima do ping e do
   * nome ao lado (a lista lateral e os tiles da chamada so reservam espaco
   * para o tamanho normal do avatar). O min() trava em 1,6x: da para ver a
   * moldura sem ela engolir o que esta do lado.
   */
  width: min(calc(100% / var(--furo, .65)), 160%);
  height: min(calc(100% / var(--furo, .65)), 160%);
  /* o base.css poe max-width:100% em toda imagem, e e justamente disso que a
     moldura precisa escapar: ela existe para transbordar o avatar */
  max-width: none;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 2;
}
/* o ponto de presenca continua por cima de tudo */
.avatar-wrap .presence-dot { z-index: 3; }

/* ---- escolher moldura ---- */
.grade-molduras {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  padding: 0 12px 12px;
  max-height: 340px;
  overflow-y: auto;
}
.opcao-moldura {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px 10px;
  background: var(--modal-alt);
  border: 1px solid var(--divider);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--t-toque) ease, background var(--t-toque) ease;
}
.opcao-moldura:hover { background: var(--hover); color: var(--text-bright); }
/* a escolhida ganha o mesmo contorno do servidor aberto no trilho */
.opcao-moldura.ativa {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
  color: var(--text-bright);
  font-weight: 600;
}
.opcao-moldura img { width: 56px; height: 56px; }
.opcao-moldura .ellipsis { max-width: 100%; }

/* placa de identificacao: faixa decorativa atras do nome, na lista de membros */
.member-row.com-placa {
  background-size: cover;
  background-position: center;
  /* a placa e desenhada com borda propria; o raio da linha cortaria o desenho */
  border-radius: 10px;
  position: relative;
}
/* o hover normal pinta o fundo e apagaria a placa: aqui ele vira um veu */
.member-row.com-placa:hover { background-color: transparent; }
.member-row.com-placa::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0);
  transition: background var(--t-toque) ease;
  pointer-events: none;
}
.member-row.com-placa:hover::before { background: rgba(255, 255, 255, 0.12); }
.member-row.com-placa > * { position: relative; z-index: 1; }

/* sobre placa clara o texto padrao (claro) sumiria */
.member-row.placa-clara .display-name,
.member-row.placa-clara .sub { color: #17131f; }
.member-row.placa-clara .marca-cargo { background: rgba(0, 0, 0, 0.18); color: #17131f; }
