/* Chat de clientes «Lara» (chat-web.mjs + chat-web-panel.mjs). Sobrio tipo iOS, un solo acento (naranja de la marca), Manrope.
   Los colores salen de los tokens de la web (--orange, --ink, --muted, --line, --soft); los valores de respaldo son los mismos. */
.csv-chat-fab, .csv-chat {
  --chat-orange: var(--orange, #bc4b14);
  --chat-orange-dark: var(--orange-dark, #a53f0e);
  --chat-ink: var(--ink, #252a2e);
  --chat-muted: var(--muted, #626970);
  --chat-line: var(--line, #e1e3e5);
  --chat-soft: var(--soft, #f6f6f5);
  --chat-font: var(--body, 'Manrope', Arial, sans-serif);
  --chat-lift: 0px;
  font-family: var(--chat-font);
}
/* Si el banner de cookies está visible, todo sube lo que mide el banner (la web publica --consent-banner-height). */
body:has(#csv-consent-banner) .csv-chat-fab, body:has(#csv-consent-banner) .csv-chat { --chat-lift: calc(var(--consent-banner-height, 0px) + 24px); }

/* ── Botón flotante ── */
.csv-chat-fab {
  position: fixed; z-index: 90; right: 20px; bottom: calc(20px + var(--chat-lift));
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 18px 0 14px;
  border: 0; border-radius: 999px; background: var(--chat-orange); color: #fff; cursor: pointer;
  font: 700 15px/1 var(--chat-font); letter-spacing: -.1px; box-shadow: 0 8px 24px #252a2e30, 0 1px 3px #252a2e20;
  transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.csv-chat-fab[hidden] { display: none; }
.csv-chat-fab:hover { background: var(--chat-orange-dark); transform: translateY(-1px); }
.csv-chat-fab:focus-visible { outline: 3px solid var(--chat-ink); outline-offset: 3px; }
.csv-chat-fab[aria-busy="true"] { opacity: .7; cursor: progress; }
.csv-chat-ico { flex: none; }

/* ── Panel ── */
.csv-chat {
  position: fixed; z-index: 120; right: 20px; bottom: calc(20px + var(--chat-lift));
  display: flex; flex-direction: column; width: 380px; height: min(600px, calc(100dvh - 40px - var(--chat-lift)));
  background: #fff; color: var(--chat-ink); border: 1px solid var(--chat-line); border-radius: 18px; overflow: hidden;
  box-shadow: 0 18px 50px #252a2e2e, 0 2px 8px #252a2e14; font-size: 15px; line-height: 1.5;
}
.csv-chat[hidden] { display: none; }
.csv-chat :is(h3, p, dl, dd, dt, ul) { margin: 0; }
.csv-chat :is(button, input, a) { font-family: inherit; }
.csv-chat :is(button, a, input):focus-visible, .csv-chat-log:focus-visible { outline: 3px solid var(--chat-orange); outline-offset: 2px; }
.csv-chat .sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.csv-chat-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 10px 8px 10px 16px; background: #fff; border-bottom: 1px solid var(--chat-line); }
.csv-chat-avatar { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--chat-soft); border: 1px solid var(--chat-line); color: var(--chat-orange); font-weight: 800; font-size: 16px; }
.csv-chat-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.csv-chat-title strong { font-size: 16px; letter-spacing: -.2px; }
.csv-chat-title span { font-size: 12.5px; color: var(--chat-muted); }
.csv-chat-close { flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--chat-ink); cursor: pointer; }
.csv-chat-close:hover { background: var(--chat-soft); }
.csv-chat-close .icon { width: 20px; height: 20px; }

.csv-chat-log { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 16px 14px; overflow-y: auto; overscroll-behavior: contain; background: var(--chat-soft); -webkit-overflow-scrolling: touch; }
.csv-chat-msg { display: flex; flex-direction: column; gap: 8px; max-width: 90%; }
.csv-chat-msg.is-bot { align-self: flex-start; align-items: flex-start; }
.csv-chat-msg.is-user { align-self: flex-end; align-items: flex-end; max-width: 86%; }
.csv-chat-msg.is-wide { max-width: 100%; align-self: stretch; }
.csv-chat-bubble { padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; font-size: 15px; line-height: 1.5; }
.is-bot > .csv-chat-bubble { background: #fff; border: 1px solid var(--chat-line); border-bottom-left-radius: 6px; }
.is-user > .csv-chat-bubble { background: var(--chat-orange); color: #fff; border-bottom-right-radius: 6px; }
.csv-chat-bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; font-weight: 600; }
.is-bot > .csv-chat-bubble a { color: var(--chat-orange-dark); }

/* Escribiendo… */
.is-typing .csv-chat-bubble { display: inline-flex; align-items: center; gap: 5px; padding: 14px 16px; }
.is-typing .csv-chat-bubble span { width: 7px; height: 7px; border-radius: 50%; background: var(--chat-muted); opacity: .45; animation: csv-chat-dot 1.2s infinite ease-in-out; }
.is-typing .csv-chat-bubble span:nth-child(2) { animation-delay: .15s; }
.is-typing .csv-chat-bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes csv-chat-dot { 0%, 70%, 100% { transform: translateY(0); opacity: .45; } 35% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .is-typing .csv-chat-bubble span { animation: none; opacity: .7; } .csv-chat-fab { transition: none; } }

/* Tarjetas de coche */
.csv-chat-cards { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.csv-chat-card { position: relative; display: flex; flex-direction: row; align-items: stretch; gap: 10px; padding: 8px; background: #fff; border: 1px solid var(--chat-line); border-radius: 14px; overflow: hidden; }
.csv-chat-card:hover { border-color: #b9bdc0; }
.csv-chat-card-img { flex: none; display: block; width: 96px; height: 72px; object-fit: cover; border-radius: 10px; background: var(--chat-soft); }
.csv-chat-card-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.csv-chat-card h3 { font-size: 13.5px; line-height: 1.3; font-weight: 700; letter-spacing: -.1px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.csv-chat-card-price { font-size: 16px; font-weight: 800; letter-spacing: -.3px; }
.csv-chat-card-fee { font-size: 12.5px; color: var(--chat-ink); }
.csv-chat-card-fee span { color: var(--chat-muted); }
.csv-chat-card-legal { font-size: 11px; line-height: 1.35; color: var(--chat-muted); }
.csv-chat-card-store { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--chat-muted); }
.csv-chat-card-store .icon { flex: none; width: 13px; height: 13px; }
.csv-chat-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.csv-chat-card-store { min-width: 0; }
.csv-chat-card-store span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csv-chat-card .csv-chat-card-link { flex: none; min-height: 44px; padding: 0 2px; border: 0; border-radius: 0; background: transparent; color: var(--chat-orange-dark); font-size: 13px; }
.csv-chat-card .csv-chat-card-link:hover { background: transparent; text-decoration: underline; }
.csv-chat-card .csv-chat-card-link::after { content: ''; position: absolute; inset: 0; }

/* Botones */
.csv-chat-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 1px solid var(--chat-line); border-radius: 12px; background: #fff; color: var(--chat-ink); font: 700 14px/1.2 var(--chat-font); text-decoration: none; cursor: pointer; text-align: center; }
.csv-chat-btn:hover { background: var(--chat-soft); border-color: #b9bdc0; }
.csv-chat-btn .icon { flex: none; width: 18px; height: 18px; }
.csv-chat-btn--primary { background: var(--chat-orange); border-color: var(--chat-orange); color: #fff; }
.csv-chat-btn--primary:hover { background: var(--chat-orange-dark); border-color: var(--chat-orange-dark); }
.csv-chat-btn[disabled] { opacity: .5; cursor: progress; }
.csv-chat-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Confirmar cita */
.csv-chat-confirm { display: flex; flex-direction: column; gap: 10px; padding: 14px; background: #fff; border: 1px solid var(--chat-line); border-radius: 14px; }
.csv-chat-confirm h3 { font-size: 16px; letter-spacing: -.2px; outline: none; }
.csv-chat-confirm dl { display: grid; gap: 6px; }
.csv-chat-confirm dl > div { display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 8px; font-size: 14px; }
.csv-chat-confirm dt { color: var(--chat-muted); }
.csv-chat-confirm dd { font-weight: 600; overflow-wrap: anywhere; }
.csv-chat-confirm-note { font-size: 12.5px; color: var(--chat-muted); }
.csv-chat-check { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; font-size: 13.5px; line-height: 1.45; cursor: pointer; }
.csv-chat-check input { flex: none; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--chat-orange); }
.csv-chat-check a { color: var(--chat-orange-dark); font-weight: 600; }
.csv-chat-error { display: none; padding: 8px 10px; border-radius: 10px; background: var(--chat-soft); border: 1px solid var(--chat-orange); color: var(--chat-orange-dark); font-size: 13px; font-weight: 600; }
.csv-chat-error.is-visible { display: block; }
.csv-chat-confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.csv-chat-confirm-actions > .csv-chat-btn { flex: 1 1 auto; }
.csv-chat-confirm.is-done { align-items: flex-start; }
.csv-chat-done-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--chat-soft); color: var(--chat-orange); }
.csv-chat-done-icon.is-ok { background: var(--chat-orange); color: #fff; }
.csv-chat-done-icon .icon { width: 20px; height: 20px; }
.csv-chat-when { font-weight: 700; }

/* Sugerencias */
.csv-chat-chips { flex: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px 4px; background: var(--chat-soft); }
.csv-chat-chips[hidden] { display: none; }
.csv-chat-chip { min-height: 44px; padding: 0 14px; border: 1px solid var(--chat-line); border-radius: 999px; background: #fff; color: var(--chat-ink); font: 600 14px/1.2 var(--chat-font); cursor: pointer; }
.csv-chat-chip:hover { border-color: var(--chat-ink); }

/* Formulario y pie */
.csv-chat-form { flex: none; display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: #fff; border-top: 1px solid var(--chat-line); }
.csv-chat-form input[name="mensaje"] { flex: 1; min-width: 0; height: 48px; padding: 0 16px; border: 1px solid var(--chat-line); border-radius: 24px; background: var(--chat-soft); color: var(--chat-ink); font-size: 16px; }
.csv-chat-form input[name="mensaje"]:focus { background: #fff; border-color: var(--chat-ink); outline: 0; }
.csv-chat-form input[name="mensaje"]:disabled { opacity: .6; }
.csv-chat-send { flex: none; display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 0; border-radius: 50%; background: var(--chat-orange); color: #fff; cursor: pointer; }
.csv-chat-send:hover { background: var(--chat-orange-dark); }
.csv-chat-send[disabled] { opacity: .45; cursor: not-allowed; }
.csv-chat-send .icon { width: 20px; height: 20px; }
.csv-chat-foot { flex: none; padding: 2px 14px calc(8px + env(safe-area-inset-bottom, 0px)); background: #fff; }
.csv-chat-foot p { font-size: 11.5px; line-height: 1.4; color: var(--chat-muted); }
.csv-chat-foot a { color: var(--chat-muted); text-decoration: underline; text-underline-offset: 2px; }
.csv-chat-foot a.csv-chat-link-wa { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; color: var(--chat-ink); font: 700 14px/1.2 var(--chat-font); text-decoration: none; }
.csv-chat-foot a.csv-chat-link-wa:hover { color: var(--chat-orange-dark); }
.csv-chat-link-wa .icon { width: 20px; height: 20px; color: var(--chat-orange); }
.csv-chat-btn--wa .icon { color: var(--chat-orange); }

/* ── Móvil: botón por encima de la barra fija de la ficha / navegación inferior; panel a pantalla completa ── */
@media (max-width: 767px) {
  /* El banner de cookies ocupa media pantalla: hasta que se elija, el botón no flota sobre la página. */
  body:has(#csv-consent-banner) .csv-chat-fab { display: none; }
  .csv-chat-fab { right: 14px; bottom: calc(92px + env(safe-area-inset-bottom, 0px) + var(--chat-lift)); min-height: 46px; padding: 0 16px 0 12px; font-size: 14px; }
  .csv-chat { inset: 0; width: 100%; height: 100dvh; max-height: none; border: 0; border-radius: 0; z-index: 140; box-shadow: none; }
  .csv-chat-head { padding-top: calc(10px + env(safe-area-inset-top, 0px)); padding-left: calc(16px + env(safe-area-inset-left, 0px)); }
  .csv-chat-log { padding-left: calc(14px + env(safe-area-inset-left, 0px)); padding-right: calc(14px + env(safe-area-inset-right, 0px)); }
  .csv-chat-form { padding-bottom: 10px; }
  body.csv-chat-lock { overflow: hidden; }
}

/* ── v3: visor del coche, tarjeta de cuota y tarjeta de cita (mismo estilo sobrio, un solo acento) ── */
.csv-chat-log { position: relative; }
.csv-chat-card-link { cursor: pointer; }
.csv-chat-legal { font-size: 11.5px; line-height: 1.4; color: var(--chat-muted); }
.csv-chat-sub { font-size: 13.5px; line-height: 1.45; color: var(--chat-muted); }

/* Base de las tarjetas anchas (cuota, cita) */
.csv-chat-panelcard { display: flex; flex-direction: column; gap: 10px; padding: 14px; background: #fff; border: 1px solid var(--chat-line); border-radius: 14px; }
.csv-chat-panelcard h3 { font-size: 16px; letter-spacing: -.2px; line-height: 1.3; outline: none; }
.csv-chat-panelcard.is-loading { color: var(--chat-muted); }
.csv-chat-panelcard[aria-busy="true"] { opacity: .65; }
.csv-chat-wide { width: 100%; }

/* Visor: carrusel con scroll-snap (deslizar en móvil), flechas y teclado en escritorio */
.csv-chat-viewer { overflow: hidden; background: #fff; border: 1px solid var(--chat-line); border-radius: 14px; }
.csv-chat-viewer.is-loading[aria-busy="true"] { opacity: 1; }
.csv-chat-gallery { position: relative; background: var(--chat-soft); aspect-ratio: 4 / 3; }
.csv-chat-gallery.is-empty { display: grid; place-items: center; color: var(--chat-muted); font-size: 13.5px; }
.csv-chat-slides { display: flex; width: 100%; height: 100%; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
.csv-chat-slides::-webkit-scrollbar { display: none; }
.csv-chat-slides:focus-visible { outline: 3px solid var(--chat-orange); outline-offset: -3px; }
.csv-chat-slide { flex: 0 0 100%; width: 100%; height: 100%; scroll-snap-align: center; scroll-snap-stop: always; }
.csv-chat-slide img { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; background: var(--chat-soft); }
.csv-chat-gal-btn { position: absolute; top: 50%; z-index: 1; display: grid; place-items: center; width: 44px; height: 44px; margin-top: -22px; padding: 0; border: 0; border-radius: 50%; background: #ffffffe6; color: var(--chat-ink); box-shadow: 0 2px 8px #252a2e30; cursor: pointer; }
.csv-chat-gal-btn.is-prev { left: 8px; }
.csv-chat-gal-btn.is-next { right: 8px; }
.csv-chat-gal-btn:hover { background: #fff; }
.csv-chat-gal-btn[disabled] { opacity: 0; pointer-events: none; }
.csv-chat-gal-count { position: absolute; right: 10px; bottom: 10px; padding: 3px 10px; border-radius: 999px; background: #252a2ecc; color: #fff; font-size: 12.5px; font-weight: 700; line-height: 1.5; font-variant-numeric: tabular-nums; }
.csv-chat-v-body { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 14px; }
.csv-chat-viewer h3 { font-size: 16px; line-height: 1.3; letter-spacing: -.2px; }
.csv-chat-v-price { font-size: 22px; font-weight: 800; letter-spacing: -.5px; line-height: 1.2; }
.csv-chat-v-was { margin-left: 8px; font-size: 14px; font-weight: 600; color: var(--chat-muted); letter-spacing: 0; }
.csv-chat-v-fee { font-size: 14px; }
.csv-chat-specs { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 2px 0 0; padding: 0; list-style: none; font-size: 13px; }
.csv-chat-specs li { display: inline-flex; align-items: center; gap: 5px; }
.csv-chat-specs .icon, .csv-chat-points .icon, .csv-chat-v-warranty .icon { flex: none; width: 15px; height: 15px; color: var(--chat-orange); }
.csv-chat-points { display: grid; gap: 3px; margin: 0; padding: 8px 10px; list-style: none; font-size: 13px; background: var(--chat-soft); border-radius: 10px; }
.csv-chat-points li { display: flex; align-items: flex-start; gap: 6px; }
.csv-chat-v-warranty { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.csv-chat-v-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.csv-chat-v-actions > .csv-chat-btn { flex: 1 1 auto; }
.csv-chat-v-actions > .csv-chat-btn--primary { flex-basis: 100%; }
.csv-chat-btn--quiet { border-color: transparent; background: transparent; color: var(--chat-orange-dark); }
.csv-chat-btn--quiet:hover { background: var(--chat-soft); border-color: transparent; text-decoration: underline; }

/* Cuota */
.csv-chat-q-fee { display: flex; align-items: baseline; gap: 4px; }
.csv-chat-q-fee strong { font-size: 28px; font-weight: 800; letter-spacing: -.8px; line-height: 1.1; }
.csv-chat-q-fee span { font-size: 15px; color: var(--chat-muted); font-weight: 600; }
.csv-chat-q-dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.csv-chat-q-dl > div { display: flex; flex-direction: column; min-width: 0; }
.csv-chat-q-dl dt { font-size: 12px; color: var(--chat-muted); }
.csv-chat-q-dl dd { font-size: 14.5px; font-weight: 700; overflow-wrap: anywhere; }

/* Chips de selección (plazo, entrada, día, hora) */
.csv-chat-pickgroup { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.csv-chat-pick-label { font-size: 12.5px; font-weight: 700; color: var(--chat-muted); }
.csv-chat-chiprow { display: flex; flex-wrap: wrap; gap: 8px; }
.csv-chat-pick { min-height: 44px; min-width: 44px; padding: 0 14px; border: 1px solid var(--chat-line); border-radius: 999px; background: #fff; color: var(--chat-ink); font: 600 14px/1.2 var(--chat-font); cursor: pointer; font-variant-numeric: tabular-nums; }
.csv-chat-pick:hover { border-color: var(--chat-ink); }
.csv-chat-pick[aria-pressed="true"] { background: var(--chat-orange); border-color: var(--chat-orange); color: #fff; }
.csv-chat-q-form { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.csv-chat-q-form input { flex: 1; min-width: 0; height: 44px; padding: 0 14px; border: 1px solid var(--chat-line); border-radius: 12px; background: var(--chat-soft); color: var(--chat-ink); font-size: 16px; }
.csv-chat-q-form input:focus { background: #fff; border-color: var(--chat-ink); outline: 0; }

/* Cita: datos del cliente */
.csv-chat-field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 700; color: var(--chat-muted); }
.csv-chat-field input { height: 48px; padding: 0 14px; border: 1px solid var(--chat-line); border-radius: 12px; background: var(--chat-soft); color: var(--chat-ink); font-size: 16px; font-weight: 500; }
.csv-chat-field input:focus { background: #fff; border-color: var(--chat-ink); outline: 0; }

@media (prefers-reduced-motion: no-preference) { .csv-chat-slides { scroll-behavior: smooth; } }
@media (max-width: 767px) {
  .csv-chat-gal-btn { width: 44px; height: 44px; background: #ffffffd9; }
  .csv-chat-panelcard { padding: 14px 12px; }
}
.csv-chat-tiendas { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.csv-chat-tienda { flex-direction: column; }
.csv-chat-tienda .csv-chat-card-foot { margin-top: 6px; }
