/* =====================================================================================================
   CONEXÕES WHATSAPP (V4) — lista compacta, janelas centralizadas, chaves liga/desliga.
   Só usa os tokens da V4 (--accent, --mint, --line…), então segue o tema claro/escuro sozinho.
   ===================================================================================================== */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.cx-page { --cx-ok-bg: var(--mint-soft); --cx-ok: var(--mint); --cx-on: #2f8a2a; }
:root[data-theme="dark"] .cx-page { --cx-on: #6cc24a; }
.cx-pad { padding: 18px; }
.cx-head { align-items: flex-start; gap: 16px; }
.cx-head-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.cx-new:disabled { opacity: .55; cursor: not-allowed; }
.cx-iconbtn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.cx-iconbtn:hover { background: var(--hover); }
.cx-iconbtn:disabled { cursor: progress; opacity: .7; }
.cx-iconbtn.spin svg { animation: cx-spin .9s linear infinite; }
@keyframes cx-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cx-iconbtn.spin svg { animation: none; } }

.cx-usage { font-size: 13px; color: var(--muted); margin: 2px 0 12px; }
.cx-usage b { color: var(--ink); }
.cx-usage.full b { color: var(--coral); }
.cx-alert { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.cx-alert.ok { background: var(--cx-ok-bg); color: var(--cx-ok); }
.cx-alert.warn { background: var(--amber-soft); color: var(--amber); }
.cx-alert.bad { background: var(--coral-soft); color: var(--coral); }
.cx-bad { color: var(--coral); }
.cx-muted { color: var(--muted); font-size: 13px; }

/* ---------- filtros e busca ---------- */
.cx-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cx-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.cx-filter { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.cx-filter span { color: var(--muted); font-weight: 500; margin-left: 2px; }
.cx-filter:hover { background: var(--hover); }
.cx-filter.on { background: var(--v4-chip-on-bg, var(--mint-soft)); border-color: var(--v4-chip-on-line, var(--mint)); color: var(--v4-chip-on-ink, var(--mint)); }
.cx-search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--field-bg); border-radius: 10px; padding: 0 10px; min-width: 260px; color: var(--muted); }
.cx-search input { border: 0; background: transparent; padding: 9px 0; font: inherit; color: var(--ink); width: 100%; outline: none; }
.cx-search:focus-within { outline: 2px solid #74b721; outline-offset: 1px; }

/* ---------- lista compacta ---------- */
.cx-table { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.cx-row { display: grid; grid-template-columns: 40px minmax(120px, 1.3fr) minmax(100px, 1fr) 158px 170px minmax(96px, .9fr) 82px 188px; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 14px; }
.cx-row:first-child { border-top: 0; }
.cx-row:not(.cx-th):hover { background: var(--row-alt); }
.cx-th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-top: 9px; padding-bottom: 9px; background: var(--row-alt); }
.cx-row > span { min-width: 0; overflow-wrap: anywhere; }
.cx-row > .cx-c-actions, .cx-row > .cx-c-status { overflow-wrap: normal; }
.cx-c-label b { font-weight: 650; }
.cx-c-date { color: var(--muted); font-size: 13px; }
.cx-c-phone { white-space: nowrap; }
.cx-c-phone .cx-muted { white-space: normal; }
.cx-c-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cx-kind { font-style: normal; font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; margin-left: 4px; white-space: nowrap; }
.cx-sm { padding: 5px 12px; font-size: 13px; white-space: nowrap; }
.cx-empty { padding: 26px 16px; color: var(--muted); margin: 0; text-align: center; }
.cx-foot { margin: 12px 2px 0; font-size: 13px; }
.cx-link { background: none; border: 0; padding: 0; color: var(--mint); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.cx-avatar { display: inline-grid; place-items: center; border-radius: 50%; overflow: hidden; color: var(--mint); background: var(--row-alt); flex-shrink: 0; }
.cx-avatar img, .cx-avatar svg { width: 100%; height: 100%; object-fit: cover; display: block; }

.cx-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.cx-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.cx-chip.ok { background: var(--cx-ok-bg); color: var(--cx-ok); }
.cx-chip.wait { background: var(--amber-soft); color: var(--amber); }
.cx-chip.bad { background: var(--coral-soft); color: var(--coral); }
.cx-chip.idle { background: var(--slate-soft, var(--line)); color: var(--muted); }

/* telas pequenas: cada conexão vira um bloco compacto, com as ações sempre visíveis */
@media (max-width: 1100px) {
  .cx-th { display: none; }
  .cx-row { grid-template-columns: 44px 1fr auto; grid-template-areas: "pic label status" "pic phone status" "pic profile actions" "pic proxy actions"; row-gap: 2px; padding: 12px 14px; }
  .cx-c-pic { grid-area: pic; align-self: start; }
  .cx-c-label { grid-area: label; }
  .cx-c-phone { grid-area: phone; font-size: 13px; white-space: normal; }
  .cx-c-profile { grid-area: profile; font-size: 13px; color: var(--muted); }
  .cx-c-status { grid-area: status; justify-self: end; }
  .cx-c-proxy { grid-area: proxy; font-size: 12px; color: var(--muted); }
  .cx-c-date { display: none; }
  .cx-c-actions { grid-area: actions; align-self: end; }
}
@media (max-width: 560px) {
  .cx-head { flex-direction: column; }
  .cx-head-actions { width: 100%; }
  .cx-new { flex: 1; }
  .cx-search { min-width: 0; width: 100%; }
  .cx-row { grid-template-columns: 40px 1fr; grid-template-areas: "pic label" "pic phone" "pic profile" "pic status" "pic actions"; }
  .cx-c-status { justify-self: start; }
  .cx-c-proxy { display: none; }
  .cx-c-actions { justify-content: flex-start; margin-top: 6px; }
}

/* ---------- janelas ---------- */
.cx-back { position: fixed; inset: 0; background: rgba(10, 16, 11, .48); display: grid; place-items: center; z-index: 70; padding: 16px; }
.cx-modal { background: var(--surface); color: var(--ink); border-radius: 18px; padding: 20px 22px; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.cx-modal-sm { width: min(440px, 100%); }
.cx-mhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cx-mhead h3 { margin: 0; font-size: 18px; }
.cx-x { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.cx-x:hover { background: var(--hover); color: var(--ink); }
.cx-desc { margin: -4px 0 4px; }
.cx-hint { margin: -6px 0 2px; font-size: 12px; }
.cx-req { color: var(--coral); }
.cx-modal select, .cx-modal input[type="text"], .cx-modal input[type="search"] { width: 100%; border: 1px solid var(--line); background: var(--field-bg); color: var(--ink); border-radius: 10px; padding: 9px 11px; font: inherit; }
.cx-modal select:focus, .cx-modal input:focus { outline: 2px solid #74b721; outline-offset: 1px; }
.cx-mfoot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.cx-mfoot button:disabled { opacity: .55; cursor: not-allowed; }
.cx-btn-danger { background: var(--coral); color: #fff; border: 1px solid var(--coral); border-radius: 10px; padding: 8px 16px; font-weight: 700; cursor: pointer; }
.cx-danger { color: var(--coral); border-color: var(--coral-soft); }
.cx-sec { margin: 12px 0 2px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.cx-expander { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 1px solid var(--line); background: var(--row-alt); color: var(--ink); border-radius: 10px; padding: 10px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.cx-expander small { color: var(--muted); font-weight: 500; }
.cx-expander[aria-expanded="true"] svg { transform: rotate(180deg); }
.cx-proxy-body { display: flex; flex-direction: column; gap: 6px; padding: 10px 2px 0; }
.cx-proxy-body .modal-hint { margin: 0; }
.cx-results { list-style: none; margin: 0; padding: 4px; border: 1px solid var(--line); border-radius: 10px; max-height: 210px; overflow-y: auto; }
.cx-results button { width: 100%; text-align: left; border: 0; background: transparent; color: var(--ink); padding: 8px 10px; border-radius: 8px; font: inherit; cursor: pointer; }
.cx-results button:hover, .cx-results button:focus-visible { background: var(--hover); }
.cx-results small { color: var(--muted); }
.cx-chosen { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--v4-chip-on-line, var(--line)); background: var(--v4-chip-on-bg, var(--row-alt)); border-radius: 10px; padding: 9px 12px; }

.cx-ident { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 6px 0 4px; }
.cx-ident-name { font-size: 16px; }
.cx-ident > div { font-size: 13px; line-height: 1.5; min-width: 0; }
.cx-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cx-actions button:disabled { opacity: .5; cursor: not-allowed; }
.cx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 0; }
.cx-kv dt { font-size: 12px; color: var(--muted); }
.cx-kv dd { margin: 1px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.cx-flows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cx-flows li { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
@media (max-width: 520px) { .cx-grid { grid-template-columns: 1fr; } .cx-ident { grid-template-columns: auto 1fr; } .cx-ident .cx-chip { grid-column: 1 / -1; justify-self: start; } }

/* chave liga/desliga: verde ligada, cinza desligada */
.cx-switchrow { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 8px 0; border-top: 1px solid var(--line); }
.cx-switchrow:first-of-type { border-top: 0; }
.cx-switchrow small { display: block; color: var(--muted); font-size: 12px; line-height: 1.45; margin-top: 2px; }
.cx-switch { position: relative; flex-shrink: 0; width: 44px; height: 26px; border-radius: 999px; border: 0; background: #b9c0b6; cursor: pointer; transition: background .15s; }
.cx-switch span { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.cx-switch.on { background: var(--cx-on); }
.cx-switch.on span { transform: translateX(18px); }
.cx-switch:disabled { opacity: .5; cursor: not-allowed; }
:root[data-theme="dark"] .cx-switch:not(.on) { background: #4a554b; }

.cx-toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 80; max-width: min(520px, calc(100vw - 32px)); }
.cx-toast.on { opacity: 1; transform: translate(-50%, 0); }
:root[data-theme="dark"] .cx-modal, :root[data-theme="dark"] .cx-results { color-scheme: dark; }

/* ---------- Conectar (QR code / código) ---------- */
.cx-tabs { display: flex; gap: 4px; padding: 4px; background: var(--row-alt); border-radius: 10px; margin: 4px 0 12px; }
.cx-tab { flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.cx-tab.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.cx-pair { display: grid; justify-items: center; gap: 10px; min-height: 120px; margin: 4px 0 8px; text-align: center; }
.cx-qr { width: 264px; max-width: 100%; aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--line); background: #fff; padding: 8px; image-rendering: pixelated; }
.cx-paircode { font: 700 30px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; color: var(--ink); background: var(--row-alt); border: 1px dashed var(--line); border-radius: 12px; padding: 14px 20px; user-select: all; }
.cx-pair-wait { display: grid; justify-items: center; gap: 10px; align-content: center; color: var(--muted); font-size: 14px; min-height: 120px; }
.cx-pair-wait p { margin: 0; color: var(--ink); }
.cx-pair-done { display: grid; justify-items: center; gap: 4px; padding: 18px 0 6px; }
.cx-pair-done p { margin: 0; }
.cx-pair-live { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.cx-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); animation: cx-pulse 1.4s ease-in-out infinite; }
.cx-spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--mint); animation: cx-spin .8s linear infinite; }
.cx-steps { margin: 6px 0 0; padding-left: 20px; font-size: 13px; line-height: 1.55; color: var(--muted); }
.cx-steps b { color: var(--ink); font-weight: 600; }
.cx-mfoot-left { justify-content: flex-start; margin-top: 4px; }
@keyframes cx-spin { to { transform: rotate(360deg); } }
@keyframes cx-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .cx-dot, .cx-spinner { animation: none; } }
