/* Web chat assistant (assets/chat/chat.js builds the markup). Only the site's tokens: --bg --surface --ink
   --muted --line --line-strong --action --s-* --t-* --r-* --btn-h --ease --dur. Light only, like the site. */

/* the launcher: ink on paper, so it never competes with the blue "Pedir diagnóstico gratis" */
.cs-chat__launcher {
  position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 45;
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: 48px; padding: 0 var(--s-5) 0 var(--s-4); border: 1px solid transparent; border-radius: var(--r-btn);
  background: var(--ink); color: var(--bg); font: 500 var(--t-body)/1 var(--font-text); cursor: pointer;
  box-shadow: 0 6px 24px color-mix(in oklab, var(--ink) 22%, transparent);
  transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease), translate 240ms var(--ease);
}
.cs-chat__launcher:hover { background: color-mix(in oklab, var(--ink) 86%, var(--bg)); }
.cs-chat__launcher:active { transform: translateY(1px) scale(.985); }
.cs-chat__launcher:focus-visible { outline-color: var(--ink); outline-offset: 3px; }
/* over the dark footer (chat.js sets data-on-dark): a light button with an ink icon, so it never melts into the navy */
.cs-chat__launcher[data-on-dark] { background: var(--bg, #f3f0ea); color: var(--ink); border-color: var(--line-strong); }
.cs-chat__launcher[data-on-dark]:hover { background: color-mix(in oklab, var(--bg, #f3f0ea) 90%, var(--ink)); }
.cs-chat__launcher[data-on-dark]:focus-visible { outline: 2px solid var(--bg, #f3f0ea); outline-offset: 3px; box-shadow: 0 0 0 5px var(--ink); }
.cs-chat__launcher svg { flex: none; width: 18px; height: 18px; }

/* the panel: a non-modal dialog, 380 x 560 at the corner on a desktop */
.cs-chat__panel {
  position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 60;
  display: flex; flex-direction: column; width: 380px; height: min(560px, calc(100vh - 48px)); height: min(560px, calc(100dvh - 48px));
  background: var(--bg); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r-lg); overflow: hidden;
  box-shadow: 0 12px 48px color-mix(in oklab, var(--ink) 20%, transparent);
  font: 400 var(--t-body)/1.45 var(--font-text);
  animation: cs-chat-in 200ms var(--ease);
}
@keyframes cs-chat-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.cs-chat__head { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); border-bottom: 1px solid var(--line); }
.cs-chat__title { margin: 0; font: 600 var(--t-body)/1.2 var(--font-text); letter-spacing: 0; }
.cs-chat__tag { padding: 2px var(--s-2); border: 1px solid var(--line-strong); border-radius: var(--r-sm); color: var(--muted); font: 500 var(--t-label)/1.3 var(--font-text); }
.cs-chat__close {
  display: inline-flex; align-items: center; justify-content: center; margin-left: auto; width: var(--btn-h); height: var(--btn-h);
  border: 0; border-radius: var(--r-btn); background: none; color: var(--ink); cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.cs-chat__close:hover { background: color-mix(in oklab, var(--ink) 8%, var(--bg)); }
.cs-chat__close svg { width: 16px; height: 16px; }

.cs-chat__log { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
.cs-chat__log:focus-visible { outline-offset: -2px; }
.cs-chat__msg { max-width: 88%; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); overflow-wrap: anywhere; white-space: pre-wrap; }
.cs-chat__msg--bot { align-self: flex-start; background: var(--surface); }
.cs-chat__msg--me { align-self: flex-end; background: var(--ink); color: var(--bg); }
.cs-chat__msg--error { background: color-mix(in oklab, var(--ink) 8%, var(--bg)); border: 1px solid var(--line-strong); }
.cs-chat__msg a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.cs-chat__msg--bot a { color: var(--action); text-decoration-color: currentColor; }
.cs-chat__msg a:hover { text-decoration-thickness: 2px; }

.cs-chat__chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.cs-chat__chips .btn { height: auto; min-height: var(--btn-h-sm); padding: var(--s-2) var(--s-4); white-space: normal; text-align: left; line-height: 1.25; }

.cs-chat__typing { padding: var(--s-3) var(--s-4); }
.cs-chat__dots { display: inline-flex; gap: 5px; align-items: center; height: 1.45em; }
.cs-chat__dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: cs-chat-dot 1.1s var(--ease) infinite; }
.cs-chat__dots i:nth-child(2) { animation-delay: .15s; }
.cs-chat__dots i:nth-child(3) { animation-delay: .3s; }
@keyframes cs-chat-dot { 0%, 70%, 100% { opacity: .35; transform: none; } 35% { opacity: 1; transform: translateY(-3px); } }

.cs-chat__form { flex: none; padding: var(--s-3) var(--s-4) var(--s-3); border-top: 1px solid var(--line); background: var(--bg); }
.cs-chat__row { display: flex; align-items: flex-end; gap: var(--s-2); }
.cs-chat__input {
  flex: 1 1 auto; min-width: 0; min-height: var(--btn-h); max-height: 132px; margin: 0; padding: 10px var(--s-3); resize: none;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--bg); color: var(--ink);
  font: 400 16px/1.4 var(--font-text);   /* 16px: a phone never zooms in on focus */
}
.cs-chat__input::placeholder { color: var(--muted); }
.cs-chat__send {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: var(--btn-h); height: var(--btn-h);
  border: 0; border-radius: var(--r-btn); background: var(--action); color: var(--action-ink); cursor: pointer;
  transition: background-color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.cs-chat__send:hover:not(:disabled) { background: color-mix(in oklab, var(--action) 86%, var(--ink)); }
.cs-chat__send:disabled { opacity: .4; cursor: default; }
.cs-chat__count { display: block; margin-top: var(--s-1); color: var(--muted); font-size: var(--t-label); text-align: right; }
.cs-chat__note { margin: var(--s-2) 0 0; color: var(--muted); font-size: var(--t-label); line-height: 1.4; }
.cs-chat__note a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }

/* the "Pruébalo" buttons in the page: a long label wraps instead of running off a phone */
.cs-try { height: auto; min-height: var(--btn-h); padding-block: var(--s-3); white-space: normal; text-align: center; line-height: 1.3; }

/* a phone: a near-full-screen sheet; the launcher floats above the action bar (which is 64px + the safe area) once it is shown */
@media (max-width: 639px) {
  .cs-chat__launcher { right: var(--s-4); bottom: calc(var(--s-4) + env(safe-area-inset-bottom)); }
  /* chat.js mirrors the action bar's data-bar onto the launcher, so these are plain attribute selectors on the launcher
     (no :root:has(), no layout): the lift is a translate, which only composites; hover/press keep using transform */
  .cs-chat__launcher[data-bar="shown"], .cs-chat__launcher[data-bar="always"] { translate: 0 calc(var(--s-4) - 64px - var(--s-3)); }
  /* on the hero (and wherever the action bar steps aside for an on-screen CTA) the launcher steps aside too, so it never
     covers a page button; the "Pruébalo" buttons in #ejemplo and #contacto still open the chat there */
  .cs-chat__launcher[data-bar]:not([data-bar="shown"], [data-bar="always"]) { opacity: 0; visibility: hidden; pointer-events: none; }
  .cs-chat__launcher { transition: opacity .2s ease, visibility .2s, translate .2s ease, transform var(--dur) var(--ease), background-color var(--dur) var(--ease); }
  /* a compact round icon on a phone, so it covers little of the page; the label stays for screen readers (visually hidden, not removed) */
  .cs-chat__launcher { width: 48px; height: 48px; min-height: 48px; padding: 0; justify-content: center; border-radius: 50%; gap: 0; }
  .cs-chat__launcher svg { width: 22px; height: 22px; }
  .cs-chat__launcher > span { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
  .cs-chat__panel {
    left: 0; right: 0; bottom: 0; width: auto; height: calc(100vh - var(--s-5)); height: calc(100dvh - var(--s-5));
    border-width: 1px 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .cs-chat__form { padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom)); }
  .cs-chat__chips .btn { min-height: var(--btn-h); }
  .cs-chat__msg { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .cs-chat__panel { animation: none; }
  .cs-chat__launcher { transition: none; }
  .cs-chat__dots i { animation: none; opacity: .6; }
}
@media print { .cs-chat { display: none; } }
