:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #17201c;
  --muted: #5f6d66;
  --border: #dde4e0;
  --primary: #128c5e;
  --primary-text: #ffffff;
  --danger: #c0392b;
  --warn-bg: #fff4d6;
  --warn-text: #7a5a00;
  --bubble-me: #d9fdd3;
  --bubble-them: #ffffff;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #171e1b;
    --surface-2: #1f2824;
    --text: #e6ece9;
    --muted: #93a39b;
    --border: #2a3530;
    --primary: #25b37c;
    --primary-text: #06130d;
    --danger: #e5675a;
    --warn-bg: #3a3014;
    --warn-text: #f3d77a;
    --bubble-me: #1f4a37;
    --bubble-them: #222b27;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 10px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand.big { font-size: 26px; justify-content: center; }
.logo {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: var(--primary-text); font-weight: 800;
}
#tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#tabs button {
  background: none; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 8px;
  cursor: pointer; font: inherit; white-space: nowrap;
}
#tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; min-width: 0;
}
.grid { display: grid; gap: 16px; }
/* Assistente da API oficial */
.meta-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.meta-summary .chip.ok { background: rgba(37, 211, 102, .15); }
.step h2 { display: flex; align-items: center; gap: 8px; }
.step .n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--border, #ddd); font-size: 14px; }
.step.ok .n { background: #25d366; color: #fff; }
.step.ok .n::after { content: ''; }
.step ol { padding-left: 18px; line-height: 1.6; }
.step .out { margin-top: 10px; font-size: 14px; line-height: 1.6; }
.step .out.good { color: inherit; }
.step .out.bad { color: #d93025; }
.step tr.sel td { background: rgba(37, 211, 102, .08); }
.step .add-number { margin-top: 12px; }
.step .add-number summary { cursor: pointer; font-weight: 600; }
.row.wrap { flex-wrap: wrap; }
.days-pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.days-pick label { display: flex; align-items: center; gap: 4px; padding: 4px 10px; border: 1px solid var(--border, #ccc); border-radius: 999px; cursor: pointer; font-size: 13px; margin: 0; }
.days-pick label:has(input:checked) { background: var(--accent, #25d366); color: #fff; border-color: transparent; }
.days-pick input { display: none; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; }
.row.space { justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
textarea { resize: vertical; }
.row.gap input { flex: 1; min-width: 160px; width: auto; }
.row.gap select { width: auto; }

.btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: none; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 3px 8px; font-size: 13px; }

.status-line { font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--primary); }
.dot.wait { background: #e0a100; }
.qr-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.qr-box img { width: 240px; height: 240px; background: #fff; border-radius: 8px; padding: 6px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
.warn { background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 8px; }

.group-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.group-head input[name="name"] { flex: 1; min-width: 180px; font-weight: 700; width: auto; }
.features { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip.on { background: var(--primary); color: var(--primary-text); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.in { color: var(--primary); } .out { color: var(--danger); }
tr.off td { opacity: 0.5; }

.chat {
  display: flex; flex-direction: column; gap: 6px; max-height: 520px; overflow-y: auto;
  background: var(--surface-2); border-radius: 10px; padding: 10px; margin: 10px 0;
}
.small-chat { max-height: 300px; min-height: 120px; }
.bubble { max-width: 85%; padding: 6px 10px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.user { align-self: flex-start; background: var(--bubble-them); border: 1px solid var(--border); }
.bubble.assistant { align-self: flex-end; background: var(--bubble-me); }
.bubble.system { align-self: center; font-size: 12px; color: var(--muted); background: none; max-width: 100%; }
.bubble .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bubble-pre { white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 10px; margin: 0; font-family: inherit; }

.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20;
  max-width: calc(100% - 32px);
}

/* ---------- Ao vivo / badges ---------- */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live .dot { animation: pulse 2s infinite; }
.live.off .dot { animation: none; background: var(--muted); }
@keyframes pulse { 50% { opacity: 0.35; } }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; font-size: 11px; line-height: 18px;
  text-align: center; background: var(--primary); color: var(--primary-text); font-weight: 700; margin-left: 4px;
}
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12px; word-break: break-all; }
.info { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; color: var(--text); line-height: 1.6; }
.info ol { margin: 6px 0 10px; padding-left: 20px; }
.hint { display: block; font-size: 12px; color: var(--muted); }
.save-bar { position: sticky; bottom: 12px; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }

/* ---------- Painel: últimas mensagens ---------- */
.recent { display: flex; flex-direction: column; }
.recent-item { display: flex; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 8px; }
.recent-item:hover { background: var(--surface-2); }
.recent-item .txt { flex: 1; min-width: 0; }
.recent-item .txt div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Conversas (estilo WhatsApp Web) ---------- */
.wa {
  display: grid; grid-template-columns: 330px 1fr; height: calc(100vh - 120px); min-height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.wa-side { display: flex; flex-direction: column; border-right: 1px solid var(--border); min-width: 0; }
.wa-side > input { margin: 10px; width: auto; }
.conv-list { overflow-y: auto; flex: 1; }
.conv {
  display: flex; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.conv:hover { background: var(--surface-2); }
.conv.sel { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--primary); }
.conv .txt { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.conv .prev { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .tags { display: flex; gap: 4px; margin-top: 2px; flex-wrap: wrap; }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  color: #fff; font-size: 16px;
}
.chip.warn-chip { background: var(--warn-bg); color: var(--warn-text); }
.chip.ok { background: var(--primary); color: var(--primary-text); }
.chip.bad { background: var(--danger); color: #fff; }

.wa-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.wa-empty { flex: 1; display: grid; place-items: center; font-size: 15px; }
.wa-pane { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.wa-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.wa-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.wa-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-head label.check { margin: 0; }
.wa-msgs {
  flex: 1; overflow-y: auto; padding: 14px 6%; display: flex; flex-direction: column; gap: 4px;
  background: var(--surface-2);
}
.wa-msgs .bubble { max-width: 75%; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06); }
.wa-msgs .bubble .meta { text-align: right; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); padding: 2px 10px; border-radius: 8px; margin: 8px 0; }
.tool { align-self: center; max-width: 90%; font-size: 12px; color: var(--muted); }
.tool summary { cursor: pointer; list-style: none; background: var(--surface); padding: 2px 10px; border-radius: 8px; border: 1px dashed var(--border); }
.tool pre { white-space: pre-wrap; word-break: break-word; margin: 4px 0; font-size: 11px; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); padding: 2px 10px; border-radius: 8px; max-width: 90%; text-align: center; }
.sys.err { color: var(--danger); }
.wa-compose { display: flex; gap: 8px; align-items: flex-end; padding: 10px; border-top: 1px solid var(--border); background: var(--surface); }
.wa-compose select { width: auto; max-width: 190px; }
.wa-compose textarea { flex: 1; min-height: 40px; max-height: 140px; resize: none; }
.wa-compose label.btn { margin: 0; }
.wa-pane .hint { padding: 0 12px 8px; margin: 0; background: var(--surface); }
.only-mobile { display: none; }
.typing-dots { align-self: flex-end; font-size: 12px; color: var(--muted); font-style: italic; }

/* Status dos recados */
.st { white-space: nowrap; }

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  #tabs { order: 3; flex-basis: 100%; }
  main { padding: 16px 12px 60px; }
  .wa { grid-template-columns: 1fr; height: calc(100vh - 150px); }
  .wa.open .wa-side { display: none; }
  .wa:not(.open) .wa-main { display: none; }
  .only-mobile { display: inline-block; }
  .wa-msgs { padding: 10px; }
  .wa-compose { flex-wrap: wrap; }
  .wa-compose select { max-width: 100%; flex-basis: 100%; }
  .wa-msgs .bubble { max-width: 88%; }
}
