.chat-widget {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(30,41,59,0.06), 0 24px 48px -24px rgba(30,41,59,0.22);
  display: flex;
  flex-direction: column;
  height: min(640px, 78vh);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(16px, 4vw, 24px);
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  flex: 0 0 auto;
}

.chat-header__mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--gradient);
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.chat-header__type {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.chat-header__name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.chat-header__status {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-header__status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.chat-header__status.is-offline::before { background: var(--danger); }

.chat-header__cta {
  margin-left: auto;
  flex: 0 0 auto;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--gradient);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform var(--t-fast), opacity var(--t-fast);
  white-space: nowrap;
}

.chat-header__cta:hover { opacity: .92; }
.chat-header__cta:active { transform: scale(0.97); }

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px clamp(16px, 4vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  line-height: 1.55;
  word-wrap: break-word;
}

.msg--bot {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.msg--bot .md-p { margin: 0 0 8px; }
.msg--bot .md-p:last-child { margin-bottom: 0; }
.msg--bot .md-h { margin: 10px 0 6px; line-height: 1.3; color: var(--text); }
.msg--bot .md-h:first-child { margin-top: 0; }
.msg--bot .md-hr { border: none; border-top: 1px solid var(--line); margin: 8px 0; }
.msg--bot .md-quote {
  margin: 6px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--primary);
  color: var(--muted);
  background: var(--bg-3);
  border-radius: 0 6px 6px 0;
}
.msg--bot .md-list { margin: 0 0 8px; padding-left: 20px; }
.msg--bot .md-list li { margin-bottom: 4px; }
.msg--bot code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.msg--bot pre {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
}
.msg--bot pre code { background: none; padding: 0; }
.msg--bot table { border-collapse: collapse; width: 100%; margin: 8px 0 10px; font-size: 13px; }
.msg--bot th, .msg--bot td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.msg--bot th { background: var(--bg-3); font-weight: 600; }

.msg--user {
  align-self: flex-end;
  background: var(--gradient);
  color: #fff;
  white-space: pre-wrap;
  border-bottom-right-radius: 4px;
  font-weight: 400;
}

.msg--system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  max-width: 100%;
}

.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 13px 15px;
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chips {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 clamp(16px, 4vw, 24px) 12px;
}

.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  white-space: normal;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast);
}

.chip:hover { border-color: var(--primary); color: var(--primary); }

.chat-input {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px clamp(16px, 4vw, 24px);
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}

.chat-input textarea {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  padding: 11px 15px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.4;
}

.chat-input textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.chat-input textarea::placeholder { color: var(--muted); }

.chat-input button {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--gradient);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--t-fast);
}

.chat-input button:hover { opacity: .9; }

.chat-input button:disabled {
  opacity: .4;
  cursor: default;
}

/* ---- Modal: formulario de lead -------------------------------------- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
  z-index: 40;
}

.sheet-overlay.is-open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -46%);
  z-index: 41;
  width: min(420px, calc(100vw - 32px));
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px clamp(18px, 4vw, 26px) 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base), transform var(--t-base);
  box-shadow: 0 24px 64px -20px rgba(15, 23, 42, .35);
}

.sheet.is-open { opacity: 1; transform: translate(-50%, -50%); pointer-events: auto; }

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sheet__title {
  font-weight: 700;
  font-size: 19px;
  color: var(--text);
}

.sheet__close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}

.sheet__note {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.sheet__form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet__form input,
.sheet__form textarea {
  padding: 12px 15px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14.5px;
  resize: none;
}

.sheet__form textarea { min-height: 72px; }

.sheet__form input:focus,
.sheet__form textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.sheet__form input::placeholder,
.sheet__form textarea::placeholder { color: var(--muted); }

.sheet__confirm {
  margin-top: 4px;
  padding: 13px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--gradient);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: opacity var(--t-fast);
}

.sheet__confirm:hover { opacity: .92; }
.sheet__confirm:disabled { opacity: .5; cursor: default; }

.sheet__error {
  margin-top: 10px;
  font-size: 13px;
  color: var(--danger);
}

.sheet__success {
  margin-top: 4px;
  text-align: center;
  font-size: 15px;
  color: var(--text);
  padding: 12px 0 4px;
}
