/* Kormat chatbot widget — bottom-right floating CTA + chat panel.
   Tokens align with .kf-* inquiry modal (brand green #7cb436, noto-sc font,
   z 9000/9999). Chatbot sits at bottom-right to avoid the top-right Contact
   FAB. Hidden while the inquiry modal is open. */

:root {
  --kc-green: #7cb436;
  --kc-green-dark: #6a9b2d;
  --kc-green-soft: #e8efe4;
  --kc-ivory: #fafbf8;
  --kc-border: #e8e9e2;
  --kc-text: #2a2e25;
  --kc-text-soft: #6b6f63;
  --kc-shadow-fab: 0 10px 24px rgba(124, 180, 54, 0.32),
                   0 2px 6px rgba(0, 0, 0, 0.08),
                   0 1px 0 rgba(255, 255, 255, 0.22) inset;
  --kc-shadow-panel: 0 24px 60px rgba(20, 35, 10, 0.18),
                     0 4px 14px rgba(0, 0, 0, 0.08);
  --kc-font: var(--noto-sc, -apple-system, BlinkMacSystemFont, "Segoe UI",
             Roboto, "Noto Sans SC", "Helvetica Neue", Arial, sans-serif);
}

/* ── FAB (closed state) ──────────────────────────────────────────── */
/* Heidi-persona FAB: round face avatar + corner chat-bubble badge.
   White inner with brand-green ring carries the color story while letting
   the face read cleanly — pure green background washed out the skin tones. */
.kc-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9000;
  width: 62px;
  height: 62px;
  padding: 0;
  border: 3px solid var(--kc-green);
  border-radius: 9999px;
  background: #fff;
  color: #fff;
  cursor: pointer;
  display: block;
  box-shadow: var(--kc-shadow-fab);
  overflow: visible; /* badge needs to spill outside the disc */
  transition:
    transform 220ms cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 220ms cubic-bezier(0.4, 0, 0.2, 1),
    border-color 220ms ease,
    opacity 200ms ease;
  /* enter from bottom-right after page settles */
  animation: kc-fab-enter 520ms cubic-bezier(0.34, 1.4, 0.64, 1) 800ms backwards;
}

.kc-fab__face {
  width: 100%;
  height: 100%;
  border-radius: 9999px;
  object-fit: cover;
  display: block;
  background: #ecead8; /* fallback while image loads */
}

/* Online indicator: solid green dot with a soft pulsing ring (the
   Slack/Messenger/WhatsApp convention — instantly recognized as
   "available person, ready to chat"). */
.kc-fab__badge {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 14px;
  height: 14px;
  border-radius: 9999px;
  background: #22c55e; /* slightly brighter green than brand for the dot to read at this size */
  border: 2px solid #fff;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: kc-fab-pulse 1800ms ease-out infinite;
}

@keyframes kc-fab-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

@keyframes kc-fab-enter {
  from { transform: translateY(24px) scale(0.7); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* One-time wiggle ~1.5s after enter to draw attention */
.kc-fab.kc-wiggle {
  animation:
    kc-fab-enter 520ms cubic-bezier(0.34, 1.4, 0.64, 1) 800ms backwards,
    kc-wiggle 600ms cubic-bezier(0.36, 0.07, 0.19, 0.97) 2000ms 1;
}

@keyframes kc-wiggle {
  0%, 100% { transform: rotate(0); }
  20%      { transform: rotate(-9deg); }
  40%      { transform: rotate(7deg); }
  60%      { transform: rotate(-5deg); }
  80%      { transform: rotate(3deg); }
}

.kc-fab:hover {
  transform: translateY(-3px);
  border-color: #6fa42d;
  box-shadow:
    0 16px 32px rgba(124, 180, 54, 0.42),
    0 4px 10px rgba(0, 0, 0, 0.1);
}

.kc-fab:active { transform: translateY(-1px); }

.kc-fab:focus-visible {
  outline: 3px solid rgba(124, 180, 54, 0.45);
  outline-offset: 3px;
}

/* Hide FAB while inquiry modal or chat panel is open */
body.kf-modal-open .kc-fab,
body.kc-open .kc-fab {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
}

/* ── Peek bubble (one-time teaser next to FAB) ───────────────────── */
.kc-peek {
  position: fixed;
  bottom: calc(1.5rem + 62px + 10px);
  right: 1.5rem;
  z-index: 9000;
  max-width: 240px;
  padding: 0.75rem 0.875rem 0.75rem 1rem;
  background: #fff;
  color: var(--kc-text);
  border-radius: 14px;
  border: 1px solid var(--kc-border);
  font-family: var(--kc-font);
  font-size: 0.8125rem;
  line-height: 1.4;
  box-shadow:
    0 14px 32px rgba(20, 35, 10, 0.14),
    0 2px 6px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transition:
    opacity 280ms ease,
    transform 280ms cubic-bezier(0.34, 1.4, 0.64, 1);
  pointer-events: none;
}

.kc-peek.kc-peek--show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.kc-peek__text { flex: 1; }

.kc-peek__close {
  background: transparent;
  border: 0;
  padding: 0;
  margin: -2px -2px 0 0;
  width: 18px;
  height: 18px;
  font-size: 16px;
  line-height: 1;
  color: var(--kc-text-soft);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kc-peek__close:hover { color: var(--kc-text); background: rgba(0,0,0,0.04); }

/* Little tail pointing toward FAB */
.kc-peek::after {
  content: "";
  position: absolute;
  bottom: -7px;
  right: 22px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-right: 1px solid var(--kc-border);
  border-bottom: 1px solid var(--kc-border);
  transform: rotate(45deg);
}

/* ── Chat Panel (open state) ─────────────────────────────────────── */
.kc-panel {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9100;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: 580px;
  max-height: calc(100vh - 2rem);
  background: var(--kc-ivory);
  border: 1px solid var(--kc-border);
  border-radius: 18px;
  box-shadow: var(--kc-shadow-panel);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--kc-font);
  color: var(--kc-text);
}

.kc-panel[data-kc-open] {
  display: flex;
  animation: kc-panel-in 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

.kc-panel.kc-panel--leaving {
  animation: kc-panel-out 200ms cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes kc-panel-in {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes kc-panel-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(16px) scale(0.98); }
}

/* Header */
.kc-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--kc-border);
  background: #fff;
}

.kc-avatar {
  width: 36px;
  height: 36px;
  border-radius: 9999px;
  background: #ecead8; /* neutral cream — frames the avatar warmly */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.kc-avatar img {
  width: 100%;
  height: 100%;
  /* cover fills the circle with the face avatar (PNG is pre-framed). */
  object-fit: cover;
  display: block;
}

.kc-header__text { flex: 1; min-width: 0; }
.kc-header__name {
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--kc-text);
}
.kc-header__status {
  font-size: 0.75rem;
  color: var(--kc-text-soft);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.kc-header__status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: var(--kc-green);
  box-shadow: 0 0 0 3px rgba(124, 180, 54, 0.16);
}

.kc-close {
  background: transparent;
  border: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  color: var(--kc-text-soft);
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 160ms ease, color 160ms ease;
}
.kc-close:hover { background: rgba(0,0,0,0.05); color: var(--kc-text); }

/* Message list */
.kc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  scroll-behavior: smooth;
}

.kc-msg {
  max-width: 85%;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
  animation: kc-msg-in 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes kc-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.kc-msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--kc-border);
  padding: 0.625rem 0.875rem;
  border-radius: 14px 14px 14px 4px;
}

.kc-msg--user {
  align-self: flex-end;
  background: var(--kc-green-soft);
  color: var(--kc-text);
  padding: 0.625rem 0.875rem;
  border-radius: 14px 14px 4px 14px;
}

.kc-msg p { margin: 0 0 0.5rem; }
.kc-msg p:last-child { margin-bottom: 0; }
.kc-msg ul, .kc-msg ol { margin: 0.25rem 0 0.5rem; padding-left: 1.125rem; }
.kc-msg li { margin: 0.125rem 0; }
.kc-msg strong { font-weight: 700; }
.kc-msg code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.8125em;
  background: rgba(0,0,0,0.05);
  padding: 0.05em 0.3em;
  border-radius: 4px;
}

/* CTA card under bot messages */
.kc-cta {
  align-self: flex-start;
  max-width: 85%;
  margin-top: -2px;
  background: #fff;
  border: 1px solid var(--kc-green);
  border-radius: 12px;
  padding: 0.75rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--kc-green-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  text-align: left;
  font-family: inherit;
  transition:
    background 180ms ease,
    border-color 180ms ease,
    transform 120ms ease;
  animation: kc-msg-in 320ms cubic-bezier(0.16, 1, 0.3, 1) 60ms backwards;
}

.kc-cta:hover {
  background: rgba(124, 180, 54, 0.06);
  border-color: var(--kc-green-dark);
  transform: translateY(-1px);
}

.kc-cta:active { transform: translateY(0); }

.kc-cta__arrow { font-size: 1rem; line-height: 1; flex-shrink: 0; }

/* Barky CTA variant — amber accent so visitors instantly distinguish it from
   the sales-team green CTA. Same shape and motion as the base card. */
.kc-cta--barky {
  border-color: #f59e0b;
  color: #b45309;
  background: #fffbeb;
}
.kc-cta--barky:hover {
  background: #fef3c7;
  border-color: #d97706;
}

/* Inline link inside bot bubbles — used by [[L:label]] (Barky link) */
.kc-inline-link {
  color: var(--kc-green-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}
.kc-inline-link:hover { color: var(--kc-green); }

/* Typing indicator */
.kc-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--kc-border);
  border-radius: 14px 14px 14px 4px;
  padding: 0.75rem 0.875rem;
  display: flex;
  gap: 4px;
}

.kc-typing span {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: var(--kc-text-soft);
  animation: kc-blink 1.2s infinite ease-in-out;
}

.kc-typing span:nth-child(2) { animation-delay: 0.15s; }
.kc-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes kc-blink {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1; transform: translateY(-3px); }
}

/* Suggested question chips */
.kc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0.5rem 1rem 0.25rem;
}

.kc-chip {
  background: #fff;
  border: 1px solid var(--kc-border);
  border-radius: 9999px;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--kc-text);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
  white-space: nowrap;
}

.kc-chip:hover {
  background: var(--kc-green-soft);
  border-color: var(--kc-green);
}

/* Composer */
.kc-composer {
  border-top: 1px solid var(--kc-border);
  padding: 0.625rem 0.75rem 0.75rem;
  background: #fff;
}

.kc-composer__row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--kc-ivory);
  border: 1px solid var(--kc-border);
  border-radius: 14px;
  padding: 0.5rem 0.5rem 0.5rem 0.875rem;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.kc-composer__row:focus-within {
  border-color: var(--kc-green);
  box-shadow: 0 0 0 3px rgba(124, 180, 54, 0.14);
}

.kc-input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--kc-text);
  max-height: 100px;
  /* Match the 32px send button so the single-line placeholder reads as
     vertically centered with align-items: flex-end on the row. */
  min-height: 32px;
  padding: 6px 0;
}

.kc-input::placeholder { color: var(--kc-text-soft); }

.kc-send {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9999px;
  background: var(--kc-green);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 160ms ease, transform 120ms ease;
}

.kc-send:hover { background: var(--kc-green-dark); }
.kc-send:active { transform: scale(0.94); }
.kc-send:disabled { background: #c8ccc0; cursor: not-allowed; }

.kc-send__icon {
  width: 16px;
  height: 16px;
  stroke: #fff;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Mobile — fullscreen panel.
   `inset: 0` + `100dvh` matches the visible viewport so the textarea
   and close button stay reachable when the URL bar shows. */
@media (max-width: 640px) {
  .kc-fab {
    bottom: 1rem;
    right: 1rem;
    width: 64px;
    height: 64px;
  }
  .kc-fab__badge { width: 14px; height: 14px; right: 2px; bottom: 2px; }

  .kc-peek {
    bottom: calc(1rem + 64px + 10px);
    right: 1rem;
    max-width: calc(100vw - 2rem);
  }

  .kc-panel {
    /* Default: fill the inset-0 rectangle (Safari/KakaoTalk track their
       own correct viewport). */
    inset: 0;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* iOS Chrome ONLY — larger floating panel.
     Earlier `max-height: calc(100vh - 7rem)` was clamping the panel
     because Chrome iOS's `vh` math returns a smaller-than-expected
     value, so 540px never got room to render. Now we set explicit
     height + a max-height in `dvh` (Chrome iOS honors dvh better than
     vh for clamping). `!important` forces this over base/mobile rules. */
  body.kf-ios-chrome .kc-panel {
    position: fixed !important;
    top: auto !important;
    bottom: 1rem !important;
    right: 0.5rem !important;
    left: 0.5rem !important;
    width: auto !important;
    height: 640px !important;
    max-height: 88dvh !important;
    max-width: none !important;
    border-radius: 18px !important;
    border: 1px solid var(--kc-border) !important;
    padding-bottom: 0 !important;
  }

  /* Containment guards: messages list owns its own scroll and never chains
     to the body. Without contain, swiping past the top of the message list
     pulls the underlying page down on iOS. */
  .kc-messages {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* Bump composer textarea to 16px on mobile. iOS Safari auto-zooms the
     viewport when focusing any <input>/<textarea> with font-size < 16px,
     and the zoom is NOT released on blur — leaving the chat panel header
     sticking out past the visible viewport width (so the close X disappears
     off the right edge until the user pinches back out). 16px is the iOS
     threshold below which zoom triggers. */
  .kc-input {
    font-size: 16px;
  }

  @keyframes kc-panel-in {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* Body lock while chat panel is open.
   NOTE: do NOT use `overflow: hidden` on body — iOS Safari has a known
   layout-viewport miscalc bug when body overflow toggles while sticky
   elements (like our .banner-sticky-wrapper) are pinned. Symptom: after
   closing the chat, footer ends up with hundreds of px of phantom
   whitespace below it. We rely on the panel's own contained scroll
   (overscroll-behavior: contain on .kc-messages) to prevent scroll-chain
   instead. */
body.kc-open {
  overscroll-behavior: contain;
  touch-action: pan-y;
}

@media (prefers-reduced-motion: reduce) {
  .kc-fab,
  .kc-fab.kc-wiggle,
  .kc-fab__badge,
  .kc-panel[data-kc-open],
  .kc-msg,
  .kc-cta { animation: none; }
}
