/**
 * @file chat-widget.css
 * Persistent floating "Chat with Us" widget (bottom-right, sitewide).
 * Wraps the LibraryH3lp IM embed with a modern, collapsible panel.
 */

/* ─────────────────────────────────────────
   Outer wrapper — fixed position anchor
   ───────────────────────────────────────── */
.chat-widget {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9000;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 0.625rem;
  font-family: var(--font-body, 'Open Sans', sans-serif);
  /* Prevent the invisible panel bounding box from blocking page clicks */
  pointer-events: none;
}

/* ─────────────────────────────────────────
   Tab / trigger button
   ───────────────────────────────────────── */
.chat-widget__tab {
  pointer-events: auto; /* always clickable */
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--gmu-primary-green, #005239);
  color: #fff;
  border: none;
  border-radius: 2rem;
  padding: 0.7rem 1.2rem 0.7rem 1rem;
  font-size: 0.9375rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  transition:
    background    0.15s ease,
    box-shadow    0.15s ease,
    transform     0.15s ease,
    padding       0.35s ease,
    width         0.35s ease,
    height        0.35s ease,
    border-radius 0.35s ease;
  white-space: nowrap;
  line-height: 1;
  overflow: hidden;
}

.chat-widget__tab:hover {
  background: #003d29;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.32);
  transform: translateY(-2px);
}

.chat-widget__tab:focus-visible {
  outline: 3px solid var(--gmu-accent-yellow, #ffc733);
  outline-offset: 3px;
}

/* Yellow accent underline on the tab text when open */
.chat-widget--open .chat-widget__tab {
  background: #003d29;
}

/* ─────────────────────────────────────────
   Collapsible panel
   ───────────────────────────────────────── */
.chat-widget__panel {
  width: 360px;
  height: 480px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22), 0 2px 8px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  display: flex;
  flex-direction: column;

  /* Hidden by default — animate in */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px) scale(0.97);
  transform-origin: bottom right;
  transition:
    opacity    0.22s ease,
    transform  0.22s ease,
    visibility 0s   linear 0.22s;
}

.chat-widget--open .chat-widget__panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto; /* panel receives clicks only when open */
  transform: translateY(0) scale(1);
  transition:
    opacity    0.22s ease,
    transform  0.22s ease,
    visibility 0s   linear 0s;
}

/* ─────────────────────────────────────────
   Panel — header bar
   ───────────────────────────────────────── */
.chat-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--gmu-primary-green, #005239);
  color: #fff;
  flex-shrink: 0;
  border-bottom: 3px solid var(--gmu-accent-yellow, #ffc733);
}

.chat-widget__header-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.chat-widget__header-icon {
  flex-shrink: 0;
  opacity: 0.9;
}

.chat-widget__header-title {
  font-family: var(--font-heading, 'Open Sans', sans-serif);
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-widget__close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 6px;
  opacity: 0.75;
  transition: opacity 0.15s, background 0.15s;
}

.chat-widget__close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.18);
}

.chat-widget__close:focus-visible {
  outline: 2px solid var(--gmu-accent-yellow, #ffc733);
  outline-offset: 1px;
  opacity: 1;
}

/* ─────────────────────────────────────────
   Panel — body (LibraryH3lp renders here)
   ───────────────────────────────────────── */
.chat-widget__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  position: relative;
}

/* Whatever LibraryH3lp injects (div, form, iframe…) fills the body */
.chat-widget__body > * {
  flex: 1;
  width: 100% !important;
  max-width: 100% !important;
}

/* Ensure any injected iframe fills the space */
.chat-widget__body iframe {
  display: block;
  width: 100% !important;
  height: 100% !important;
  border: none;
  flex: 1;
}

/* ─────────────────────────────────────────
   Loading / connecting state
   (inside .needs-js before LibraryH3lp loads)
   ───────────────────────────────────────── */
.chat-widget__connecting {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.875rem;
  height: 100%;
  padding: 2rem 1.5rem;
  text-align: center;
  color: #555;
}

.chat-widget__connecting-icon {
  color: var(--gmu-primary-green, #005239);
  animation: chat-pulse 2s ease-in-out infinite;
}

@keyframes chat-pulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%       { opacity: 0.55; transform: scale(0.9); }
}

.chat-widget__connecting-text {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #333;
}

.chat-widget__connecting-sub {
  margin: 0;
  font-size: 0.8rem;
  color: #888;
}

/* ─────────────────────────────────────────
   Responsive — small screens
   ───────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-widget {
    bottom: 0.75rem;
    right: 0.75rem;
  }

  .chat-widget__panel {
    width: calc(100vw - 1.5rem);
    height: 420px;
    border-radius: 14px 14px 0 14px;
  }

  .chat-widget__tab {
    font-size: 0.875rem;
    padding: 0.6rem 1rem 0.6rem 0.85rem;
  }
}

/* ─────────────────────────────────────────
   Mobile: collapse "Chat with Us" tab to a
   circular icon-only button after page load.
   The label is wrapped in .chat-widget__tab-label
   so it can be animated out cleanly.
   ───────────────────────────────────────── */
.chat-widget__tab-label {
  display: inline-block;
  max-width: 8rem;
  overflow: hidden;
  white-space: nowrap;
  opacity: 1;
  /* Fade out faster than the button shrinks so the text is gone
     before the icon settles into its circular shape. */
  transition: max-width 0.3s ease, opacity 0.12s ease, margin 0.3s ease;
}

@media (max-width: 600px) {
  /* When collapsed: hide label, shrink padding to make a circle.
     The widget gets .chat-widget--collapsed via JS ~3.5s after load. */
  .chat-widget--collapsed .chat-widget__tab {
    padding: 0.75rem;
    gap: 0;
    border-radius: 50%;
    width: 3rem;
    height: 3rem;
    justify-content: center;
  }

  .chat-widget--collapsed .chat-widget__tab-label {
    max-width: 0;
    opacity: 0;
    margin: 0;
  }

  /* When the panel is open, always show the full button regardless of
     collapsed state (so the user knows what closes the chat). */
  .chat-widget--open .chat-widget__tab {
    padding: 0.6rem 1rem 0.6rem 0.85rem;
    border-radius: 2rem;
    width: auto;
    height: auto;
    gap: 0.45rem;
  }
  .chat-widget--open .chat-widget__tab-label {
    max-width: 8rem;
    opacity: 1;
  }
}

/* ─────────────────────────────────────────
   Keep the tab distinguishable on same-green
   backgrounds (e.g. footer) — white ring is
   invisible on white page areas, separates the
   green pill from the green footer.
   ───────────────────────────────────────── */
.chat-widget__tab {
  box-shadow: 0 0 0 2px #fff, 0 4px 18px rgba(0, 0, 0, 0.28);
}
.chat-widget__tab:hover {
  box-shadow: 0 0 0 2px #fff, 0 6px 22px rgba(0, 0, 0, 0.34);
}
