/* Tela do agente — usa os tokens do DESIGN SYSTEM KIT - MAG */

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg-primary);
  color: var(--fg1);
  display: flex; flex-direction: column;
  min-height: 100dvh;
}
[hidden], .gone { display: none !important; }
button { font-family: var(--font-body); }

.btn-pill { border-radius: var(--radius-full); }

/* ---------- barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--space-4);
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
}
.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; flex: 1 1 auto; }
.brand-mark { width: 30px; height: 30px; object-fit: contain; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand-text .eyebrow { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-name {
  font-family: var(--font-heading); font-weight: 700; letter-spacing: var(--tracking-tight);
  font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.config { display: flex; align-items: center; gap: var(--space-2); flex: none; }
.cfg {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border-primary); border-radius: var(--radius-full);
  background: var(--bg-card);
}
.cfg-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: var(--tracking-wide); color: var(--fg3); }
.cfg-select {
  width: auto; border: none; background: transparent; box-shadow: none !important;
  padding: 6px 8px; font-size: 13px; font-weight: 500; border-radius: var(--radius-full);
  color: var(--fg1);
}
.cfg-select:focus { background: var(--bg-highlight-subtle); }
.cfg-select:disabled { color: var(--fg2); opacity: 1; cursor: default; }
select.cfg-select { appearance: none; -webkit-appearance: none; padding-right: 24px;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg3) 50%), linear-gradient(135deg, var(--fg3) 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 9px) 52%;
  background-size: 4px 4px; background-repeat: no-repeat; }
select.cfg-select:disabled { background-image: none; padding-right: 10px; }
.cfg-limit .cfg-select { width: 62px; }

.top-actions { display: flex; align-items: center; gap: var(--space-2); flex: none; }
.counter {
  font-size: 12.5px; font-weight: 600; color: var(--fg2);
  padding: 7px 12px; border-radius: var(--radius-full); background: var(--bg-tertiary);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.counter.warn { background: var(--warning-light); color: var(--warning); }
.counter.done { background: var(--bg-negative); color: var(--text-negative); }

.icon-btn.config-toggle { display: none; }
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--radius-full); border: 1px solid var(--border-primary);
  background: var(--bg-card); color: var(--fg2); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn[aria-expanded="true"] { background: var(--bg-highlight-subtle); color: var(--fg1); border-color: var(--lima-400); }

/* ---------- palco ---------- */
.stage { flex: 1 1 auto; display: flex; flex-direction: column; }

/* captura */
.intro { flex: 1; display: flex; align-items: center; justify-content: center; padding: var(--space-8) 16px; }
.intro-card {
  width: 100%; max-width: 440px;
  background: var(--bg-card); border: 1px solid var(--border-primary);
  border-radius: var(--radius-3xl); box-shadow: var(--shadow-lg);
  padding: 36px 28px 28px; text-align: center;
}
.intro-mark { width: 56px; height: 56px; object-fit: contain; margin-bottom: var(--space-3); }
[data-theme="dark"] .intro-mark { filter: drop-shadow(0 0 22px rgba(250,252,89,0.45)); }
.intro-title {
  margin: 0 0 var(--space-2); font-size: clamp(26px, 6vw, 32px); font-weight: 900;
  letter-spacing: -0.02em; line-height: 1.05;
}
.intro-desc { margin: 0 auto var(--space-6); max-width: 340px; font-size: 15px; color: var(--fg2); line-height: 1.5; }
.lead-form { display: flex; flex-direction: column; gap: var(--space-4); text-align: left; }
.field .field-label { margin-bottom: 6px; }
.lead-form .input { font-size: 16px; padding: 13px 16px; border-radius: var(--radius-lg); }
.lead-form .btn { margin-top: var(--space-2); }
.alert-err {
  background: var(--bg-negative); color: var(--text-negative);
  border: 1px solid color-mix(in srgb, var(--cereja) 35%, transparent);
  border-radius: var(--radius-lg); padding: 10px 14px; font-size: 13.5px;
}

/* ---------- conversa ---------- */
.chat { flex: 1; }
.thread {
  max-width: 760px; margin: 0 auto; width: 100%;
  padding: var(--space-8) 16px var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-6);
}
.msg { display: flex; gap: var(--space-3); align-items: flex-start; animation: rise .25s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-avatar {
  width: 30px; height: 30px; flex: none; border-radius: var(--radius-full);
  background: var(--lima); display: flex; align-items: center; justify-content: center; margin-top: 2px;
}
.msg-avatar img { width: 18px; height: 18px; object-fit: contain; }
.msg-body { min-width: 0; flex: 1; }
.msg.assistant .msg-content { font-size: 15.5px; line-height: 1.65; color: var(--fg1); overflow-wrap: anywhere; }
.msg-content p { margin: 0 0 0.75em; color: inherit; font-size: inherit; }
.msg-content p:last-child, .msg-content ul:last-child, .msg-content ol:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { margin: 0 0 0.75em; padding-left: 1.3em; }
.msg-content li { margin: 0.2em 0; }
.msg-content strong { font-weight: 650; }
.msg-content h4 { font-family: var(--font-heading); font-size: 17px; margin: 0.4em 0 0.4em; }
.msg-content code { background: var(--bg-tertiary); padding: 1px 6px; border-radius: 6px; }
.msg-content hr { border: none; border-top: 1px solid var(--border-primary); margin: 1em 0; }
.msg-content blockquote { margin: 0 0 0.75em; padding-left: 12px; border-left: 3px solid var(--lima-400); color: var(--fg2); }

.msg.user { justify-content: flex-end; }
.msg.user .msg-content {
  max-width: min(80%, 560px);
  background: var(--bg-card); border: 1px solid var(--border-primary);
  padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  font-size: 15.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
}

.msg-tools { display: flex; gap: 4px; margin-top: 6px; opacity: 0; transition: opacity var(--transition-fast); }
.msg:hover .msg-tools, .msg:focus-within .msg-tools, .msg.last .msg-tools { opacity: 1; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 5px; border: none; background: transparent; cursor: pointer;
  color: var(--fg3); font-size: 12px; font-weight: 500; padding: 5px 8px; border-radius: var(--radius-md);
}
.tool-btn:hover { background: var(--bg-tertiary); color: var(--fg1); }
.tool-btn svg { width: 14px; height: 14px; }

.typing { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--fg3); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.msg-error { color: var(--text-negative); font-size: 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- composer ---------- */
.composer-wrap {
  position: sticky; bottom: 0; z-index: 5;
  padding: 0 16px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg-primary) 28%);
}
.composer-wrap > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.icebreakers { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-3) 0 var(--space-2); }
.icebreakers:empty { display: none; }
.limit-banner {
  margin-bottom: var(--space-2); padding: 12px 16px; border-radius: var(--radius-xl);
  background: var(--bg-card); border: 1px solid var(--border-primary); font-size: 14px; color: var(--fg2);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
}
.limit-banner.done-banner { background: var(--lima); border-color: var(--lima); color: var(--text-on-lima); justify-content: center; text-align: center; }
.composer {
  display: flex; align-items: flex-end; gap: var(--space-2);
  background: var(--bg-card); border: 1px solid var(--border-secondary);
  border-radius: 26px; padding: 8px 8px 8px 18px; box-shadow: var(--shadow-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.composer:focus-within { border-color: var(--lima-400); box-shadow: var(--shadow-md), 0 0 0 3px rgba(250,252,89,0.22); }
.composer textarea {
  flex: 1; resize: none; border: none; outline: none; background: transparent; color: var(--fg1);
  font-family: var(--font-body); font-size: 16px; line-height: 1.5; padding: 7px 0; max-height: 200px;
}
.composer textarea::placeholder { color: var(--fg-disabled); }
.composer textarea:disabled { cursor: not-allowed; }
.send {
  width: 38px; height: 38px; flex: none; border-radius: var(--radius-full); border: none; cursor: pointer;
  background: var(--lima); color: var(--text-on-lima); display: inline-flex; align-items: center; justify-content: center;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}
.send svg { width: 18px; height: 18px; }
.send:hover:not(:disabled) { transform: scale(1.05); }
.send:disabled { opacity: .35; cursor: default; }
.composer-note { margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--fg3); min-height: 1em; }

/* ---------- celular ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: var(--space-2) var(--space-3); }
  .brand { flex: 1 1 0; }
  .icon-btn.config-toggle { display: inline-flex; order: 2; }
  .top-actions { order: 3; }
  #start-btn { display: none; } /* no celular o formulário já tem o botão */
  .in-chat .icon-btn.config-toggle, .in-chat .config { display: none; } /* travado durante a conversa */
  .config {
    order: 4; width: 100%; display: none;
    flex-direction: column; align-items: stretch; padding: var(--space-2) 0 var(--space-1);
  }
  .config.open { display: flex; }
  .cfg { justify-content: space-between; border-radius: var(--radius-lg); padding: 4px 4px 4px 14px; }
  .cfg-select { flex: 1; text-align: right; text-align-last: right; }
  .cfg-limit .cfg-select { flex: none; width: 80px; }
  .top-actions .btn { padding: 10px 16px; }
}
@media (max-width: 480px) {
  .brand-text .eyebrow { display: none; }
  .brand-name { font-size: 15.5px; }
  .counter { padding: 6px 10px; }
  .counter-word { display: none; }
  .intro-card { padding: 28px 20px 22px; border-radius: var(--radius-2xl); }
  .msg.user .msg-content { max-width: 88%; }
}
