/* Extras do chat (chat/js/chat_extras.js): bandeja de anexos, área de soltar arquivos, botões "Copiar"
 * em códigos e busca na conversa. Usa as cores do tema de cada tela (cliente e atendente), com reserva. */
.cx-tray, .cx-codes, .cx-search, .cx-drop, .cx-attach-menu, .cx-search-toggle, .client-history-msg {
    --cx-surface: var(--bg-card, var(--bg-sidebar, #ffffff));
    --cx-soft: var(--bg-input, var(--hover-bg, #f5f7fa));
    --cx-line: var(--border-color, #e2e8f0);
    --cx-text: var(--text-main, #0f172a);
    --cx-muted: var(--text-muted, #64748b);
    --cx-accent: var(--accent-text, color-mix(in srgb, var(--primary-color, #00bfa5) 70%, var(--text-main, #0f172a)));
    --cx-primary: var(--primary-color, #00bfa5);
    --cx-on-primary: var(--action-text, #ffffff);
    --cx-danger: #dc2626;
    --cx-ok: #15803d;
}
:root[data-client-theme="dark"] .cx-tray, :root[data-client-theme="dark"] .cx-codes, :root[data-client-theme="dark"] .cx-search,
body.dark-mode .cx-tray, body.dark-mode .cx-codes, body.dark-mode .cx-search, body.dark-mode .cx-drop { --cx-danger: #f87171; --cx-ok: #4ade80; }
.cx-sr-only, .cx-copy-buffer { position: fixed !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; opacity: 0; }
.cx-tray :focus-visible, .cx-codes :focus-visible, .cx-search :focus-visible, .cx-attach-menu :focus-visible, .cx-search-toggle:focus-visible {
    outline: 2px solid var(--cx-accent); outline-offset: 2px;
}

/* ---- Códigos com "Copiar" ------------------------------------------------------------------------------ */
.cx-codes { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; white-space: normal; text-align: left; font-size: 12px; line-height: 1.35; min-width: min(240px, 100%); }
.mensagem.sistema .cx-codes { margin-inline: auto; max-width: 360px; }
.cx-code { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "kind actions" "value value"; align-items: center; gap: 4px 8px; padding: 7px 8px 7px 10px; border: 1px solid var(--cx-line); border-radius: 10px; background: color-mix(in srgb, var(--cx-surface) 82%, transparent); color: var(--cx-text); }
.cx-code-kind { grid-area: kind; display: inline-flex; align-items: center; gap: 6px; min-width: 0; color: var(--cx-muted); font-size: 10.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.cx-code-kind i { color: var(--cx-accent); font-size: 13px; }
.cx-code-value { grid-area: value; min-width: 0; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 12px; color: var(--cx-text); overflow-wrap: anywhere; word-break: break-all; user-select: all; }
.cx-code-value.is-full { white-space: normal; }
.cx-code-actions { grid-area: actions; display: inline-flex; gap: 6px; }
.cx-code-btn { min-height: 32px; display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border: 1px solid var(--cx-line); border-radius: 999px; background: var(--cx-surface); color: var(--cx-accent); font: inherit; font-size: 11.5px; font-weight: 700; line-height: 1; text-decoration: none; cursor: pointer; white-space: nowrap; }
.cx-code-btn:hover { border-color: var(--cx-accent); background: color-mix(in srgb, var(--cx-primary) 10%, var(--cx-surface)); }
.cx-code-btn.is-done { color: var(--cx-ok); border-color: color-mix(in srgb, var(--cx-ok) 45%, transparent); }
.cx-code-btn.is-failed { color: var(--cx-danger); }
/* Bolha enviada do atendente com fundo cheio da cor principal (tema antigo). */
.stream-message-row.sent .msg-bubble .cx-code { background: color-mix(in srgb, var(--cx-surface) 92%, transparent); }

/* ---- Bandeja de anexos ----------------------------------------------------------------------------------- */
.cx-menu-host { position: relative; }
.cx-tray { margin: 0 0 8px; padding: 10px; border: 1px solid var(--cx-line); border-radius: 14px; background: var(--cx-surface); color: var(--cx-text); box-shadow: 0 6px 24px #0f172a0f; }
.cx-tray-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; margin: 0 2px 8px; }
.cx-tray-title { font-size: 13px; }
.cx-tray-note { flex: 1; min-width: 160px; color: var(--cx-muted); font-size: 11px; }
.cx-tray-link { padding: 4px 6px; border: 0; background: none; color: var(--cx-muted); font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; }
.cx-tray-link:hover { color: var(--cx-danger); }
.cx-tray-list { display: flex; flex-direction: column; gap: 8px; max-height: min(26vh, 230px); margin: 0; padding: 0; overflow-y: auto; list-style: none; overscroll-behavior: contain; }
.cx-item { display: grid; grid-template-columns: 52px minmax(0, 1fr) 36px; align-items: start; gap: 10px; padding: 6px; border: 1px solid var(--cx-line); border-radius: 12px; background: var(--cx-soft); }
.cx-item[data-state="erro"], .cx-item[data-state="erro-envio"] { border-color: color-mix(in srgb, var(--cx-danger) 55%, var(--cx-line)); }
.cx-item[data-state="enviando"], .cx-item[data-state="otimizando"] { opacity: .78; }
.cx-thumb { width: 52px; height: 52px; display: grid; place-items: center; overflow: hidden; border-radius: 9px; background: var(--cx-surface); color: var(--cx-accent); font-size: 24px; }
.cx-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cx-item[data-state="otimizando"] .cx-thumb i, .cx-item[data-state="enviando"] .cx-thumb { animation: cx-pulse 1.1s ease-in-out infinite alternate; }
@keyframes cx-pulse { from { opacity: 1; } to { opacity: .45; } }
.cx-item-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cx-item-name { overflow: hidden; font-size: 12.5px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.cx-item-meta { color: var(--cx-muted); font-size: 11px; }
.cx-item-meta.is-error { color: var(--cx-danger); font-weight: 600; }
.cx-item-caption { width: 100%; min-height: 34px; margin-top: 2px; padding: 6px 10px; border: 1px solid var(--cx-line); border-radius: 9px; background: var(--cx-surface); color: var(--cx-text); font: inherit; font-size: 13px; }
.cx-item-caption::placeholder { color: var(--cx-muted); }
.cx-item-caption:focus { border-color: var(--cx-accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--cx-primary) 18%, transparent); }
.cx-item-remove { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--cx-muted); cursor: pointer; }
.cx-item-remove:hover { color: var(--cx-danger); background: color-mix(in srgb, var(--cx-danger) 10%, transparent); }
.cx-tray-status { margin: 6px 2px 0; color: var(--cx-muted); font-size: 11.5px; }
.cx-tray-status:empty { display: none; }
.cx-tray-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.cx-tray-secondary, .cx-tray-send { min-height: 38px; display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border-radius: 10px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.cx-tray-secondary { border: 1px solid var(--cx-line); background: var(--cx-surface); color: var(--cx-text); }
.cx-tray-send { border: 0; background: var(--cx-primary); color: var(--cx-on-primary); }
.cx-tray-send:hover:not(:disabled) { filter: brightness(.95); }
.cx-tray button:disabled { opacity: .55; cursor: not-allowed; }
.cx-file-input { display: none !important; }

.cx-attach-menu { position: absolute; z-index: 40; left: 12px; bottom: calc(100% - 8px); min-width: 210px; display: flex; flex-direction: column; padding: 6px; border: 1px solid var(--cx-line); border-radius: 14px; background: var(--cx-surface); color: var(--cx-text); box-shadow: 0 12px 40px #0f172a29; }
.cx-attach-option { min-height: 46px; display: flex; align-items: center; gap: 12px; padding: 8px 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer; }
.cx-attach-option i { color: var(--cx-accent); font-size: 18px; }
.cx-attach-option:hover, .cx-attach-option:focus-visible { background: var(--cx-soft); }

.cx-drop { position: absolute; inset: 8px; z-index: 50; display: grid; place-items: center; border: 2px dashed var(--cx-accent); border-radius: 16px; background: color-mix(in srgb, var(--cx-surface) 88%, transparent); backdrop-filter: blur(2px); pointer-events: none; }
.cx-drop.is-blocked { border-color: var(--cx-danger); }
.cx-drop-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 22px; text-align: center; color: var(--cx-text); }
.cx-drop-card i { color: var(--cx-accent); font-size: 34px; }
.cx-drop.is-blocked .cx-drop-card i { color: var(--cx-danger); }
.cx-drop-card strong { font-size: 16px; }
.cx-drop-card span { color: var(--cx-muted); font-size: 12px; }

/* ---- Busca ------------------------------------------------------------------------------------------------- */
.cx-search-toggle { flex: 0 0 auto; width: 40px; height: 40px; margin-left: auto; display: grid; place-items: center; border: 1px solid var(--cx-line); border-radius: 10px; background: transparent; color: var(--cx-muted); font-size: 16px; cursor: pointer; }
.cx-search-toggle:hover, .cx-search-toggle.is-active { color: var(--cx-accent); background: var(--cx-soft); }
.cx-search { flex-shrink: 0; padding: 10px 20px; border-bottom: 1px solid var(--cx-line); background: var(--cx-surface); color: var(--cx-text); }
.cx-search-row { display: flex; align-items: center; gap: 4px; padding: 3px 3px 3px 12px; border: 1px solid var(--cx-line); border-radius: 12px; background: var(--cx-soft); }
.cx-search-row:focus-within { border-color: var(--cx-accent); }
.cx-search-icon { color: var(--cx-muted); }
.cx-search-input { flex: 1; min-width: 0; height: 36px; padding: 0 6px; border: 0; background: transparent; color: var(--cx-text); font: inherit; font-size: 14px; outline: none; }
.cx-search-input::-webkit-search-cancel-button { display: none; }
.cx-search-count { flex: 0 0 auto; color: var(--cx-muted); font-size: 11.5px; white-space: nowrap; }
.cx-search-nav { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--cx-text); cursor: pointer; }
.cx-search-nav:hover:not(:disabled) { background: var(--cx-surface); color: var(--cx-accent); }
.cx-search-nav:disabled { opacity: .4; cursor: default; }
.cx-search-scope { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cx-scope-btn { min-height: 32px; display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border: 1px solid var(--cx-line); border-radius: 999px; background: transparent; color: var(--cx-muted); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.cx-scope-btn[aria-pressed="true"] { border-color: var(--cx-accent); background: color-mix(in srgb, var(--cx-primary) 12%, var(--cx-surface)); color: var(--cx-accent); }
.cx-search-results { max-height: min(42vh, 380px); margin-top: 8px; overflow-y: auto; overscroll-behavior: contain; }
.cx-result-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.cx-result { width: 100%; display: flex; flex-direction: column; gap: 3px; padding: 9px 11px; border: 1px solid var(--cx-line); border-radius: 11px; background: var(--cx-surface); color: var(--cx-text); font: inherit; text-align: left; cursor: pointer; }
.cx-result:hover { border-color: var(--cx-accent); background: var(--cx-soft); }
.cx-result-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; }
.cx-result-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-result-chip { flex: 0 0 auto; padding: 1px 8px; border-radius: 999px; background: var(--cx-soft); color: var(--cx-muted); font-size: 10.5px; font-weight: 700; }
.cx-result-chip.is-current { background: color-mix(in srgb, var(--cx-primary) 14%, var(--cx-surface)); color: var(--cx-accent); }
.cx-result-meta { color: var(--cx-muted); font-size: 11px; }
.cx-result-snippet { margin: 2px 0 0; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cx-result-more { width: 100%; min-height: 38px; display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 8px; border: 1px dashed var(--cx-line); border-radius: 10px; background: transparent; color: var(--cx-accent); font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.cx-search-empty { margin: 8px 2px; color: var(--cx-muted); font-size: 12.5px; }

mark.cx-hit { padding: 0 1px; border-radius: 3px; background: color-mix(in srgb, #facc15 55%, transparent); color: inherit; }
.cx-hit-current mark.cx-hit { background: #f59e0b; color: #1c1917; }
.stream-message-row.cx-hit-current .msg-bubble, .mensagem.cx-hit-current, .client-history-msg.cx-hit-current, .client-history-msg.is-focused {
    box-shadow: 0 0 0 2px var(--cx-accent, var(--primary-color, #00bfa5));
}
.client-history-msg.is-focused:focus { outline: none; }

@media (max-width: 640px) {
    .cx-search { padding: 8px 10px; }
    .cx-search-count { max-width: 74px; overflow: hidden; text-overflow: ellipsis; }
    .cx-tray { padding: 8px; border-radius: 12px; }
    .cx-tray-note { display: none; }
    .cx-tray-actions .cx-tray-secondary span { display: none; }
    .cx-tray-actions .cx-tray-secondary { padding: 7px 11px; }
    .cx-tray-actions .cx-tray-secondary::after { content: none; }
    .cx-item { grid-template-columns: 44px minmax(0, 1fr) 34px; gap: 8px; }
    .cx-thumb { width: 44px; height: 44px; font-size: 20px; }
    .cx-search-toggle { width: 38px; height: 38px; }
}
@media (prefers-reduced-motion: reduce) {
    .cx-item[data-state="otimizando"] .cx-thumb i, .cx-item[data-state="enviando"] .cx-thumb { animation: none; }
}
