/* Mensagens: conversas sem tarefa (lista à esquerda, conversa à direita) */
.page-container:has(.msg-layout) { max-width: none; }
.msg-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - 300px); min-height: 480px; border: 1px solid var(--border-card, var(--border-color)); border-radius: 14px; overflow: hidden; background: var(--bg-card, var(--bg-surface)); box-shadow: var(--shadow-card, none); }

/* ---- lista ---- */
.msg-list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border-card, var(--border-color)); background: var(--bg-side, var(--bg-surface)); }
.msg-list-head { padding: 0.85rem 0.85rem 0.6rem; display: flex; flex-direction: column; gap: 0.6rem; border-bottom: 1px solid rgba(15, 23, 42, 0.08); }
.msg-new-btn { width: 100%; justify-content: center; gap: 0.4rem; padding: 0.55rem 0.8rem; border-radius: 10px; font-weight: 700; }
.msg-search { display: flex; align-items: center; gap: 0.45rem; padding: 0.4rem 0.65rem; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 10px; color: var(--text-muted); }
.msg-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-family: inherit; font-size: 0.85rem; color: var(--text-primary); }
.msg-filters { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.msg-filter { font-family: inherit; font-size: 0.74rem; font-weight: 600; padding: 0.22rem 0.6rem; border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--text-secondary); cursor: pointer; }
.msg-filter:hover { background: rgba(15, 23, 42, 0.06); }
.msg-filter.active { background: var(--bg-surface); border-color: var(--border-color); color: var(--text-primary); box-shadow: var(--shadow-card, none); }
.msg-list { flex: 1; min-height: 0; overflow-y: auto; }
.msg-empty { padding: 2.2rem 1.2rem; text-align: center; color: var(--text-muted); font-size: 0.85rem; line-height: 1.5; }
.msg-item { position: relative; display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.75rem 0.85rem; border-bottom: 1px solid rgba(15, 23, 42, 0.07); cursor: pointer; }
.msg-item:hover { background: rgba(255, 255, 255, 0.55); }
.msg-item.active { background: var(--bg-card, var(--bg-surface)); box-shadow: inset 3px 0 0 var(--accent-primary); }
.msg-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-item-top { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.msg-item-title { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-item.is-unread .msg-item-title { font-weight: 800; }
.msg-item-time { flex-shrink: 0; font-size: 0.72rem; color: var(--text-muted); }
.msg-item-preview { font-size: 0.8rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-item.is-unread .msg-item-preview { color: var(--text-primary); font-weight: 600; }
.msg-item-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.msg-item-chips:empty { display: none; }
.msg-unread { flex-shrink: 0; align-self: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent-primary); color: #fff; font-size: 0.72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.msg-ava { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--bg-surface-elevated); }
.msg-ava.sm { width: 26px; height: 26px; }
.msg-ava.xs { width: 18px; height: 18px; }
.msg-ava-dept, .msg-ava-group { display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.msg-ava-group { background: #64748b; }
.msg-tag { font-size: 0.68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--bg-surface-elevated); color: var(--text-secondary); border: 1px solid var(--border-color); }
.msg-tag.is-warn { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.msg-tag.is-wait { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.msg-tag.is-info { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.msg-tag.is-ok { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.msg-tag.is-bad { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

/* ---- conversa ---- */
.msg-thread-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-card, var(--bg-surface)); }
.msg-thread-empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; max-width: 360px; text-align: center; color: var(--text-muted); font-size: 0.88rem; line-height: 1.5; padding: 2rem; }
.msg-thread-empty b { color: var(--text-primary); font-size: 1.05rem; }
.msg-thread-head { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1.1rem; border-bottom: 1px solid var(--border-card, var(--border-color)); }
.msg-thread-title { flex: 1; min-width: 0; }
.msg-thread-title h2 { margin: 0; font-size: 1.02rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-thread-sub { font-size: 0.78rem; color: var(--text-secondary); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-thread-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.msg-thread-actions .deleg-btn { display: inline-flex; align-items: center; gap: 0.35rem; }
.msg-back { display: none; border: 0; background: transparent; color: var(--text-secondary); cursor: pointer; padding: 4px; border-radius: 8px; }
.msg-messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding: 0.9rem 1.1rem; }
.msg-messages .chat-bubble { max-width: 72%; background: var(--bg-card, var(--bg-surface)); border: 1px solid var(--border-card, var(--border-color)); box-shadow: var(--shadow-card, none); }
.msg-messages .chat-row.mine .chat-bubble { background: color-mix(in srgb, var(--accent-primary) 8%, var(--bg-card, var(--bg-surface))); }
.msg-messages .chat-system-pill { display: inline-flex; align-items: center; gap: 8px; background: transparent; border: 0; box-shadow: none; }
.msg-open-task { font-family: inherit; font-size: 0.74rem; font-weight: 700; color: var(--accent-primary); background: transparent; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.msg-composer { border-top: 1px solid var(--border-card, var(--border-color)); padding: 0.6rem 1rem 0.8rem; display: flex; flex-direction: column; gap: 0.4rem; background: var(--bg-card, var(--bg-surface)); }
.msg-composer.drag-over { outline: 2px dashed var(--accent-primary); outline-offset: -4px; }
.msg-banner { font-size: 0.78rem; color: #1d4ed8; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; padding: 0.4rem 0.65rem; }
.msg-banner[hidden] { display: none; }
.msg-composer-row { display: flex; align-items: flex-end; gap: 0.45rem; padding: 0.35rem 0.5rem; border: 1px solid var(--border-card, var(--border-color)); border-radius: 14px; background: var(--bg-card, var(--bg-surface)); box-shadow: var(--shadow-card, none); }
.msg-composer-row textarea { flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent; font-family: inherit; font-size: 0.9rem; line-height: 1.4; color: var(--text-primary); padding: 0.4rem 0.2rem; max-height: 140px; }
.msg-icon-btn { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; padding: 6px; border-radius: 8px; display: inline-flex; }
.msg-icon-btn:hover { background: var(--bg-surface-elevated); color: var(--text-primary); }
.msg-send { width: 34px; height: 34px; margin-left: 0; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-files:empty { display: none; }
.msg-file-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; padding: 3px 8px; border-radius: 8px; background: var(--bg-card, var(--bg-surface)); border: 1px solid var(--border-card, var(--border-color)); }
.msg-file-chip button { border: 0; background: transparent; cursor: pointer; color: var(--text-muted); font-size: 1rem; line-height: 1; }

/* ---- nova mensagem / janelas ---- */
.msg-new-dialog { max-width: 560px; }
.msg-field-label { display: block; margin: 0.7rem 0 0.3rem; font-size: 0.78rem; font-weight: 700; color: var(--text-secondary); }
.msg-field-label:first-child { margin-top: 0; }
.msg-to-box { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0.35rem 0.5rem; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-surface); min-height: 42px; }
.msg-to-box:focus-within { border-color: var(--accent-primary); }
.msg-to-box input { flex: 1; min-width: 140px; border: 0; outline: 0; background: transparent; font-family: inherit; font-size: 0.9rem; color: var(--text-primary); padding: 0.2rem; }
#msg-to-chips { display: contents; }
.msg-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 0.82rem; font-weight: 600; padding: 3px 8px; border-radius: 8px; background: var(--bg-surface-elevated); border: 1px solid var(--border-color); cursor: pointer; }
.msg-chip.is-dept { background: #eef2ff; border-color: #c7d2fe; color: #4338ca; }
.msg-chip b { color: var(--text-muted); }
.msg-to-list { margin-top: 4px; max-height: 240px; overflow-y: auto; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-surface); box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12); }
.msg-to-list[hidden] { display: none; }
.msg-to-list.is-static { box-shadow: none; }
.msg-to-group { padding: 6px 10px 2px; font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.msg-to-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; cursor: pointer; }
.msg-to-item:hover { background: var(--bg-surface-elevated); }
.msg-to-item.is-disabled { opacity: 0.55; cursor: not-allowed; }
.msg-to-item div { display: flex; flex-direction: column; min-width: 0; }
.msg-to-item small { color: var(--text-muted); font-size: 0.74rem; }
.msg-to-empty { padding: 0.9rem; text-align: center; color: var(--text-muted); font-size: 0.85rem; }
.msg-to-hint { margin-top: 6px; font-size: 0.78rem; color: var(--text-secondary); line-height: 1.4; display: flex; gap: 6px; align-items: flex-start; }
.msg-to-hint:empty { display: none; }
.msg-to-hint .is-bad { color: #b91c1c; font-weight: 600; }
.msg-new-text { width: 100%; resize: vertical; min-height: 92px; font-family: inherit; }
.msg-quote { font-size: 0.82rem; color: var(--text-secondary); background: var(--bg-surface-elevated); border-left: 3px solid var(--accent-primary); border-radius: 6px; padding: 0.4rem 0.6rem; margin-bottom: 0.6rem; max-height: 76px; overflow: hidden; }

/* ---- celular: lista OU conversa ---- */
@media (max-width: 800px) {
  .msg-layout { grid-template-columns: 1fr; height: calc(100vh - 230px); }
  .msg-thread-pane { display: none; }
  .msg-layout.has-open .msg-list-pane { display: none; }
  .msg-layout.has-open .msg-thread-pane { display: flex; }
  .msg-back { display: inline-flex; }
  .msg-messages .chat-bubble { max-width: 88%; }
  .msg-thread-actions .deleg-btn { padding: 0.25rem 0.5rem; }
}

/* janelas de mensagem: botao roxo e campos neutros */
.msg-new-dialog .btn-label-submit { background: var(--accent-primary); border-color: var(--accent-primary); }
.msg-new-dialog .btn-label-submit:hover { filter: brightness(1.08); }
.msg-new-dialog .label-input-text { border-color: var(--border-color); box-shadow: none; }
.msg-new-dialog .label-input-text:focus { border-color: var(--accent-primary); outline: none; }
.msg-to-hint > span { flex: 1; min-width: 0; }

/* link Criar tarefa sempre visivel na mensagem */
.msg-task-link { font-family: inherit; font-size: inherit; font-weight: 700; color: var(--accent-primary); background: transparent; border: 0; padding: 0; cursor: pointer; }
.msg-task-link:hover { text-decoration: underline; }

/* Arrastar arquivo na conversa: a caixa vira o alvo e diz "Solte aqui para anexar" */
.msg-thread-pane.file-drag .msg-messages { outline: 2px dashed var(--accent-primary); outline-offset: -6px; background: color-mix(in srgb, var(--accent-primary) 6%, transparent); }
.msg-thread-pane.file-drag .msg-composer { position: relative; outline: 2px dashed var(--accent-primary); outline-offset: -4px; background: color-mix(in srgb, var(--accent-primary) 8%, var(--bg-card, var(--bg-surface))); }
.msg-thread-pane.file-drag .msg-composer > * { opacity: 0.2; }
.msg-thread-pane.file-drag .msg-composer::after { content: "Solte aqui para anexar o arquivo à mensagem"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; font-weight: 700; color: var(--accent-primary); pointer-events: none; }
.msg-thread-pane.file-drag .msg-composer.drag-over { background: color-mix(in srgb, var(--accent-primary) 18%, var(--bg-card, var(--bg-surface))); }
