/* ============================================================
   Caribbean Watersports — concierge chat widget
   Self-contained styles. Loaded via <link rel="stylesheet" href="css/chat.css">
   Paired with js/chat.js. All selectors are namespaced under .cws-chat*
   so they never collide with the main site styles.
   ============================================================ */

/* ---------- design tokens (scoped fallbacks) ----------
   The main site already defines these on :root, but we redeclare them on the
   widget root so the widget renders correctly even if loaded on a page that
   doesn't include styles.css. */
.cws-chat,
.cws-chat-launcher {
  --cws-ocean-900: #063540;
  --cws-ocean-800: #0a4f5c;
  --cws-teal-500: #13a3b0;
  --cws-aqua-400: #2bd0c4;
  --cws-sand-100: #fdf8f0;
  --cws-coral-500: #ff6b5e;
  --cws-sun-400: #ffb43d;
  --cws-ink-900: #0c2025;
  --cws-ink-700: #33474d;
  --cws-shadow: 0 30px 70px -25px rgba(6, 53, 64, 0.5);
  --cws-radius: 18px;
  --cws-ease: cubic-bezier(0.16, 0.84, 0.44, 1);

  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  box-sizing: border-box;
}
.cws-chat *,
.cws-chat-launcher * {
  box-sizing: border-box;
}

/* ============================================================
   Launcher button — bottom-LEFT (site's Call/Text buttons are bottom-right)
   ============================================================ */
.cws-chat-launcher {
  position: fixed;
  left: 1.1rem;
  bottom: 1.1rem;
  z-index: 90; /* above the site floaters (z-index:50) and below modals (100) */
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.05rem 0 0.7rem;
  min-height: 56px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1;
  background: linear-gradient(135deg, var(--cws-teal-500), var(--cws-aqua-400));
  box-shadow: var(--cws-shadow);
  transition: transform 0.2s var(--cws-ease), box-shadow 0.2s, opacity 0.2s;
}
.cws-chat-launcher:hover {
  transform: translateY(-2px) scale(1.03);
}
.cws-chat-launcher:active {
  transform: translateY(0) scale(0.99);
}
.cws-chat-launcher__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-size: 1.35rem;
  line-height: 1;
}
.cws-chat-launcher__label {
  font-weight: 700;
  letter-spacing: 0.2px;
  padding-right: 0.15rem;
}

/* Hide the launcher while the panel is open (the panel takes its place). */
.cws-chat-launcher.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

/* ============================================================
   Panel
   ============================================================ */
.cws-chat {
  position: fixed;
  left: 1.1rem;
  bottom: 1.1rem;
  z-index: 95;
  width: 360px;
  max-width: calc(100vw - 2.2rem);
  height: 520px;
  max-height: calc(100vh - 2.2rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--cws-sand-100);
  border-radius: var(--cws-radius);
  box-shadow: var(--cws-shadow);
  /* Hidden by default; .is-open reveals it. */
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom left;
  transition: opacity 0.25s var(--cws-ease),
    transform 0.25s var(--cws-ease), visibility 0.25s;
}
.cws-chat.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ---------- header ---------- */
.cws-chat__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.95rem 1rem;
  color: #fff;
  background: linear-gradient(135deg, var(--cws-ocean-900), var(--cws-ocean-800));
}
.cws-chat__avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cws-teal-500), var(--cws-aqua-400));
  font-size: 1.2rem;
}
.cws-chat__titles {
  flex: 1 1 auto;
  min-width: 0;
}
.cws-chat__title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cws-chat__subtitle {
  font-size: 0.78rem;
  opacity: 0.85;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cws-chat__close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  background: rgba(255, 255, 255, 0.14);
  transition: background 0.2s;
}
.cws-chat__close:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ---------- messages ---------- */
.cws-chat__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 0.9rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  scroll-behavior: smooth;
}

/* Live-agent banner */
.cws-chat__agent-flag {
  align-self: center;
  margin: 0.1rem 0 0.3rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--cws-ocean-800);
  background: rgba(43, 208, 196, 0.18);
  border: 1px solid rgba(19, 163, 176, 0.4);
  border-radius: 999px;
}

/* ---------- bubbles ---------- */
.cws-msg {
  max-width: 82%;
  padding: 0.55rem 0.8rem;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: cws-pop 0.22s var(--cws-ease);
}
.cws-msg a {
  color: inherit;
  text-decoration: underline;
}

/* user — right, coral->teal gradient */
.cws-msg--user {
  align-self: flex-end;
  color: #fff;
  background: linear-gradient(135deg, var(--cws-coral-500), var(--cws-teal-500));
  border-bottom-right-radius: 5px;
}
.cws-msg--user a {
  color: #fff;
}

/* bot — left, white card */
.cws-msg--bot {
  align-self: flex-start;
  color: var(--cws-ink-900);
  background: #fff;
  border: 1px solid rgba(6, 53, 64, 0.08);
  box-shadow: 0 6px 16px -10px rgba(6, 53, 64, 0.4);
  border-bottom-left-radius: 5px;
}
.cws-msg--bot a {
  color: var(--cws-ocean-800);
}

/* agent — left, with captain badge */
.cws-msg--agent {
  align-self: flex-start;
  position: relative;
  color: var(--cws-ink-900);
  background: #fff;
  border: 1px solid rgba(19, 163, 176, 0.35);
  box-shadow: 0 6px 16px -10px rgba(6, 53, 64, 0.4);
  border-bottom-left-radius: 5px;
}
.cws-msg__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.2rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--cws-teal-500);
}

/* system — centered, small muted */
.cws-msg--system {
  align-self: center;
  max-width: 92%;
  text-align: center;
  font-size: 0.78rem;
  color: var(--cws-ink-700);
  background: transparent;
  padding: 0.15rem 0.5rem;
  animation: none;
}

/* ---------- quick replies ---------- */
.cws-chat__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.15rem 0.1rem 0.3rem;
}
.cws-chip {
  border: 1.5px solid var(--cws-teal-500);
  background: #fff;
  color: var(--cws-ocean-800);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.18s;
}
.cws-chip:hover {
  background: var(--cws-teal-500);
  color: #fff;
  transform: translateY(-1px);
}

/* ---------- typing indicator ---------- */
.cws-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.65rem 0.85rem;
  background: #fff;
  border: 1px solid rgba(6, 53, 64, 0.08);
  border-radius: 16px;
  border-bottom-left-radius: 5px;
}
.cws-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cws-teal-500);
  opacity: 0.4;
  animation: cws-blink 1.2s infinite ease-in-out both;
}
.cws-typing span:nth-child(2) {
  animation-delay: 0.18s;
}
.cws-typing span:nth-child(3) {
  animation-delay: 0.36s;
}

/* ---------- lead-capture mini form ---------- */
.cws-lead {
  margin: 0.2rem 0.1rem 0.3rem;
  padding: 0.7rem 0.75rem;
  background: #fff;
  border: 1px solid rgba(19, 163, 176, 0.3);
  border-radius: 14px;
  box-shadow: 0 6px 16px -12px rgba(6, 53, 64, 0.4);
}
.cws-lead__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.cws-lead__title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--cws-ink-900);
  line-height: 1.3;
}
.cws-lead__dismiss {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--cws-ink-700);
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.2rem;
  border-radius: 6px;
}
.cws-lead__dismiss:hover {
  color: var(--cws-coral-500);
}
.cws-lead__row {
  display: flex;
  gap: 0.4rem;
}
.cws-lead input {
  flex: 1 1 0;
  min-width: 0;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid rgba(6, 53, 64, 0.15);
  border-radius: 9px;
  background: var(--cws-sand-100);
  color: var(--cws-ink-900);
}
.cws-lead input:focus {
  outline: none;
  border-color: var(--cws-teal-500);
}
.cws-lead__save {
  flex: 0 0 auto;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  padding: 0.45rem 0.85rem;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--cws-teal-500), var(--cws-aqua-400));
}
.cws-lead__save:hover {
  filter: brightness(1.05);
}

/* ---------- input row ---------- */
.cws-chat__form {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.7rem;
  border-top: 1px solid rgba(6, 53, 64, 0.08);
  background: #fff;
}
.cws-chat__input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid rgba(6, 53, 64, 0.15);
  border-radius: 999px;
  background: var(--cws-sand-100);
  color: var(--cws-ink-900);
}
.cws-chat__input::placeholder {
  color: var(--cws-ink-700);
  opacity: 0.7;
}
.cws-chat__input:focus {
  outline: none;
  border-color: var(--cws-teal-500);
}
.cws-chat__input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.cws-chat__send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  font-size: 1.15rem;
  line-height: 1;
  background: linear-gradient(135deg, var(--cws-teal-500), var(--cws-aqua-400));
  transition: transform 0.18s, filter 0.18s;
}
.cws-chat__send:hover {
  filter: brightness(1.05);
  transform: scale(1.05);
}
.cws-chat__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ---------- accessibility helpers ---------- */
.cws-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Visible focus rings — AA-friendly, never suppressed. */
.cws-chat :focus-visible,
.cws-chat-launcher:focus-visible {
  outline: 3px solid var(--cws-sun-400);
  outline-offset: 2px;
}

/* ---------- animations ---------- */
@keyframes cws-pop {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes cws-blink {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---------- mobile: near-fullscreen ---------- */
@media (max-width: 480px) {
  .cws-chat {
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    transform-origin: bottom center;
  }
  .cws-chat-launcher__label {
    /* keep it compact but still labelled on small screens */
    display: inline;
  }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .cws-chat,
  .cws-chat-launcher,
  .cws-msg,
  .cws-chat__send,
  .cws-chip,
  .cws-chat__messages {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
  .cws-typing span {
    animation: none !important;
    opacity: 0.6;
  }
}
