/* ============================================================
   chats.css — Área Chats global + visão de chat (lista + thread).
   Layout de duas colunas no desktop; pilha navegável no mobile.
   ============================================================ */

.chats-layout {
  display: grid;
  grid-template-columns: 72px 320px minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

/* rail vertical de ícones (Recentes / Global / Comunidades + cada comunidade) */
.chats-rail {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) 0;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.chats-rail__btn {
  position: relative;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  color: var(--text-dim);
  transition: background var(--t-fast), color var(--t-fast), border-radius var(--t-fast);
}
.chats-rail__btn:hover { background: var(--surface-3); color: var(--text); }
.chats-rail__btn.is-active { background: var(--accent-soft); color: var(--accent); }
.chats-rail__btn.is-active::before {
  content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 22px; border-radius: var(--r-pill); background: var(--accent);
}
.chats-rail__btn .avatar { width: 38px; height: 38px; }
.chats-rail__badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: var(--fw-bold);
}
.chats-rail__sep { width: 28px; height: 1px; background: var(--border); margin: var(--s-1) 0; }

.chats-aside {
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface);
}
.chats-aside__head { padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); border-bottom: 1px solid var(--border); }
.chats-aside__head .segmented { width: 100%; }
.chats-aside__head .segmented__item { flex: 1; text-align: center; }
.chats-aside__list { flex: 1; overflow-y: auto; padding: var(--s-2); }

/* cabeçalho de grupo (Obliviny / Comunidades) */
.chats-group {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-3) var(--s-1);
  color: var(--text-mute);
  font-size: var(--fs-xs); font-weight: var(--fw-bold);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.chats-group__count {
  min-width: 18px; height: 18px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text-dim);
  font-size: 10px; letter-spacing: 0;
}
.chats-group__empty { padding: var(--s-2) var(--s-3) var(--s-3); color: var(--text-mute); font-size: var(--fs-sm); }

/* ícone da comunidade na lista: quadrado arredondado (não círculo) */
.comm-glyph { border-radius: var(--r-md) !important; }

.chat-entry {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3); border-radius: var(--r-md);
  transition: background var(--t-fast);
}
.chat-entry:hover { background: var(--surface-2); }
.chat-entry.is-active { background: var(--accent-soft); }
.chat-entry__body { flex: 1; min-width: 0; }
.chat-entry__top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.chat-entry__name { font-weight: var(--fw-semibold); display: flex; align-items: center; gap: 6px; }
.chat-entry__time { color: var(--text-mute); font-size: var(--fs-xs); flex: none; }
.chat-entry__preview { color: var(--text-mute); font-size: var(--fs-sm); }
.chat-entry__community { color: var(--accent); font-size: var(--fs-xs); font-weight: var(--fw-semibold); }
.chat-entry__unread {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--accent); color: var(--on-accent); font-size: var(--fs-xs);
  font-weight: var(--fw-bold); display: grid; place-items: center; flex: none;
}

/* thread */
.chat-thread { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.chat-thread__head {
  flex: none; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-4);
  /* efeito vidro: fundo translúcido + blur (deixa ver o wallpaper atrás) */
  position: relative; z-index: 3;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border-bottom: 1px solid color-mix(in srgb, #fff 10%, transparent);
}
.chat-thread__back { display: none; }
.chat-thread__title { font-weight: var(--fw-bold); display: flex; align-items: center; gap: 6px; }
.chat-thread__sub { color: var(--text-mute); font-size: var(--fs-xs); }
.chat-thread__scroll {
  flex: 1; overflow-y: auto; padding: var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-2);
}
.chat-thread__compose {
  flex: none; display: flex; align-items: flex-end; gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border-top: 1px solid color-mix(in srgb, #fff 10%, transparent);
}
.chat-thread__compose .input { border-radius: var(--r-pill); }

.msg { display: flex; gap: var(--s-2); max-width: 78%; }
.msg__bubble {
  padding: var(--s-3) var(--s-3);
  background: var(--surface-2);
  border-radius: var(--r-md);
  border-top-left-radius: 4px;
}
.msg__author { font-size: var(--fs-xs); font-weight: var(--fw-bold); color: var(--accent); margin-bottom: 2px; }
.msg__text { font-size: var(--fs-sm); word-break: break-word; }
.msg__time { font-size: 10px; color: var(--text-mute); margin-top: 4px; text-align: right; }
.msg--mine { align-self: flex-end; flex-direction: row-reverse; }
.msg--mine .msg__bubble {
  background: var(--bubble, var(--accent));
  color: #fff;
  border-radius: var(--r-md); border-top-right-radius: 4px;
}
.msg--mine .msg__author { color: rgba(255,255,255,0.85); }
.msg--mine .msg__time { color: rgba(255,255,255,0.75); }

/* mídia em mensagens */
.msg__media { display: flex; flex-wrap: wrap; gap: 4px; }
.msg__mediaitem { width: 110px; height: 110px; border-radius: var(--r-md); object-fit: cover; background: center/cover no-repeat var(--surface-3); }
/* imagem única: preserva a proporção (sem corte) */
.msg__mediaimg { max-width: min(240px, 70vw); max-height: 320px; width: auto; height: auto; border-radius: var(--r-md); display: block; }
/* mensagem só-imagem: sem balão, só a imagem */
.msg__bubble--media { background: none; padding: 0; box-shadow: none; }
.msg--mine .msg__bubble--media { background: none; }
.msg__bubble--media .msg__media { margin: 0; }
.msg__bubble--media .msg__time { margin-top: 4px; color: var(--text-mute); text-shadow: none; }
.msg--mine .msg__bubble--media .msg__time { color: var(--text-mute); }

/* composer com anexo */
.chat-thread__composewrap { flex: none; display: flex; flex-direction: column; }
.chat-pending {
  display: none; gap: 12px; padding: var(--s-3); flex-wrap: wrap;
  background: transparent;
}
.chat-pthumb {
  position: relative; width: 60px; height: 60px; border-radius: var(--r-md);
  background: center/cover no-repeat transparent; display: grid; place-items: center; color: var(--text-mute);
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  animation: pthumb-in .26s cubic-bezier(.2,.8,.3,1.3) both;
}
.chat-pthumb--vid { background: var(--surface-3); }
@keyframes pthumb-in { from { opacity: 0; transform: scale(.7) translateY(8px); } }
.chat-prm {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  background: #4b4b52; border: 2px solid var(--surface); color: #fff;
  display: grid; place-items: center; cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.chat-prm:hover { background: var(--danger); transform: scale(1.15); }
.chat-prm:active { transform: scale(.92); }
@media (prefers-reduced-motion: reduce) { .chat-pthumb { animation: none; } .chat-prm:hover { transform: none; } }
.chat-add {
  flex: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: #fff; border: none;
  background: var(--accent);
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.chat-add:hover { transform: rotate(90deg) scale(1.08); box-shadow: 0 4px 14px var(--accent-soft); }
.chat-add:active { transform: rotate(90deg) scale(0.95); }
@media (prefers-reduced-motion: reduce) { .chat-add:hover { transform: none; } }

/* botão de título do thread (abre configurações) */
.chat-thread__titlebtn { background: none; border: none; text-align: left; cursor: pointer; color: inherit; padding: 0; min-width: 0; width: 100%; }
.chat-thread__chev { opacity: .6; vertical-align: middle; }

/* ===== configurações da conversa ===== */
.cset { height: 100%; min-height: 0; display: flex; flex-direction: column; }
.cset-body { display: flex; flex-direction: column; height: 100%; min-height: 0; }
/* chatSettings: aqui .cset-body é só WRAPPER full-height (header + scroll), NÃO a área rolável.
   Anula o card centralizado herdado de settings.css (.cset-body max-width:1100px). 2 classes vencem por especificidade. */
.cset--chat .cset-body {
  display: flex; flex-direction: column;
  height: 100%; min-height: 0;
  max-width: none; width: 100%; margin: 0; padding: 0; overflow: visible;
}
.cset-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s-5) var(--s-4) var(--s-7); display: flex; flex-direction: column; gap: var(--s-5); width: 100%; max-width: 560px; margin: 0 auto; }
.cset-hero { display: flex; flex-direction: column; align-items: center; gap: var(--s-2); padding: 0 0 var(--s-3); }
/* capa retangular no topo do hero */
.cset-cover {
  position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: 200px;
  border-radius: var(--r-lg); overflow: hidden;
  display: flex; align-items: flex-end; justify-content: center;
  background: center/cover no-repeat var(--surface-2);
  background-image: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 40%, #000));
}
.cset-cover.has-img { background-image: none; }
.cset-cover__scrim { position: absolute; inset: 0; background: linear-gradient(0deg, rgba(0,0,0,0.7), rgba(0,0,0,0) 55%); }
/* nome do chat dentro da capa (rodapé) */
.cset-cover__name { position: relative; z-index: 1; padding: var(--s-4) var(--s-5); color: #fff; text-align: center; }
.cset-hero__name { font-size: var(--fs-2xl); font-weight: var(--fw-bold); }
.cset-hero__sub { font-size: var(--fs-md); }
.cset-group { display: flex; flex-direction: column; gap: var(--s-2); }
.cset-group__title { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--text-mute); padding: 0 var(--s-2); }
.cset-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.cset-row {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; text-align: left;
  padding: var(--s-4); background: none; border: none; color: var(--text); cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
}
.cset-row:last-child { border-bottom: none; }
.cset-row:hover { background: var(--surface-2); }
.cset-row__icwrap { flex: none; width: 38px; height: 38px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--surface-2); color: var(--text); }
.cset-row__ic { color: inherit; }
.cset-row__label { font-size: var(--fs-md); font-weight: var(--fw-medium); }
.cset-row__chev { flex: none; }
.cset-row--danger .cset-row__label { color: var(--danger); }
.cset-row--danger .cset-row__icwrap { background: var(--danger-soft, rgba(239,68,68,.14)); color: var(--danger); }

/* card de descrição (expande ao clicar) */
.cset-desc {
  display: flex; flex-direction: column; gap: var(--s-2); width: 100%; text-align: left;
  padding: var(--s-4); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); color: var(--text); cursor: pointer;
}
.cset-desc__top { display: flex; align-items: center; gap: var(--s-3); }
.cset-desc__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.cset-desc__chev { flex: none; }
.cset-desc__full { padding: var(--s-4); }
.cset-desc__text { color: var(--text-dim); font-size: var(--fs-sm); white-space: pre-wrap; overflow-wrap: anywhere; }
.cset-desc__text.is-clamped { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cset-roletag { flex: none; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-mute); text-transform: capitalize; padding: 2px 8px; border-radius: var(--r-pill); background: var(--surface-2); }

/* papel de parede */
.wp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-2); }
.wp-tile {
  position: relative; aspect-ratio: 3/4; border-radius: var(--r-md); cursor: pointer;
  border: 2px solid var(--border); color: var(--text-mute);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: var(--surface-2);
}
.wp-tile.is-on { border-color: var(--accent); }
.wp-tile__lbl { font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.wp-tile__chk { position: absolute; top: 6px; right: 6px; color: #fff; background: var(--accent); border-radius: 50%; padding: 2px; }
.wp-prev {
  align-self: center;   /* não esticar no flex-column do scroll */
  width: 230px; height: 380px; margin: 0 auto;
  border-radius: 22px; padding: var(--s-3);
  display: flex; flex-direction: column; gap: var(--s-2); justify-content: flex-end;
  box-shadow: inset 0 0 0 1px var(--border), 0 12px 34px rgba(0,0,0,0.4);
  background: var(--bg); overflow: hidden;
}
/* botão único de criar/enviar imagem de fundo */
.wp-actions { display: flex; flex-direction: column; gap: var(--s-2); align-items: center; }
.wp-sectlbl { align-self: flex-start; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-mute); margin-top: var(--s-2); }
.wp-swatches { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.wp-sw {
  width: 42px; height: 42px; flex: none; border-radius: 50%; cursor: pointer;
  border: none; padding: 0; display: grid; place-items: center; color: #fff;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
  transition: transform .12s ease;
}
.wp-sw:hover { transform: scale(1.08); }
.wp-sw.is-on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.wp-sw.is-on svg { filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.wp-sw--none { background: var(--bg); box-shadow: inset 0 0 0 1px var(--border); }
.wp-sw--none.is-on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.wp-sw--palette { background: conic-gradient(from 0deg, #ef4444, #f59e0b, #22c55e, #3b82f6, #a855f7, #ef4444); }
.wp-create {
  width: 230px; height: 130px; border-radius: var(--r-lg); cursor: pointer;
  border: 1.5px dashed var(--border-strong, var(--border)); background: var(--surface-2) center/cover no-repeat;
  color: var(--text); position: relative; overflow: hidden;
}
.wp-create.has-img { border-style: solid; }
.wp-create.has-img .wp-create__inner { background: rgba(0,0,0,0.4); }
.wp-create__inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.wp-create__lbl { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.wp-remove { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; color: var(--danger); cursor: pointer; font-weight: var(--fw-semibold); font-size: var(--fs-sm); padding: var(--s-2); }
.wp-prev__bubble {
  max-width: 70%; padding: var(--s-2) var(--s-3); border-radius: var(--r-md); font-size: var(--fs-sm);
  opacity: 0; transform: translateY(10px) scale(.92);
  animation: wp-chat 5.4s cubic-bezier(.2,.8,.3,1.2) infinite both;
}
.wp-prev__bubble--them { align-self: flex-start; background: var(--surface-2); color: var(--text); border-top-left-radius: 4px; }
.wp-prev__bubble--me { align-self: flex-end; background: var(--bubble, var(--accent)); color: #fff; border-top-right-radius: 4px; }
/* conversa em loop: cada balão surge em sequência e some no fim do ciclo */
.wp-prev__bubble:nth-child(1) { animation-delay: 0s; }
.wp-prev__bubble:nth-child(2) { animation-delay: 0.9s; }
.wp-prev__bubble:nth-child(3) { animation-delay: 1.8s; }
@keyframes wp-chat {
  0%   { opacity: 0; transform: translateY(10px) scale(.92); }
  8%   { opacity: 1; transform: translateY(0) scale(1); }
  82%  { opacity: 1; transform: translateY(0) scale(1); }
  92%, 100% { opacity: 0; transform: translateY(-6px) scale(.98); }
}
@media (prefers-reduced-motion: reduce) {
  .wp-prev__bubble { animation: none; opacity: 1; transform: none; }
}

/* balão */
.bub-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-2); }
.bub-tile { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3); border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.bub-tile.is-on { border-color: var(--accent); background: var(--surface-2); }
.bub-tile__dot { width: 18px; height: 18px; border-radius: 50%; flex: none; }
.bub-tile__chk { margin-left: auto; color: var(--accent); }

.chat-day {
  align-self: center; font-size: var(--fs-xs); color: var(--text-mute);
  background: var(--surface-2); padding: 2px 12px; border-radius: var(--r-pill); margin: var(--s-2) 0;
}

.chats-empty { display: grid; place-items: center; height: 100%; }

/* MOBILE: rail + lista (visão lista) / thread em tela cheia */
@media (max-width: 767px) {
  .chats-layout { grid-template-columns: 64px minmax(0,1fr); }
  .chats-aside { border-right: none; }
  .chats-rail__btn { width: 42px; height: 42px; }
  .chats-rail__btn .avatar { width: 34px; height: 34px; }
  .chats-layout[data-pane="thread"] .chats-rail,
  .chats-layout[data-pane="thread"] .chats-aside { display: none; }
  .chats-layout[data-pane="thread"] { grid-template-columns: minmax(0,1fr); }
  .chats-layout[data-pane="list"] .chat-thread { display: none; }
  .chat-thread__back { display: inline-grid; }
}
/* reserva espaço para a barra de abas inferior */
@media (max-width: 639px) {
  .chats-layout { height: calc(100% - var(--bottomnav-h)); }
}

/* ---- Anti-spam: barra de flood/cooldown no compositor ---- */
.chat-flood {
  overflow: hidden;
  animation: floodIn .2s ease;
}
.chat-flood__inner {
  display: flex; align-items: center; gap: var(--s-2);
  margin: 0 var(--s-3) var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid var(--danger); border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.chat-flood__count { font-variant-numeric: tabular-nums; font-weight: var(--fw-bold); }
@keyframes floodIn { from { opacity: 0; transform: translateY(6px); } }

/* ---- Config: temporizador (cooldown) ---- */
.cd-wrap, .bw-wrap { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-3); }
.cd-grid { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.cd-chip {
  padding: var(--s-2) var(--s-4); border-radius: var(--r-pill);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.cd-chip:hover { border-color: var(--accent); }
.cd-chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.cset-hint { font-size: var(--fs-sm); line-height: var(--lh-normal); margin: 0; }

/* ---- Config: palavras proibidas ---- */
.bw-add { display: flex; align-items: center; gap: var(--s-2); }
.bw-tags { display: flex; flex-wrap: wrap; gap: var(--s-2); min-height: 24px; }
.bw-list { display: flex; flex-wrap: wrap; gap: var(--s-2); }
