/* Tokens adaptados de ui-design.md §1 — zero CDN, CSS puro. */
:root {
  --bg: #0b141b;
  --card: #182128;
  --card-low: #141d24;
  --card-high: #222b33;
  --input-bg: #060f16;
  --line: #3d494d;
  --outline: #869398;
  --txt: #dae3ee;
  --muted: #bcc9ce;
  --accent: #4cd6fb;
  --accent2: #00b4d8;
  --on-accent: #003642;
  --ok: #4cd6fb;
  --warn: #f5c66c;
  --err: #ffb4ab;
  --err-bg: #93000a;
  --radius-sm: 4px;
  --radius-lg: 8px;
  --gap-card: 16px;
  --pad-input: 12px;
  --pad-container: 24px;
  --gutter: 20px;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh;
  background: linear-gradient(160deg, #060f16, var(--bg) 40%);
  color: var(--txt);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
}
code, .mono, input, textarea, select, pre {
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* Shell */
#topbar {
  height: 64px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--gutter); border-bottom: 1px solid var(--line); background: var(--bg);
}
#topbar .brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.2rem; color: var(--accent); }
#topbar .who { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: .8rem; }
#topbar button.ghost { background: transparent; border: 1px solid var(--line); color: var(--txt);
  padding: .4rem .8rem; border-radius: var(--radius-sm); cursor: pointer; font: inherit; }

#layout { display: flex; min-height: calc(100vh - 64px); }
#sidebar { width: 240px; flex-shrink: 0; background: var(--card-low); border-right: 1px solid var(--line);
  padding: 1rem .75rem; display: flex; flex-direction: column; gap: .25rem; }
#sidebar a { display: block; padding: .55rem .75rem; border-radius: var(--radius-sm); color: var(--muted);
  text-decoration: none; font-size: .88rem; }
#sidebar a:hover { background: var(--card); color: var(--txt); }
#sidebar a.active { background: var(--card-high); color: var(--accent); font-weight: 600; }
#sidebar .admin-only { display: none; }
main { flex: 1; padding: var(--pad-container); max-width: 1100px; }

@media (max-width: 760px) {
  #layout { flex-direction: column; }
  #sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
}

/* Componentes */
h1 { font-size: 1.4rem; margin: 0 0 .3rem; }
h2 { font-size: 1rem; margin: 0 0 .9rem; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.sub { color: var(--muted); font-size: .88rem; margin: 0 0 1.3rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 1.1rem 1.2rem; margin-bottom: var(--gap-card); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--gap-card); }
.stat-card { background: var(--card-low); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg); padding: 1rem 1.2rem; }
.stat-card .n { font-size: 1.9rem; font-weight: 700; }
.stat-card .l { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; }
label { display: block; font-size: .78rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .05em; margin: .7rem 0 .3rem; }
input, textarea, select {
  width: 100%; padding: var(--pad-input); background: var(--input-bg); color: var(--txt);
  border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent2); }
button.primary {
  padding: .65rem 1.2rem; border: none; border-radius: var(--radius-sm);
  background: var(--accent2); color: var(--on-accent); font-weight: 700; cursor: pointer;
  text-transform: uppercase; letter-spacing: .04em; font-size: .85rem;
}
button.primary:hover { filter: brightness(1.1); }
button.ghost {
  padding: .6rem 1.1rem; border: 1px solid var(--line); background: transparent; color: var(--txt);
  border-radius: var(--radius-sm); cursor: pointer; font: inherit;
}
button.danger {
  padding: .5rem 1rem; border: none; border-radius: var(--radius-sm);
  background: var(--err-bg); color: #fff; cursor: pointer; font: inherit; font-size: .82rem;
}
button:disabled { opacity: .4; cursor: not-allowed; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: .6rem .5rem; border-bottom: 1px solid var(--line); background: var(--card-high); }
td { padding: .7rem .5rem; border-bottom: 1px solid var(--line); font-size: .88rem; }
tr:hover td { background: rgba(255,255,255,.02); }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 600; text-transform: uppercase; border: 1px solid var(--line); }
.chip.connected { color: var(--accent); border-color: rgba(76,214,251,.3); background: rgba(76,214,251,.08); }
.chip.awaiting { color: var(--warn); border-color: rgba(245,198,108,.3); background: rgba(245,198,108,.08); }
.chip.neutral { color: var(--muted); }
.chip.deleted { opacity: .55; }
.chip.expired { color: var(--warn); border-color: rgba(245,198,108,.3); background: rgba(245,198,108,.08); }
.err-text { color: var(--err); font-size: .85rem; margin-top: .6rem; }
.hint { color: var(--muted); font-size: .74rem; margin-top: .3rem; }
/* Telefone do aparelho pareado, embaixo da descrição: menor que .hint de
   propósito, para ficar claro qual das duas linhas é a descrição. */
.hint-phone { color: var(--muted); font-size: .68rem; margin-top: .1rem;
  opacity: .8; font-variant-numeric: tabular-nums; }
code.mono-block { display: block; background: var(--input-bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .8rem; word-break: break-all; }

/* Modal — qualquer <div id="..."> de overlay usa o mesmo padrão via seletor de atributo */
[id$="Overlay"] {
  position: fixed; inset: 0; background: rgba(6,15,22,.8); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
[id$="Overlay"].open { display: flex; }
[id$="Overlay"] .panel { background: var(--card-high); border: 1px solid var(--line);
  border-radius: var(--radius-lg); max-width: 440px; width: 100%; padding: 1.3rem; }
[id$="Overlay"] .actions { display: flex; gap: .7rem; margin-top: 1.2rem; justify-content: flex-end; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 380px; }
.login-card .brand { text-align: center; font-size: 1.4rem; font-weight: 700; color: var(--accent); margin-bottom: 1.5rem; }

/* ---- Conversas (feature 003) ---- */
.num { text-align: right; white-space: nowrap; }
.last-msg-dir { font-size: .72rem; color: var(--muted); margin-bottom: .2rem; }
.last-msg {
  width: 100%;
  min-width: 220px;
  resize: vertical;
  font-size: .82rem;
  line-height: 1.3;
  background: var(--input-bg);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .35rem .5rem;
}
.chat-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--txt);
  font-size: 1.1rem;
  line-height: 1;
  padding: .45rem .6rem;
  cursor: pointer;
}
.chat-btn:hover { background: var(--card-high); border-color: var(--accent); }

/* Pisca discreto indicando que a tela se atualiza sozinha. */
.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: live-pulse 2s ease-in-out infinite;
}
@keyframes live-pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* Modal da conversa: 80% da tela, com o corpo rolando por dentro. */
.thread-panel {
  width: 80vw;
  max-width: 80vw;
  height: 80vh;
  display: flex;
  flex-direction: column;
}
.thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: .6rem;
  margin-bottom: .6rem;
}
.thread-head h2 { margin: 0; font-size: 1rem; }
.thread-body { flex: 1; overflow-y: auto; padding-right: .4rem; }
@media (max-width: 720px) {
  .thread-panel { width: 95vw; max-width: 95vw; height: 90vh; }
}

/* Separador de dia, como no WhatsApp. */
.day-sep {
  display: flex;
  justify-content: center;
  margin: .9rem 0 .6rem;
}
.day-sep span {
  background: var(--card-high);
  color: var(--muted);
  border-radius: 999px;
  padding: .2rem .8rem;
  font-size: .74rem;
}

.bubble-row { display: flex; margin-bottom: .4rem; }
.bubble-row.mine { justify-content: flex-end; }
.bubble {
  max-width: 72%;
  padding: .5rem .7rem;
  border-radius: var(--radius-lg);
  background: var(--card-low);
  border: 1px solid var(--line);
  word-wrap: break-word;
}
.bubble-row.mine .bubble { background: var(--accent2); color: var(--on-accent); border-color: var(--accent2); }
.bubble-meta {
  font-size: .7rem;
  opacity: .8;
  margin-top: .25rem;
  text-align: right;
  white-space: nowrap;
}
/* Autor do balão numa conversa de grupo — todos escrevem no mesmo lugar. */
.bubble-author {
  font-size: .72rem;
  font-weight: 600;
  opacity: .75;
  margin-bottom: .15rem;
}
/* Selo da lista: conversa de grupo, gravada mas não repassada à automação. */
.tag-group {
  display: inline-block;
  font-size: .72rem;
  padding: .1rem .4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}
.chat-id { font-size: .72rem; opacity: .75; }
.tick { margin-left: .35rem; letter-spacing: -2px; }
.tick-read { color: #4fc3f7; opacity: 1; }
.tick-failed { color: var(--err); letter-spacing: 0; }
.media-tag { font-size: .82rem; opacity: .9; margin-bottom: .2rem; }

/* Aviso de ação destrutiva (rotação de api-key) */
.danger-note {
  background: var(--err-bg);
  color: var(--err);
  border: 1px solid var(--err);
  border-radius: var(--radius-sm);
  padding: .7rem .8rem;
  margin: .6rem 0;
  font-size: .9rem;
  line-height: 1.4;
}
/* Botões de ação em linha de tabela: só ícone, com tooltip.
   O rótulo continua existindo em aria-label — leitor de tela não lê emoji, e
   sem isso o botão vira "botão" sem mais nada. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  text-decoration: none;
  color: var(--txt);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
.icon-btn:hover { background: var(--card-high); border-color: var(--accent); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn[disabled] { opacity: .4; cursor: not-allowed; }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }

/* Prévia de mídia enviada dentro do balão. */
.media-box { margin-bottom: .3rem; }
.media-img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  background: var(--input-bg);
.media-box audio { width: 100%; max-width: 260px; }
.media-caption { font-size: .9rem; }
/* Faixa de status da mensagem de teste: sobrevive ao fechamento do modal. */
#testStatusBar {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 60;
  gap: .6rem;
  flex-wrap: wrap;
  border: 1px solid var(--accent);
  padding: .6rem .9rem;
  font-size: .85rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
#testStatusBar button { padding: .35rem .7rem; font-size: .8rem; }
