/* Asistente de IA de Simbiatec 2.0. Usa los tokens de marca de styles.css */
.chatbot { --chat-w: 400px; position: fixed; z-index: 60; right: 24px; bottom: 24px; display: flex; flex-direction: column; align-items: flex-end; gap: 14px; pointer-events: none; }
.chatbot > * { pointer-events: auto; }

/* Botón flotante: color de acción */
.chat-launcher { display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 22px 0 18px; border: 0; border-radius: 999px; background: var(--mar-700); color: var(--paper); font-weight: 600; font-size: .95rem; cursor: pointer; box-shadow: var(--shadow-lift); transition: transform .3s var(--ease), opacity .3s, background-color .2s, visibility .3s; }
.chat-launcher svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--oro-300); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.chat-launcher:hover { background: var(--mar-800); }
.chatbot.is-open .chat-launcher { display: none; }
.chatbot.near-contact:not(.is-open) .chat-launcher { opacity: 0; visibility: hidden; transform: translateY(12px); }
.menu-open ~ .chatbot .chat-launcher { opacity: 0; visibility: hidden; }

/* Panel */
.chat-panel { width: var(--chat-w); height: min(620px, calc(100dvh - 48px)); display: flex; flex-direction: column; border: 1px solid var(--paper-line); border-radius: 24px; background: var(--paper); box-shadow: var(--shadow-lift); overflow: hidden; transform-origin: bottom right; animation: chat-in .28s var(--ease); }
.chat-panel[hidden] { display: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.chat-header { display: flex; align-items: center; gap: 12px; padding: 14px 12px 14px 18px; border-bottom: 1px solid var(--paper-line); background: var(--mar-100); }
.chat-mark { flex: none; width: 34px; height: 34px; background: url("assets/simbolo-claro.svg") center / contain no-repeat; }
.chat-heading { flex: 1; min-width: 0; }
.chat-title { font-family: var(--display); font-size: 1rem; font-weight: 600; letter-spacing: -.01em; color: var(--ink); }
.chat-title:focus { outline: none; }
.chat-title:focus-visible { outline: 2px solid var(--mar-500); }
.chat-sub { font-size: .8125rem; line-height: 1.4; color: var(--ink-soft); }
.chat-icon-btn { flex: none; width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 999px; background: transparent; color: var(--ink-soft); cursor: pointer; transition: background-color .2s, color .2s; }
.chat-icon-btn:hover { background: var(--paper); color: var(--ink); }
.chat-icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Mensajes */
.chat-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; scrollbar-color: var(--paper-line) transparent; }
.chat-msg { max-width: 88%; display: grid; gap: 8px; }
.chat-msg-body { padding: 11px 15px; border-radius: 18px; font-size: .95rem; line-height: 1.55; overflow-wrap: anywhere; }
.chat-msg-body p { max-width: none; }
.chat-msg-body p + p, .chat-msg-body p + ul, .chat-msg-body ul + p { margin-top: 8px; }
.chat-msg-body ul { display: grid; gap: 4px; padding-left: 18px; list-style: disc; }
.chat-msg-body li::marker { color: var(--oro-500); }
.chat-msg-body strong { font-weight: 600; color: var(--ink); }
.chat-msg-model { align-self: flex-start; }
.chat-msg-model .chat-msg-body { background: var(--paper-alt); border: 1px solid var(--paper-line); border-bottom-left-radius: 6px; color: var(--ink); }
.chat-msg-user { align-self: flex-end; }
.chat-msg-user .chat-msg-body { background: var(--mar-700); color: var(--paper); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.chat-msg.is-error .chat-msg-body { background: color-mix(in oklab, var(--forja-300) 18%, var(--paper)); border-color: color-mix(in oklab, var(--forja-300) 70%, var(--paper)); color: var(--forja-600); }
.chat-action { justify-self: start; display: inline-flex; align-items: center; min-height: 36px; padding: 0 15px; border: 1px solid var(--mar-700); border-radius: 999px; background: transparent; color: var(--mar-700); font-size: .875rem; font-weight: 600; text-decoration: none; cursor: pointer; }
.chat-action:hover { background: var(--mar-100); }
.chat-action-ghost { border-color: var(--paper-line); color: var(--ink); }
.chat-msg.is-error { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-msg.is-error .chat-msg-body { flex-basis: 100%; }

.chat-typing { flex-direction: row; display: flex; gap: 5px; padding: 14px 16px; background: var(--paper-alt); border: 1px solid var(--paper-line); border-radius: 18px 18px 18px 6px; }
.chat-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--mar-400); animation: chat-dot 1.2s infinite ease-in-out; }
.chat-typing i:nth-of-type(2) { animation-delay: .15s; }
.chat-typing i:nth-of-type(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 16px 12px; }
.chat-suggestions[hidden] { display: none; }
.chat-chip { padding: 8px 14px; border: 1px solid var(--ink-faint); border-radius: 999px; background: var(--paper); color: var(--ink); font-size: .875rem; font-weight: 500; text-align: left; cursor: pointer; transition: border-color .2s, background-color .2s; }
.chat-chip:hover { border-color: var(--mar-600); background: var(--mar-100); }

/* Redacción */
.chat-compose { padding: 12px 14px; border-top: 1px solid var(--paper-line); display: grid; gap: 8px; }
.chat-field { display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 16px; border: 1px solid var(--ink-faint); border-radius: 22px; background: var(--paper); transition: border-color .2s, box-shadow .2s; }
.chat-field:focus-within { border-color: var(--mar-600); box-shadow: 0 0 0 3px color-mix(in oklab, var(--mar-300) 45%, transparent); }
.chat-input { flex: 1; min-height: 40px; max-height: 140px; padding: 9px 0; border: 0; background: transparent; resize: none; font-size: 1rem; line-height: 1.4; color: var(--ink); }
.chat-input:focus { outline: none; }
.chat-input::placeholder { color: var(--ink-faint); }
.chat-send { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 999px; background: var(--mar-700); color: var(--paper); cursor: pointer; transition: background-color .2s, opacity .2s; }
.chat-send:hover { background: var(--mar-800); }
.chat-send:disabled { opacity: .4; cursor: not-allowed; }
.chat-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chat-foot { display: flex; justify-content: space-between; gap: 12px; }
.chat-hint { font-size: .8125rem; color: var(--ink-soft); line-height: 1.45; max-width: none; }
.chat-hint a { color: var(--mar-700); font-weight: 600; }
.chat-counter { flex: none; font-size: .8125rem; font-weight: 600; color: var(--ink-soft); }
.chat-counter.is-over { color: var(--forja-600); }
.chat-contact-link { justify-self: start; font-size: .875rem; font-weight: 600; color: var(--mar-700); }
.chat-panel.is-unavailable .chat-field { opacity: .55; }

/* Enlace al asistente dentro de la página */
.chat-inline { display: inline-flex; align-items: center; gap: 10px; margin-top: 28px; padding: 0; border: 0; background: none; color: var(--mar-700); font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 5px; text-decoration-color: var(--mar-300); }
.chat-inline:hover { color: var(--mar-800); text-decoration-color: currentColor; }
.contact-copy .chat-inline, .faq-list .chat-inline { justify-self: start; text-align: left; }
.contact-copy .chat-inline { margin-top: 4px; }

/* Móvil */
@media (max-width: 860px) {
  .chatbot { right: var(--gutter); bottom: max(14px, env(safe-area-inset-bottom)); }
  .chat-launcher { width: 52px; padding: 0; justify-content: center; }
  .chat-launcher-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .mobile-cta { right: calc(var(--gutter) + 62px); }
  body:has(.contact-form :focus) .chat-launcher { opacity: 0; visibility: hidden; }
  .chatbot.in-hero:not(.is-open) .chat-launcher { opacity: 0; visibility: hidden; transform: translateY(12px); }
}
@media (max-width: 560px) {
  .chatbot.is-open { inset: 0; right: 0; bottom: 0; }
  .chat-panel { width: 100%; height: 100dvh; border-radius: 0; border: 0; }
  .chat-msg { max-width: 92%; }
  html.chat-lock, html.chat-lock body { overflow: hidden; }
}
@media (min-width: 561px) and (max-width: 860px) {
  .chat-panel { width: min(var(--chat-w), calc(100vw - 32px)); }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel { animation: none; }
  .chat-typing i { animation: none; opacity: .7; }
}
