/* Hop On Cebu — premium site assistant */

.site-chat-root {
  --chat-teal: var(--color-primary, #145e6b);
  --chat-teal-deep: #0d4a54;
  --chat-glow: rgba(20, 94, 107, 0.35);
  --chat-panel-w: min(400px, calc(100vw - 24px));
  --chat-font: Inter, system-ui, sans-serif;
  --chat-serif: "Instrument Serif", Georgia, serif;
  font-family: var(--chat-font);
  position: fixed;
  inset: 0;
  z-index: 10050;
  pointer-events: none;
}

[data-theme="dark"] .site-chat-root {
  --chat-glow: rgba(42, 156, 164, 0.4);
  --chat-teal-deep: #1a5c62;
}

/* FAB — lives in .fab-stack (outside .site-chat-root), so define tokens here too */
.site-chat-fab {
  --chat-teal: var(--color-primary, #145e6b);
  --chat-teal-deep: #0d4a54;
  --chat-glow: rgba(20, 94, 107, 0.42);
  position: relative;
  width: 50px;
  height: 50px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(
    145deg,
    #1a8a98 0%,
    var(--chat-teal, #145e6b) 45%,
    var(--chat-teal-deep, #0d4a54) 100%
  );
  box-shadow:
    0 0 0 2px #fff,
    0 0 0 4px rgba(20, 94, 107, 0.55),
    0 8px 26px var(--chat-glow);
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.25s cubic-bezier(0.34, 1.2, 0.64, 1),
    box-shadow 0.25s ease,
    opacity 0.2s ease,
    visibility 0.2s ease;
}

.site-chat-fab:hover {
  transform: scale(1.06);
  box-shadow:
    0 0 0 2px #fff,
    0 0 0 4px rgba(20, 94, 107, 0.65),
    0 10px 30px var(--chat-glow);
}

.site-chat-fab:active {
  transform: scale(0.98);
}

[data-theme="dark"] .site-chat-fab {
  --chat-teal: var(--color-primary, #2a9ca4);
  --chat-teal-deep: #1a5c62;
  --chat-glow: rgba(42, 156, 164, 0.45);
  background: linear-gradient(
    145deg,
    #3eb8c4 0%,
    var(--chat-teal, #2a9ca4) 50%,
    var(--chat-teal-deep, #1a5c62) 100%
  );
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.95),
    0 0 0 5px rgba(42, 156, 164, 0.5),
    0 8px 28px var(--chat-glow);
}

.site-chat-fab svg {
  width: 22px;
  height: 22px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.site-chat-fab .site-chat-fab-icon--close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

.site-chat-fab[aria-expanded="true"] .site-chat-fab-icon--open {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

.site-chat-fab[aria-expanded="true"] .site-chat-fab-icon--close {
  opacity: 1;
  transform: none;
}

.site-chat-fab-label {
  position: absolute;
  right: calc(100% + 10px);
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: var(--radius-pill, 999px);
  background: var(--color-surface, #fff);
  color: var(--color-text, #1a1a1a);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-md, 0 8px 30px rgba(0, 0, 0, 0.12));
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
  pointer-events: none;
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.site-chat-fab:not([aria-expanded="true"]):hover .site-chat-fab-label,
.site-chat-fab:not([aria-expanded="true"]):focus-visible .site-chat-fab-label {
  opacity: 1;
  transform: translateX(0);
}

@media (max-width: 640px) {
  .site-chat-fab-label {
    display: none;
  }
}

/* Panel — must stack above backdrop (backdrop was covering + blurring the panel) */
.site-chat-panel {
  position: fixed;
  z-index: 2;
  right: max(var(--space-4), env(safe-area-inset-right));
  bottom: calc(72px + env(safe-area-inset-bottom));
  width: var(--chat-panel-w);
  max-height: min(640px, calc(100dvh - 100px));
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  overflow: hidden;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.18),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  transition:
    opacity 0.28s ease,
    transform 0.32s cubic-bezier(0.34, 1.2, 0.64, 1),
    visibility 0.28s;
  pointer-events: none;
  isolation: isolate;
}

.site-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  bottom: max(20px, env(safe-area-inset-bottom));
  max-height: calc(
    100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
  );
}

.site-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: rgba(10, 12, 14, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
  pointer-events: none;
}

/* Desktop: no dim overlay — panel floats clearly; page stays sharp */
@media (min-width: 769px) {
  .site-chat-backdrop {
    display: none;
  }

  /* Clear Instagram FAB below the panel */
  body.site-chat-open .site-chat-panel.is-open {
    bottom: calc(58px + env(safe-area-inset-bottom));
  }
}

.site-chat-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.site-chat-panel.is-open,
.site-chat-backdrop.is-open {
  pointer-events: auto;
}

/* Header */
.site-chat-head {
  position: relative;
  padding: 18px 18px 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--chat-teal) 0%, var(--chat-teal-deep) 55%, #0a3d45 100%);
  overflow: hidden;
}

.site-chat-head::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 100% 0%, rgba(255, 255, 255, 0.15), transparent 50%),
    radial-gradient(ellipse 50% 40% at 0% 100%, rgba(0, 0, 0, 0.12), transparent 50%);
  pointer-events: none;
}

.site-chat-head-inner {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.site-chat-avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.site-chat-avatar img {
  width: 28px;
  height: 28px;
  display: block;
}

.site-chat-head-text {
  flex: 1;
  min-width: 0;
}

.site-chat-head h2 {
  margin: 0;
  font-family: var(--chat-serif);
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.site-chat-head-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.75rem;
  opacity: 0.92;
}

.site-chat-live {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.site-chat-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6ee7b7;
  box-shadow: 0 0 8px #6ee7b7;
  animation: site-chat-pulse 2s ease-in-out infinite;
}

@keyframes site-chat-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.site-chat-close {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
}

.site-chat-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Quick prompts */
.site-chat-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px 4px;
  background: var(--color-surface-2, #f9f8f5);
  border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.06));
}

[data-theme="dark"] .site-chat-prompts {
  background: var(--color-surface-2, #262522);
}

.site-chat-prompt {
  padding: 7px 12px;
  border-radius: var(--radius-pill, 999px);
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.1));
  background: var(--color-surface, #fff);
  color: var(--color-text, #1a1a1a);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.site-chat-prompt:hover {
  border-color: var(--chat-teal);
  background: var(--color-primary-light, #dcecef);
  transform: translateY(-1px);
}

[data-theme="dark"] .site-chat-prompt:hover {
  background: var(--color-primary-light, #1a3335);
}

/* Messages */
.site-chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 220px;
  max-height: min(380px, 45dvh);
  background:
    linear-gradient(180deg, var(--color-bg, #f7f6f2) 0%, var(--color-surface, #fff) 120px);
}

[data-theme="dark"] .site-chat-messages {
  background: linear-gradient(180deg, var(--color-bg, #141412) 0%, var(--color-surface, #1e1d1b) 120px);
}

.site-chat-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 100%;
}

.site-chat-row--user {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.site-chat-row--bot .site-chat-bubble-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--color-primary-light, #dcecef);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.site-chat-row--bot .site-chat-bubble-avatar img {
  width: 18px;
  height: 18px;
}

.site-chat-bubble {
  max-width: min(88%, 300px);
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}

.site-chat-bubble a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-chat-row--bot .site-chat-bubble {
  background: var(--color-surface, #fff);
  color: var(--color-text, #1a1a1a);
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
}

.site-chat-row--user .site-chat-bubble {
  background: linear-gradient(145deg, var(--chat-teal), var(--chat-teal-deep));
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px var(--chat-glow);
}

.site-chat-typing .site-chat-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
  min-width: 56px;
}

.site-chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted, #6b6b6b);
  animation: site-chat-bounce 1.2s ease-in-out infinite;
}

.site-chat-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.site-chat-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes site-chat-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* Composer */
.site-chat-foot {
  border-top: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
  background: var(--color-surface, #fff);
  padding: 0 0 env(safe-area-inset-bottom);
}

.site-chat-disclaimer {
  padding: 8px 14px 0;
  font-size: 0.6875rem;
  line-height: 1.4;
  color: var(--color-text-muted, #6b6b6b);
  text-align: center;
}

.site-chat-disclaimer a {
  color: var(--chat-teal);
  font-weight: 500;
}

.site-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
}

.site-chat-form textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  padding: 11px 14px;
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.12));
  border-radius: 14px;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  background: var(--color-bg, #f7f6f2);
  color: var(--color-text, #1a1a1a);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.site-chat-form textarea:focus {
  outline: none;
  border-color: var(--chat-teal);
  box-shadow: 0 0 0 3px rgba(20, 94, 107, 0.15);
}

.site-chat-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(145deg, var(--chat-teal), var(--chat-teal-deep));
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.site-chat-send:hover:not(:disabled) {
  transform: scale(1.05);
}

.site-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Stack with Instagram FAB */
.fab-stack .site-chat-fab {
  position: static;
}

body.has-site-chat .fab-stack {
  z-index: 55;
  position: fixed;
}

/* Panel open: chat above page; hide toggle (close is in panel header) so it cannot cover the input */
body.site-chat-open .fab-stack {
  z-index: 10040;
}

body.site-chat-open .site-chat-fab {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.85);
}

/* Mobile: room for sticky bar when closed; when open, panel uses safe top inset */
@media (max-width: 899px) {
  body.has-app-tabbar .site-chat-panel:not(.is-open) {
    bottom: calc(var(--app-tabbar-h, 56px) + 68px + env(safe-area-inset-bottom));
  }

  body.has-app-tabbar.pad-mobile-bar:not(.booking-handoff) .site-chat-panel.is-open {
    bottom: calc(var(--sticky-bar-h, 72px) + 8px + env(safe-area-inset-bottom));
    max-height: calc(
      100dvh - 16px - var(--sticky-bar-h, 72px) - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
  }

  body.pad-mobile-bar:not(.has-app-tabbar):not(.booking-handoff) .site-chat-panel.is-open {
    bottom: calc(var(--sticky-bar-h, 72px) + 8px + env(safe-area-inset-bottom));
    max-height: calc(
      100dvh - 16px - var(--sticky-bar-h, 72px) - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
  }
}

@media (max-width: 768px) {
  .site-chat-panel {
    z-index: 2;
    max-height: min(85dvh, 680px);
  }
}

@media (max-width: 480px) {
  .site-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    border-radius: 20px;
    transform-origin: bottom center;
  }

  /* Floating card (~¾ screen) — not full-screen sheet; common for support chat */
  .site-chat-panel.is-open {
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    max-height: min(72dvh, calc(100dvh - 88px - env(safe-area-inset-top)));
  }

  body.site-chat-open {
    overflow: hidden;
  }

  .site-chat-messages {
    max-height: none;
    min-height: 200px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-chat-panel,
  .site-chat-fab,
  .site-chat-backdrop,
  .site-chat-live-dot,
  .site-chat-typing-dot {
    animation: none;
    transition-duration: 0.01ms;
  }
}
