:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6ea;
  --text: #111b21;
  --muted: #667781;
  --accent: #00a884;
  --accent-strong: #008069;
  --accent-contrast: #ffffff;
  --ok: #00a884;
  --ok-soft: #e1f7f1;
  --warn: #b37a00;
  --warn-soft: #fff6db;
  --danger: #d93025;
  --danger-soft: #fdecea;
  --idle: #8696a0;
  --idle-soft: #eef0f2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 20px rgba(0, 0, 0, .06);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a;
    --surface: #111b21;
    --surface-2: #202c33;
    --border: #26343c;
    --text: #e9edef;
    --muted: #8696a0;
    --ok-soft: #10302a;
    --warn: #e0a82e;
    --warn-soft: #3a3118;
    --danger: #f2655c;
    --danger-soft: #3b1d1b;
    --idle-soft: #1b262d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 22px; }
h3 { font-size: 18px; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- botões e campos ---------- */

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); filter: none; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn-small { padding: 6px 10px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; }
.field input, .field select {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.checks { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow: auto; }
.checks .check { margin: 0; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 9px 12px; margin: 0 0 14px; font-size: 14px; }

/* ---------- entrar ---------- */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow); padding: 32px 28px; display: flex; flex-direction: column;
}
.auth-card h1 { font-size: 22px; margin: 14px 0 6px; }
.auth-card > p { margin: 0 0 22px; }
.auth-card .btn { width: 100%; padding: 11px; }
.auth-logo { border-radius: 14px; }

/* ---------- central ---------- */

.topbar {
  display: flex; align-items: center; gap: 24px; padding: 10px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand img { border-radius: 8px; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: none; border: 0; font: inherit; color: var(--muted); font-weight: 600;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
.tab.active { color: var(--text); background: var(--surface-2); }
.me { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.me-name { font-size: 14px; color: var(--muted); margin-right: 4px; }

.content { max-width: 1200px; margin: 0 auto; padding: 28px 24px 48px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.view-head p { margin: 6px 0 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; display: flex; flex-direction: column; gap: 14px; border-top: 4px solid var(--idle);
}
.card[data-tone="ok"] { border-top-color: var(--ok); }
.card[data-tone="warn"] { border-top-color: var(--warn); }
.card[data-tone="danger"] { border-top-color: var(--danger); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-name { font-weight: 700; font-size: 17px; }
.card-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
  background: var(--idle-soft); color: var(--idle);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); }
.badge[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); }
.badge[data-tone="danger"] { background: var(--danger-soft); color: var(--danger); }
.card-hint { font-size: 13px; color: var(--muted); margin: -4px 0 0; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.metric b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.metric span { font-size: 12px; color: var(--muted); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.card-actions .btn-primary { flex: 1 1 auto; }
.empty { background: var(--surface); border-radius: var(--radius); padding: 32px; text-align: center; color: var(--muted); }

.table-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: 0; }
.table td:last-child { text-align: right; }
.table .inactive td { color: var(--muted); }

.dialog {
  border: 0; border-radius: 16px; padding: 24px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog-wide { width: min(900px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.log {
  background: #0b141a; color: #d1d7db; border-radius: 8px; padding: 12px; margin: 0 0 14px;
  max-height: 60vh; overflow: auto; font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: #111b21; color: #fff; padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px;
  max-width: calc(100vw - 32px);
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .me { width: 100%; margin: 0; }
  .me-name { margin-right: auto; }
  .content { padding: 20px 16px 40px; }
  .view-head { flex-direction: column; align-items: stretch; }
  .cards { grid-template-columns: 1fr; }
}

/* ---------- peças comuns (os Indicadores ficam em bi.css) ---------- */

.segmented { display: inline-flex; flex-wrap: wrap; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-2); }
.segmented button {
  border: 0; background: none; font: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.panel h3 { margin: 0 0 12px; font-size: 16px; }

.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.num, .table th.num { text-align: right; }
.cell-sub { font-size: 12px; color: var(--muted); }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover, .table-click tbody tr:focus-visible { background: var(--surface-2); outline: none; }
.note-warn { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 9px 12px; margin: 0 0 16px; font-size: 14px; font-weight: 600; }

/* ---------- clientes ---------- */

:root { --sim: #5b3fd1; --sim-contrast: #ffffff; }
@media (prefers-color-scheme: dark) {
  :root { --sim: #8a74f0; --sim-contrast: #0b141a; }
}

.view-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.empty-cell { text-align: center !important; color: var(--muted); padding: 32px 14px !important; white-space: normal !important; }
.table td .badge + .cell-sub { margin-top: 3px; }
#clients-note { margin: 12px 2px 0; }

/* formulários maiores (cliente, configurações) */
.field small { font-weight: 400; }
.field textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; width: 100%; resize: vertical; min-height: 44px;
}
.field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field textarea[readonly] { background: var(--surface-2); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; min-width: 0; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.input-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-section { border: 0; margin: 0; padding: 0; min-width: 0; }
.form-section legend { font-weight: 700; font-size: 14px; padding: 0; margin-bottom: 10px; }
.form-more { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin: 0 0 14px; }
.form-more summary { cursor: pointer; font-weight: 600; }
.form-more[open] summary { margin-bottom: 10px; }
.variables code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; cursor: help; }
.dialog-medium { width: min(560px, calc(100vw - 32px)); }
.dialog h4 { margin: 0 0 8px; font-size: 14px; }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { filter: brightness(.92); }
.btn-whatsapp { background: var(--accent-strong); color: #fff; }
.btn-whatsapp:hover { filter: brightness(1.08); }

.copy-box {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin: 0 0 14px;
}
.copy-box code { flex: 1 1 220px; min-width: 0; word-break: break-all; font-size: 13px; }
.copy-label { width: 100%; font-size: 12px; font-weight: 600; color: var(--muted); }
.credentials { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 14px; }
.credentials dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.credentials dd { margin: 0; font-family: ui-monospace, Consolas, monospace; font-weight: 700; }
.hint { font-size: 13px; background: var(--warn-soft); color: var(--text); border-radius: 8px; padding: 9px 12px; margin: 0 0 14px; }

.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-head h3 { margin: 0 0 4px; }
.detail-head p { margin: 0; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.detail-box { background: var(--surface-2); border-radius: 10px; padding: 14px; min-width: 0; }
.detail-box .copy-box { background: var(--surface); }
.detail-box p { margin: 8px 0 0; }
.wa-bubble {
  background: var(--ok-soft); border-radius: 10px 10px 10px 2px; padding: 10px 12px;
  white-space: pre-wrap; word-break: break-word; font-size: 14px; max-height: 220px; overflow: auto;
}
.wa-bubble.empty { background: var(--surface); color: var(--muted); }
.events { list-style: none; margin: 0 0 8px; padding: 0; max-height: 220px; overflow: auto; font-size: 13px; }
.events li { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.events li:last-child { border-bottom: 0; }
.events .event-at { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 105px; }
.events .event-detail { color: var(--muted); flex-basis: 100%; padding-left: 115px; }
.events li.failed b { color: var(--danger); }
.block-kind { margin-bottom: 14px; }

@media (max-width: 720px) {
  .form-grid, .detail-grid, .field-row, .field-row-3 { grid-template-columns: 1fr; }
  .events .event-detail { padding-left: 0; }
}

/* ---------- o que o cliente vê ---------- */

/* aviso de pagamento */
.notice {
  display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  background: var(--warn-soft); border-bottom: 1px solid var(--border);
}
.notice[data-tone="danger"] { background: var(--danger-soft); }
.notice-body { flex: 1; min-width: 0; }
.notice-title { display: block; color: var(--warn); }
.notice[data-tone="danger"] .notice-title { color: var(--danger); }
.notice-text { margin: 4px 0 0; font-size: 14px; white-space: pre-line; max-width: 900px; }
.notice .btn { flex: none; }

/* bloqueado ou cancelado */
.blocked-card { max-width: 440px; align-items: center; text-align: center; }
.blocked-icon {
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center;
  background: var(--danger-soft); color: var(--danger);
}
#blocked[data-kind="canceled"] .blocked-icon { background: var(--idle-soft); color: var(--idle); }
.blocked-card h1 { margin: 16px 0 10px; }
.blocked-message { margin: 0 0 22px; white-space: pre-line; }
.blocked-card .btn { width: 100%; padding: 11px; }
.blocked-phone { margin: 8px 0 18px; }

/* conectar o WhatsApp */
.connect { display: flex; align-items: center; gap: 28px; margin-bottom: 16px; border-top: 4px solid var(--warn); }
.connect-steps { flex: 1; min-width: 0; }
.connect-steps h3 { font-size: 20px; margin: 0 0 6px; }
.connect-steps > p { margin: 0 0 14px; }
.steps { margin: 0 0 14px; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.connect-status { font-size: 14px; color: var(--muted); margin: 0; }
.connect-qr {
  flex: none; width: 280px; height: 280px; border-radius: 12px; background: #fff;
  display: grid; place-items: center; border: 1px solid var(--border);
}
.connect-qr .qr { width: 264px; height: 264px; image-rendering: pixelated; }
.qr-wait { display: grid; place-items: center; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid #d7dde1; border-top-color: #00a884;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.connect-done { border-top-color: var(--ok); }
.connect-check {
  flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok-soft); color: var(--ok); font-size: 32px; font-weight: 700;
}
.connect-done .card-actions { margin-top: 12px; }
#qr-body .connect-qr { margin: 12px auto; }
#qr-body .connect-status { text-align: center; }
.connect-ok { color: var(--ok); font-weight: 700; text-align: center; padding: 24px 0; margin: 0; }

@media (max-width: 720px) {
  .notice { flex-direction: column; align-items: stretch; padding: 12px 16px; }
  .connect { flex-direction: column-reverse; align-items: stretch; }
  .connect-qr { margin: 0 auto; width: min(280px, 100%); height: auto; aspect-ratio: 1; }
  .connect-qr .qr { width: 94%; height: auto; }
}

/* faixa da simulação ("Ver como o cliente") */
.sim-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 8px 24px;
  background: var(--sim); color: var(--sim-contrast); font-size: 14px;
}
.sim-bar-text { flex: 1 1 260px; }
.sim-scenarios { background: rgba(255, 255, 255, .16); }
.sim-scenarios button { color: inherit; opacity: .85; font-size: 13px; padding: 5px 10px; }
.sim-scenarios button.active { opacity: 1; background: var(--surface); color: var(--text); }
.sim-close { background: var(--surface); color: var(--text); }
.simulating .auth { min-height: calc(100vh - 48px); }
@media (max-width: 720px) {
  .sim-bar { padding: 8px 16px; }
}

/* cliente com um WhatsApp só: a Central é só a porta de entrada (QR Code e avisos); o resto fica no painel */
.solo .tabs, .solo #view-lubots .view-head, .solo #cards { display: none; }
.solo #connect { max-width: 920px; margin: 0 auto; }
