/* Chat assistant (includes/site/chat.php, assets/js/chat.js). Loaded only where the chat is active.
   Desktop: launcher + floating panel bottom right. Mobile (< 768px): full-screen panel opened from
   the "Chat" item of the sticky bar, sized on the visual viewport so the keyboard never covers the field. */

.chat-av { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface); color: var(--ink); }
.chat-av svg { width: 22px; height: 22px; }

/* ---------- launcher (desktop only) */
.chat-launcher { display: none; }
@media (min-width: 768px) {
  .chat-launcher {
    position: fixed; right: 24px; bottom: 24px; z-index: 30;
    display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 20px 0 10px;
    border-radius: 999px; background: var(--ink); color: var(--paper); font-weight: 600; font-size: .9375rem;
    text-decoration: none; box-shadow: 0 6px 20px rgba(18, 20, 22, .24);
    transition: opacity var(--t), transform var(--t), background var(--t);
  }
  .chat-launcher:hover { background: var(--ink-2); }
  .chat-launcher:focus-visible { outline: none; box-shadow: var(--focus); }
  .chat-launcher.is-hidden, .chat.is-open .chat-launcher { opacity: 0; transform: translateY(12px); pointer-events: none; visibility: hidden; }
  .chat-launcher.is-in { animation: chat-in 420ms cubic-bezier(.2, .7, .2, 1) both; }
}
@keyframes chat-in { from { opacity: 0; transform: translateY(16px); } }

/* ---------- sticky bar with the "Chat" item (4 columns, icon above label) */
.sticky-bar--chat { grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.3fr); }
.sticky-bar--chat .sticky-bar__item:not(.sticky-bar__item--cta) { flex-direction: column; gap: 2px; font-size: .75rem; }
.sticky-bar__item--chat { border: 0; padding: 0; background: none; color: inherit; font-family: inherit; }
.sticky-bar__item--chat[hidden] { display: none; }
.sticky-bar__item--chat:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

/* ---------- preview bubble (once per session, model and vehicle pages) */
.chat-peek {
  position: fixed; right: 16px; bottom: calc(var(--sticky-h) + 12px + env(safe-area-inset-bottom)); z-index: 31;
  display: flex; align-items: flex-start; max-width: min(320px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); border-radius: var(--radius-lg); box-shadow: 0 10px 32px rgba(18, 20, 22, .22);
}
.chat-peek[hidden] { display: none; }
@media (min-width: 768px) { .chat-peek { right: 24px; bottom: 88px; } }
.chat-peek__text { display: flex; gap: 10px; align-items: center; padding: 14px 4px 14px 14px; border: 0; background: none; text-align: left; font-size: .9375rem; line-height: 1.35; font-weight: 500; }
.chat-peek__text .chat-av { background: var(--ink); color: var(--paper); }
.chat-peek__x { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border: 0; background: none; color: var(--muted); }
.chat-peek__x .icon { width: 18px; height: 18px; }
.chat-peek button:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius); }

/* ---------- panel */
.chat__panel[hidden] { display: none; }
.chat__panel {
  position: fixed; z-index: 950; left: 0; right: 0; top: var(--chat-top, 0); height: var(--chat-h, 100dvh);
  display: flex; flex-direction: column; background: var(--paper); color: var(--ink); overflow: hidden;
}
@media (min-width: 768px) {
  .chat__panel {
    left: auto; top: auto; right: 24px; bottom: 24px; width: 380px; height: min(620px, calc(100vh - 48px));
    border-radius: var(--radius-lg); box-shadow: 0 16px 48px rgba(18, 20, 22, .28);
  }
}
.chat__panel:focus { outline: none; }
.chat__head { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 6px 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--ink); color: var(--paper); }
.chat__who { flex: 1; min-width: 0; }
.chat__name { font-weight: 700; line-height: 1.2; }
.chat__sub { font-size: var(--fs-label); color: var(--muted-on-ink); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__icon { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: var(--paper); }
.chat__icon:hover { background: var(--ink-2); }
.chat__icon:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat__icon .icon { width: 22px; height: 22px; }

.chat__log { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 8px; }
.chat__log > * { flex-shrink: 0; }
.chat-row { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.chat-row .chat-av { width: 28px; height: 28px; background: var(--ink); color: var(--paper); }
.chat-row .chat-av svg { width: 18px; height: 18px; }
.chat-row--cont { padding-left: 36px; }
.chat-row--cont .chat-av { display: none; }
.chat-row--me { align-self: flex-end; }
.chat-b { padding: 10px 14px; border-radius: 16px 16px 16px 4px; background: var(--ink); color: var(--paper); font-size: .9375rem; line-height: 1.45; overflow-wrap: anywhere; }
.chat-b a { color: var(--accent); }
.chat-row--me .chat-b { border-radius: 16px 16px 4px 16px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.chat-b--err { background: #FCE9E7; color: var(--err); border: 1px solid #F2C4BF; }
.chat-b--typing { display: flex; gap: 4px; padding: 14px; }
.chat-b--typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-on-ink); animation: chat-dot 1s infinite ease-in-out; }
.chat-b--typing i:nth-child(2) { animation-delay: .15s; }
.chat-b--typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
.chat-row:not(.chat-row--typing) { animation: chat-in 240ms ease-out both; }

/* card (model / offer / summary) */
.chat-card { width: 100%; max-width: 300px; margin-left: 36px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; font-size: .9375rem; }
.chat-card img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--paper-2); }
.chat-card__body { display: grid; gap: 6px; padding: 12px 14px 14px; }
.chat-card__t { font-weight: 700; line-height: 1.25; }
.chat-card__p { font-size: 1.375rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.chat-card dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: var(--fs-small); }
.chat-card dt { color: var(--muted); }
.chat-card dd { text-align: right; font-variant-numeric: tabular-nums; }
.chat-card details { font-size: var(--fs-label); color: var(--muted); }
.chat-card summary { cursor: pointer; font-weight: 600; color: var(--ink); min-height: 32px; display: flex; align-items: center; }
.chat-card a { font-weight: 600; font-size: var(--fs-small); }

/* ---------- input area */
.chat__form { position: relative; flex: none; padding: 8px 14px 6px; border-top: 1px solid var(--line); background: var(--paper); }
.chat__in { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.chat__in:empty { display: none; }
.chat-chip {
  min-height: 44px; padding: 8px 16px; border: 1.5px solid var(--accent); border-radius: 999px;
  background: var(--accent); color: var(--ink); font-weight: 600; font-size: .9375rem; line-height: 1.2; text-align: center;
}
.chat-chip:hover { background: var(--accent-press); border-color: var(--accent-press); }
.chat-chip--alt { background: var(--surface); border-color: var(--line); }
.chat-chip--alt:hover { background: var(--paper-2); border-color: var(--line); }
.chat-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chat-chip:focus-visible, .chat-send:focus-visible { outline: none; box-shadow: var(--focus); }
.chat-chip:disabled { opacity: .45; cursor: default; }
.chat-text { display: flex; gap: 8px; width: 100%; }
.chat-text input {
  flex: 1; min-width: 0; min-height: 48px; padding: 10px 14px; border: 1.5px solid #8E8B83; border-radius: var(--radius);
  background: var(--surface); font-size: 1rem;
}
.chat-text input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent); }
.chat-text input[aria-invalid="true"] { border-color: var(--err); }
.chat-send { flex: none; min-width: 48px; min-height: 48px; padding: 0 14px; border: 0; border-radius: var(--radius); background: var(--accent); color: var(--ink); font-weight: 700; }
.chat-note { width: 100%; font-size: var(--fs-label); line-height: 1.4; color: var(--muted); }
.chat-note a { color: var(--ink); }
.chat-check { display: flex; gap: 8px; align-items: flex-start; width: 100%; font-size: var(--fs-small); line-height: 1.35; cursor: pointer; }
.chat-check input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--ink); }

.chat__exit { flex: none; display: flex; justify-content: center; gap: 20px; padding: 6px 14px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--paper); font-size: var(--fs-small); }
.chat__exit a { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; font-weight: 600; text-decoration: none; }
.chat__exit a:hover { text-decoration: underline; }
.chat__exit .icon { width: 18px; height: 18px; }
.chat__exit .icon--whatsapp { color: var(--wa); }
.chat-wa { display: inline-flex; align-items: center; gap: 8px; margin-left: 36px; min-height: 44px; padding: 0 16px; border-radius: 999px; background: var(--wa); color: #fff; font-weight: 600; text-decoration: none; }
.chat-wa .icon { width: 20px; height: 20px; }

html.chat-lock { overflow: hidden; }
@media (min-width: 768px) { html.chat-lock { overflow: visible; } }
@media (prefers-reduced-motion: reduce) {
  .chat-row, .chat-launcher.is-in { animation: none !important; }
}
