/* Disparador — componentes. Requer tokens.css. CSS puro, BEM simples.
   Marcacao de referencia: docs/design/prototipo.html

   CONVENCOES
   - Bloco: .nome | elemento: .nome__parte | modificador: .nome--variante
   - Icone: <svg class="icon"><use href="/assets/icons.svg#i-send"/></svg>  (.icon--sm .icon--lg .icon--xl)
   - Status vira modificador direto: <span class="badge badge--running">  (valor do campo `status` da API)

   BLOCOS
   .app .app--embedded        shell: grid sidebar + .main
   .sidebar  __brand __nav __link(--active | aria-current="page") __label __foot
   .topbar   __title __spacer __user __name
   .content                   area de conteudo (max 1280px)
   .page-header  __title __sub __actions
   .toolbar  __spacer         barra de filtros/acoes acima de tabelas
   .btn  --primary --secondary --danger --ghost  --sm --icon  [disabled] [aria-busy="true"]
   .field  __label __hint __error   (--error)     .field-row (campos lado a lado)
   .input .select .textarea .file .checkbox .switch(__track)   .input-group (__icon)
   .chip (--removable)  .chips
   .table-wrap > .table  (--hover)  th/td.num  td.actions   .table__sub  .mono
   .pagination  __info __controls
   .badge  --neutral --brand --success --warning --danger --info  + aliases de status
   .card  __header __title __body __footer       .grid (--2 --3 --4)
   .metric  __label __value __hint               .metrics
   .progress  __seg(--sent --delivered --read --failed)   .progress--sm   .legend  __item __dot
   .meter (__bar, --warn, --full)                uso de limite (ex.: 3/30 por hora)
   .tabs  __tab (--active | aria-selected="true")
   .alert  --info --warning --danger --success   __icon __body
   .modal-overlay > .modal  (--wide)  __header __title __body __footer   (--static p/ preview)
   .toast-region > .toast  --success --error --warning --info   __body __close
   .empty  __icon __title __text
   .account  __head __name __phone __meta __actions       card de conta WhatsApp
   .qr-box (--connected | --expired)  __ok __title __phone __overlay   area do QR e seus estados
   .qr-status (--ok | --warn)   .qr-countdown   .steps    texto de estado e passo a passo do pareamento
   .selbar (--all)  __text __actions     faixa de selecao de contatos; .table .check = coluna do checkbox
   .btn--link                                             acao textual dentro de frase
   .metrics--3                                            3 metricas lado a lado (modal de disparo)
   .grid--compose  > .sticky                              composicao: form (3fr) + previa fixa (2fr); 1 coluna <= 900px
   .wa-chat (--light | --dark)  .wa-day  .wa-bubble (--tail --media)  .wa-text .wa-caption .wa-meta .wa-ticks
   .wa-media .wa-img .wa-video .wa-play .wa-duration .wa-doc .wa-audio     preview fiel ao WhatsApp (ver bloco proprio)
   .split  __side __main                                  duas colunas (listas | contatos)
   .listnav  __item (--active)                            lista navegavel lateral
   .kv  (dl em grade rotulo/valor)   .code (codigo de pareamento)   .spinner
   .login  __card __brand __title __error
   utilitarios: .muted .faint .nowrap .stack(--sm) .row(--between) .sr-only .hidden */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: var(--fw-regular) var(--fs-md)/var(--lh) var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--fs-xl); font-weight: var(--fw-semibold); line-height: 1.25; }
h2 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); line-height: 1.3; }
h3 { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
a { color: var(--brand-soft-fg); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
h1[tabindex="-1"]:focus { outline: none; }   /* alvo de foco programatico apos trocar de tela; nao e controle */
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }
code, .mono { font-family: var(--font-mono); font-size: .93em; }
[hidden], .hidden { display: none !important; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack--sm { gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row--between { justify-content: space-between; }

/* ---------- Icones ---------- */
.icon {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon--sm { width: 14px; height: 14px; }
.icon--lg { width: 20px; height: 20px; }
.icon--xl { width: 32px; height: 32px; }
.spinner { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- Shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; align-self: start;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar__brand {
  height: var(--topbar-h); padding: 0 var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-2);
  font-weight: var(--fw-semibold); font-size: var(--fs-lg);
  border-bottom: 1px solid var(--border);
}
.sidebar__brand .icon { color: var(--brand); }
.sidebar__nav { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3) var(--sp-2); }
.sidebar__link {
  display: flex; align-items: center; gap: var(--sp-3);
  height: 34px; padding: 0 var(--sp-3); border-radius: var(--radius);
  color: var(--text-muted); font-weight: var(--fw-medium); text-decoration: none;
}
.sidebar__link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar__link--active, .sidebar__link[aria-current="page"] { background: var(--brand-soft); color: var(--brand-soft-fg); }
.sidebar__foot { margin-top: auto; padding: var(--sp-3) var(--sp-4); font-size: var(--fs-xs); color: var(--text-faint); border-top: 1px solid var(--border); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-6);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar__title { font-weight: var(--fw-semibold); }
.topbar__spacer { flex: 1; }
.topbar__user { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-muted); font-size: var(--fs-sm); }
.topbar__name { color: var(--text); font-weight: var(--fw-medium); }
.content { width: 100%; max-width: 1280px; padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-5); }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.page-header__sub { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }
.page-header__actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.toolbar__spacer { flex: 1; }

/* Shell embutido (prototipo): sem altura de viewport */
.app--embedded { min-height: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.app--embedded .sidebar { position: static; height: auto; align-self: stretch; }
.app--embedded .topbar { position: static; }

@media (max-width: 800px) {
  :root { --sidebar-w: 56px; }
  .sidebar__label, .sidebar__brand span, .sidebar__foot { display: none; }
  .sidebar__brand, .sidebar__link { justify-content: center; padding: 0; }
  .content { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); }
}

/* ---------- Botoes ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 var(--sp-3);
  border: 1px solid transparent; border-radius: var(--radius);
  font-size: var(--fs-md); font-weight: var(--fw-medium); line-height: 1;
  white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--brand); color: var(--brand-contrast); }
.btn--primary:hover { background: var(--brand-hover); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--surface-2); }
.btn--danger { background: var(--danger-solid); color: #fff; }
.btn--danger:hover { filter: brightness(.92); }
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--sm { height: var(--control-h-sm); padding: 0 var(--sp-2); font-size: var(--fs-sm); }
.btn--icon { width: var(--control-h); padding: 0; }
.btn--icon.btn--sm { width: var(--control-h-sm); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn[aria-busy="true"] { pointer-events: none; opacity: .8; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field__label { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field__error { font-size: var(--fs-xs); color: var(--danger-fg); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-4); }

.input, .select, .textarea {
  width: 100%; height: var(--control-h); padding: 0 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
}
.textarea { height: auto; min-height: 96px; padding: 8px 10px; resize: vertical; line-height: var(--lh); }
.select { appearance: none; padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% - 1px), calc(100% - 10px) calc(50% - 1px); background-size: 5px 5px; background-repeat: no-repeat; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }
.input[disabled], .select[disabled], .textarea[disabled], .input[readonly] { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
.field--error .input, .field--error .select, .field--error .textarea, .input[aria-invalid="true"] { border-color: var(--danger-solid); }
.input--sm, .select--sm { height: var(--control-h-sm); font-size: var(--fs-sm); }
.input--narrow { width: 96px; }

.input-group { position: relative; }
.input-group__icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.input-group .input { padding-left: 30px; }

.file { width: 100%; padding: 3px; height: var(--control-h); font-size: var(--fs-sm); color: var(--text-muted);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.file::file-selector-button { height: 24px; margin-right: var(--sp-2); padding: 0 10px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font: inherit; font-weight: var(--fw-medium); }
.file::file-selector-button:hover { background: var(--border); }

.checkbox { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; font-size: var(--fs-sm); }
.checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }

.switch { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; font-size: var(--fs-sm); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { position: relative; width: 32px; height: 18px; border-radius: var(--radius-pill); background: var(--border-strong); transition: background-color .12s; flex: none; }
.switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .12s; }
.switch input:checked + .switch__track { background: var(--brand); }
.switch input:checked + .switch__track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .switch__track { opacity: .5; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-xs); font-family: var(--font-mono); }
.chip--var { background: var(--brand-soft); border-color: transparent; color: var(--brand-soft-fg); cursor: pointer; }
.chip button { all: unset; display: inline-flex; cursor: pointer; color: var(--text-faint); }
.chip button:hover { color: var(--danger-fg); }

/* ---------- Tabela ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 6px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-muted); font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table--hover tbody tr:hover { background: var(--surface-hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table__sub { display: block; color: var(--text-muted); font-size: var(--fs-xs); }
.table tr[aria-selected="true"], .table tr.is-selected { background: var(--brand-soft); }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--border); background: var(--surface); font-size: var(--fs-sm); color: var(--text-muted); }
.table-wrap > .pagination { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.pagination__controls { display: flex; align-items: center; gap: var(--sp-1); }

/* ---------- Badges de status ---------- */
.badge {
  --b-fg: var(--text-muted); --b-bg: var(--surface-2); --b-bd: var(--border);
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px;
  border-radius: var(--radius-pill); border: 1px solid var(--b-bd);
  background: var(--b-bg); color: var(--b-fg);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); line-height: 1; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge--neutral, .badge--draft, .badge--queued, .badge--canceled, .badge--skipped, .badge--skipped_optout, .badge--skipped_not_on_wa
  { --b-fg: var(--text-muted); --b-bg: var(--surface-2); --b-bd: var(--border); }
.badge--brand, .badge--running, .badge--delivered, .badge--tested
  { --b-fg: var(--brand-soft-fg); --b-bg: var(--brand-soft); --b-bd: transparent; }
.badge--success, .badge--connected, .badge--completed, .badge--read, .badge--replied
  { --b-fg: var(--success-fg); --b-bg: var(--success-bg); --b-bd: var(--success-bd); }
.badge--warning, .badge--paused, .badge--pairing
  { --b-fg: var(--warning-fg); --b-bg: var(--warning-bg); --b-bd: var(--warning-bd); }
.badge--danger, .badge--disconnected, .badge--failed
  { --b-fg: var(--danger-fg); --b-bg: var(--danger-bg); --b-bd: var(--danger-bd); }
.badge--info, .badge--testing, .badge--sending, .badge--sent
  { --b-fg: var(--info-fg); --b-bg: var(--info-bg); --b-bd: var(--info-bd); }
/* Sem ponto: estados "vazios"/terminais neutros ficam com ponto oco */
.badge--draft::before, .badge--queued::before, .badge--canceled::before,
.badge--skipped::before, .badge--skipped_optout::before, .badge--skipped_not_on_wa::before
  { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }

/* ---------- Cards e metricas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card__header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.card__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.card__body { padding: var(--sp-4); }
.card__footer { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-2); }
.grid { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.metrics { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-3) var(--sp-4); }
.metric__label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: var(--fw-semibold); }
.metric__value { font-size: var(--fs-2xl); font-weight: var(--fw-semibold); line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; }
.metric__hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.metric--success .metric__value { color: var(--success-fg); }
.metric--danger .metric__value { color: var(--danger-fg); }

/* ---------- Progresso segmentado ---------- */
/* Larguras (style="width:NN%") sao % do total e EXCLUSIVAS: se a API for cumulativa
   (read <= delivered <= sent), use sent-delivered, delivered-read, read e failed. */
.progress { display: flex; height: 10px; border-radius: var(--radius-pill); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); overflow: hidden; }
.progress--sm { height: 6px; }
.progress__seg { height: 100%; min-width: 0; }
.progress__seg--sent { background: var(--seg-sent); }
.progress__seg--delivered { background: var(--seg-delivered); }
.progress__seg--read { background: var(--seg-read); }
.progress__seg--failed { background: var(--seg-failed); }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); font-size: var(--fs-xs); color: var(--text-muted); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__item b { color: var(--text); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.legend__dot { width: 8px; height: 8px; border-radius: 2px; background: var(--border-strong); }
.legend__dot--sent { background: var(--seg-sent); }
.legend__dot--delivered { background: var(--seg-delivered); }
.legend__dot--read { background: var(--seg-read); }
.legend__dot--failed { background: var(--seg-failed); }

.meter { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-xs); color: var(--text-muted); }
.meter__head { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.meter__track { height: 6px; border-radius: var(--radius-pill); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); overflow: hidden; }
.meter__bar { height: 100%; background: var(--brand); }
.meter--warn .meter__bar { background: var(--warning-solid); }
.meter--full .meter__bar { background: var(--danger-solid); }

/* ---------- Abas ---------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); }
.tabs__tab { all: unset; box-sizing: border-box; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 var(--sp-3);
  color: var(--text-muted); font-weight: var(--fw-medium); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs__tab:hover { color: var(--text); }
.tabs__tab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tabs__tab--active, .tabs__tab[aria-selected="true"] { color: var(--brand-soft-fg); border-bottom-color: var(--brand); }

/* ---------- Alertas ---------- */
.alert { --a-fg: var(--info-fg); --a-bg: var(--info-bg); --a-bd: var(--info-bd);
  display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4);
  background: var(--a-bg); border: 1px solid var(--a-bd); border-radius: var(--radius); color: var(--text); font-size: var(--fs-sm); }
.alert__icon { color: var(--a-fg); margin-top: 1px; }
.alert__body { flex: 1; min-width: 0; }
.alert__body strong { font-weight: var(--fw-semibold); }
.alert--warning { --a-fg: var(--warning-fg); --a-bg: var(--warning-bg); --a-bd: var(--warning-bd); }
.alert--danger  { --a-fg: var(--danger-fg);  --a-bg: var(--danger-bg);  --a-bd: var(--danger-bd); }
.alert--success { --a-fg: var(--success-fg); --a-bg: var(--success-bg); --a-bd: var(--success-bd); }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: var(--sp-4); background: var(--overlay); }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 48px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal--wide { max-width: 720px; }
.modal__header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.modal__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.modal__body { padding: var(--sp-4); overflow-y: auto; display: flex; flex-direction: column; gap: var(--sp-4); }
.modal__footer { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); }
.modal-overlay--static { position: relative; inset: auto; z-index: 0; border-radius: var(--radius-lg); padding: var(--sp-8) var(--sp-4); }

/* ---------- Toast ---------- */
.toast-region { position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: 200; display: flex; flex-direction: column; gap: var(--sp-2); width: min(360px, calc(100vw - 32px)); }
.toast { --t-solid: var(--info-solid);
  display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3);
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--t-solid);
  border-radius: var(--radius); box-shadow: var(--shadow-md); font-size: var(--fs-sm); }
.toast .icon { color: var(--t-solid); margin-top: 1px; }
.toast__body { flex: 1; min-width: 0; }
.toast__close { all: unset; cursor: pointer; display: inline-flex; color: var(--text-faint); }
.toast__close:hover { color: var(--text); }
.toast--success { --t-solid: var(--success-solid); }
.toast--error   { --t-solid: var(--danger-solid); }
.toast--warning { --t-solid: var(--warning-solid); }
.toast--info    { --t-solid: var(--info-solid); }
.toast-region--static { position: static; width: 360px; max-width: 100%; }

/* ---------- Estado vazio ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-2); padding: var(--sp-10) var(--sp-4);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.empty__icon { color: var(--text-faint); }
.empty__title { font-weight: var(--fw-semibold); }
.empty__text { color: var(--text-muted); font-size: var(--fs-sm); max-width: 420px; margin-bottom: var(--sp-2); }

/* ---------- Contas ---------- */
.account { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.account--off { opacity: .75; }
.account__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); }
.account__name { font-weight: var(--fw-semibold); }
.account__phone { font-size: var(--fs-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.account__meta { display: flex; flex-direction: column; gap: var(--sp-2); }
.account__actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.qr-box { width: 220px; height: 220px; margin: 0 auto; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: var(--sp-3); background: #fff; color: #586171; border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: var(--fs-sm); }
.qr-box img { width: 100%; height: 100%; display: block; }
.code { font-family: var(--font-mono); font-size: var(--fs-2xl); font-weight: var(--fw-semibold); letter-spacing: .12em; text-align: center; padding: var(--sp-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------- Duas colunas / lista lateral / chave-valor ---------- */
.split { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--sp-4); align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.listnav { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.listnav__item { all: unset; box-sizing: border-box; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: 8px var(--sp-3); cursor: pointer; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.listnav__item:last-child { border-bottom: 0; }
.listnav__item:hover { background: var(--surface-hover); }
.listnav__item:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.listnav__item--active, .listnav__item[aria-current="true"] { background: var(--brand-soft); color: var(--brand-soft-fg); font-weight: var(--fw-medium); }
.listnav__count { color: var(--text-muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px var(--sp-4); margin: 0; font-size: var(--fs-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp-4); background: var(--bg); }
.login__card { width: 100%; max-width: 360px; padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.login__brand { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.login__brand .icon { color: var(--brand); }
.login__title { color: var(--text-muted); font-size: var(--fs-sm); margin-top: -8px; }
.login__error { margin: 0; }
.login--embedded { min-height: 0; padding: var(--sp-8) var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-lg); }

/* ---------- Metricas: 3 colunas fixas (modal de disparo) ---------- */
.metrics--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 560px) { .metrics--3 { grid-template-columns: 1fr; } }

/* ---------- Botao-link (acao textual dentro de frases) ---------- */
.btn--link { display: inline; height: auto; padding: 0; border: 0; border-radius: var(--radius-sm); background: none; color: var(--brand-soft-fg);
  font: inherit; font-weight: var(--fw-medium); line-height: inherit; white-space: normal; text-align: left; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.btn--link:hover { text-decoration-thickness: 2px; }

/* ---------- QR: estados (mesma caixa 220x220 em todos, sem salto de layout) ----------
   Fluxo: --loading -> (padrao: QR) + .qr-status "Aguardando leitura" -> --connected
          ou --expired (overlay "QR expirado" + Novo QR).
   O QR fica sempre sobre branco (leitura do celular), tambem no tema escuro. */
.qr-box { position: relative; }
.qr-box--connected { flex-direction: column; gap: var(--sp-2); background: var(--success-bg); border-color: var(--success-bd); color: var(--success-fg); }
.qr-box__ok { color: var(--success-solid); }
.qr-box__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.qr-box__phone { font-family: var(--font-mono); font-size: var(--fs-md); font-variant-numeric: tabular-nums; color: var(--text); }
.qr-box--expired img { opacity: .12; }
.qr-box__overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-3); border-radius: inherit; background: rgba(255, 255, 255, .86); color: #1a1f29; font-weight: var(--fw-medium); }
.qr-status { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); text-align: center; }
.qr-status--ok { color: var(--success-fg); font-weight: var(--fw-medium); }
.qr-status--warn { color: var(--warning-fg); }
.qr-countdown { width: 220px; margin: 0 auto; }
.steps { margin: 0; padding-left: var(--sp-5); display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-sm); color: var(--text-muted); }

/* ---------- Selecao de contatos ----------
   <div class="table-wrap"><div class="selbar" role="status">...</div><table>...
   Linhas selecionadas: <tr aria-selected="true">. Coluna do checkbox: th/td.check
   O checkbox do cabecalho usa input.indeterminate (so via JS) quando so parte da pagina esta marcada. */
.selbar { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); padding: var(--sp-2) var(--sp-3);
  background: var(--brand-soft); color: var(--brand-soft-fg); border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.selbar__text { flex: 1 1 260px; min-width: 0; }
.selbar__text b { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.selbar__actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.selbar--all { box-shadow: inset 3px 0 0 var(--brand); }
.table .check { width: 36px; padding-right: 0; }
.table .check .checkbox { display: flex; }
.table .check .checkbox input { display: block; }

/* ---------- Preview fiel ao WhatsApp (.wa-*) ----------
   Mostra EXATAMENTE como a mensagem de saida aparece no celular do destinatario.
   Estrutura:
     <div class="wa-chat">                          fundo da conversa (+ --light | --dark p/ forcar tema; padrao = tema do painel)
       <div class="wa-day">Hoje</div>               (opcional)
       <div class="wa-bubble wa-bubble--tail">      balao verde de saida; --tail = rabinho (1o balao do grupo)
         <div class="wa-text">texto<span class="wa-meta">...</span></div>
   Texto: use <strong> <em> <del> <code> e <a>. Quebras de linha sao preservadas (white-space: pre-wrap):
     NAO indente nem quebre a marcacao dentro de .wa-text; escape o conteudo (textContent).
   Hora + status (.wa-meta): <span class="wa-meta"><time>14:02</time>
       <span class="wa-ticks wa-ticks--read"><svg class="icon"><use href="/assets/icons.svg#i-check-check"/></svg>
       <span class="sr-only">Lida</span></span></span>
     .wa-ticks--sent (1 tique cinza: i-check) | --delivered (2 cinza) | --read (2 azul). No preview use --delivered.
     .wa-meta fica no canto inferior direito do balao; .wa-text e .wa-caption reservam o espaco sozinhos.
   Midia (balao com .wa-bubble--media, largura fixa max 330px):
     imagem:    <div class="wa-media"><img class="wa-img" src alt></div>
     video:     <div class="wa-media"><div class="wa-video"><video|div.wa-video__ph/><span class="wa-play">..</span><span class="wa-duration">..</span></div></div>
     documento: <div class="wa-doc"><span class="wa-doc__icon wa-doc__icon--pdf|docx|xlsx">..</span><div class="wa-doc__info"><div class="wa-doc__name">..</div><div class="wa-doc__sub">PDF · 1,2 MB</div></div></div>
     audio:     <div class="wa-audio">..</div>
     legenda:   <div class="wa-caption wa-text">..</div> abaixo da midia (a .wa-meta vai junto).
     sem legenda: imagem/video -> .wa-media--shade + .wa-meta--overlay (hora sobre a midia);
                  documento/audio -> .wa-meta--flow dentro de <div class="wa-foot"> abaixo. */
.wa-chat {
  --wa-bg:        light-dark(#efeae2, #0b141a);
  --wa-out:       light-dark(#d9fdd3, #005c4b);
  --wa-text:      light-dark(#111b21, #e9edef);
  --wa-meta:      light-dark(#596a73, #b4cdc7);
  --wa-tick-read: light-dark(#2a9fd6, #53bdeb);
  --wa-link:      light-dark(#0a6f9d, #7fd0f2);
  --wa-day-bg:    light-dark(#ffffff, #182229);
  --wa-day-fg:    light-dark(#54656f, #8696a0);
  --wa-doc-bg:    light-dark(#cdf1c7, #004a3c);
  --wa-media-bg:  light-dark(#cfd4d6, #1f2c34);
  --wa-code-bg:   light-dark(rgba(11, 20, 26, .07), rgba(255, 255, 255, .12));
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  min-width: 0; padding: var(--sp-4) var(--sp-4) var(--sp-4) var(--sp-3);
  background: var(--wa-bg); border-radius: var(--radius-lg);
  font-family: var(--font-sans);
}
.wa-chat--light { color-scheme: light; }
.wa-chat--dark  { color-scheme: dark; }
.wa-day { align-self: center; margin-bottom: var(--sp-2); padding: 4px 10px; border-radius: 7px; background: var(--wa-day-bg); color: var(--wa-day-fg);
  font-size: 12px; line-height: 1.2; text-transform: uppercase; box-shadow: 0 1px .5px rgba(11, 20, 26, .13); }

.wa-bubble {
  position: relative; max-width: min(80%, 330px); padding: 6px 7px 8px 9px;
  background: var(--wa-out); color: var(--wa-text); border-radius: 8px;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
  font-size: 14px; line-height: 19px;
}
/* rabinho no canto superior direito */
.wa-bubble--tail { border-top-right-radius: 0; }
.wa-bubble--tail::before { content: ""; position: absolute; top: 0; right: -8px; width: 8px; height: 13px; background: var(--wa-out);
  clip-path: path("M0 0H8C5.6 1 2.2 4.2 0 13Z"); }

.wa-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.wa-text::after { content: ""; display: inline-block; width: 64px; height: 1px; }   /* reserva a hora/tiques */
.wa-text strong { font-weight: 700; }
.wa-text em { font-style: italic; }
.wa-text del { text-decoration: line-through; }
.wa-text code { padding: 0 3px; border-radius: 3px; background: var(--wa-code-bg); font-family: var(--font-mono); font-size: 13px; }
.wa-text a { color: var(--wa-link); text-decoration: none; }
.wa-text a:hover { text-decoration: underline; }

.wa-meta { position: absolute; right: 7px; bottom: 5px; display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; line-height: 1; color: var(--wa-meta); white-space: nowrap; user-select: none; }
.wa-meta time { font-variant-numeric: tabular-nums; }
.wa-ticks { display: inline-flex; color: var(--wa-meta); }
.wa-ticks .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.wa-ticks--read { color: var(--wa-tick-read); }
.wa-meta--flow { position: static; }
.wa-foot { display: flex; justify-content: flex-end; padding: 3px 4px 0 0; }
.wa-meta--overlay { color: #fff; text-shadow: 0 0 4px rgba(0, 0, 0, .55); right: 8px; bottom: 7px; z-index: 1; }
.wa-meta--overlay .wa-ticks { color: #fff; }
.wa-meta--overlay .wa-ticks--read { color: #6fd0f7; }

/* midia: balao com 3px de moldura e largura de celular */
.wa-bubble--media { width: min(80%, 330px); padding: 3px; }
.wa-caption { padding: 5px 4px 3px 6px; }
.wa-media { position: relative; overflow: hidden; border-radius: 6px; background: var(--wa-media-bg); }
.wa-media--shade::after { content: ""; position: absolute; inset: auto 0 0 0; height: 48px; pointer-events: none;
  background: linear-gradient(to top, rgba(0, 0, 0, .42), transparent); }
.wa-img { display: block; width: 100%; height: auto; max-height: 360px; object-fit: cover; }
.wa-video { position: relative; aspect-ratio: 16 / 9; }
.wa-video > video, .wa-video__ph { display: block; width: 100%; height: 100%; object-fit: cover; }
.wa-video > .wa-img { height: 100%; max-height: none; }
.wa-video__ph { background: linear-gradient(160deg, #3a4a54, #1b262d); }   /* quando nao ha quadro para mostrar */
.wa-play { position: absolute; inset: 0; margin: auto; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%;
  background: rgba(11, 20, 26, .55); color: #fff; }
.wa-play .icon { width: 22px; height: 22px; margin-left: 2px; fill: currentColor; }
/* com <video controls> o navegador ja mostra o tempo: some o chip para nao sobrepor a barra nativa */
.wa-video > video[controls] ~ .wa-duration { display: none; }
.wa-duration { position: absolute; left: 7px; bottom: 7px; z-index: 1; display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; line-height: 1; color: #fff; text-shadow: 0 0 4px rgba(0, 0, 0, .55); font-variant-numeric: tabular-nums; }
.wa-duration .icon { width: 13px; height: 13px; }

.wa-doc { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 9px 10px; border-radius: 6px; background: var(--wa-doc-bg); }
.wa-doc__icon { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; background: #d6403a; color: #fff; }
.wa-doc__icon--docx { background: #2f6fc0; }
.wa-doc__icon--xlsx { background: #1e8e4e; }
.wa-doc__info { min-width: 0; }
.wa-doc__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-doc__sub { margin-top: 1px; font-size: 12px; line-height: 1.2; color: var(--wa-meta); text-transform: uppercase; font-variant-numeric: tabular-nums; }

.wa-audio { display: flex; align-items: center; gap: 10px; padding: 6px 6px 18px 4px; }
.wa-audio__play { flex: none; width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: var(--wa-meta); color: var(--wa-out); font: inherit; cursor: pointer; }
.wa-audio__play .icon { fill: currentColor; margin-left: 2px; }
.wa-audio__track { position: relative; flex: 1; min-width: 0; height: 3px; border-radius: 2px; background: light-dark(rgba(11, 20, 26, .2), rgba(255, 255, 255, .28)); }
.wa-audio__track::before { content: ""; position: absolute; left: 0; top: 50%; width: 11px; height: 11px; transform: translateY(-50%); border-radius: 50%; background: var(--wa-meta); }
.wa-audio__time { position: absolute; left: 62px; bottom: 5px; font-size: 11px; line-height: 1; color: var(--wa-meta); font-variant-numeric: tabular-nums; }
.wa-bubble--media .wa-audio { position: relative; }

/* ---------- Composicao: formulario + previa (colapsa em tela estreita; previa fixa ao rolar) ---------- */
.grid--compose { display: grid; gap: var(--sp-4); grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
.grid--compose > .sticky { position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); max-height: calc(100vh - var(--topbar-h) - var(--sp-8)); overflow: auto; }
@media (max-width: 900px) {
  .grid--compose { grid-template-columns: 1fr; }
  .grid--compose > .sticky { position: static; max-height: none; overflow: visible; }
}
