/* ==========================================================================
 * HAONchat — builder.css  [owner: Builder]
 * --------------------------------------------------------------------------
 * Estilos do dashboard de 3 colunas (#appShell) do construtor de chatbot:
 *   ESQUERDA = funil (cartões de etapa numerados) + persona + FAQ
 *   CENTRO   = preview de conversa estilo WhatsApp (bolhas clonadas de
 *              web-ref/wapool.css) + simulador
 *   DIREITA  = status do bot + "Salvar e ligar" + ponto de montagem do brinde
 *
 * Regras do CONTRATO:
 *  - Zero cor hardcoded fora de fallbacks de var() — só CSS vars do styles.css.
 *  - Dark-aware automático (as vars já trocam via [data-theme="dark"]).
 *  - Responsivo: 3col (desktop) -> empilha no mobile (ordem builder->preview->pool).
 *  - Ergonomia 54: alvos grandes, label negrito acima do input, CTA laranja
 *    único (Salvar e ligar) min-height 54px, feedback humano, prefers-reduced-motion.
 *  - NÃO redeclara tokens nem utilities do styles.css; só ACRESCENTA.
 * ========================================================================== */

/* host dentro do #appShell */
.bld-host{
  display:flex;flex-direction:column;gap:16px;
  width:100%;min-height:0;
  padding:clamp(14px,2.4vw,26px);
  box-sizing:border-box;
}

/* ---------- cabeçalho ---------- */
.bld-head{
  display:flex;align-items:center;justify-content:space-between;gap:14px;flex-wrap:wrap;
}
.bld-head-title{font-size:clamp(20px,2.6vw,26px);font-weight:700;color:var(--ink);line-height:1.15}
.bld-head-sub{font-size:14.5px;color:var(--soft);margin-top:3px;line-height:1.4}

/* loading inicial */
.bld-loading{display:flex;flex-direction:column;align-items:center;gap:14px;padding:60px 18px;color:var(--soft);text-align:center}
.bld-loading p{font-size:15px}

/* ==========================================================================
 * GRID de 3 colunas. Esquerda e direita com largura controlada; centro flui.
 * ========================================================================== */
.bld-grid{
  display:grid;
  grid-template-columns:minmax(320px,1.05fr) minmax(0,1.15fr) minmax(300px,.95fr);
  gap:16px;
  align-items:start;
  min-height:0;
}
.bld-col{display:flex;flex-direction:column;gap:16px;min-width:0;min-height:0}

/* painel reutilizável (card) */
.bld-panel{
  background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:var(--shadow-sm);
  padding:clamp(15px,2vw,20px);
  display:flex;flex-direction:column;gap:14px;min-width:0;
}
.bld-panel-head{display:flex;align-items:flex-start;gap:11px}
.bld-panel-head strong{display:block;font-family:var(--font-display);font-size:16.5px;font-weight:700;color:var(--ink);line-height:1.2}
.bld-panel-head span{display:block;font-size:13px;color:var(--soft);margin-top:2px;line-height:1.4}

/* ícone redondo dos cabeçalhos */
.bld-ico{
  flex:0 0 auto;width:36px;height:36px;border-radius:11px;
  display:grid;place-items:center;color:var(--blue-700);background:var(--blue-100);
}
.bld-ico svg{width:19px;height:19px}
.bld-ico.green{color:var(--green-700);background:var(--green-100)}

.bld-divider{height:1px;background:var(--line);border:0;margin:2px 0}

/* seção dentro de um painel */
.bld-section{display:flex;flex-direction:column;gap:11px}
.bld-section-head{display:flex;align-items:flex-start;gap:10px}
.bld-section-head b{font-size:15px;font-weight:700;color:var(--ink);line-height:1.2}
.bld-section-head span{display:block;font-size:12.5px;color:var(--soft);margin-top:1px;line-height:1.4}
.bld-section-head .bld-ico{width:30px;height:30px;border-radius:9px}
.bld-section-head .bld-ico svg{width:16px;height:16px}

/* botão "adicionar" largura cheia, tracejado discreto */
.bld-add{border-style:dashed!important;color:var(--blue-700)}
.bld-add:hover{border-color:var(--blue-500)!important;background:var(--blue-100)}
.bld-add .bld-ico{width:auto;height:auto;background:none;color:inherit}
.bld-add .bld-ico svg{width:18px;height:18px}

/* estado vazio compacto dentro de uma seção */
.bld-empty{
  font-size:13.5px;color:var(--soft);line-height:1.5;text-align:center;
  padding:18px 14px;border:1px dashed var(--line-strong);border-radius:12px;
  background:color-mix(in srgb,var(--line) 22%,transparent);
}

/* ==========================================================================
 * ESQUERDA — cartões de ETAPA do funil (numerados)
 * ========================================================================== */
.bld-stages{display:flex;flex-direction:column;gap:10px}
.bld-stage{
  display:flex;gap:12px;align-items:flex-start;
  padding:13px 14px;border:1px solid var(--line);border-radius:14px;
  background:var(--card);
  transition:border-color .15s ease, box-shadow .18s ease, transform .12s ease;
}
.bld-stage:hover{border-color:var(--green-500);box-shadow:var(--shadow-sm)}
.bld-stage-num{
  flex:0 0 auto;width:30px;height:30px;border-radius:50%;
  display:grid;place-items:center;
  font-family:var(--font-display);font-size:14px;font-weight:800;
  font-variant-numeric:tabular-nums;
  color:#fff;background:linear-gradient(135deg,var(--green-700),var(--green-500));
  box-shadow:0 3px 9px rgba(31,106,74,.3);
}
.bld-stage-body{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;gap:5px}
.bld-stage-name{font-size:15px;font-weight:700;color:var(--ink);line-height:1.2;word-break:break-word}
.bld-stage-goal,.bld-stage-msg{font-size:13px;color:var(--soft);line-height:1.45;word-break:break-word}
.bld-stage-msg{
  color:var(--ink);background:var(--green-050);
  border:1px solid color-mix(in srgb,var(--green-500) 22%,transparent);
  border-radius:10px;padding:7px 10px;font-size:13px;
}
.bld-tag{
  display:inline-block;font-size:10px;font-weight:800;letter-spacing:.04em;
  text-transform:uppercase;color:var(--blue-700);
  margin-right:6px;vertical-align:1px;
}
.bld-faded{color:var(--muted);font-style:italic}

/* coluna de ações do cartão (editar/subir/descer/remover) */
.bld-stage-acts,.bld-faq-acts{
  flex:0 0 auto;display:flex;flex-direction:column;gap:5px;align-items:center;
}
.bld-iconbtn{
  width:34px;height:34px;flex:0 0 auto;border-radius:9px;
  display:grid;place-items:center;
  border:1px solid var(--line);background:var(--card);color:var(--soft);
  cursor:pointer;transition:border-color .14s, color .14s, background .14s;
}
.bld-iconbtn svg{width:17px;height:17px}
.bld-iconbtn:hover{border-color:var(--blue-500);color:var(--blue-700);background:var(--blue-100)}
.bld-iconbtn:disabled{opacity:.4;cursor:default;background:var(--card);border-color:var(--line);color:var(--muted)}
.bld-iconbtn.danger:hover{border-color:color-mix(in srgb,var(--red-600) 50%,transparent);color:var(--red-600);background:var(--red-100)}

/* persona */
.bld-persona .field{margin-bottom:0}

/* FAQ */
.bld-faqs{display:flex;flex-direction:column;gap:9px}
.bld-faq{
  display:flex;gap:11px;align-items:flex-start;
  padding:11px 13px;border:1px solid var(--line);border-radius:13px;background:var(--card);
  transition:border-color .15s ease;
}
.bld-faq:hover{border-color:var(--blue-500)}
.bld-faq-body{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;gap:4px}
.bld-faq-q{font-size:14px;font-weight:700;color:var(--ink);line-height:1.3;word-break:break-word}
.bld-faq-q::before{content:"";}
.bld-faq-a{font-size:13px;color:var(--soft);line-height:1.45;word-break:break-word}
.bld-faq-acts{flex-direction:row}

/* ==========================================================================
 * CENTRO — preview de conversa estilo WhatsApp (clona wapool.css)
 * ========================================================================== */
.bld-preview-panel{position:sticky;top:14px}
.bld-wa{
  display:flex;flex-direction:column;min-height:0;
  height:clamp(360px,52vh,560px);
  border:1px solid var(--line);border-radius:16px;overflow:hidden;
  background:var(--bg);
}
/* barra superior (avatar do robô + nome + ponto ao vivo) */
.bld-wa-bar{
  display:flex;align-items:center;gap:11px;flex:0 0 auto;
  padding:11px 14px;background:var(--green-700);color:#fff;
}
.bld-wa-av{
  flex:0 0 auto;width:38px;height:38px;border-radius:50%;
  display:grid;place-items:center;color:#fff;
  background:rgba(255,255,255,.16);
}
.bld-wa-av svg{width:21px;height:21px}
.bld-wa-bar-tx{display:flex;align-items:center;gap:9px;min-width:0}
.bld-wa-bar-tx b{font-size:15px;font-weight:700;color:#fff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* área das mensagens — fundo de pontinhos como WhatsApp */
.bld-wa-msgs{
  flex:1 1 auto;min-height:0;overflow-y:auto;
  display:flex;flex-direction:column;gap:8px;
  padding:16px;
  background-image:radial-gradient(color-mix(in srgb,var(--ink) 6%,transparent) 1px, transparent 1px);
  background-size:18px 18px;
}
.bld-wa-hint{
  margin:auto;max-width:80%;text-align:center;
  font-size:13.5px;color:var(--muted);line-height:1.5;
}

/* BOLHAS — verde enviado (bot, direita) / cinza recebido (lead, esquerda) */
.bld-bubble{
  max-width:80%;padding:8px 12px;border-radius:14px;
  font-size:14px;line-height:1.42;
  box-shadow:0 1px 1px rgba(16,42,73,.08);
  animation:bldBubbleIn .2s ease;
  word-break:break-word;position:relative;
}
.bld-bubble.lead{align-self:flex-start;background:var(--card);color:var(--ink);border-bottom-left-radius:4px}
.bld-bubble.bot{
  align-self:flex-end;border-bottom-right-radius:4px;
  background:var(--green-100);color:var(--green-800);
  border:1px solid color-mix(in srgb,var(--green-500) 26%,transparent);
}
[data-theme="dark"] .bld-bubble.bot{color:var(--green-500)}
.bld-bubble-tx{display:block}
.bld-bubble-tm{display:block;font-size:10px;opacity:.55;margin-top:3px;text-align:right}
@keyframes bldBubbleIn{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}

/* "digitando…" */
.bld-typing{padding:11px 14px}
.bld-dots{display:inline-flex;gap:4px}
.bld-dots i{width:7px;height:7px;border-radius:50%;background:var(--green-600);animation:bldDot 1s infinite ease-in-out}
.bld-dots i:nth-child(2){animation-delay:.15s}
.bld-dots i:nth-child(3){animation-delay:.3s}
@keyframes bldDot{0%,60%,100%{opacity:.3;transform:translateY(0)}30%{opacity:1;transform:translateY(-3px)}}

/* barra de digitar do simulador */
.bld-wa-input{
  flex:0 0 auto;display:flex;align-items:center;gap:9px;
  padding:10px 12px;background:var(--card);border-top:1px solid var(--line);
}
.bld-wa-input input{
  flex:1 1 auto;min-width:0;min-height:44px;
  border:1px solid var(--line-strong);border-radius:var(--radius-pill);
  background:var(--bg);color:var(--ink);
  padding:9px 16px;font-size:16px;line-height:1.4;
  -webkit-appearance:none;appearance:none;
  transition:border-color .15s ease, box-shadow .15s ease;
}
.bld-wa-input input:focus{
  outline:none;border-color:var(--green-600);
  box-shadow:0 0 0 4px color-mix(in srgb,var(--green-500) 16%,transparent);
}
.bld-wa-send{
  flex:0 0 auto;width:46px;height:46px;border-radius:50%;
  display:grid;place-items:center;color:#fff;cursor:pointer;border:none;
  background:linear-gradient(135deg,var(--green-700),var(--green-500));
  box-shadow:0 5px 14px rgba(31,106,74,.34);
  transition:transform .12s ease, box-shadow .18s ease, filter .18s ease;
}
.bld-wa-send svg{width:20px;height:20px}
.bld-wa-send:hover{filter:brightness(1.05);box-shadow:0 8px 20px rgba(31,106,74,.44)}
.bld-wa-send:active{transform:scale(.96)}

/* rodapé do preview (nota + limpar) */
.bld-wa-foot{display:flex;align-items:center;justify-content:space-between;gap:11px;flex-wrap:wrap}
.bld-sim-note{font-size:12px;color:var(--muted);line-height:1.4}

/* ==========================================================================
 * DIREITA — status do bot + brinde
 * ========================================================================== */
.bld-status{
  border:1px solid var(--line);border-radius:14px;padding:14px;
  background:var(--card);display:flex;flex-direction:column;gap:13px;
}
.bld-status-row{display:flex;align-items:flex-start;gap:11px}
.bld-status-dot{
  flex:0 0 auto;width:13px;height:13px;border-radius:50%;margin-top:4px;
  background:var(--muted);
}
.bld-status-tx{min-width:0}
.bld-status-tx b{display:block;font-size:16px;font-weight:700;color:var(--ink);line-height:1.2}
.bld-status-name{font-size:13px;color:var(--soft);margin-top:2px;word-break:break-word}
.bld-status-tx span{display:block;font-size:13px;color:var(--soft);margin-top:3px;line-height:1.45}
.bld-status-acts{display:flex;gap:9px;flex-wrap:wrap}
.bld-status-acts .btn{flex:1 1 auto}

/* cores por estado */
.bld-status-ok{border-color:color-mix(in srgb,var(--green-500) 45%,transparent);background:var(--green-050)}
.bld-status-ok .bld-status-dot{background:var(--green-500);animation:haon-pulse-dot 1.7s ease-out infinite}
.bld-status-off .bld-status-dot{background:var(--red-500)}
.bld-status-err{border-color:color-mix(in srgb,var(--yellow-500) 45%,transparent);background:var(--yellow-100)}
.bld-status-err .bld-status-dot{background:var(--yellow-600)}
.bld-status-checking .bld-status-dot{background:var(--blue-500)}

/* CTA principal (laranja, único, grande) — herda .btn.orange.lg de styles.css */
.bld-save{margin-top:2px}
.bld-save .bld-ico{width:auto;height:auto;background:none;color:inherit}
.bld-save .bld-ico svg{width:20px;height:20px}

/* brinde (Pool) */
.bld-gift-mount{min-height:60px}
.bld-gift-mount:empty::before{
  content:"";display:block;height:50px;border-radius:12px;
  background:linear-gradient(100deg,color-mix(in srgb,var(--line) 30%,transparent) 25%,color-mix(in srgb,var(--line) 12%,transparent) 50%,color-mix(in srgb,var(--line) 30%,transparent) 75%);
  background-size:200% 100%;animation:bldShimmer 1.4s linear infinite;
}
@keyframes bldShimmer{from{background-position:200% 0}to{background-position:-200% 0}}

/* ==========================================================================
 * TOAST próprio (só usado se o app.js não expuser um global)
 * ========================================================================== */
.bld-toast{
  position:fixed;left:50%;bottom:26px;z-index:600;
  transform:translateX(-50%) translateY(150%);
  background:var(--ink);color:var(--bg);
  padding:14px 20px;border-radius:13px;box-shadow:var(--shadow-lg);
  max-width:min(92vw,460px);font-size:14.5px;font-weight:600;line-height:1.4;
  transition:transform .3s cubic-bezier(.2,.9,.3,1);
}
.bld-toast.show{transform:translateX(-50%) translateY(0)}
.bld-toast.err{box-shadow:var(--shadow-lg),inset 0 0 0 1.5px var(--red-500)}
.bld-toast.warn{box-shadow:var(--shadow-lg),inset 0 0 0 1.5px var(--yellow-500)}

/* ==========================================================================
 * RESPONSIVO — empilha. Ordem no mobile: builder -> preview -> pool.
 * Breakpoints coerentes com o CONTRATO (880px e 520px) + um aperto de
 * notebook em 1240/1080 que NÃO muda a ordem das colunas (só largura).
 * ========================================================================== */
/* notebook menor: aperta as colunas laterais (ainda 3 colunas) */
@media (max-width:1240px){
  .bld-grid{grid-template-columns:minmax(290px,1fr) minmax(0,1.1fr) minmax(280px,.95fr);gap:14px}
}
/* tablet largo: comprime mais, mas mantém as 3 colunas enquanto couber */
@media (max-width:1080px){
  .bld-grid{grid-template-columns:minmax(260px,.95fr) minmax(0,1.15fr) minmax(260px,.9fr);gap:12px}
}
/* ===== BREAKPOINT DO SISTEMA (880px): empilha tudo em 1 coluna ===== */
/* Ordem garantida builder -> preview -> pool; direita vira pilha vertical;
 * o cockpit de Pool já é uma lista (.pool-list) e ocupa a largura cheia. */
@media (max-width:880px){
  .bld-grid{grid-template-columns:1fr;gap:14px}
  .bld-col-left{order:1}
  .bld-col-center{order:2}
  .bld-col-right{order:3;grid-column:auto;flex-direction:column}
  .bld-status-panel,.bld-gift-panel{flex:1 1 auto}
  /* preview não fica mais grudado no topo (atrapalha o scroll empilhado) */
  .bld-preview-panel{position:static}
  .bld-wa{height:clamp(340px,58vh,480px)}
  .bld-stage-acts{flex-direction:row;flex-wrap:wrap}
  /* alvos maiores no toque (>=44px aqui, >=48px em 520) */
  .bld-iconbtn{width:44px;height:44px}
  .bld-head{align-items:flex-start}
  .bld-head #bldReconfigure{width:100%}
}
/* ===== BREAKPOINT DO SISTEMA (520px): celular estreito ===== */
@media (max-width:520px){
  .bld-host{padding:12px;gap:14px}
  .bld-panel{padding:14px}
  .bld-bubble{max-width:86%}
  .bld-wa-foot{justify-content:center}
  .bld-wa-foot #bldWaReset{width:100%}
  /* toque cheio no celular: ícones de etapa e botões do cabeçalho >=48px */
  .bld-iconbtn{width:48px;height:48px}
  .bld-stage-acts{gap:8px}
  /* ações de status empilham 100% — nada de dois botões colados estreitos */
  .bld-status-acts{flex-direction:column}
  .bld-status-acts .btn{width:100%}
  /* cabeçalho: título e ação não brigam por largura */
  .bld-head{flex-direction:column;align-items:stretch;gap:10px}
}

/* ==========================================================================
 * PREFERS-REDUCED-MOTION
 * ========================================================================== */
@media (prefers-reduced-motion:reduce){
  .bld-bubble,.bld-dots i,.bld-status-ok .bld-status-dot,.bld-gift-mount:empty::before,.bld-wa-send,.bld-stage{
    animation:none!important;transition:none!important;
  }
}
/* ===== HAONCHAT_BUILDER_V1_END ===== */
