:root {
  --bg: #0b1210;
  --surface: #131c19;
  --surface-2: #1b2622;
  --border: rgba(255, 255, 255, 0.09);
  --text: #eef5f2;
  --muted: #9fb3ab;
  --faint: #6b7f78;
  --green: #25d366;
  --green-dark: #128c7e;
  --warning: #fbbf24;
  --danger: #f87171;
  --info: #60a5fa;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-tap-highlight-color: transparent; }
button, input, textarea { font: inherit; color: inherit; }

.tela { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.topo {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.topo h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topo .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.icone-btn { background: none; border: 0; padding: 6px 8px; font-size: 20px; cursor: pointer; color: var(--text); }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 14px; cursor: pointer; padding: 6px; }

.filtros { display: flex; gap: 8px; padding: 10px 14px; flex-shrink: 0; overflow-x: auto; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 6px 14px; white-space: nowrap; cursor: pointer; }
.chip.ativo { background: var(--green-dark); border-color: var(--green-dark); }
.busca { margin: 0 14px 8px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }

.lista { flex: 1; overflow-y: auto; }
.item { display: block; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.item:active { background: var(--surface-2); }
.item .linha { display: flex; justify-content: space-between; gap: 8px; }
.item strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .hora { color: var(--faint); font-size: 12px; flex-shrink: 0; }
.item .previa { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 4px; }
.item .linha .previa { flex: 1; min-width: 0; }
.item.nao-lida strong, .item.nao-lida .previa { color: var(--text); font-weight: 700; }
.item.nao-lida .hora { color: var(--green); font-weight: 600; }
.contador { flex-shrink: 0; align-self: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--green); color: #06110c; font-size: 12px; font-weight: 700; display: inline-flex;
  align-items: center; justify-content: center; }
.vazio { padding: 30px 14px; color: var(--muted); text-align: center; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--surface-2); color: var(--muted); margin-right: 4px; }
.badge.ok { background: rgba(37, 211, 102, 0.15); color: var(--green); }
.badge.warn { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.badge.info { background: rgba(96, 165, 250, 0.15); color: var(--info); }
.badge.bad { background: rgba(248, 113, 113, 0.15); color: var(--danger); }

.aviso { padding: 8px 14px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 85%; padding: 7px 11px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .meta { display: block; font-size: 11px; color: var(--faint); margin-top: 2px; }
.bubble.cliente { align-self: flex-start; background: var(--surface-2); }
.bubble.ia { align-self: flex-end; background: rgba(18, 140, 126, 0.45); }
.bubble.loja { align-self: flex-end; background: rgba(96, 165, 250, 0.22); }
.bubble.sistema { align-self: center; background: transparent; color: var(--faint); font-size: 12px; text-align: center; }
.bubble img { max-width: 100%; max-height: 300px; border-radius: 8px; display: block; }
.bubble video, .bubble audio { max-width: 100%; display: block; }
.bubble .transcricao { display: block; margin-top: 6px; font-size: 13px; font-style: italic; }
.bubble a { color: var(--green); }

.responder { display: flex; gap: 8px; padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0; align-items: flex-end; }
.responder textarea { flex: 1; resize: none; max-height: 140px; border-radius: 18px; border: 1px solid var(--border);
  background: var(--bg); padding: 9px 14px; }
.enviar { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--green-dark); font-size: 18px; cursor: pointer; flex-shrink: 0; }
.enviar:disabled { opacity: 0.5; }

.responder .icone-btn { align-self: center; padding: 6px 4px; }
.faint { color: var(--faint); font-size: 12px; }

/* Anexo escolhido (prévia antes de enviar) */
.anexo { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface);
  border-top: 1px solid var(--border); flex-shrink: 0; }
.anexo img, .anexo video { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.anexo .doc { font-size: 34px; width: 56px; text-align: center; flex-shrink: 0; }
.anexo .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.anexo .info strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }

/* Menu do clipe */
.menu-anexo { display: flex; justify-content: space-around; padding: 12px; background: var(--surface);
  border-top: 1px solid var(--border); flex-shrink: 0; }
.menu-anexo button { display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--surface-2);
  border: 0; border-radius: 14px; padding: 12px 18px; font-size: 26px; cursor: pointer; min-width: 88px; }
.menu-anexo span { font-size: 13px; color: var(--muted); }

/* Gravando áudio */
.gravando { display: flex; align-items: center; gap: 10px; padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); flex-shrink: 0; }
.gravando #cronometro { font-variant-numeric: tabular-nums; font-weight: 600; }
.gravando .faint { flex: 1; }
.ponto { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: piscar 1s infinite; }
@keyframes piscar { 50% { opacity: 0.2; } }

.login { max-width: 360px; margin: 0 auto; padding: 60px 20px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; }
.login input { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.login button { padding: 12px; border-radius: 10px; border: 0; background: var(--green-dark); font-weight: 600; cursor: pointer; }
.erro { color: var(--danger); font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #1d2b27; border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 16px; max-width: calc(100% - 32px); z-index: 10; }
#toast.erro { border-color: var(--danger); }
