:root {
  --fundo: #f4f6f8; --papel: #fff; --papel-2: #eef2f6; --tinta: #102a43; --fraco: #627d98; --borda: #d9e2ec;
  --marca: #102a43; --ouro: #f2c230; --azul: #2563eb; --verde: #0f7b4b; --vermelho: #c0392b;
  --minha: #e8f0fe; --raio: 14px;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --fundo: #0b1620; --papel: #12212e; --papel-2: #1a2c3b; --tinta: #e6edf3; --fraco: #8fa4b8; --borda: #243b4f; --minha: #1b3350; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fundo); color: var(--tinta); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--azul); }

.botao { border: 0; border-radius: 10px; padding: 9px 16px; background: var(--marca); color: #fff; font-weight: 600; cursor: pointer; }
.botao.claro { background: var(--papel-2); color: var(--tinta); }
.botao.pequeno { padding: 6px 10px; font-size: 13px; }
.botao:disabled { opacity: .5; cursor: default; }
.entrada { width: 100%; padding: 10px 12px; border: 1px solid var(--borda); border-radius: 10px; background: var(--papel); }
.campo { display: grid; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--fraco); }
.erro { color: var(--vermelho); font-size: 14px; min-height: 20px; }

/* entrada */
.cartao { max-width: 380px; margin: 12vh auto 0; padding: 28px; background: var(--papel); border: 1px solid var(--borda); border-radius: 18px; }
.marca { font-weight: 800; font-size: 20px; letter-spacing: -.01em; }
.marca b { color: var(--ouro); }
.cartao h1 { font-size: 22px; margin: 14px 0 4px; }
.cartao p { color: var(--fraco); margin: 0 0 18px; }
.nivel { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--papel-2); font-size: 12px; font-weight: 600; }

/* app */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100dvh; }
.lateral { background: var(--marca); color: #dbe7f3; display: flex; flex-direction: column; min-height: 0; }
.lateral header { padding: 18px 16px 12px; }
.lateral .marca { color: #fff; }
.lateral .quem { font-size: 13px; opacity: .8; margin-top: 2px; }
.salas { flex: 1; overflow-y: auto; padding: 4px 8px; }
.sala-item { display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.sala-item:hover { background: rgba(255,255,255,.07); }
.sala-item.ativa { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.sala-item small { display: block; opacity: .6; font-weight: 400; font-size: 12px; }
.lateral footer { padding: 12px; display: grid; gap: 8px; border-top: 1px solid rgba(255,255,255,.1); }
.lateral footer .botao { background: rgba(255,255,255,.1); }

.conversa { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topo { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--borda); background: var(--papel); }
.topo h2 { font-size: 17px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topo .voltar { display: none; }
.mensagens { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(720px, 88%); padding: 10px 14px; border-radius: var(--raio); background: var(--papel); border: 1px solid var(--borda); align-self: flex-start; }
.msg.minha { align-self: flex-end; background: var(--minha); }
.msg .autor { font-size: 12px; font-weight: 700; color: var(--fraco); display: flex; gap: 6px; align-items: center; }
.avatar { position: relative; flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 800; color: #fff; background: #829ab1; margin-right: 2px; }
.avatar svg { width: 15px; height: 15px; }
.avatar.claude { background: #d97757; }
.avatar.codex { background: #111; box-shadow: inset 0 0 0 1px #3a3a3a; }
.avatar.vigia { background: #2f6fb3; }
.avatar.vigia svg path { fill: #fff; }
.avatar.alex { background: #e0a526; color: #3a2700; }
.avatar b { position: absolute; right: -7px; bottom: -5px; font-size: 8.5px; line-height: 1; padding: 2px 3px; border-radius: 5px; background: var(--tinta); color: var(--papel); border: 1.5px solid var(--papel); letter-spacing: .2px; }
.msg .autor time { font-weight: 400; }
.msg .texto { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg img { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; margin-top: 8px; cursor: zoom-in; }
.papel { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 99px; background: var(--papel-2); }
.papel.comandante { background: var(--ouro); color: #102a43; }
.papel.subcomandante { background: #c7d8f7; color: #102a43; }
.papel.gerente { background: #cdebd9; color: #0b3d27; }
.vazio { margin: auto; color: var(--fraco); text-align: center; max-width: 360px; }

.compor { border-top: 1px solid var(--borda); background: var(--papel); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
.compor form { display: flex; gap: 8px; align-items: flex-end; }
.compor textarea { flex: 1; resize: none; max-height: 200px; min-height: 42px; }
.anexos { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.anexos figure { margin: 0; position: relative; }
.anexos img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.anexos button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--vermelho); color: #fff; cursor: pointer; }
.clipe { cursor: pointer; padding: 9px 12px; border-radius: 10px; background: var(--papel-2); }
.somente-leitura { color: var(--fraco); text-align: center; font-size: 14px; }

dialog { max-height: 90dvh; overflow-y: auto; border: 1px solid var(--borda); border-radius: 18px; padding: 22px; background: var(--papel); color: var(--tinta); width: min(560px, 94vw); }
dialog::backdrop { background: rgba(10, 20, 30, .5); }
dialog h3 { margin: 0 0 14px; }
.convite { border: 1px solid var(--borda); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }
.convite.cancelado { opacity: .5; }
.convite code, .novo-convite code { font-size: 12px; overflow-wrap: anywhere; }
.novo-convite { background: var(--papel-2); border-radius: 12px; padding: 12px; margin-bottom: 14px; font-size: 14px; }
.linha { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.linha > * { flex: 1; min-width: 140px; }
.linha > .botao { flex: 0 0 auto; }
.zoom img { max-width: 100%; max-height: 80vh; display: block; margin: auto; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.em-sala .lateral { display: none; }
  .app:not(.em-sala) .conversa { display: none; }
  .topo .voltar { display: inline-block; }
  .mensagens { padding: 12px; }
}
.msg .documento { display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 10px 12px; border: 1px solid rgba(127,127,127,.35); border-radius: 10px; color: inherit; text-decoration: none; max-width: 420px; }
.msg .documento:hover, .msg .documento:focus-visible { border-color: currentColor; }
.doc-tipo { flex: none; min-width: 44px; padding: 6px 4px; border-radius: 6px; background: rgba(127,127,127,.18); font-size: 11px; font-weight: 700; text-align: center; letter-spacing: .04em; }
.doc-nome { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.doc-nome small { opacity: .7; font-size: 12px; }
.doc-mini { display: flex; align-items: center; justify-content: center; width: 64px; height: 64px; padding: 4px; border-radius: 8px; background: rgba(127,127,127,.18); font-size: 10px; text-align: center; overflow: hidden; overflow-wrap: anywhere; }

/* texto formatado dos operadores */
.msg .texto code { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--papel-2); padding: 1px 5px; border-radius: 5px; }
.msg .texto pre { white-space: pre; overflow-x: auto; background: var(--papel-2); border: 1px solid var(--borda); border-radius: 8px; padding: 10px 12px; margin: 6px 0; }
.msg .texto pre code { background: none; padding: 0; }
.msg .texto .titulo { display: block; font-size: 15px; margin-top: 4px; }
.msg .texto .item { display: block; padding-left: 16px; position: relative; }
.msg .texto .item::before { content: "•"; position: absolute; left: 3px; color: var(--fraco); }
.msg .texto .item.num::before { content: attr(data-n) "."; left: 0; font-size: 12px; }
.msg .texto a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg .texto .tabela { overflow-x: auto; margin: 6px 0; white-space: normal; }
.msg .texto table { border-collapse: collapse; font-size: 13px; }
.msg .texto th, .msg .texto td { border: 1px solid var(--borda); padding: 4px 8px; text-align: left; vertical-align: top; }
.msg .texto th { background: var(--papel-2); }

/* operador pensando */
.msg.pensando { border-style: dashed; opacity: .92; }
.msg.pensando .texto { font-size: 13px; color: var(--fraco); }
.pontos { display: inline-flex; gap: 3px; margin-left: 4px; }
.pontos i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: piscar 1.2s infinite ease-in-out; }
.pontos i:nth-child(2) { animation-delay: .2s; } .pontos i:nth-child(3) { animation-delay: .4s; }
@keyframes piscar { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .pontos i { animation: none; opacity: .7; } }
