/* Chat con visitantes. Usa los tokens de la landing (--sl-*) y valores equivalentes fuera de ella.
   Fuera de la landing el tema y los snippets aplican reglas globales (p, h2, button, textarea, section),
   algunas con !important: los botones usan `.nlp-chat button.…` y solo se fuerzan esas propiedades. */
@property --nlp-angle { syntax: '<angle>'; initial-value: 0deg; inherits: false; }

.nlp-chat {
    --nlp-ink: var(--sl-ink, #0b1026); --nlp-text: var(--sl-text, #3d4562); --nlp-muted: var(--sl-muted, #7a819c);
    --nlp-bg: var(--sl-bg, #f9f9fe); --nlp-bg-2: var(--sl-bg-2, #eef1fa); --nlp-line: var(--sl-line, #e3e6f2);
    --nlp-night: var(--sl-night, #070b1a); --nlp-night-2: var(--sl-night-2, #0d1430);
    --nlp-blue: var(--sl-blue, #2373ff); --nlp-cyan: var(--sl-cyan, #26baf0); --nlp-coral: var(--sl-coral, #ff6170); --nlp-online: #39d98a;
    --nlp-grad: var(--sl-grad, linear-gradient(100deg, #26baf0, #2373ff));
    --nlp-font: var(--sl-font-body, 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif);
    --nlp-ease: var(--sl-ease, cubic-bezier(.2, .7, .2, 1)); --nlp-spring: cubic-bezier(.34, 1.56, .64, 1);
    position: fixed; right: 24px; bottom: 24px; z-index: 10000;
    display: flex; flex-direction: column; align-items: flex-end; gap: 14px; margin: 0; padding: 0; background: none;
    color: var(--nlp-ink); font-family: var(--nlp-font); font-size: 15px; font-weight: 400; line-height: 1.45; text-align: left; -webkit-font-smoothing: antialiased;
}
.nlp-chat *, .nlp-chat *::before, .nlp-chat *::after { box-sizing: border-box; }
.nlp-chat[hidden], .nlp-chat [hidden] { display: none !important; }
.nlp-chat p, .nlp-chat h2, .nlp-chat button, .nlp-chat textarea { font-family: var(--nlp-font) !important; letter-spacing: normal; text-transform: none; }
.nlp-chat p { font-size: inherit; font-weight: inherit; line-height: inherit; }
.nlp-chat button { font-size: inherit; line-height: inherit; cursor: pointer; }
.nlp-chat :focus-visible { outline: 3px solid var(--nlp-cyan) !important; outline-offset: 2px; }

/* Lanzador */
.nlp-chat button.nlp-chat__toggle {
    position: relative; isolation: isolate; display: inline-flex; align-items: center; gap: 10px;
    padding: 8px 22px 8px 8px; border: 0; border-radius: 999px; color: #fff; font-weight: 600; font-size: 15px;
    background: var(--nlp-grad); box-shadow: 0 14px 34px -10px rgba(35, 115, 255, .75), inset 0 1px 0 rgba(255, 255, 255, .3);
    transition: transform .35s var(--nlp-spring), box-shadow .3s var(--nlp-ease);
    animation: nlp-launch .8s var(--nlp-spring) 1.2s backwards;
}
.nlp-chat button.nlp-chat__toggle::before {
    content: ''; position: absolute; inset: -3px; z-index: -1; border-radius: inherit; filter: blur(10px); opacity: .7;
    background: conic-gradient(from var(--nlp-angle), #38c8ff, #2373ff, #ff6170, #38c8ff); animation: nlp-spin 4s linear infinite;
}
.nlp-chat button.nlp-chat__toggle:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 20px 44px -12px rgba(35, 115, 255, .9), inset 0 1px 0 rgba(255, 255, 255, .3); }
.nlp-chat__toggle-icon { position: relative; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, .18); }
.nlp-chat__toggle-icon svg { width: 22px; height: 22px; }
.nlp-chat__toggle-icon::after { content: ''; position: absolute; right: 0; bottom: 1px; width: 11px; height: 11px; border-radius: 50%; background: var(--nlp-online); box-shadow: 0 0 0 2px #2373ff; animation: nlp-pulse 2.4s infinite; }
.nlp-chat__badge {
    position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
    display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; background: var(--nlp-coral);
    box-shadow: 0 0 0 3px #fff; animation: nlp-pop .5s var(--nlp-spring) both;
}

/* Aviso de mensaje nuevo con el chat cerrado */
.nlp-chat__peek { position: relative; width: min(320px, calc(100vw - 48px)); animation: nlp-rise .6s var(--nlp-spring) both; }
.nlp-chat button.nlp-chat__peek-body {
    display: flex; gap: 12px; width: 100%; padding: 16px 18px; border: 0; border-radius: 22px 22px 6px 22px; text-align: left; color: var(--nlp-text); font-weight: 400;
    background: rgba(255, 255, 255, .97); background-color: rgba(255, 255, 255, .97) !important; backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 24px 60px -20px rgba(11, 16, 38, .45), 0 0 0 1px var(--nlp-line); transition: transform .3s var(--nlp-ease);
}
.nlp-chat button.nlp-chat__peek-body:hover { transform: translateY(-2px); }
.nlp-chat__peek-body strong { display: block; margin-bottom: 2px; color: var(--nlp-ink); font-size: 14px; font-weight: 700; }
.nlp-chat__peek-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px; }
.nlp-chat button.nlp-chat__peek-close {
    position: absolute; top: -10px; left: -10px; display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%;
    color: var(--nlp-muted); background: #fff; background-color: #fff !important; box-shadow: 0 4px 14px -4px rgba(11, 16, 38, .35); opacity: 0; transition: opacity .2s;
}
.nlp-chat__peek:hover .nlp-chat__peek-close, .nlp-chat button.nlp-chat__peek-close:focus-visible { opacity: 1; }
.nlp-chat__peek-close svg { width: 14px; height: 14px; }

/* Avatar del equipo */
.nlp-chat__avatar {
    position: relative; flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
    color: #fff; font-weight: 700; font-size: 16px; background: var(--sl-grad-brand, linear-gradient(135deg, #38c8ff, #2373ff 50%, #ff6170));
}
.nlp-chat__avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #fff; }
.nlp-chat__avatar::after { content: ''; position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--nlp-online); box-shadow: 0 0 0 2.5px var(--nlp-avatar-ring, #fff); }
.nlp-chat--offline .nlp-chat__header .nlp-chat__avatar::after { background: #f5b84a; }

/* Panel */
.nlp-chat__panel {
    display: flex; flex-direction: column; width: min(390px, calc(100vw - 48px)); height: min(640px, calc(100dvh - 48px));
    overflow: hidden; border-radius: var(--sl-radius, 28px); background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%);
    box-shadow: 0 0 0 1px rgba(11, 16, 38, .06), 0 40px 100px -30px rgba(11, 16, 38, .55);
    transform-origin: bottom right; animation: nlp-open .5s var(--nlp-spring) both;
}
.nlp-chat__header {
    --nlp-avatar-ring: var(--nlp-night-2);
    position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; padding: 20px 18px 20px 20px; color: #fff;
    background: radial-gradient(120% 140% at 0% 0%, rgba(38, 186, 240, .35), transparent 55%), radial-gradient(90% 120% at 100% 0%, rgba(255, 97, 112, .28), transparent 60%), linear-gradient(160deg, var(--nlp-night-2), var(--nlp-night));
}
.nlp-chat__header::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .25), transparent); }
.nlp-chat__agent { display: flex; align-items: center; gap: 12px; min-width: 0; }
.nlp-chat__agent .nlp-chat__avatar { width: 44px; height: 44px; box-shadow: 0 0 0 3px rgba(255, 255, 255, .12); }
.nlp-chat .nlp-chat__header h2 { margin: 0; padding: 0; color: #fff !important; font-family: var(--sl-font-display, var(--nlp-font)) !important; font-size: 17px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nlp-chat .nlp-chat__status { margin: 2px 0 0; color: rgba(255, 255, 255, .68) !important; font-size: 13px; line-height: 1.3; }
.nlp-chat button.nlp-chat__close {
    flex: none; display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 50%; color: #fff;
    background: rgba(255, 255, 255, .08); background-color: rgba(255, 255, 255, .08) !important; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16); transition: background-color .2s, transform .3s var(--nlp-ease);
}
.nlp-chat button.nlp-chat__close:hover { background-color: rgba(255, 255, 255, .16) !important; transform: rotate(90deg); }
.nlp-chat__close svg { width: 18px; height: 18px; }

/* Conversación */
.nlp-chat__messages {
    flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 20px 16px 12px; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth;
    background: radial-gradient(80% 50% at 100% 0%, rgba(35, 115, 255, .06), transparent), var(--nlp-bg);
    scrollbar-width: thin; scrollbar-color: var(--nlp-line) transparent;
}
.nlp-chat__welcome { margin-bottom: 14px; padding: 18px; border-radius: 20px; background: #fff; box-shadow: 0 1px 0 var(--nlp-line), 0 12px 30px -18px rgba(11, 16, 38, .3); animation: nlp-rise .6s var(--nlp-ease) .1s both; }
.nlp-chat .nlp-chat__welcome p { margin: 0; color: var(--nlp-text) !important; font-size: 14px; }
.nlp-chat .nlp-chat__welcome .nlp-chat__hello { margin-bottom: 4px; color: var(--nlp-ink) !important; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.nlp-chat__suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.nlp-chat button.nlp-chat__chip {
    margin: 0; padding: 8px 14px; border: 1.5px solid #d6e4ff; border-radius: 999px; color: var(--nlp-blue); font-size: 13.5px; font-weight: 600; line-height: 1.3;
    background: #f3f7ff; background-color: #f3f7ff !important; transition: background-color .2s, border-color .2s, transform .3s var(--nlp-spring);
}
.nlp-chat button.nlp-chat__chip:hover { border-color: var(--nlp-blue); background-color: #e4efff !important; transform: translateY(-2px); }

.nlp-chat .nlp-chat__message {
    position: relative; max-width: 82%; margin: 0; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45;
    align-self: flex-start; border-radius: 20px 20px 20px 6px; color: var(--nlp-ink) !important; background: #fff;
    box-shadow: 0 1px 0 var(--nlp-line), 0 6px 18px -12px rgba(11, 16, 38, .3); animation: nlp-bubble .45s var(--nlp-spring) both; transform-origin: bottom left;
}
.nlp-chat .nlp-chat__message--visitor { align-self: flex-end; border-radius: 20px 20px 6px 20px; color: #fff !important; background: var(--nlp-grad); box-shadow: 0 10px 24px -14px rgba(35, 115, 255, .9); transform-origin: bottom right; }
.nlp-chat .nlp-chat__message + .nlp-chat__message { margin-top: 2px; }
.nlp-chat .nlp-chat__message--agent + .nlp-chat__message--visitor, .nlp-chat .nlp-chat__message--visitor + .nlp-chat__message--agent { margin-top: 12px; }
.nlp-chat__message--agent + .nlp-chat__message--agent { border-top-left-radius: 6px; }
.nlp-chat__message--visitor + .nlp-chat__message--visitor { border-top-right-radius: 6px; }
.nlp-chat__message[data-nonce] { opacity: .65; }
.nlp-chat__message[data-nonce]::after { content: 'Enviando…'; display: block; margin-top: 2px; font-size: 11px; opacity: .85; text-align: right; }
.nlp-chat__message[data-nonce].is-sent { opacity: 1; }
.nlp-chat__message[data-nonce].is-sent::after { content: 'Enviado'; }

/* Redacción */
.nlp-chat__form {
    display: flex; align-items: flex-end; gap: 8px; margin: 0; padding: 12px 12px 8px 18px;
    border-top: 1px solid var(--nlp-line); background: #fff;
}
.nlp-chat textarea.nlp-chat__input {
    flex: 1; min-width: 0; max-height: 120px; margin: 0; padding: 10px 0 !important; border: 0 !important; border-radius: 0; resize: none; overflow-y: auto;
    color: var(--nlp-ink); background: transparent; background-color: transparent !important; box-shadow: none !important;
    font-size: 16px !important; font-weight: 400 !important; line-height: 1.4 !important; vertical-align: bottom;
}
.nlp-chat textarea.nlp-chat__input:focus { outline: none !important; }
.nlp-chat textarea.nlp-chat__input::placeholder { color: #9aa0b8; opacity: 1; }
.nlp-chat button.nlp-chat__send {
    flex: none; display: grid; place-items: center; width: 42px; height: 42px; margin: 0; padding: 0; border: 0; border-radius: 50%; color: #fff;
    background: var(--nlp-grad); box-shadow: 0 10px 22px -10px rgba(35, 115, 255, .9); transition: transform .3s var(--nlp-spring), opacity .2s;
}
.nlp-chat__send svg { width: 18px; height: 18px; transition: transform .3s var(--nlp-ease); }
.nlp-chat button.nlp-chat__send:hover:not(:disabled) { transform: scale(1.08); }
.nlp-chat button.nlp-chat__send:hover:not(:disabled) svg { transform: translate(1px, -1px); }
.nlp-chat .nlp-chat__input:placeholder-shown + .nlp-chat__send { opacity: .4; transform: scale(.9); }
.nlp-chat button:disabled, .nlp-chat textarea.nlp-chat__input:disabled { cursor: wait; opacity: .5; }
.nlp-chat .nlp-chat__note { margin: 0; padding: 0 16px 12px; background: #fff; color: var(--nlp-muted) !important; font-size: 11.5px; line-height: 1.3; text-align: center; }

/* Panel abierto: el lanzador cede su sitio */
.nlp-chat.is-open .nlp-chat__toggle, .nlp-chat.is-open .nlp-chat__peek { display: none; }

@keyframes nlp-spin { to { --nlp-angle: 360deg; } }
@keyframes nlp-pulse { 0% { box-shadow: 0 0 0 2px #2373ff, 0 0 0 2px rgba(57, 217, 138, .7); } 70%, 100% { box-shadow: 0 0 0 2px #2373ff, 0 0 0 10px rgba(57, 217, 138, 0); } }
@keyframes nlp-launch { from { opacity: 0; transform: translateY(30px) scale(.6); } }
@keyframes nlp-open { from { opacity: 0; transform: translateY(24px) scale(.92); filter: blur(6px); } }
@keyframes nlp-rise { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes nlp-bubble { from { opacity: 0; transform: translateY(10px) scale(.9); } }
@keyframes nlp-pop { from { transform: scale(0); } }

@media (max-width: 640px) {
    .nlp-chat { right: 16px; bottom: 16px; }
    .nlp-chat button.nlp-chat__toggle { padding: 8px; }
    .nlp-chat__toggle-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .nlp-chat__toggle-icon { width: 44px; height: 44px; background: transparent; }
    .nlp-chat.is-open { inset: 0; }
    .nlp-chat__panel { width: 100%; height: 100dvh; border-radius: 0; animation-name: nlp-sheet; }
    .nlp-chat__header { padding-top: max(20px, env(safe-area-inset-top)); }
    .nlp-chat .nlp-chat__note { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    @keyframes nlp-sheet { from { transform: translateY(100%); } }
}
@media (prefers-reduced-motion: reduce) {
    .nlp-chat *, .nlp-chat *::before, .nlp-chat *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
