/*
 * "Ask JW Cruises": the visitors' chat bubble and panel (plan step A18, proposed; assets/js/visitor-chat.js builds them).
 * Colours are main.css's variables, so Daniel's colour changer and the dark sections move them too. Text is large enough
 * to read without zooming (1rem and up). Every animation and transition sits inside
 * @media (prefers-reduced-motion: no-preference) (Daniel, 2026-10-05): a device set to reduce motion gets none.
 * The bubble sits bottom right; the back-to-top button is bottom left (main.css .scroll-top), so they never meet.
 */

#jw-vc {
  position: static;
}

.jw-vc-bubble {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 99990;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-color, #009977);
  color: var(--contrast-color, #ffffff);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.jw-vc-bubble:focus-visible,
.jw-vc-close:focus-visible,
.jw-vc-send:focus-visible,
.jw-vc-tip:focus-visible,
.jw-vc-text:focus-visible,
.jw-vc-links a:focus-visible {
  outline: 3px solid var(--heading-color, #232523);
  outline-offset: 2px;
}

/* Development: the red ribbon along the bottom (config/environment.php) must not cover the bubble. */
#jw-dev-ribbon ~ #jw-vc .jw-vc-bubble {
  bottom: 42px;
}

#jw-dev-ribbon ~ #jw-vc .jw-vc-panel {
  bottom: 108px;
}

.jw-vc-panel {
  position: fixed;
  right: 16px;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  z-index: 99991;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, 75vh);
  display: flex;
  flex-direction: column;
  background: var(--surface-color, #ffffff);
  color: var(--default-color, #000000);
  border: 1px solid color-mix(in srgb, var(--default-color, #000000), transparent 80%);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  padding: 0;                 /* main.css gives every section 30px above and below */
  scroll-margin-top: 0;
  font-size: 1rem;
  text-align: left;
}

.jw-vc-panel[hidden] {
  display: none;
}

.jw-vc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 10px 16px;
  background: var(--accent-color, #009977);
  color: var(--contrast-color, #ffffff);
}

.jw-vc-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: inherit;
}

.jw-vc-close {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.15rem;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
}

.jw-vc-disclosure {
  margin: 0;
  padding: 8px 16px;
  font-size: 0.9rem;
  line-height: 1.4;
  background: color-mix(in srgb, var(--accent-color, #009977), transparent 90%);
  border-bottom: 1px solid color-mix(in srgb, var(--default-color, #000000), transparent 85%);
}

.jw-vc-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 4px;
}

.jw-vc-msg {
  margin: 0 0 10px;
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.jw-vc-msg .jw-vc-body {
  margin: 0;
  white-space: pre-line;
}

.jw-vc-ai {
  background: color-mix(in srgb, var(--default-color, #000000), transparent 93%);
  border-bottom-left-radius: 4px;
}

.jw-vc-visitor {
  margin-left: auto;
  background: var(--accent-color, #009977);
  color: var(--contrast-color, #ffffff);
  border-bottom-right-radius: 4px;
}

.jw-vc-waiting .jw-vc-body {
  font-size: 1.4rem;
  line-height: 1;
}

.jw-vc-links {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.jw-vc-links li {
  margin: 4px 0 0;
}

.jw-vc-links a {
  color: var(--accent-color, #009977);
  font-weight: 600;
  text-decoration: underline;
}

.jw-vc-tips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
}

.jw-vc-tip {
  border: 1px solid var(--accent-color, #009977);
  background: transparent;
  color: var(--accent-color, #009977);
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}

.jw-vc-form {
  margin: 0;
  padding: 8px 12px 12px;
  border-top: 1px solid color-mix(in srgb, var(--default-color, #000000), transparent 85%);
}

.jw-vc-text {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: 140px;
  resize: vertical;
  padding: 8px 10px;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--default-color, #000000);
  background: var(--surface-color, #ffffff);
  border: 1px solid color-mix(in srgb, var(--default-color, #000000), transparent 70%);
  border-radius: 8px;
}

.jw-vc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.jw-vc-count {
  font-size: 0.85rem;
  opacity: 0.8;
}

.jw-vc-send {
  border: 0;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent-color, #009977);
  color: var(--contrast-color, #ffffff);
  cursor: pointer;
}

.jw-vc-send:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Phones: the panel takes the width, with a 16px gutter on each side and no sideways scroll. */
@media (max-width: 575.98px) {
  .jw-vc-panel {
    left: 16px;
    right: 16px;
    width: auto;
    height: min(560px, calc(100vh - 120px));
    height: min(560px, calc(100dvh - 120px));
  }
}

@media (prefers-reduced-motion: no-preference) {
  .jw-vc-bubble {
    transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
  }

  .jw-vc-bubble:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  }

  .jw-vc-is-open .jw-vc-panel:not([hidden]) {
    animation: jw-vc-rise 0.2s ease-out;
  }

  @keyframes jw-vc-rise {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}
