/* ==========================================================================
   The OLS 24/7 Guide: the chat window
   Design: ux-spec-24-7-guide.md (10-05). Loaded only by js/guide.js, with its
   own ?v= (SPEC 4.1). Reads the site tokens styles.css defines on :root and
   never redefines one. Every class starts with ols-guide.
   ========================================================================== */

/* --- The Guide tokens (ux-spec 0): defined once, on the window's root --- */
.ols-guide {
  --guide-radius: 12px;
  --guide-radius-control: 8px;
  --guide-shadow-float: 0 8px 32px rgba(0,0,0,0.18);
  --guide-shadow-launcher: 0 4px 16px rgba(0,0,0,0.08);
  --guide-gap: 16px;
  --guide-cta-bar-h: 56px;
  --guide-panel-w: 400px;
  --guide-panel-h: 640px;
  --guide-z-float: 98;
  --guide-z-sheet: 1100;
  --guide-enter: 250ms ease-out;
  --guide-exit: 175ms ease-in;

  /* Derived, not new values: where the launcher and the panel sit above the
     bottom edge (the mobile CTA bar is on screen below 1024px). */
  --ols-guide-bottom: calc(var(--guide-cta-bar-h) + var(--guide-gap) + env(safe-area-inset-bottom, 0px));
  --ols-guide-right: calc(var(--guide-gap) + env(safe-area-inset-right, 0px));

  font-family: var(--font-body);
  color: var(--color-charcoal);
}

@media (min-width: 768px) {
  .ols-guide {
    --guide-gap: 24px;
  }
}

@media (min-width: 1024px) {
  .ols-guide {
    --ols-guide-bottom: calc(var(--guide-gap) + env(safe-area-inset-bottom, 0px));
  }
}

/* --- The deviation (ux-spec 0, approved 10-05: "Charcoal on teal") ---
   Inside the Guide, anything a visitor reads or finds is charcoal: labels and
   icons on teal fills, links (with a teal underline), and the focus ring.
   One block, so P2.18 or the visual refresh can lift it site-wide. */
.ols-guide {
  --guide-focus: 3px solid var(--color-charcoal);
}

.ols-guide__launcher,
.ols-guide__send,
.ols-guide__call {
  color: var(--color-charcoal);
}

.ols-guide a,
.ols-guide__link {
  color: var(--color-charcoal);
  text-decoration-color: var(--color-teal);
}
/* --- end of the deviation --- */

/* --- Shared pieces --- */
.ols-guide *,
.ols-guide *::before,
.ols-guide *::after {
  box-sizing: border-box;
}

.ols-guide__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.ols-guide__icon {
  display: block;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ols-guide :focus-visible,
.ols-guide__link:focus-visible {
  outline: var(--guide-focus);
  outline-offset: 2px;
}

.ols-guide a,
.ols-guide__link {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: text-decoration-thickness var(--transition-fast);
}

.ols-guide a:hover,
.ols-guide__link:hover {
  color: var(--color-charcoal);
  text-decoration-thickness: 2px;
}

.ols-guide__badge {
  display: inline-block;
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 4px;
  background-color: var(--color-teal-tint);
  color: var(--color-charcoal);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* --- The launcher (ux-spec 1.2) --- */
.ols-guide__launcher {
  position: fixed;
  right: var(--ols-guide-right);
  bottom: var(--ols-guide-bottom);
  z-index: var(--guide-z-float);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: var(--guide-radius-control);
  background-color: var(--color-teal);
  box-shadow: var(--guide-shadow-launcher);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast), background-color var(--transition-fast),
    box-shadow var(--transition-fast), transform var(--transition-fast);
}

.ols-guide__launcher.is-shown {
  opacity: 1;
}

.ols-guide__launcher:hover {
  background-color: var(--color-teal-dark);
  box-shadow: var(--guide-shadow-float);
}

.ols-guide__launcher:active {
  transform: translateY(1px);
}

.ols-guide__launcher[hidden] {
  display: none;
}

@media (max-width: 767px) {
  /* A page field has focus: the keyboard would lift the launcher over it. */
  .ols-guide.is-field-focus .ols-guide__launcher {
    visibility: hidden;
  }
}

/* --- The window: panel (768px and up), sheet (phones), or in the page --- */
.ols-guide__window {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--guide-radius);
  background-color: var(--color-white);
}

.ols-guide__window[hidden] {
  display: none;
}

.ols-guide__window--float {
  position: fixed;
  right: var(--ols-guide-right);
  bottom: var(--ols-guide-bottom);
  z-index: var(--guide-z-float);
  width: min(var(--guide-panel-w), calc(100vw - 2 * var(--guide-gap)));
  height: min(var(--guide-panel-h), calc(100vh - var(--ols-nav-h) - var(--ols-guide-bottom) - var(--guide-gap)));
  box-shadow: var(--guide-shadow-float);
  transform-origin: bottom right;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity var(--guide-exit), transform var(--guide-exit);
}

.ols-guide__window--float.is-open {
  opacity: 1;
  transform: none;
  transition: opacity var(--guide-enter), transform var(--guide-enter);
}

/* The phone sheet (ux-spec 3): covers everything, follows the visual viewport. */
.ols-guide__window--float.is-sheet {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--guide-z-sheet);
  width: 100%;
  height: auto;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  opacity: 1;
  transform: translateY(100%);
  transition: transform var(--guide-exit);
}

.ols-guide__window--float.is-sheet.is-open {
  transform: none;
  transition: transform var(--guide-enter);
}

/* While the on-screen keyboard is up the sheet takes the visual viewport's
   height and top, so the composer rides right above the keyboard. */
.ols-guide__window--float.is-sheet.has-vv {
  bottom: auto;
  top: var(--ols-guide-vv-top);
  height: var(--ols-guide-vv-h);
}

/* --- The Ask the Guide page's mount (ux-spec 1.7): height from the first frame --- */
#ols-guide-page.ols-guide {
  display: block;
  height: max(420px, calc(100vh - var(--ols-nav-h) - var(--guide-cta-bar-h) - 32px));
}

@supports (height: 100svh) {
  #ols-guide-page.ols-guide {
    height: max(420px, calc(100svh - var(--ols-nav-h) - var(--guide-cta-bar-h) - 32px));
  }
}

@media (min-width: 768px) {
  #ols-guide-page.ols-guide {
    height: clamp(480px, 70vh, 720px);
  }
}

.ols-guide--page .ols-guide__window {
  height: 100%;
  box-shadow: var(--shadow-card);
}

/* --- Header (ux-spec 1.4.1) --- */
.ols-guide__header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--color-border);
  background-color: var(--color-white);
}

.ols-guide--page .ols-guide__header {
  padding-right: 16px;
}

.ols-guide__mark-icon {
  display: block;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
}

.ols-guide__title {
  margin: 0;
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: normal;
  color: var(--color-charcoal);
  text-wrap: balance;
}

.ols-guide__title:focus {
  outline: none;
}

.ols-guide__title:focus-visible {
  outline: var(--guide-focus);
  outline-offset: 2px;
}

.ols-guide__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: var(--guide-radius-control);
  background-color: transparent;
  color: var(--color-charcoal);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.ols-guide__close:hover {
  background-color: var(--color-teal-tint);
}

.ols-guide__window--float.is-sheet .ols-guide__close {
  width: 48px;
  height: 48px;
}

/* --- The conversation (ux-spec 1.4.2) ---
   The scroller is a wrapper holding the log and, after it, the handoff line. */
.ols-guide__scroll {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--color-offwhite);
}

.ols-guide__log {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* The handoff line (ux-spec 1.4.2): color, underline, hover and focus come from the
   Guide's one link style (.ols-guide a and the focus rule), so none is written here. */
.ols-guide__handoff {
  display: flex;
  align-self: flex-start;
  align-items: center;
  min-height: 44px;
  margin-top: 4px;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.6;
  border-radius: var(--guide-radius-control);
}

.ols-guide__handoff[hidden] {
  display: none;
}

@media (max-width: 767px) {
  .ols-guide__handoff {
    min-height: 48px;
  }
}

.ols-guide__msg {
  flex-shrink: 0;
  max-width: 85%;
  margin: 0;
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--color-charcoal);
  overflow-wrap: anywhere;
}

.ols-guide__msg--guide {
  align-self: flex-start;
  border: 1px solid var(--color-border);
  border-radius: var(--guide-radius-control) var(--guide-radius) var(--guide-radius) var(--guide-radius);
  background-color: var(--color-white);
}

.ols-guide__msg--visitor {
  align-self: flex-end;
  border-radius: var(--guide-radius) var(--guide-radius-control) var(--guide-radius) var(--guide-radius);
  background-color: var(--color-teal-tint);
  white-space: pre-wrap;
}

.ols-guide__msg p {
  margin: 0;
}

.ols-guide__msg p + p,
.ols-guide__msg p + ul,
.ols-guide__msg ul + p,
.ols-guide__msg ul + ul {
  margin-top: 12px;
}

.ols-guide__msg ul {
  margin: 0;
  padding-left: 20px;
  list-style: disc;
}

.ols-guide__msg li + li {
  margin-top: 4px;
}

.ols-guide__msg strong {
  font-weight: 600;
}

/* The notice (ux-spec 1.4.3): the DS Inline Note, full column width. */
.ols-guide__notice {
  display: flex;
  flex-shrink: 0;
  align-items: flex-start;
  gap: 12px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--guide-radius);
  background-color: var(--color-teal-tint);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.6;
  color: var(--color-charcoal);
}

.ols-guide__notice .ols-guide__icon {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  color: var(--color-teal);
  stroke-width: 1.5;
}

.ols-guide__notice p {
  margin: 0;
}

@media (min-width: 768px) {
  .ols-guide__notice {
    font-size: 16px;
  }
}

/* The typing indicator (ux-spec 2.4). */
.ols-guide__dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
}

.ols-guide__dot {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-teal-dark);
  animation: ols-guide-dot 1.2s ease-in-out infinite;
}

.ols-guide__dot:nth-child(2) {
  animation-delay: 0.2s;
}

.ols-guide__dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes ols-guide-dot {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.ols-guide__typing-note {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.5;
}

/* The call button (ux-spec 1.5): the DS Primary, charcoal label (the deviation). */
.ols-guide__call {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 14px 16px;
  border-radius: var(--guide-radius-control);
  background-color: var(--color-teal);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.02em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  text-wrap: balance;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.ols-guide a.ols-guide__call {
  text-decoration-line: none;
}

.ols-guide__call:hover {
  background-color: var(--color-teal-dark);
}

.ols-guide__call:active {
  transform: translateY(1px);
}

@media (max-width: 359px) {
  .ols-guide__call {
    white-space: normal;
  }
}

/* The DS Secondary button: Try again, Start a new conversation. */
.ols-guide__secondary {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 28px;
  border: 2px solid var(--color-teal);
  border-radius: var(--guide-radius-control);
  background-color: var(--color-white);
  color: var(--color-charcoal);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.ols-guide__secondary:hover {
  background-color: var(--color-teal-tint);
}

.ols-guide__secondary:active {
  transform: translateY(1px);
}

.ols-guide__actions {
  display: flex;
  flex-shrink: 0;
  flex-direction: column;
  gap: 12px;
}

.ols-guide__actions .ols-guide__secondary {
  align-self: flex-start;
}

@media (min-width: 768px) {
  .ols-guide__actions--closed {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .ols-guide__actions--closed .ols-guide__call,
  .ols-guide__actions--closed .ols-guide__secondary {
    flex: 1 1 auto;
    width: auto;
  }
}

/* "Not sent." under a visitor message (ux-spec 2.10). */
.ols-guide__not-sent {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  align-self: flex-end;
  gap: 6px;
  margin-top: -6px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-charcoal);
}

.ols-guide__not-sent .ols-guide__icon {
  width: 16px;
  height: 16px;
  color: var(--color-error);
}

/* Loading and resting on the Ask the Guide page (ux-spec 2.1, 2.7). */
.ols-guide__center {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background-color: var(--color-offwhite);
}

.ols-guide__loading {
  margin: 0;
  font-size: 16px;
  opacity: 0;
}

.ols-guide__loading.is-shown {
  opacity: 1;
}

.ols-guide__rest {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 480px;
}

.ols-guide__rest .ols-guide__icon {
  width: 48px;
  height: 48px;
  color: var(--color-teal);
  stroke-width: 1.5;
}

.ols-guide__rest-title {
  margin: 0;
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--color-charcoal);
}

.ols-guide__rest-text {
  margin: 0 0 4px;
  font-size: 16px;
  line-height: 1.6;
}

/* --- The composer and the footer link (ux-spec 1.4.5, 1.4.6) --- */
.ols-guide__bottom {
  flex-shrink: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  background-color: var(--color-white);
}

.ols-guide__composer[hidden] {
  display: none;
}

.ols-guide__label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--color-charcoal);
}

.ols-guide__row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.ols-guide__box {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  height: 48px;
  max-height: 120px;
  margin: 0;
  padding: 11px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--guide-radius-control);
  background-color: var(--color-white);
  color: var(--color-charcoal);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
}

.ols-guide__box:focus,
.ols-guide__box:focus-visible {
  padding: 10px 11px;
  border: 2px solid var(--color-teal-dark);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-teal) 15%, transparent);
}

.ols-guide__send {
  display: inline-flex;
  flex: 0 0 48px;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: var(--guide-radius-control);
  background-color: var(--color-teal);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.ols-guide__send:hover {
  background-color: var(--color-teal-dark);
}

.ols-guide__send[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.6;
}

.ols-guide__count {
  margin: 4px 0 0;
  font-size: 14px;
  line-height: 1.5;
  text-align: right;
}

.ols-guide__count[hidden] {
  display: none;
}

.ols-guide__footer-link {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 8px auto 0;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

/* The footer link's tap target (ux-spec 3: 44px, 48px on phones; it measured about 21px). The words
   keep their size and sit centered in the taller box, so the space above them replaces the old margin. */
.ols-guide__footer-link--tap48 {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 0;
}

@media (max-width: 767px) {
  .ols-guide__footer-link--tap48 {
    min-height: 48px;
  }
}

/* --- The page footer stays clear of the launcher (ux-spec 1.2) --- */
.ols-guide-shown .footer::after {
  content: "";
  display: block;
  height: var(--ols-guide-clearance, 0px);
}

/* --- Reduced motion: state changes happen at once (ux-spec 6) --- */
@media (prefers-reduced-motion: reduce) {
  .ols-guide__launcher,
  .ols-guide__window--float,
  .ols-guide__window--float.is-open,
  .ols-guide__window--float.is-sheet,
  .ols-guide__window--float.is-sheet.is-open {
    transform: none;
    transition: none;
  }

  .ols-guide__window--float {
    opacity: 1;
  }

  .ols-guide__dot {
    animation: none;
    opacity: 1;
  }

  .ols-guide__typing-text {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
}

/* --- Never printed --- */
@media print {
  .ols-guide__launcher,
  .ols-guide__window--float {
    display: none !important;
  }
}
