/* MTS booking-assistant chat widget. Brand tokens mirror the site palette
   (accent #E30613, WhatsApp #25D366, ink/paper). Compositor-friendly motion
   only (transform/opacity); no layout-shifting properties animated. */
.mts-chat {
  --mc-accent: #E30613;
  --mc-accent-dk: #B8050F;
  --mc-ink: #111111;
  --mc-paper: #F4F4F2;
  --mc-line: #D8D8D2;
  --mc-muted: #6b6b66;
  --mc-wa: #25D366;
  --mc-radius: 16px;
  --mc-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  position: fixed;
  right: clamp(12px, 4vw, 28px);
  bottom: clamp(12px, 4vw, 28px);
  z-index: 2147483000;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ── Launcher: CTA speech-bubble above a Toyota Hiace avatar ─────────────────── */
.mts-chat__launcher {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}
.mts-chat__launcher:hover { transform: translateY(-2px); }
.mts-chat__launcher:active { transform: translateY(0); }
.mts-chat__launcher:focus-visible { outline: 3px solid #111; outline-offset: 4px; border-radius: 999px; }
.mts-chat[data-open="true"] .mts-chat__launcher { display: none; }

.mts-chat__launcher-cta {
  position: relative;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--mc-accent);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--mc-shadow);
  animation: mts-cta-pulse 3.4s ease-in-out infinite;
}
/* Speech-bubble tail pointing down toward the avatar */
.mts-chat__launcher-cta::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  border-width: 6px 6px 0 6px;
  border-style: solid;
  border-color: var(--mc-accent) transparent transparent transparent;
}

.mts-chat__launcher-avatar {
  position: relative;
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--mc-ink);
  border: 3px solid #fff;
  box-shadow: var(--mc-shadow);
}
.mts-chat__launcher-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.mts-chat__launcher-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--mc-wa);
  border: 2px solid #fff;
  font-size: 0.8rem;
  line-height: 1;
}

@keyframes mts-cta-pulse {
  0%, 82%, 100% { transform: scale(1); }
  88% { transform: scale(1.06); }
  94% { transform: scale(1); }
}

/* Step aside while a booking modal (.bk-overlay) owns the screen, so the
   launcher never floats over it. */
.mts-chat[data-hidden-by-modal="true"] { display: none; }

/* ── Panel ────────────────────────────────────────────────────────────────── */
.mts-chat__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  width: min(380px, calc(100vw - 24px));
  /* dvh so the panel shrinks with the visual viewport when the mobile
     keyboard/toolbars appear; vh is the fallback for older engines. */
  height: min(560px, calc(100vh - 48px));
  height: min(560px, calc(100dvh - 48px));
  background: var(--mc-paper);
  border: 1px solid var(--mc-line);
  border-radius: var(--mc-radius);
  box-shadow: var(--mc-shadow);
  overflow: hidden;
  transform: translateY(12px) scale(0.98);
  opacity: 0;
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1), opacity 180ms ease;
}
.mts-chat[data-open="true"] .mts-chat__panel {
  display: flex;
  transform: translateY(0) scale(1);
  opacity: 1;
}

.mts-chat__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--mc-accent);
  color: #fff;
}
.mts-chat__title { font-size: 1rem; font-weight: 700; line-height: 1.2; }
/* Solid near-white (not opacity) to clear WCAG AA 4.5:1 against --mc-accent. */
.mts-chat__subtitle { font-size: 0.72rem; color: rgba(255, 255, 255, 0.95); font-weight: 500; }
.mts-chat__close {
  margin-left: auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 150ms ease;
}
.mts-chat__close:hover { background: rgba(255, 255, 255, 0.35); }
.mts-chat__close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Visually hidden but announced to screen readers (typing indicator label). */
.mts-chat__sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mts-chat__log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.mts-chat__msg {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.mts-chat__msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--mc-line);
  color: var(--mc-ink);
  border-bottom-left-radius: 4px;
}
.mts-chat__msg--user {
  align-self: flex-end;
  background: var(--mc-ink);
  color: var(--mc-paper);
  border-bottom-right-radius: 4px;
}

.mts-chat__handoff {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  padding: 11px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--mc-wa);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease;
}
.mts-chat__handoff:hover { transform: translateY(-1px); filter: brightness(1.05); }
.mts-chat__handoff:focus-visible { outline: 3px solid var(--mc-ink); outline-offset: 2px; }

/* Typing indicator */
.mts-chat__typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.mts-chat__typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--mc-muted);
  animation: mts-bounce 1.2s infinite ease-in-out;
}
.mts-chat__typing span:nth-child(2) { animation-delay: 0.18s; }
.mts-chat__typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes mts-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.mts-chat__form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--mc-line);
  background: #fff;
}
.mts-chat__input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--mc-line);
  border-radius: 999px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--mc-ink);
  background: var(--mc-paper);
}
.mts-chat__input:focus-visible { outline: 2px solid var(--mc-accent); outline-offset: 0; }
.mts-chat__send {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--mc-accent);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}
.mts-chat__send:hover:not(:disabled) { background: var(--mc-accent-dk); }
.mts-chat__send:active:not(:disabled) { transform: scale(0.94); }
.mts-chat__send:disabled { opacity: 0.5; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
  .mts-chat__launcher,
  .mts-chat__panel,
  .mts-chat__handoff,
  .mts-chat__send { transition: none; }
  .mts-chat__typing span { animation: none; opacity: 0.7; }
  .mts-chat__launcher-cta { animation: none; }
}
