: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: baseline; }
.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; }
}
