/* ==========================================================================
   KCT chat widget (assets/js/kct-chat.js)
   Uses the theme tokens from style.css with fallbacks so it also renders on
   pages that load it without the main stylesheet.
   ========================================================================== */

.kct-chat {
  --kc-ink: var(--ink, #0d0d0d);
  --kc-paper: var(--paper, #ffffff);
  --kc-bg: #f6f5f2;
  --kc-line: var(--line, #e2e0db);
  --kc-muted: var(--muted, #6f6c66);
  --kc-accent: var(--accent, #ff4800);
  --kc-accent-strong: var(--accent-strong, #e63f1d);
  --kc-accent-soft: #fff1eb;
  --kc-font: var(--font-sans, "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif);
  --kc-ease: cubic-bezier(0.23, 1, 0.32, 1);
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9990; /* below the booking popup (10000) so "Book a call" opens on top */
  font-family: var(--kc-font);
  color: var(--kc-ink);
  -webkit-font-smoothing: antialiased;
}
.kct-chat *, .kct-chat *::before, .kct-chat *::after { box-sizing: border-box; }
.kct-chat [hidden] { display: none !important; }

/* ---------------- Launcher ---------------- */
.kct-chat-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  padding: 0;
  margin: 0 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: var(--kc-ink);
  color: var(--kc-paper);
  cursor: pointer;
  box-shadow: 0 10px 28px -8px rgba(13, 13, 13, 0.45), 0 2px 6px rgba(13, 13, 13, 0.18);
  transition: transform 0.25s var(--kc-ease), background 0.2s ease;
  animation: kct-chat-float 4.5s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}
.kct-chat-launcher:hover { transform: scale(1.06); background: #1d1d1d; }
.kct-chat-launcher:active { transform: scale(0.96); }
.kct-chat-launcher:focus-visible { outline: 3px solid var(--kc-accent); outline-offset: 3px; }

/* Orange ripple that breathes out of the button */
.kct-chat-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}
.kct-chat-pulse::before,
.kct-chat-pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--kc-accent);
  opacity: 0;
  animation: kct-chat-ripple 3.2s var(--kc-ease) infinite;
}
.kct-chat-pulse::after { animation-delay: 1.6s; }

.kct-chat-ico { position: absolute; transition: transform 0.35s var(--kc-ease), opacity 0.25s ease; }
.kct-chat-ico--chat { transform-origin: 50% 60%; animation: kct-chat-wiggle 6s ease-in-out infinite; }
.kct-chat-bub { fill: var(--kc-accent); }
.kct-chat-dot { fill: #fff; animation: kct-chat-dots 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.kct-chat-dot--2 { animation-delay: 0.18s; }
.kct-chat-dot--3 { animation-delay: 0.36s; }
.kct-chat-ico--close { opacity: 0; transform: rotate(-90deg) scale(0.6); }

.kct-chat.is-open .kct-chat-launcher { animation: none; }
.kct-chat.is-open .kct-chat-pulse { display: none; }
.kct-chat.is-open .kct-chat-ico--chat { opacity: 0; transform: rotate(90deg) scale(0.6); animation: none; }
.kct-chat.is-open .kct-chat-ico--close { opacity: 1; transform: none; }

.kct-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--kc-accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 0 0 3px var(--kc-paper);
  animation: kct-chat-pop 0.4s var(--kc-ease);
}

/* ---------------- Teaser bubble ---------------- */
.kct-chat-teaser {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: max-content;
  max-width: min(280px, calc(100vw - 48px));
  padding: 14px 34px 14px 16px;
  background: var(--kc-paper);
  border: 1px solid var(--kc-line);
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 14px 36px -12px rgba(13, 13, 13, 0.28);
  cursor: pointer;
  animation: kct-chat-rise 0.45s var(--kc-ease);
}
.kct-chat-teaser-text { margin: 0; font-size: 14.5px; line-height: 1.45; color: var(--kc-ink); }
.kct-chat-teaser-x {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--kc-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.kct-chat-teaser-x:hover { background: #f1f0ec; color: var(--kc-ink); }

/* ---------------- Panel ---------------- */
.kct-chat-panel {
  position: absolute;
  right: 0;
  bottom: 78px;
  display: flex;
  flex-direction: column;
  width: 384px;
  height: min(620px, calc(100vh - 120px));
  height: min(620px, calc(100dvh - 120px));
  background: var(--kc-bg);
  border: 1px solid var(--kc-line);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 64px -20px rgba(13, 13, 13, 0.4), 0 4px 14px rgba(13, 13, 13, 0.08);
  transform-origin: bottom right;
  animation: kct-chat-open 0.35s var(--kc-ease);
}

.kct-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 14px 16px;
  background: var(--kc-ink);
  color: #fff;
}
.kct-chat-avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  color: var(--kc-accent);
  font-weight: 700;
}
.kct-chat-avatar img { display: block; width: 22px; height: 22px; }
.kct-chat-online {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px var(--kc-ink);
}
.kct-chat-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; margin-right: auto; }
.kct-chat-title strong { font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; }
.kct-chat-title span { font-size: 12.5px; color: rgba(255, 255, 255, 0.66); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kct-chat-hbtn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}
.kct-chat-hbtn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.kct-chat-hbtn:focus-visible { outline: 2px solid var(--kc-accent); outline-offset: 1px; }

/* ---------------- Messages ---------------- */
.kct-chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 14px 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.kct-msg { display: flex; animation: kct-chat-msg 0.32s var(--kc-ease); }
.kct-msg--user { justify-content: flex-end; }
.kct-bubble {
  max-width: 86%;
  padding: 10px 14px;
  font-size: 14.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  border-radius: 16px;
}
.kct-msg--bot .kct-bubble {
  background: var(--kc-paper);
  border: 1px solid var(--kc-line);
  border-bottom-left-radius: 5px;
  color: var(--kc-ink);
}
.kct-msg--user .kct-bubble {
  background: var(--kc-ink);
  color: #fff;
  border-bottom-right-radius: 5px;
  white-space: pre-wrap;
}
.kct-msg--bot + .kct-msg--bot .kct-bubble { border-top-left-radius: 5px; }
.kct-msg--user + .kct-msg--user .kct-bubble { border-top-right-radius: 5px; }
.kct-msg--user + .kct-msg--bot,
.kct-msg--bot + .kct-msg--user { margin-top: 6px; }
.kct-bubble a { color: var(--kc-accent-strong); text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }
.kct-bubble a:hover { color: var(--kc-ink); }
.kct-bubble strong { font-weight: 600; }
.kct-msg--note .kct-bubble {
  max-width: 100%;
  padding: 2px 4px;
  background: none;
  border: 0;
  font-size: 12px;
  color: var(--kc-muted);
}
.kct-msg--note .kct-bubble a { color: var(--kc-muted); }

/* Typing indicator */
.kct-msg--typing .kct-bubble { display: inline-flex; gap: 5px; padding: 14px 16px; }
.kct-msg--typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b4b1aa;
  animation: kct-chat-typing 1.2s ease-in-out infinite;
}
.kct-msg--typing span:nth-child(2) { animation-delay: 0.15s; }
.kct-msg--typing span:nth-child(3) { animation-delay: 0.3s; }

/* ---------------- Quick replies ---------------- */
.kct-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 14px 12px;
}
.kct-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--kc-ink);
  background: var(--kc-paper);
  border: 1px solid #d9d6cf;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  animation: kct-chat-msg 0.3s var(--kc-ease) both;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}
.kct-chip:hover { border-color: var(--kc-accent); color: var(--kc-accent-strong); transform: translateY(-1px); }
.kct-chip:focus-visible { outline: 2px solid var(--kc-accent); outline-offset: 2px; }
.kct-chip--book { background: var(--kc-ink); border-color: var(--kc-ink); color: #fff; }
.kct-chip--book:hover { background: var(--kc-accent); border-color: var(--kc-accent); color: #fff; }

/* ---------------- Composer ---------------- */
.kct-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 12px;
  padding: 6px 6px 6px 14px;
  background: var(--kc-paper);
  border: 1px solid var(--kc-line);
  border-radius: 16px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.kct-chat-form:focus-within { border-color: #c9c5bd; box-shadow: 0 0 0 3px rgba(255, 72, 0, 0.12); }
.kct-chat-input {
  flex: 1;
  min-height: 24px;
  max-height: 120px;
  margin: 0;
  padding: 7px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px; /* ≥15px avoids iOS zoom-on-focus at 16 with rounding */
  line-height: 1.4;
  color: var(--kc-ink);
}
.kct-chat-input::placeholder { color: #9c988f; }
.kct-chat-send {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--kc-accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}
.kct-chat-send:hover { background: var(--kc-accent-strong); }
.kct-chat-send:active { transform: scale(0.94); }
.kct-chat-send:focus-visible { outline: 2px solid var(--kc-ink); outline-offset: 2px; }
.kct-chat-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.kct-chat-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.kct-chat-foot {
  margin: 0;
  padding: 8px 12px 10px;
  font-size: 11.5px;
  text-align: center;
  color: #9c988f;
}
.kct-chat-foot a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ---------------- Animations ---------------- */
@keyframes kct-chat-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes kct-chat-ripple {
  0% { transform: scale(1); opacity: 0.55; }
  80%, 100% { transform: scale(1.65); opacity: 0; }
}
@keyframes kct-chat-wiggle {
  0%, 82%, 100% { transform: rotate(0); }
  85% { transform: rotate(-12deg); }
  88% { transform: rotate(10deg); }
  91% { transform: rotate(-6deg); }
  94% { transform: rotate(3deg); }
}
@keyframes kct-chat-dots { 0%, 60%, 100% { transform: translateY(0); opacity: 0.75; } 30% { transform: translateY(-2.2px); opacity: 1; } }
@keyframes kct-chat-typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes kct-chat-open { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes kct-chat-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes kct-chat-msg { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes kct-chat-pop { from { transform: scale(0); } to { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .kct-chat-launcher, .kct-chat-ico--chat, .kct-chat-dot, .kct-chat-pulse::before, .kct-chat-pulse::after,
  .kct-chat-panel, .kct-msg, .kct-chip, .kct-chat-teaser, .kct-chat-badge, .kct-msg--typing span { animation: none !important; }
  .kct-chat-ico, .kct-chip, .kct-chat-launcher { transition: none; }
}

/* ---------------- Phones: full-screen sheet ---------------- */
@media (max-width: 640px) {
  .kct-chat { right: 16px; bottom: 16px; }
  .kct-chat-launcher { width: 58px; height: 58px; }
  .kct-chat-teaser { bottom: 70px; }
  .kct-chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    animation-name: kct-chat-rise;
  }
  .kct-chat-head { padding-top: max(14px, env(safe-area-inset-top)); }
  .kct-chat-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .kct-chat-input { font-size: 16px; } /* prevents iOS zoom on focus */
  .kct-chat.is-open .kct-chat-launcher { display: none; }
  html.kct-chat-open, html.kct-chat-open body { overflow: hidden; }
}

@media print { .kct-chat { display: none !important; } }
