/* Rev. 2.4 — Conversa interna da empresa e rolagem das conversas dos chamados (sistema e portal). */

/* ---------- Conversa da empresa ---------- */
.cchat { position: relative; display: flex; flex-direction: column; min-height: 0; }
.cchat-scroll { position: relative; overflow-y: auto; overscroll-behavior: contain; max-height: min(62vh, 640px); min-height: 220px; padding: 6px 0 10px; scroll-behavior: auto; }
.cchat-page .cchat-scroll { max-height: calc(100vh - 330px); min-height: 320px; }
.cchat-panel .cchat-scroll { max-height: 440px; }
.cchat-more-wrap { display: flex; justify-content: center; padding: 6px 0 2px; }
.cchat-more-wrap[hidden] { display: none; }
.cchat-list { display: flex; flex-direction: column; }
.cchat-empty[hidden] { display: none; }
.cchat-empty { padding: 28px 18px; }
.cchat-loading { padding: 18px; }

.cmsg { position: relative; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; padding: 9px 16px; border-left: 3px solid transparent; transition: background .3s; }
.cmsg:hover { background: var(--hover); }
.cmsg.is-new { border-left-color: var(--petrol); background: color-mix(in srgb, var(--petrol-50) 70%, transparent); }
.cmsg.is-target { background: var(--signal-100); }
.cmsg .avatar { width: 32px; height: 32px; font-size: 12px; }
.cmsg-main { min-width: 0; }
.cmsg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; line-height: 1.3; }
.cmsg-head b { font-weight: 600; font-size: 13px; }
.cmsg-role { font-size: 11.5px; color: var(--ink-3); }
.cmsg-head time { font-size: 11.5px; color: var(--ink-3); }
.cmsg-edited { font-size: 11px; color: var(--ink-4); font-style: italic; }
.cmsg-body { margin-top: 3px; font-size: 13.5px; }
.cmsg .cmsg-body p { margin: 0 0 6px; }
.cmsg .cmsg-body p:last-child, .cmsg .cmsg-body > :last-child { margin-bottom: 0; }
.cmsg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cmsg-thumb { display: block; width: 112px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.cmsg-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cmsg-file { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; color: var(--ink-2); background: var(--panel); }
.cmsg-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmsg-file small { color: var(--ink-4); flex: none; }
.cmsg-file:hover { border-color: var(--petrol-400); color: var(--petrol); }
.cmsg-tools { position: absolute; top: 6px; right: 12px; display: flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--panel); box-shadow: 0 0 0 1px var(--line); opacity: 0; transition: opacity .15s; }
.cmsg:hover .cmsg-tools, .cmsg:focus-within .cmsg-tools { opacity: 1; }
@media (hover: none) { .cmsg-tools { opacity: 1; box-shadow: none; background: transparent; } }
.cmsg-tool { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 7px; border: 0; border-radius: 6px; background: transparent; color: var(--ink-3); font: inherit; font-size: 11.5px; cursor: pointer; }
.cmsg-tool:hover { background: var(--line-2); color: var(--ink); }
.cmsg-tool.danger:hover { background: var(--coral-100); color: var(--coral); }
.cmsg.is-editing .cmsg-body, .cmsg.is-editing .cmsg-tools { display: none; }
.cmsg-editor { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.cmsg-editor[hidden] { display: none; }
.cmsg-editor-foot { display: flex; justify-content: flex-end; gap: 6px; }

.cchat-divider { display: flex; align-items: center; gap: 10px; margin: 6px 16px; color: var(--petrol); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.cchat-divider::before, .cchat-divider::after { content: ""; flex: 1; border-top: 1px solid currentColor; opacity: .45; }

.cchat-jump { position: absolute; left: 50%; transform: translateX(-50%); bottom: 132px; z-index: 5; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 14px; border: 0; border-radius: 999px; background: var(--petrol); color: #fff; font: inherit; font-size: 12.5px; font-weight: 600; box-shadow: 0 6px 18px #0003; cursor: pointer; }
.cchat-jump[hidden] { display: none; }

.cchat-composer { position: relative; border-top: 1px solid var(--line); padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--panel); }
.cchat-composer textarea { min-height: 60px; max-height: 220px; resize: vertical; }
.cchat-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cchat-foot .btn-primary { margin-left: auto; }
.cchat-hint { font-size: 11.5px; color: var(--ink-4); }
.cchat-hint kbd { font-size: 10.5px; }
.cchat-status:empty { display: none; }
.cchat-files { display: flex; flex-wrap: wrap; gap: 6px; }
.cchat-files:empty { display: none; }
.cchat-chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 4px 0 10px; border-radius: 999px; background: var(--petrol-50); color: var(--ink-2); font-size: 12px; max-width: 280px; }
.cchat-chip small { color: var(--ink-4); }
.cchat-chip button { border: 0; background: transparent; color: var(--ink-3); width: 20px; height: 20px; border-radius: 50%; cursor: pointer; font-size: 15px; line-height: 1; }
.cchat-chip button:hover { background: var(--coral-100); color: var(--coral); }
.cchat-composer .mention-picker { bottom: calc(100% - 4px); }
.cchat-readonly { margin: 0; padding: 10px 16px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 6px; }

/* botão com contador na lista de empresas */
.cchat-col { width: 84px; }
td.center, th.center { text-align: center; }
.cchat-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 30px; height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink-3); background: var(--panel); font-size: 12px; font-weight: 600; }
.cchat-btn:hover { border-color: var(--petrol-400); color: var(--petrol); }
.cchat-btn.is-empty { border-style: dashed; color: var(--ink-4); }
.cchat-count { min-width: 16px; text-align: center; }
.cchat-btn.has-unread { border-color: var(--petrol); background: var(--petrol); color: #fff; }
.cchat-btn.has-unread::after { content: ""; position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%; background: var(--coral); border: 2px solid var(--panel); }
.cchat-badge { --b: var(--petrol); margin-left: 2px; }

/* janela da conversa (lista de empresas) */
.cchat-dialog { width: min(760px, calc(100vw - 24px)); max-width: none; padding: 0; overflow: hidden; }
.cchat-dialog[open] { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.cchat-dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.cchat-dialog-head h2 { margin: 0; font-size: 16px; }
.cchat-dialog-head p { margin: 2px 0 0; }
.cchat-dialog-body { min-height: 0; flex: 1; display: flex; flex-direction: column; }
.cchat-dialog .cchat-scroll { max-height: calc(100vh - 290px); }
@media (max-width: 640px) {
  .cchat-dialog { width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .cchat-dialog[open] { max-height: 100dvh; }
  .cchat-dialog .cchat-scroll { max-height: none; flex: 1; }
  .cchat-page .cchat-scroll { max-height: calc(100dvh - 300px); min-height: 260px; }
  .cchat-dialog-body .cchat { flex: 1; }
  .cchat-hint { display: none; }
  .cmsg { padding: 7px 12px; gap: 8px; }
}

/* ---------- Conversa dos chamados: área com rolagem própria (sistema e portal) ---------- */
.thread-scroll { position: relative; max-height: clamp(340px, calc(100vh - 320px), 900px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.thread-scroll .msg:first-child { border-top: 0; }
.thread-older { display: flex; justify-content: center; padding: 8px; border-top: 1px solid var(--line-2); }
.thread-older .btn[disabled] { opacity: .7; cursor: progress; }
.thread-older[hidden], .thread-scroll .msg.is-collapsed { display: none; }
.thread-scroll + .composer { border-top: 1px solid var(--line); }
@media (max-width: 760px) { .thread-scroll { position: relative; max-height: 64vh; max-height: 64dvh; } }
@media print { .thread-scroll { position: relative; max-height: none; overflow: visible; } .thread-older { display: none; } .thread-scroll .msg.is-collapsed { display: grid; } }

/* Projetos › Empresas e fases: empresa, fase e contato responsável na mesma linha; observações abaixo (Rev. 2.4) */
.project-grid { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1.4fr) !important; }
.project-grid .contact-notes { grid-column: 1 / -1 !important; }
@media (max-width: 760px) { .project-grid { grid-template-columns: minmax(0, 1fr) !important; } }

/* Rev. 2.4.1 — arrastar e soltar, prévia das fotos antes do envio e exclusão individual de anexos */
[data-dropzone] { position: relative; }
[data-dropzone].is-dragover::after { content: "Solte aqui para anexar"; position: absolute; inset: 6px; z-index: 40; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--petrol); border-radius: 12px; background: color-mix(in srgb, var(--petrol-50) 88%, transparent); color: var(--petrol); font-weight: 600; font-size: 15px; pointer-events: none; }
.cchat-chip.has-thumb { height: 34px; padding-left: 3px; border-radius: 8px; }
.cchat-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; flex: none; }
.cchat-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
.cmsg-att { position: relative; display: inline-flex; }
.cmsg-att-del { position: absolute; top: -6px; right: -6px; margin: 0; opacity: 0; transition: opacity .15s; }
.cmsg-att:hover .cmsg-att-del, .cmsg-att:focus-within .cmsg-att-del { opacity: 1; }
@media (hover: none) { .cmsg-att-del { opacity: 1; } }
.cmsg-att-del button { display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 2px solid var(--panel); border-radius: 50%; background: var(--coral); color: #fff; cursor: pointer; box-shadow: 0 2px 6px #0003; }
.cmsg-att-del button:hover { filter: brightness(1.1); }
.cmsg-att:not(.is-image) .cmsg-att-del { top: -7px; right: -7px; }

/* Rev. 2.6 — campo de envio de fotos e arquivos com progresso (link externo e portal) */
.uploader { display: flex; flex-direction: column; gap: 8px; }
.uploader-pick { position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1.5px dashed var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.uploader-pick:hover, .uploader.is-dragover .uploader-pick { border-color: var(--petrol); background: var(--petrol-50); }
.uploader-pick input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.uploader-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--petrol-100); color: var(--petrol); flex: none; }
.uploader-txt { display: flex; flex-direction: column; line-height: 1.35; }
.uploader-txt small { color: var(--ink-3); font-size: 12px; }
.uploader.compact .uploader-pick { padding: 8px 10px; }
.uploader.compact .uploader-ico { width: 30px; height: 30px; }
.uploader-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.uploader-list:empty { display: none; }
.up-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); min-width: 0; }
.up-item.is-error { border-color: color-mix(in srgb, var(--coral) 45%, var(--line)); background: var(--coral-100); }
.up-item.is-done { border-color: color-mix(in srgb, var(--leaf) 40%, var(--line)); }
.up-thumb { width: 44px; height: 44px; border-radius: 8px; overflow: hidden; flex: none; background: var(--surface); display: grid; place-items: center; }
.up-thumb img { width: 100%; height: 100%; object-fit: cover; }
.up-ico { font-size: 10.5px; font-weight: 700; color: var(--ink-3); }
.up-main { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 2px; }
.up-main b { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-main small { font-size: 11.5px; color: var(--ink-3); }
.up-item.is-error .up-st { color: var(--coral); font-weight: 600; }
.up-item.is-done .up-st { color: var(--leaf); font-weight: 600; }
.up-bar { height: 4px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.up-bar i { display: block; height: 100%; background: var(--petrol); transition: width .2s; }
.up-item.is-done .up-bar i { background: var(--leaf); }
.up-item.is-error .up-bar { display: none; }
.up-del { flex: none; width: 26px; height: 26px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-3); font-size: 18px; line-height: 1; cursor: pointer; }
.up-del:hover { background: var(--coral-100); color: var(--coral); }
.up-item .btn { flex: none; }
.uploader-status { margin: 0; font-size: 12.5px; color: var(--ink-3); }
.uploader-status:empty { display: none; }
.uploader-status.ok { color: var(--leaf); } .uploader-status.bad { color: var(--coral); font-weight: 600; }
.portal-uploader { padding: 8px 14px 0; }
@media (max-width: 560px) { .uploader-list { grid-template-columns: 1fr; } }

/* Rev. 2.6 — contadores do menu: somem quando zerados; soma no título do grupo quando ele está recolhido */
.nav .count[hidden], .group-count[hidden] { display: none !important; }
.nav-group-toggle .group-count { margin-left: auto; margin-right: 6px; }
.nav-group-toggle[aria-expanded="true"] .group-count { display: none; }

/* Rev. 2.6 — colunas configuráveis, data de abertura e geração rápida de link */
.tickets-table .col-off { display: none !important; }
.btn-icon { padding: 0 8px; }
.cols-dialog { width: min(560px, calc(100vw - 24px)); }
.cols-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px; }
.cols-grid .check { margin: 3px 0; }
.cols-grid small { display: block; color: var(--ink-4); font-size: 11px; }
.cols-dialog footer, .quick-link-dialog footer { display: flex; align-items: center; gap: 8px; }
.cols-dialog .grow { flex: 1; }
@media (max-width: 520px) { .cols-grid { grid-template-columns: 1fr; } }
.quick-link-dialog { width: min(520px, calc(100vw - 24px)); }
.quick-link-dialog footer { justify-content: flex-end; }
.ql-ok { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--leaf-100); margin-bottom: 12px; font-size: 13.5px; }
.ql-ok svg { color: var(--leaf); flex: none; }
.ql-url { display: flex; gap: 6px; }
.ql-url input { flex: 1; font-family: var(--mono, monospace); font-size: 12.5px; }
.ql-wa { margin-top: 10px; background: #1fa855 !important; border-color: #1fa855 !important; color: #fff !important; }
.ql-error { color: var(--coral); margin: 8px 0 0; }
.kcard-opened { font-size: 11px; color: var(--ink-4); }
/* Rev. 2.6 — lista de chamados mais estreita com a coluna Data de abertura */
.tickets-table td[data-col="created"] { font-variant-numeric: tabular-nums; }
.tickets-table td[data-col="created"] .col-date { font-size: 12.5px; color: var(--ink-2); }
.tickets-table td.trunc[data-col="assignee"] { max-width: 145px; }
.tickets-table th, .tickets-table td { padding-left: 10px; padding-right: 10px; }
.tickets-table th[data-col="attachments"], .tickets-table td[data-col="attachments"] { text-align: center; }
.tickets-table th[data-col="created"], .tickets-table th[data-col="attachments"], .tickets-table th[data-col="opener"] { white-space: normal; line-height: 1.2; }
.tickets-table th[data-col="created"] { width: 84px; }

/* Rev. 3.4.2 — indicador de comentários nas tabelas: balão azul, total em verde, não lidas em laranja */
.cmt-ind { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 32px; border-radius: 8px; color: #2f7ae5; text-decoration: none; transition: background .15s, transform .15s; }
.cmt-ind:hover { background: color-mix(in srgb, #2f7ae5 12%, transparent); transform: translateY(-1px); }
.cmt-ind svg { display: block; filter: drop-shadow(0 1px 1px #0002); }
.cmt-ind.is-empty { color: var(--ink-4, #a3abb8); }
.cmt-ind.is-empty svg { filter: none; opacity: .7; }
.cmt-ind .cmt-badge { position: absolute; top: -3px; right: -2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #16a34a; color: #fff;
  font: 700 11px/18px var(--font, Inter, Arial, sans-serif); text-align: center; box-shadow: 0 0 0 2px var(--panel, #fff); }
.cmt-ind.has-unread .cmt-badge { background: #ea580c; }
.cmt-ind.has-unread { color: #1d64d8; }
:root[data-theme="dark"] .cmt-ind { color: #5b9bf5; }
:root[data-theme="dark"] .cmt-ind.is-empty { color: #6b7280; }
/* o botão da conversa na lista de empresas usa o mesmo indicador */
.cchat-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 34px; min-width: 34px; height: 30px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: #2f7ae5; }
.cchat-btn:hover { background: color-mix(in srgb, #2f7ae5 12%, transparent); color: #2f7ae5; border: 0; }
.cchat-btn.is-empty { border: 0; color: var(--ink-4, #a3abb8); }
.cchat-btn.is-empty svg { opacity: .7; }
.cchat-btn svg { display: block; }
.cchat-btn .cmt-badge { position: absolute; top: -3px; right: -2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #16a34a; color: #fff;
  font: 700 11px/18px var(--font, Inter, Arial, sans-serif); text-align: center; box-shadow: 0 0 0 2px var(--panel, #fff); }
.cchat-btn.has-unread { border: 0; background: transparent; color: #1d64d8; }
.cchat-btn.has-unread .cmt-badge { background: #ea580c; }
.cchat-btn.has-unread::after { display: none; }
:root[data-theme="dark"] .cchat-btn { color: #5b9bf5; }
:root[data-theme="dark"] .cchat-btn.is-empty { color: #6b7280; }
