/* Caixa de mensagens (mensagens.html). Usa tokens.css, components.css e forms.css. Sem estilo inline (CSP).
   Cantos do portal: 12 / 20 / 28 px. Texto de mensagem nunca estoura a largura (overflow-wrap: anywhere). */
.msg { --r-sm: 12px; --r: 20px; --r-lg: 28px; background: var(--ink); color: var(--text); }
.msg [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.msg .btn, .msg .tag { border-radius: 999px; }
.msg .input { border-radius: var(--r-sm); }
.msg .h3 { font-weight: 900; text-transform: uppercase; letter-spacing: var(--track-heading); font-size: 1.0625rem; margin: 0; }
.msg [tabindex="-1"]:focus-visible { outline: var(--focus); outline-offset: 4px; }
.msg button:disabled, .msg textarea:disabled { opacity: .5; cursor: not-allowed; }
/* Dentro do shell do portal (menu lateral de shell.js): a área principal é a coluna .main de site.css. */
.msg .main { padding-block: var(--s-5); gap: var(--s-4); }
.msg-spacer { flex: 1; }
.msg-main { max-width: 1240px; }
.msg-main:focus { outline: none; }
.state-line { margin: 0; color: var(--text-muted); }
.msg-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }

/* Painéis de cadastro, desbloqueio e erro */
.msg-panel { display: grid; gap: var(--s-4); max-width: 620px; padding: clamp(18px, 4vw, 32px); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--ink-2); }
.msg-panel p { margin: 0; }
.msg-panel form { display: grid; gap: var(--s-4); }
.msg-panel .label { color: var(--acid); margin: 0; }
.msg-warn { display: grid; gap: var(--s-2); margin: 0; padding: var(--s-4); border: 1px solid var(--acid); border-radius: var(--r); background: rgba(217, 255, 63, .05); }
.msg-warn p { margin: 0; }
.msg-warn.is-danger { border-color: var(--rust); background: rgba(255, 79, 36, .07); }
.msg-why { display: grid; gap: var(--s-2); padding: var(--s-4); border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--ink); }
.msg-why p, .msg-why h2 { margin: 0; }
.msg-check { display: flex; gap: var(--s-3); align-items: flex-start; min-height: 44px; cursor: pointer; }
.msg-check input { flex: none; width: 22px; height: 22px; margin-top: 2px; accent-color: var(--acid); }
.msg-check label, .msg-check span { overflow-wrap: anywhere; min-width: 0; }
.msg-addr { display: flex; align-items: stretch; min-width: 0; }
.msg-addr .input { flex: 1 1 auto; min-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.msg-addr-domain { display: flex; align-items: center; padding: 0 var(--s-3); border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 var(--r-sm) var(--r-sm) 0; color: var(--text-muted); font-size: var(--fs-small); white-space: nowrap; }
@media (max-width: 420px) {
  .msg-addr { flex-direction: column; }
  .msg-addr .input { border-radius: var(--r-sm) var(--r-sm) 0 0; }
  .msg-addr-domain { border-left: 1px solid var(--line-strong); border-top: 0; border-radius: 0 0 var(--r-sm) var(--r-sm); min-height: 36px; }
}

/* Caixa: lista + conversa */
.msg-inbox { display: grid; gap: var(--s-4); grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); align-items: stretch; min-width: 0; }
.msg-list, .msg-thread, .msg-placeholder { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--ink-2); min-width: 0; }
.msg-list { display: grid; gap: var(--s-3); padding: var(--s-4); align-content: start; height: calc(100dvh - var(--topbar-h) - 2 * var(--s-5)); min-height: 420px; overflow-y: auto; }
.msg-list-head { display: grid; gap: var(--s-2); }
.msg-me { margin: 0; color: var(--text-muted); overflow-wrap: anywhere; }
.msg-new { display: grid; gap: var(--s-3); padding-top: var(--s-2); }
.msg-empty { margin: 0; padding: var(--s-4); border: 1px dashed var(--line-strong); border-radius: var(--r); color: var(--text-muted); }
.msg-convs { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.msg-list-title { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
/* Título nunca abaixo da própria palavra (fr "Nouvelle conversation", es e pseudo-localização são mais longos): o botão desce para a linha de baixo em vez de espremer o título. */
.msg-list-title .h3 { flex: 1 1 auto; min-width: min-content; }
.msg-new-btn { gap: 6px; padding-inline: 12px 14px; margin-inline-start: auto; }
.msg-new-btn svg { width: 16px; height: 16px; flex: none; }

/* Botão só com ícone: nome acessível em aria-label, dica visual em data-tip (mesmo texto curto). 40 px; 44 px no toque. */
.msg-ibtn { position: relative; flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid transparent; border-radius: 999px; background: transparent; color: var(--text-muted); cursor: pointer; font: inherit; }
.msg-ibtn svg { width: 20px; height: 20px; }
.msg-ibtn:hover { background: var(--ink-3); color: var(--text); }
.msg-ibtn:focus-visible, .msg-ibtn:focus-within { outline: var(--focus); outline-offset: 2px; }
.msg-ibtn[aria-expanded="true"], .msg-ibtn.is-on { color: var(--acid); border-color: var(--line-strong); background: var(--ink-3); }
.msg-ibtn:disabled, .msg-attach:has(input:disabled) { opacity: .45; cursor: not-allowed; }
@media (pointer: coarse) { .msg-ibtn { width: 44px; height: 44px; } }
.msg-ibtn[data-tip]::after { content: attr(data-tip); position: absolute; z-index: 30; top: calc(100% + 6px); left: 50%; translate: -50% 0; padding: 4px 10px; border-radius: 8px; background: var(--paper); color: var(--ink); font-size: var(--fs-label); font-weight: 700; letter-spacing: 0; text-transform: none; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s ease .25s; }
.msg-ibtn[data-tip]:hover::after, .msg-ibtn[data-tip]:focus-visible::after { opacity: 1; }
.msg-ibtn[aria-expanded="true"]::after { display: none; }
.msg-thread-actions .msg-ibtn[data-tip]::after { left: auto; right: 0; translate: none; }
.msg-compose .msg-ibtn[data-tip]::after { top: auto; bottom: calc(100% + 6px); }
@media (hover: none) { .msg-ibtn[data-tip]::after { display: none; } }
@media (prefers-reduced-motion: reduce) { .msg-ibtn[data-tip]::after { transition: none; } }
.msg-filters { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.msg-chip { min-height: 36px; padding: 4px 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: transparent; color: var(--text-muted); font: inherit; font-size: var(--fs-small); cursor: pointer; }
.msg-chip:hover { color: var(--text); background: var(--ink-3); }
.msg-chip[aria-pressed="true"] { background: var(--acid); border-color: var(--acid); color: var(--ink); font-weight: 700; }
.msg-chip:focus-visible, .msg-pin:focus-visible { outline: var(--focus); outline-offset: 2px; }
.msg-search .input { width: 100%; }
.msg-list.is-new .msg-filters, .msg-list.is-new .msg-search, .msg-list.is-new .msg-convs, .msg-list.is-new > .msg-empty, .msg-list.is-new .msg-more { display: none; }
.msg-conv-row { position: relative; }
.msg-avatar { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--ink-3); border: 1px solid var(--line-strong); color: var(--acid); font-weight: 900; font-size: .875rem; }
.msg-avatar { overflow: hidden; }
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg-avatar.is-initials { background: hsl(var(--av-h, 200) 55% 72%); color: var(--ink); border-color: transparent; }
.msg-opt { grid-template-columns: auto 1fr; align-items: center; column-gap: var(--s-3); }
.msg-opt-av { grid-row: 1 / 3; width: 32px; height: 32px; font-size: .6875rem !important; }
.msg-conv-body { display: grid; gap: 2px; min-width: 0; flex: 1; }
.msg-pin { position: absolute; top: 6px; right: 6px; min-width: 32px; min-height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--text-faint); font-size: 1rem; cursor: pointer; opacity: 0; }
.msg-conv-row:hover .msg-pin, .msg-pin:focus-visible, .msg-pin[aria-pressed="true"] { opacity: 1; }
.msg-pin[aria-pressed="true"] { color: var(--acid); }
@media (hover: none) { .msg-pin { opacity: 1; } }
.msg-foot { display: grid; gap: var(--s-2); margin-top: auto; }
.msg-ph-title { font-weight: 700; font-size: 1.125rem; }
.msg-conv { display: flex; gap: var(--s-3); align-items: center; width: 100%; min-height: 64px; padding: var(--s-3) 44px var(--s-3) var(--s-3); text-align: left; color: var(--text); background: transparent; border: 1px solid transparent; border-radius: var(--r-sm); cursor: pointer; font: inherit; }
.msg-conv:hover { background: var(--ink-3); }
.msg-conv:focus-visible { outline: var(--focus); outline-offset: 2px; }
.msg-conv[aria-current="true"] { border-color: var(--acid); background: var(--ink-3); }
.msg-conv-top, .msg-conv-bottom { display: flex; gap: var(--s-2); align-items: center; min-width: 0; }
.msg-conv-name { flex: 1; min-width: 0; font-weight: 700; font-size: .9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-conv-time { flex: none; color: var(--text-faint); font-size: var(--fs-label); }
.msg-conv-addr { flex: 1; min-width: 0; color: var(--text-muted); font-size: var(--fs-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-unread { flex: none; min-width: 24px; padding: 2px 8px; border-radius: 999px; background: var(--acid); color: var(--ink); font-weight: 900; font-size: .75rem; text-align: center; }
.msg-tag { flex: none; padding: 2px 8px; border: 1px solid var(--rust); border-radius: 999px; color: #ffb3a1; font-size: .75rem; }
.msg-more { justify-self: start; }

/* Busca de destinatários (combobox) */
.msg-combo { position: relative; }
.msg-results { list-style: none; margin: 0; padding: var(--s-1); display: grid; gap: 2px; max-height: 300px; overflow-y: auto; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--ink); }
.msg-opt { display: grid; gap: 2px; min-height: 44px; padding: var(--s-2) var(--s-3); border-radius: 8px; cursor: pointer; }
.msg-opt:hover, .msg-opt.is-active { background: var(--ink-3); outline: 2px solid var(--acid); outline-offset: -2px; }
.msg-opt[aria-disabled="true"] { opacity: .7; }
.msg-caption { margin: 0; }
.msg-combo .msg-empty { margin-top: var(--s-1); }
.msg-opt-name { font-weight: 700; overflow-wrap: anywhere; }
.msg-opt-addr { min-width: 0; color: var(--text-muted); font-size: var(--fs-small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Conversa */
.msg-thread { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; height: calc(100dvh - var(--topbar-h) - 2 * var(--s-5)); min-height: 420px; overflow: hidden; }
/* Cada parte na sua linha: o aviso escondido (display: none) sai da grade e não pode deslocar as outras. */
.msg-thread-head { grid-row: 1; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: var(--s-3); align-items: center; padding: var(--s-2) var(--s-3) var(--s-2) var(--s-4); border-bottom: 1px solid var(--line); }
.msg-notice { grid-row: 2; }
.msg-scroll { grid-row: 3; }
.msg-compose { grid-row: 4; }
.msg-peer { min-width: 0; }
/* Nome e endereço numa linha cada, com reticências (o endereço completo fica no title e no leitor de tela). */
.msg-peer-name { margin: 0; font-size: 1rem; font-weight: 900; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-peer-addr { margin: 0; color: var(--text-muted); font-size: var(--fs-label); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-peer-av { width: 36px; height: 36px; font-size: .75rem; }
.msg-back { display: none; }
.msg-thread-actions { display: flex; gap: 2px; align-items: center; }
.msg-more-wrap { position: relative; }
/* Menu "⋯" (ações raras da conversa) */
.msg-pop { position: absolute; z-index: 40; top: calc(100% + 6px); right: 0; width: min(300px, calc(100vw - 32px)); display: grid; gap: 2px; padding: var(--s-1); border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--ink-2); box-shadow: 0 16px 40px rgba(0, 0, 0, .5); }
.msg-pop-item, .msg-sec-item { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: var(--s-3); align-items: start; width: 100%; min-height: 44px; padding: var(--s-2) var(--s-3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text); font: inherit; font-size: var(--fs-small); text-align: left; cursor: pointer; }
.msg-pop-item svg, .msg-sec-item svg { width: 20px; height: 20px; margin-top: 1px; color: var(--text-muted); }
.msg-pop-item span, .msg-sec-item span { display: grid; gap: 2px; min-width: 0; }
.msg-pop-item small, .msg-sec-item small { color: var(--text-muted); font-size: var(--fs-label); line-height: 1.4; }
.msg-pop-item:hover, .msg-pop-item:focus-visible, .msg-sec-item:hover { background: var(--ink-3); }
.msg-pop-item:focus-visible, .msg-sec-item:focus-visible { outline: var(--focus); outline-offset: -2px; }
.msg-pop-item.is-danger, .msg-pop-item.is-danger svg { color: #ffb3a1; }
/* Painel "Segurança e dados" */
.msg-sec-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-1); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s-1); }
.msg-sec-item strong { font-weight: 700; }
.msg-sec-item strong { display: flex; gap: var(--s-2); align-items: center; justify-content: space-between; }
/* Interruptor visual de "Não aparecer na busca" (o estado real está em aria-checked do botão role=switch). */
.msg-switch { position: relative; flex: none; width: 36px; height: 20px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--ink); }
.msg-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-muted); transition: translate .15s ease; }
[aria-checked="true"] .msg-switch { background: var(--acid); border-color: var(--acid); }
[aria-checked="true"] .msg-switch::after { translate: 16px 0; background: var(--ink); }
[aria-busy="true"] .msg-switch { opacity: .5; }
@media (prefers-reduced-motion: reduce) { .msg-switch::after { transition: none; } }
@media (forced-colors: active) { .msg-switch { border-color: CanvasText; } [aria-checked="true"] .msg-switch::after { background: CanvasText; } }
.msg-sec .msg-me { color: var(--text); overflow-wrap: anywhere; }
.msg-notice { margin: 0; padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--rust); background: rgba(255, 79, 36, .08); color: #ffd3c7; font-size: var(--fs-small); overflow-wrap: anywhere; }
.msg-scroll { overflow-y: auto; overscroll-behavior: contain; padding: var(--s-3) var(--s-4); min-height: 0; }
.msg-scroll:focus-visible { outline: var(--focus); outline-offset: -3px; }
.msg-older { display: grid; justify-items: center; gap: var(--s-2); padding-bottom: var(--s-3); }
.msg-older p { margin: 0; text-align: center; }
#sentinel { display: block; height: 1px; width: 100%; }
.msg-msgs { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.msg-day { justify-self: center; padding: 2px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--text-muted); font-size: var(--fs-label); text-transform: capitalize; }
.msg-item { display: grid; gap: 4px; max-width: min(78%, 620px); min-width: 0; }
.msg-item.is-mine { justify-self: end; justify-items: end; }
.msg-item.is-theirs { justify-self: start; }
.msg-bubble { display: grid; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-radius: var(--r); background: var(--ink-3); border: 1px solid var(--line); min-width: 0; max-width: 100%; }
.msg-item.is-mine .msg-bubble { background: #2a2f1a; border-color: rgba(217, 255, 63, .45); border-bottom-right-radius: 6px; }
.msg-item.is-theirs .msg-bubble { border-bottom-left-radius: 6px; }
.msg-text { margin: 0; font-size: .9375rem; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; line-height: 1.5; }
.msg-bad { color: var(--text-muted); font-style: italic; }
.msg-att { display: grid; gap: var(--s-2); justify-items: start; min-width: 0; }
.msg-att .btn { max-width: 100%; height: auto; min-height: 36px; padding-block: 6px; white-space: normal; overflow-wrap: anywhere; text-align: left; }
.msg-img { display: block; max-width: 100%; max-height: 360px; border-radius: var(--r-sm); }
.msg-foot-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; font-size: var(--fs-label); color: var(--text-faint); }
.msg-act { min-height: 32px; padding: 2px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--text-muted); font: inherit; font-size: var(--fs-label); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.msg-act:hover { color: var(--text); }
/* Ações de cada mensagem: discretas; com mouse, aparecem ao passar ou ao focar a mensagem. */
@media (hover: hover) and (pointer: fine) {
  .msg-item .msg-act { opacity: 0; }
  .msg-item:hover .msg-act, .msg-item:focus-within .msg-act { opacity: 1; }
}
.msg-act:focus-visible { outline: var(--focus); outline-offset: 1px; }
.msg-compose { display: grid; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line); }
.msg-compose textarea.input { min-height: 56px; max-height: 30vh; padding: var(--s-3) var(--s-4); resize: vertical; font: inherit; }
.msg-compose-bar { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.msg-attach { cursor: pointer; }
.msg-files { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.msg-file { display: flex; gap: var(--s-2); align-items: center; max-width: 100%; padding: 2px 4px 2px 12px; border: 1px solid var(--line-strong); border-radius: 999px; font-size: var(--fs-small); }
.msg-file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-placeholder { display: grid; place-content: center; gap: var(--s-2); min-height: 320px; padding: var(--s-6); text-align: center; height: calc(100dvh - var(--topbar-h) - 2 * var(--s-5)); }
.msg-placeholder p { margin: 0; }

/* Celular (até 900 px): uma coluna; lista OU conversa */
@media (max-width: 900px) {
  .msg-inbox { grid-template-columns: minmax(0, 1fr); }
  .msg-list { height: auto; min-height: 0; }
  .msg-placeholder { display: none !important; }
  .msg-inbox.is-thread .msg-list { display: none; }
  .msg-back { display: inline-grid; }
  .msg-thread-head { grid-template-columns: auto auto minmax(0, 1fr) auto; column-gap: var(--s-2); padding: var(--s-2); }
  .msg-compose, .msg-scroll { padding-inline: var(--s-3); }
  .msg-thread { height: calc(100dvh - var(--topbar-h) - 2 * var(--s-4)); }
  .msg .main { padding-block: var(--s-4); }
  .msg-item { max-width: 92%; }
}
/* Celular estreito: o avatar sai do cabeçalho para o nome e o endereço caberem; "Nova conversa" vira "+". */
@media (max-width: 400px) {
  .msg-peer-av { display: none !important; }
  .msg-thread-head { grid-template-columns: auto minmax(0, 1fr) auto; }
  .msg-new-btn { width: 40px; padding: 0; justify-content: center; font-size: 0; }
  .msg-new-btn svg { width: 20px; height: 20px; }
}

/* Diálogos */
.msg-dialog { width: min(100% - 24px, 600px); max-height: calc(100dvh - 24px); overflow-y: auto; padding: clamp(18px, 4vw, 28px); border: 1px solid var(--line-strong); border-radius: var(--r-lg); background: var(--ink-2); color: var(--text); }
.msg-dialog::backdrop { background: rgba(17, 19, 21, .8); }
.msg-dialog form { display: grid; gap: var(--s-4); }
.msg-dialog h2, .msg-dialog p { margin: 0; }
.msg-dialog textarea.input { min-height: 80px; padding: var(--s-3) var(--s-4); resize: vertical; font: inherit; }
.msg-pick { margin: 0; padding: var(--s-3); border: 1px solid var(--line); border-radius: var(--r); max-height: 40vh; overflow-y: auto; }
.msg-pick legend { padding: 0 var(--s-2); font-weight: 700; }
.msg-pick ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.msg-codes { display: grid; gap: var(--s-2); margin: 0; }
.msg-codes dt { font-weight: 700; overflow-wrap: anywhere; }
.msg-codes dd { margin: 0 0 var(--s-2); }
.msg-code { font-family: var(--font-mono); font-size: 1.125rem; letter-spacing: .06em; word-spacing: .3em; color: var(--acid); overflow-wrap: anywhere; }
.msg-dlg-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: flex-end; }

/* Aviso fixo (sem animação) */
.msg-toast { position: fixed; z-index: 60; left: 50%; bottom: var(--s-4); translate: -50% 0; width: min(560px, calc(100% - 2 * var(--s-4))); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-3); align-items: center; padding: var(--s-3) var(--s-4); border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--ink-2); box-shadow: 0 12px 40px rgba(0, 0, 0, .5); }
.msg-toast .f-status { border: 0; padding: 0; background: none; overflow-wrap: anywhere; }
.msg-toast .f-status.is-error { color: #ffb3a1; }
.msg-toast .f-status.is-ok { color: var(--acid); }
@media (prefers-reduced-motion: reduce) { .msg * { scroll-behavior: auto !important; } }
.msg-notice { display: grid; gap: var(--s-2); justify-items: start; }
.msg-notice.is-info { border-bottom-color: var(--line); background: var(--ink-3); color: var(--text-muted); }
.msg-notice p { margin: 0; }
