:root {
  --bg: #f4f6f9; --card: #fff; --text: #1c2430; --muted: #64707f; --line: #dde2e9;
  --brand: #0b5394; --brand-soft: #e6eff8; --ok: #1e7b45; --warn: #b26a00; --bad: #b3261e;
  --ia: #6a3fb5; --ia-soft: #f1ebfb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); }
button { font: inherit; cursor: pointer; border: 1px solid var(--brand); background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 6px; }
button.secondary { background: #fff; color: var(--brand); }
button.link { background: none; border: 0; color: var(--brand); padding: 0; text-decoration: underline; }
button:disabled { opacity: .6; cursor: default; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); }
textarea { min-height: 90px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

#topbar { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--brand); color: #fff; flex-wrap: wrap; }
#topbar .brand { font-weight: 700; }
#topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#topbar nav a { color: #dce8f5; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
#topbar nav a.active, #topbar nav a:hover { background: rgba(255,255,255,.15); color: #fff; }
#topbar .who { font-size: 14px; }
#topbar .who .link { color: #fff; margin-left: 8px; }
#status-bar { padding: 6px 24px; font-size: 13px; background: #fff4e0; color: var(--warn); border-bottom: 1px solid #f0d9a8; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 24px 60px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.grid .wide { grid-column: 1 / -1; }
.error { color: var(--bad); margin-top: 8px; }
.ok { color: var(--ok); margin-top: 8px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
#topbar .pill { background: #fff; }
.pill.ia { background: var(--ia-soft); color: var(--ia); }
.st-Novo { background: #e3f1ff; color: #0b5394; }
.st-Em { background: #fff4e0; color: var(--warn); }
.st-Aguardando { background: #f2ecff; color: #5b3a9c; }
.st-Concluído { background: #e5f5eb; color: var(--ok); }
.st-Cancelado { background: #eee; color: #666; }

table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7fafd; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.case-layout { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .case-layout { grid-template-columns: 1fr; } }
.field-ia label::after { content: " • IA"; color: var(--ia); font-weight: 600; }
.field-ia input, .field-ia select, .field-ia textarea { border-color: #cdb9ef; background: #fcfaff; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 3px solid var(--line); padding: 4px 0 12px 12px; margin-left: 4px; }
.timeline li.operador { border-color: var(--brand); }
.timeline li.whatsapp { border-color: #25a244; }
.timeline .meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.timeline .text { white-space: pre-wrap; font-size: 14px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fafbfc; }
.gallery img { width: 100%; height: 110px; object-fit: cover; display: block; cursor: zoom-in; }
.gallery .pdf { height: 110px; display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--bad); text-decoration: none; }
.gallery figcaption { font-size: 12px; padding: 6px; color: var(--muted); }

#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 10; }
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 94vw; max-height: 92vh; }
#lightbox .close { position: absolute; top: 16px; right: 20px; font-size: 28px; background: none; border: 0; }

.login { max-width: 360px; margin: 12vh auto; }
.login h1 { text-align: center; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.msg { display: flex; gap: 10px; }
.msg img { width: 90px; height: 90px; object-fit: cover; border-radius: 6px; cursor: zoom-in; }

.seen-col { text-align: right; white-space: nowrap; width: 1%; }
.seen { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #fff4e0; color: #a35f00; white-space: nowrap; }
.unseen { font-size: 12px; color: var(--brand); font-weight: 600; white-space: nowrap; }
.timeline .author { font-weight: 600; color: var(--brand); }

button.danger { background: #c62828; color: #fff; border-color: #c62828; }
button.danger:hover { background: #a91f1f; }
h1 button.complement { font-size: 14px; padding: 6px 12px; vertical-align: middle; margin-right: 6px; width: auto; }
.pill.st-Rascunho { background: #fde7e7; color: #c62828; font-weight: 600; }
.draft-banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: #fde7e7; color: #8e1c1c; border: 1px solid #f3b4b4; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.draft-banner button { width: auto; flex: 0 0 auto; }

.enrich-btn { font-size: 13px; padding: 5px 10px; vertical-align: middle; margin-left: 8px; background: var(--ia-soft); color: var(--ia); border-color: var(--ia); width: auto; }
.card.enrich { border: 1px solid var(--ia); }
.card.enrich textarea { min-height: 110px; }
.enrich-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.enrich-thumbs .thumb { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 72px; height: 72px; border: 1px solid #ddd; border-radius: 6px; overflow: hidden; font-size: 12px; background: #fafafa; }
.enrich-thumbs img { width: 100%; height: 100%; object-fit: cover; }
.enrich-thumbs .thumb button { position: absolute; top: 2px; right: 2px; padding: 0 6px; font-size: 14px; line-height: 18px; background: #0009; border: 0; }
.card.enrich-done { background: var(--ia-soft); border: 1px solid var(--ia); }

.dup { display: inline-block; margin-top: 4px; font-size: 11px; padding: 1px 6px; border-radius: 99px; background: #fff3cd; color: #8a5a00; white-space: nowrap; font-weight: 600; }
.dup-banner { background: #fff3cd; color: #6b4600; border: 1px solid #f0d27a; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--brand); }
th.sorted { color: var(--brand); }

/* Caso parado há mais de 1h: pulso suave no fundo da linha */
@keyframes stale-pulse { 0%, 100% { background-color: transparent; } 50% { background-color: #ffe9c7; } }
tr.stale td { animation: stale-pulse 2.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { tr.stale td { animation: none; background-color: #fff4e0; } }

a.case-link { color: inherit; text-decoration: none; }
a.case-link:hover { text-decoration: underline; }
a.newtab { margin-left: 6px; padding: 0 5px; border-radius: 4px; color: var(--brand); text-decoration: none; font-size: 13px; opacity: .55; }
tr:hover a.newtab, a.newtab:focus { opacity: 1; }
a.newtab:hover { background: #e6eef7; }
