/* ==========================================================================
   Zapbot — camada semântica de tema (/app)
   Claro e escuro. Os tokens --zap-* (zapbot-tokens.css) continuam sendo a
   paleta bruta compartilhada com a landing; aqui eles ganham PAPEL, e o
   papel muda com o tema.

   Três estados: sem atributo = segue o sistema; [data-theme="light"] e
   [data-theme="dark"] mandam sobre ele. Toda cor é definida primeiro no
   :root puro — nenhuma vive só dentro de media query, senão o tema
   forçado herda buraco.
   ========================================================================== */

:root {
  /* --- Claro (padrão do :root) -------------------------------------- */
  --ui-bg: #f5f7f6;
  --ui-surface: #ffffff;
  --ui-surface-2: #f1f4f2;
  --ui-surface-3: #e9eeeb;
  --ui-line: rgba(7, 16, 12, 0.10);
  --ui-line-strong: rgba(7, 16, 12, 0.18);
  --ui-text: #0e1a13;
  --ui-muted: #56675d;
  --ui-faint: #8a9a91;

  /* Sobre branco o verde de marca dá 1.9:1 — não serve para texto.
     Texto verde usa o profundo; o de marca fica só em preenchimento. */
  --ui-accent: #0b7a3d;
  --ui-accent-fill: #25d366;
  --ui-accent-ink: #04160c;
  --ui-accent-soft: rgba(37, 211, 102, 0.12);

  --ui-amber: #9a5b00;
  --ui-amber-fill: #f5a524;
  --ui-amber-soft: rgba(245, 165, 36, 0.14);

  --ui-red: #b8342a;
  --ui-red-soft: rgba(241, 79, 68, 0.10);

  /* No claro a borda sozinha some sobre cinza; uma sombra baixíssima
     devolve a separação sem virar "card flutuante". */
  --ui-shadow: 0 1px 2px rgba(7, 16, 12, 0.05), 0 6px 18px -12px rgba(7, 16, 12, 0.14);
  --ui-shadow-lg: 0 20px 50px -24px rgba(7, 16, 12, 0.28);
  --ui-overlay: rgba(20, 30, 24, 0.42);
}

/* --- Escuro: segue o sistema, a não ser que o claro tenha sido forçado -- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ui-bg: #07100c;
    --ui-surface: #0d1a13;
    --ui-surface-2: #12241a;
    --ui-surface-3: #17301f;
    --ui-line: rgba(255, 255, 255, 0.08);
    --ui-line-strong: rgba(255, 255, 255, 0.16);
    --ui-text: #e8f5ec;
    --ui-muted: #8fb7a1;
    --ui-faint: #5f7d6c;

    --ui-accent: #25d366;
    --ui-accent-fill: #25d366;
    --ui-accent-ink: #04160c;
    --ui-accent-soft: rgba(37, 211, 102, 0.12);

    --ui-amber: #f5a524;
    --ui-amber-fill: #f5a524;
    --ui-amber-soft: rgba(245, 165, 36, 0.14);

    --ui-red: #f14f44;
    --ui-red-soft: rgba(241, 79, 68, 0.10);

    --ui-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -16px rgba(0, 0, 0, 0.7);
    --ui-shadow-lg: 0 30px 70px -30px rgba(0, 0, 0, 0.85);
    --ui-overlay: rgba(3, 8, 5, 0.72);
  }
}

/* --- Escuro forçado pelo botão ----------------------------------------- */
:root[data-theme="dark"] {
  --ui-bg: #07100c;
  --ui-surface: #0d1a13;
  --ui-surface-2: #12241a;
  --ui-surface-3: #17301f;
  --ui-line: rgba(255, 255, 255, 0.08);
  --ui-line-strong: rgba(255, 255, 255, 0.16);
  --ui-text: #e8f5ec;
  --ui-muted: #8fb7a1;
  --ui-faint: #5f7d6c;

  --ui-accent: #25d366;
  --ui-accent-fill: #25d366;
  --ui-accent-ink: #04160c;
  --ui-accent-soft: rgba(37, 211, 102, 0.12);

  --ui-amber: #f5a524;
  --ui-amber-fill: #f5a524;
  --ui-amber-soft: rgba(245, 165, 36, 0.14);

  --ui-red: #f14f44;
  --ui-red-soft: rgba(241, 79, 68, 0.10);

  --ui-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -16px rgba(0, 0, 0, 0.7);
  --ui-shadow-lg: 0 30px 70px -30px rgba(0, 0, 0, 0.85);
  --ui-overlay: rgba(3, 8, 5, 0.72);
}

/* Cor do chrome do navegador acompanha, senão a barra do sistema destoa. */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: var(--zap-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

a { color: var(--ui-accent); text-decoration: none; }
.hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--ui-accent-fill);
  outline-offset: 2px;
  border-radius: 6px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--zap-2);
  font-family: var(--zap-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--ui-text);
  flex: none;
}
.brand .logo { width: 26px; height: 26px; object-fit: contain; display: block; }

/* --------------------------------------------------------------------------
   Status-dot — assinatura do produto
   -------------------------------------------------------------------------- */
.zap-dot, .pill .d {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  position: relative;
  background: var(--ui-accent-fill);
}
.zap-dot--off, .pill.off .d { background: var(--ui-faint); }
.zap-dot--amber { background: var(--ui-amber-fill); }

.pill.on .d::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid var(--ui-accent-fill);
  opacity: 0.35;
  animation: zap-pulse 2.4s ease-out infinite;
}
@keyframes zap-pulse {
  0% { transform: scale(0.7); opacity: 0.6; }
  70%, 100% { transform: scale(1.35); opacity: 0; }
}

/* ==========================================================================
   Botões — o JS troca textContent nos estados de carga, então nada de
   elemento filho dentro de botão primário.
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--zap-2);
  height: 40px;
  padding: 0 var(--zap-5);
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: var(--zap-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease,
    color 0.16s ease, box-shadow 0.16s ease;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { height: 32px; padding: 0 var(--zap-3); font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--ui-accent-fill);
  color: var(--ui-accent-ink);
}
.btn-primary:not(:disabled):hover { background: #33dd72; }
.btn-primary:not(:disabled):active { background: var(--zap-green-press); }

.btn-ghost {
  background: var(--ui-surface);
  border-color: var(--ui-line);
  color: var(--ui-muted);
}
.btn-ghost:not(:disabled):hover { border-color: var(--ui-line-strong); color: var(--ui-text); }

.btn-danger {
  background: transparent;
  border-color: var(--ui-line);
  color: var(--ui-muted);
}
.btn-danger:not(:disabled):hover {
  border-color: var(--ui-red);
  color: var(--ui-red);
  background: var(--ui-red-soft);
}

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ui-line);
  border-radius: 10px;
  background: var(--ui-surface);
  color: var(--ui-muted);
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease;
}
.icon-btn:hover { color: var(--ui-text); border-color: var(--ui-line-strong); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; }

/* O ícone diz em qual dos três estados o tema está. */
.icon-btn .i-sun, .icon-btn .i-moon { display: none; }
[data-theme-mode="claro"] .icon-btn .i-sys,
[data-theme-mode="escuro"] .icon-btn .i-sys { display: none; }
[data-theme-mode="claro"] .icon-btn .i-sun { display: block; }
[data-theme-mode="escuro"] .icon-btn .i-moon { display: block; }

/* ==========================================================================
   Barra superior
   ========================================================================== */
/* O sticky vai no WRAPPER, não na .topbar.
   
   #app-header tem exatamente a altura da barra, então uma .topbar sticky
   dentro dele não tinha para onde viajar: o elemento gruda no topo do próprio
   pai e some junto com ele. O sintoma era a navbar desaparecer assim que a
   página rolava, deixando um vão de 60px acima da coluna da frota — que
   continua ancorada em top:60 esperando por ela. */
#app-header {
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar {
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-line);
}
/* Sem max-width nem centralização.
   
   A grade do portal embaixo é de borda a borda, então centralizar só a barra
   criava DUAS bordas esquerdas — e a distância entre elas crescia com a tela:
   numa janela de 1728px eram 64px de margem automática mais 32 de padding, com
   a logo em 96 e a coluna de conexões em 16.

   Os recuos são assimétricos de propósito: a esquerda acompanha a coluna de
   conexões (16px), a direita acompanha os painéis de conteúdo (32px). Cada
   lado se alinha à região que está embaixo dele, e uma única linha vertical
   desce a página de cada lado. */
.topbar__in {
  display: flex;
  align-items: center;
  gap: var(--zap-5);
  height: 60px;
  padding: 0 var(--zap-6) 0 var(--zap-4);
}
.topbar__right {
  display: flex;
  align-items: center;
  gap: var(--zap-3);
  margin-left: auto;
}

.search {
  position: relative;
  flex: 1 1 420px;
  max-width: 460px;
}
.search input {
  width: 100%;
  height: 38px;
  padding: 0 42px 0 38px;
  border-radius: 10px;
  background: var(--ui-surface-2);
  border: 1px solid transparent;
  color: var(--ui-text);
  font-family: var(--zap-sans);
  font-size: 14px;
  transition: border-color 0.16s ease, background 0.16s ease;
}
.search input::placeholder { color: var(--ui-faint); }
.search input:focus {
  outline: none;
  background: var(--ui-surface);
  border-color: var(--ui-accent-fill);
}
.search svg {
  position: absolute; left: 12px; top: 11px;
  width: 16px; height: 16px;
  fill: none; stroke: var(--ui-faint); stroke-width: 2;
  pointer-events: none;
}
.search kbd {
  position: absolute; right: 10px; top: 10px;
  font-family: var(--zap-mono);
  font-size: 11px;
  color: var(--ui-faint);
  border: 1px solid var(--ui-line);
  border-radius: 5px;
  padding: 1px 6px;
  pointer-events: none;
}
.search input:focus ~ kbd,
.search input:not(:placeholder-shown) ~ kbd { display: none; }

.who { display: flex; align-items: center; gap: var(--zap-3); }
.who .u { display: flex; flex-direction: column; line-height: 1.25; text-align: right; }
.who .u strong { font-size: 13.5px; }
.who .u span { font-size: 12px; color: var(--ui-muted); }

@media (max-width: 900px) {
  .topbar__in { gap: var(--zap-3); padding: 0 var(--zap-4); }
  .who .u, .search kbd { display: none; }
  .search { flex: 1 1 auto; }
}

/* ==========================================================================
   Painel
   ========================================================================== */
.shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--zap-6) var(--zap-6) var(--zap-8);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--zap-4);
  flex-wrap: wrap;
  margin-bottom: var(--zap-5);
}
.page-head h1 {
  font-family: var(--zap-display);
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 2px;
}
.page-head p { margin: 0; color: var(--ui-muted); font-size: 14px; }

/* --------------------------------------------------------------------------
   Trilho de saúde — "está tudo no ar?" respondido primeiro. O plano fica
   à direita como contexto, não como manchete.
   -------------------------------------------------------------------------- */
.rail {
  display: flex;
  align-items: center;
  gap: var(--zap-5);
  flex-wrap: wrap;
  padding: var(--zap-3) var(--zap-5);
  margin-bottom: var(--zap-5);
  border-radius: 12px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  box-shadow: var(--ui-shadow);
}
.rail__health { display: flex; align-items: center; gap: var(--zap-4); }
.rail__stat {
  display: inline-flex;
  align-items: center;
  gap: var(--zap-2);
  font-size: 13.5px;
  color: var(--ui-muted);
}
.rail__stat b {
  font-family: var(--zap-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--ui-text);
}
/* "fora" só ganha peso quando existe algum fora — cor é estado. */
.rail.has-off .rail__stat.is-off b { color: var(--ui-amber); }
.rail.has-off .rail__stat.is-off .zap-dot { background: var(--ui-amber-fill); }

.rail__plan {
  display: flex;
  align-items: center;
  gap: var(--zap-3);
  margin-left: auto;
}
.rail__plan-name {
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--ui-accent);
  background: var(--ui-accent-soft);
}
.rail__usage { font-family: var(--zap-mono); font-size: 12.5px; color: var(--ui-muted); }
.rail__usage b { color: var(--ui-text); font-weight: 600; }
.rail__bar {
  width: 96px; height: 4px;
  border-radius: 999px;
  background: var(--ui-surface-3);
  overflow: hidden;
}
.rail__bar i {
  display: block; height: 100%;
  border-radius: 999px;
  background: var(--ui-accent-fill);
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
}
.rail.at-limit { border-color: var(--ui-amber-fill); }
.rail.at-limit .rail__bar i { background: var(--ui-amber-fill); }
.rail__note {
  flex: 1 1 100%;
  font-size: 13px;
  color: var(--ui-amber);
}

@media (max-width: 640px) {
  .rail__plan { margin-left: 0; flex: 1 1 100%; }
}

/* --------------------------------------------------------------------------
   Cartão de instância — liderado pelo status, credenciais em mono
   -------------------------------------------------------------------------- */
.inst-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--zap-4);
}
.inst {
  display: flex;
  flex-direction: column;
  gap: var(--zap-4);
  padding: var(--zap-4) var(--zap-5) var(--zap-5);
  border-radius: 14px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  box-shadow: var(--ui-shadow);
  transition: border-color 0.16s ease, transform 0.16s ease;
  animation: ui-in 0.24s ease both;
}
.inst:hover { border-color: var(--ui-line-strong); transform: translateY(-1px); }
@keyframes ui-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.inst-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--zap-3);
}
.inst-name { font-size: 16px; font-weight: 600; line-height: 1.3; }
.inst-phone {
  font-family: var(--zap-mono);
  font-size: 12.5px;
  color: var(--ui-muted);
  margin-top: 2px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.pill.on { color: var(--ui-accent); background: var(--ui-accent-soft); }
.pill.off { color: var(--ui-muted); background: var(--ui-surface-2); }

/* Credenciais: é o que o dev veio buscar. Mono, truncado, copiável. */
.cred {
  border-radius: 10px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-line);
  overflow: hidden;
}
.cred-row {
  display: flex;
  align-items: center;
  gap: var(--zap-2);
  padding: 8px var(--zap-3);
  border-bottom: 1px solid var(--ui-line);
}
.cred-row:last-child { border-bottom: 0; }
.cred-row .k {
  flex: none;
  width: 58px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ui-faint);
}
.cred-row .v {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--zap-mono);
  font-size: 12px;
  color: var(--ui-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Webhook ausente é informação, não valor: fica em tom apagado. */
.cred-row .v.is-empty { color: var(--ui-faint); font-style: italic; cursor: default; }

/* O valor é clicável: seleciona e copia. A affordance precisa aparecer —
   texto que reage a clique sem sinal nenhum é armadilha, não atalho. */
.cred-row .v:not(.is-empty) {
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 3px;
  margin: -1px -3px;
  transition: background 0.14s ease;
}
.cred-row:hover .v:not(.is-empty) { background: var(--ui-surface); }
.cred-row .v:not(.is-empty):hover { background: var(--ui-accent-soft); }
.cred-row .v::selection { background: var(--ui-accent-fill); color: var(--ui-accent-ink); }

.copy {
  flex: none;
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid var(--ui-line);
  background: var(--ui-surface);
  color: var(--ui-muted);
  font-family: var(--zap-sans);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.copy:hover { color: var(--ui-text); border-color: var(--ui-line-strong); }
.copy.ok {
  color: var(--ui-accent-ink);
  background: var(--ui-accent-fill);
  border-color: var(--ui-accent-fill);
}

/* Webhook ausente é integração pela metade: o botão de definir chama
   atenção só enquanto está faltando. Depois de configurado ele vira
   "editar" e volta ao tom neutro dos outros. */
.copy--call {
  color: var(--ui-accent);
  border-color: var(--ui-accent-fill);
  background: var(--ui-accent-soft);
  font-weight: 600;
}
.copy--call:hover {
  color: var(--ui-accent-ink);
  background: var(--ui-accent-fill);
}

.inst-actions { display: flex; gap: var(--zap-2); }
.inst-actions .btn { flex: 1 1 auto; }

.empty {
  padding: var(--zap-8) var(--zap-5);
  text-align: center;
  border-radius: 14px;
  background: var(--ui-surface);
  border: 1px dashed var(--ui-line-strong);
}
.empty h3 { margin: 0 0 var(--zap-2); font-size: 17px; font-weight: 600; }
.empty p { margin: 0; color: var(--ui-muted); font-size: 14px; }

.skeleton {
  height: 190px;
  border-radius: 14px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--ui-surface-2), transparent);
  animation: ui-shimmer 1.3s infinite;
}
@keyframes ui-shimmer {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

/* ==========================================================================
   Modal do QR — a cerimônia de pareamento
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--zap-5);
  background: var(--ui-overlay);
  backdrop-filter: blur(6px);
  animation: ui-fade 0.18s ease;
}
@keyframes ui-fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 420px;
  padding: var(--zap-5);
  border-radius: 16px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  box-shadow: var(--ui-shadow-lg);
  animation: ui-pop 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes ui-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--zap-3);
  margin-bottom: var(--zap-2);
}
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 600; }
.modal .x {
  width: 30px; height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ui-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.modal .x:hover { color: var(--ui-text); background: var(--ui-surface-2); }
.modal .sub { margin: 0 0 var(--zap-4); font-size: 13.5px; color: var(--ui-muted); }
.modal .sub strong { color: var(--ui-text); }

/* Moldura branca nos dois temas: leitor de QR precisa desse contraste. */
.qr-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  padding: var(--zap-4);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}
.qr-frame img {
  width: 100%;
  max-width: 240px;
  display: block;
  border-radius: 4px;
  animation: ui-in 0.24s ease;
}
.qr-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--zap-2);
  margin-top: var(--zap-4);
  min-height: 34px;
  font-size: 13.5px;
  color: var(--ui-muted);
}

.spinner {
  width: 16px; height: 16px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--ui-accent-soft);
  border-top-color: var(--ui-accent-fill);
  animation: ui-spin 0.7s linear infinite;
}
.qr-frame .spinner {
  width: 26px; height: 26px;
  border-width: 3px;
  border-color: rgba(7, 16, 12, 0.15);
  border-top-color: var(--zap-green-press);
}
@keyframes ui-spin { to { transform: rotate(360deg); } }

.connected-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--zap-3);
  padding: var(--zap-6) var(--zap-4) var(--zap-4);
  text-align: center;
  animation: ui-in 0.26s ease;
}
.connected-badge .check {
  width: 54px; height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 26px;
  color: var(--ui-accent-ink);
  background: var(--ui-accent-fill);
  box-shadow: 0 0 0 8px var(--ui-accent-soft);
}
.connected-badge strong { font-size: 17px; }
.connected-badge p {
  margin: 0;
  max-width: 30ch;
  font-size: 14px;
  color: var(--ui-muted);
}
.connected-badge .btn { margin-top: var(--zap-2); min-width: 160px; }

/* ==========================================================================
   Diálogo do sistema
   Superfície elevada do mesmo sistema — mesma borda, mesmo raio, mesma
   sombra dos cartões. Não é um objeto estranho colado por cima.
   ========================================================================== */
.dlg {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: min(440px, calc(100vw - 32px));
  width: 100%;
  color: var(--ui-text);
}
.dlg::backdrop {
  background: var(--ui-overlay);
  backdrop-filter: blur(4px);
}
.dlg[open] { animation: ui-pop 0.18s cubic-bezier(0.4, 0, 0.2, 1); }
.dlg[open]::backdrop { animation: ui-fade 0.18s ease; }

/* Trava a rolagem do fundo: rolar a página atrás de um diálogo modal
   desorienta e some com o contexto da decisão. */
body.has-dialog { overflow: hidden; }

.dlg__box {
  padding: var(--zap-5);
  border-radius: 16px;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  box-shadow: var(--ui-shadow-lg);
}
.dlg__title {
  margin: 0 0 var(--zap-2);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.dlg__desc {
  margin: 0 0 var(--zap-4);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ui-muted);
}
.dlg__field { margin-bottom: var(--zap-5); }

.dlg__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--zap-2);
}
.dlg__actions .btn { min-width: 116px; }

/* Confirmação destrutiva: aqui a ação principal DESTRÓI, então ela tem
   que parecer isso. Vermelho sólido só neste caso. */
.btn-danger-solid {
  background: var(--ui-red);
  color: #fff;
  border-color: transparent;
}
.btn-danger-solid:not(:disabled):hover { filter: brightness(1.08); }

@media (max-width: 480px) {
  /* No celular o diálogo encosta na base: é onde o polegar alcança. */
  .dlg {
    max-width: 100%;
    margin: auto auto 0;
  }
  .dlg__box {
    border-radius: 16px 16px 0 0;
    padding: var(--zap-5) var(--zap-4) var(--zap-6);
  }
  .dlg__actions { flex-direction: column-reverse; }
  .dlg__actions .btn { width: 100%; height: 44px; }
}

/* ==========================================================================
   Toasts
   ========================================================================== */
/* Canto superior direito, abaixo da barra: sobrepor a busca e o botão de
   tema esconderia justamente os controles que a pessoa acabou de usar.
   column-reverse põe o mais recente no topo — o DOM continua recebendo
   append, então o mais novo é o último filho. */
.toast-wrap {
  position: fixed;
  right: var(--zap-5);
  top: calc(60px + var(--zap-3));
  z-index: 90;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--zap-2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: var(--zap-3);
  padding: 12px var(--zap-3) 14px var(--zap-4);
  border-radius: 12px;
  overflow: hidden;
  background: var(--ui-surface);
  border: 1px solid var(--ui-line);
  border-left: 2px solid var(--ui-accent-fill);
  color: var(--ui-text);
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: var(--ui-shadow-lg);
  pointer-events: auto;
  cursor: grab;
  touch-action: pan-y;
  animation: toast-in 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast.is-dragging { cursor: grabbing; transition: none; }

/* Saída: encolhe a própria altura para os de baixo subirem sem salto. */
.toast.is-out {
  height: 0 !important;
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: calc(var(--zap-2) * -1);
  opacity: 0;
  transform: translateX(24px);
  border-width: 0;
  transition: height 0.26s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.18s ease, transform 0.22s ease, padding 0.26s ease,
    margin 0.26s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Ícone: repete a informação da cor, para quem não distingue verde de
   vermelho não depender só dela. */
.toast__icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  flex: none;
  fill: none;
  stroke: var(--ui-accent);
  stroke-width: 2;
}
.toast__msg { min-width: 0; word-break: break-word; }

.toast__x {
  width: 24px;
  height: 24px;
  margin: -2px -2px 0 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ui-faint);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.toast__x:hover { color: var(--ui-text); background: var(--ui-surface-2); }
.toast__x svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }

/* A barra é o cronômetro, não enfeite: o fim dela dispara o fechamento. */
/* Sem `grid-column`: um filho absoluto COM área de grid definida passa a
   se ancorar nessa área, não na caixa de preenchimento — e a barra ficava
   recuada 18px de cada lado em vez de ir de ponta a ponta. */
.toast__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--ui-surface-3);
}
.toast__bar i {
  display: block;
  height: 100%;
  transform-origin: left center;
  background: var(--ui-accent-fill);
  animation: toast-bar linear forwards;
}
@keyframes toast-bar {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* Pausa enquanto se lê. Se a barra continuasse correndo escondida, ela
   estaria mentindo sobre o tempo que resta. */
.toast:hover .toast__bar i,
.toast:focus-within .toast__bar i,
.toast.is-dragging .toast__bar i {
  animation-play-state: paused;
}
/* Sob movimento reduzido o relógio vira setTimeout e a barra fica cheia. */
.toast.is-still .toast__bar i { animation: none; }

.toast--err {
  border-left-color: var(--ui-red);
}
.toast--err .toast__icon { stroke: var(--ui-red); }
.toast--err .toast__bar i { background: var(--ui-red); }

.toast--warn { border-left-color: var(--ui-amber-fill); }
.toast--warn .toast__icon { stroke: var(--ui-amber); }
.toast--warn .toast__bar i { background: var(--ui-amber-fill); }

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .toast.is-out { transition: none; }
}

/* ==========================================================================
   Portão de entrada — o cartão segue o tema; o painel ilustrado à
   esquerda continua escuro sempre, porque é ambiente de marca, não UI.
   ========================================================================== */
.auth-card { color: var(--ui-text); }
.auth-sub { color: var(--ui-muted); font-size: 14px; margin: var(--zap-3) 0 var(--zap-6); }

.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  margin-bottom: var(--zap-5);
  border-radius: 999px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-line);
}
.tabs::before {
  content: "";
  position: absolute;
  top: 4px; left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  border-radius: 999px;
  background: var(--ui-accent-fill);
  transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}
.tabs.is-signup::before { transform: translateX(100%); }
.tab {
  position: relative;
  z-index: 1;
  height: 38px;
  border: 0;
  background: transparent;
  border-radius: 999px;
  font-family: var(--zap-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ui-muted);
  cursor: pointer;
  transition: color 0.2s ease;
}
.tab.active { color: var(--ui-accent-ink); }

.field { margin-bottom: var(--zap-4); }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ui-muted);
}
.field input {
  width: 100%;
  height: 46px;
  padding: 0 var(--zap-4);
  border-radius: 10px;
  background: var(--ui-surface-2);
  border: 1px solid var(--ui-line);
  color: var(--ui-text);
  font-family: var(--zap-sans);
  font-size: 15px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
.field input::placeholder { color: var(--ui-faint); }
.field input:hover { border-color: var(--ui-line-strong); }
.field input:focus {
  outline: none;
  background: var(--ui-surface);
  border-color: var(--ui-accent-fill);
  box-shadow: 0 0 0 3px var(--ui-accent-soft);
}
.field .hint { margin-top: 6px; font-size: 12px; color: var(--ui-faint); }

.pw-wrap { position: relative; }
.field--pw input { padding-right: 46px; }
.pw-toggle {
  position: absolute;
  right: 6px; top: 6px;
  width: 34px; height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ui-faint);
  cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease;
}
.pw-toggle:hover { color: var(--ui-text); background: var(--ui-surface-2); }
.pw-toggle svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.pw-toggle .icon-off { display: none; }
.pw-toggle.is-on .icon-on { display: none; }
.pw-toggle.is-on .icon-off { display: block; }

.field-msg {
  display: none;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.45;
}
.field-msg.is-on { display: block; animation: ui-in 0.18s ease; }
.field-msg.is-error { color: var(--ui-red); }
.field-msg.is-warn { color: var(--ui-amber); }
.field-msg.is-ok { color: var(--ui-accent); }
.field-msg button {
  border: 0; background: transparent; padding: 0;
  font: inherit;
  color: var(--ui-accent);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
.field input.is-invalid { border-color: var(--ui-red); }
.field input.is-invalid:focus { box-shadow: 0 0 0 3px var(--ui-red-soft); }

.pw-meter { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 8px; }
.pw-meter span {
  height: 3px;
  border-radius: 999px;
  background: var(--ui-surface-3);
  transition: background 0.24s ease;
}
.pw-meter[data-score="1"] span:nth-child(-n + 1) { background: var(--ui-red); }
.pw-meter[data-score="2"] span:nth-child(-n + 2) { background: var(--ui-amber-fill); }
.pw-meter[data-score="3"] span:nth-child(-n + 3) { background: #7fd1a3; }
.pw-meter[data-score="4"] span { background: var(--ui-accent-fill); }

#signup-pw-hint strong { color: var(--ui-text); }
#signup-pw-hint.is-weak strong { color: var(--ui-red); }
#signup-pw-hint.is-fair strong { color: var(--ui-amber); }
#signup-pw-hint.is-good strong,
#signup-pw-hint.is-strong strong { color: var(--ui-accent); }

.alert {
  padding: 10px var(--zap-4);
  margin-bottom: var(--zap-4);
  border-radius: 10px;
  font-size: 13.5px;
  border: 1px solid;
  animation: ui-in 0.2s ease;
}
.alert-error { color: var(--ui-red); background: var(--ui-red-soft); border-color: var(--ui-red); }
.alert-ok { color: var(--ui-accent); background: var(--ui-accent-soft); border-color: var(--ui-accent-fill); }

#form-setup:not(.hidden) {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: var(--zap-5);
}

/* Entrada dos formulários: a direção espelha a posição da aba. */
.auth-card form.is-entering > * {
  animation: field-in-right 0.32s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.auth-card.dir-left form.is-entering > * { animation-name: field-in-left; }
.auth-card form.is-entering > *:nth-child(1) { animation-delay: 0.03s; }
.auth-card form.is-entering > *:nth-child(2) { animation-delay: 0.08s; }
.auth-card form.is-entering > *:nth-child(3) { animation-delay: 0.13s; }
.auth-card form.is-entering > *:nth-child(4) { animation-delay: 0.18s; }
.auth-card form.is-entering > *:nth-child(5) { animation-delay: 0.23s; }
@keyframes field-in-right {
  from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; }
}
@keyframes field-in-left {
  from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: none; }
}
.auth-card.is-first { animation: card-settle 0.5s cubic-bezier(0.4, 0, 0.2, 1) both; }
.auth-card.is-first form.is-entering > * { animation-name: field-in-up; }
@keyframes card-settle {
  from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; }
}
@keyframes field-in-up {
  from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; }
}

.auth-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
}
.auth-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--zap-7) var(--zap-5);
  background: var(--ui-bg);
}
.auth-card { width: 100%; max-width: 400px; }

@media (max-width: 940px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}

/* ==========================================================================
   Responsivo
   Três quebras, cada uma resolvendo um problema concreto — não larguras
   redondas por hábito.
   ========================================================================== */

/* 900px: a identidade do usuário vira redundante (ele sabe quem é) e a
   busca precisa do espaço que ela ocupava. */
@media (max-width: 900px) {
  .shell { padding: var(--zap-5) var(--zap-4) var(--zap-7); }
  .page-head h1 { font-size: 23px; }
}

/* 720px: a barra deixa de caber em uma linha. A busca desce inteira em
   vez de virar um campo espremido e inútil. */
@media (max-width: 720px) {
  .topbar__in {
    height: auto;
    flex-wrap: wrap;
    padding: var(--zap-3) var(--zap-4);
    row-gap: var(--zap-3);
  }
  /* A regra que ficava aqui (.search { order: 3 }) era da época em que a busca
     morava na barra superior e precisava quebrar para a linha de baixo. Agora
     ela vive dentro da coluna de conexões, que é um flex column — e o `order`
     órfão jogava o campo para o fim da gaveta, abaixo do plano. Removida em
     vez de sobrescrita: regra morta que ainda tem efeito é pior que nenhuma. */
  .topbar__right { gap: var(--zap-2); }

  .page-head { align-items: stretch; }
  .page-head .btn { width: 100%; }

  /* O trilho empilha: saúde primeiro, plano depois — a ordem de leitura
     é a mesma da pergunta que se faz ao abrir. */
  .rail { gap: var(--zap-3); }
  .rail__plan { margin-left: 0; flex: 1 1 100%; flex-wrap: wrap; }
  .rail__bar { flex: 1 1 80px; width: auto; }
}

/* 420px: cartão de instância em coluna única sem estourar a viewport.
   O min() evita o clássico overflow do minmax fixo em tela estreita. */
@media (max-width: 560px) {
  .inst-grid { grid-template-columns: 1fr; gap: var(--zap-3); }
  .inst { padding: var(--zap-4); }
  .shell { padding: var(--zap-4) var(--zap-3) var(--zap-6); }
  .modal { padding: var(--zap-4); }
  /* A barra vira duas linhas abaixo de 720px: o topo desce junto. */
  .toast-wrap { left: var(--zap-3); right: var(--zap-3); top: calc(104px + var(--zap-2)); width: auto; }
  .qr-frame { min-height: 220px; }
  /* Alvo de toque: no celular os botões do cartão precisam de altura. */
  .inst-actions .btn { height: 40px; }
}

/* A grade nunca pode ser mais larga que a coluna disponível. */
.inst-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
