/*!
 * WSP Chat — chat.css: the base stylesheet (behaviour only).
 *
 * Everything the drawer needs to FUNCTION: off-canvas positioning, open/close, hidden states,
 * scroll areas, the thinking animation, the launcher's fixed placement. Deliberately no colours,
 * fonts or decoration — those come from a skin (chat-default.css, or a skin plugin).
 *
 * Tokens a skin can set on .wsp-chat-drawer / :root:
 *   --wsp-chat-drawer-width   (600px)   --wsp-chat-z          (99999)
 *   --wsp-chat-transition     (.35s)    --wsp-chat-backdrop   (rgba(0,0,0,.25))
 *   --wsp-chat-input-min      (56px)    --wsp-chat-input-max  (300px)
 */

.wsp-chat-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The string bank: in the DOM (so page translators reach it) but clipped out of view. */
.wsp-chat-drawer__strings {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  pointer-events: none;
}

/* Page scroll lock while the drawer is open. */
html.wsp-chat-drawer-open {
  overflow: hidden;
  scrollbar-gutter: stable;
}

.wsp-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--wsp-chat-z, 99999) - 1);
  background: var(--wsp-chat-backdrop, rgba(0, 0, 0, 0.25));
}
.wsp-chat-backdrop[hidden] { display: none; }

/* ── Drawer shell ─────────────────────────────────────────────────────────── */
.wsp-chat-drawer,
.wsp-chat-drawer *,
.wsp-chat-drawer *::before,
.wsp-chat-drawer *::after,
.wsp-chat-section *,
.wsp-chat-launcher * { box-sizing: border-box; }

.wsp-chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: var(--wsp-chat-z, 99999);
  width: var(--wsp-chat-drawer-width, 600px);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--wsp-chat-transition, 0.35s) ease;
  will-change: transform;
  overflow: hidden;
}
.wsp-chat-drawer.is-open { transform: translateX(0); }
.wsp-chat-drawer--left { right: auto; left: 0; transform: translateX(-100%); }
.wsp-chat-drawer--left.is-open { transform: translateX(0); }
@media (max-width: 480px) { .wsp-chat-drawer { width: 100%; } }

.wsp-chat-drawer [hidden] { display: none !important; }

.wsp-chat-drawer__close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  cursor: pointer;
}

.wsp-chat-drawer__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.wsp-chat-drawer__welcome {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.wsp-chat-drawer__hello {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* The thread is the only scroll container. */
.wsp-chat-drawer__thread {
  display: none;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.wsp-chat-drawer.is-conversing .wsp-chat-drawer__welcome { display: none; }
.wsp-chat-drawer.is-conversing .wsp-chat-drawer__thread { display: flex; }
/* In a conversation the thread starts below the close button, so its scrollbar never runs under
   the ×, and it reaches the drawer's edge, so the scrollbar sits at the edge instead of against the
   bubbles. --wsp-chat-close-clearance: the room kept free for the close button. */
.wsp-chat-drawer.is-conversing .wsp-chat-drawer__body { padding-top: var(--wsp-chat-close-clearance, 32px); }
.wsp-chat-drawer.is-conversing .wsp-chat-drawer__thread {
  margin-right: calc(-1 * var(--wsp-chat-pad, 20px));
  padding-right: var(--wsp-chat-pad, 20px);
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.25) transparent;
}

.wsp-chat-drawer__form {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
}
.wsp-chat-drawer__input,
.wsp-chat-section__input {
  display: block;
  width: 100%;
  min-height: var(--wsp-chat-input-min, 56px);
  max-height: var(--wsp-chat-input-max, 300px);
  overflow-y: hidden;
  resize: none;
}
.wsp-chat-drawer__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.wsp-chat-drawer__links {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-left: auto;
  text-align: right;
}
.wsp-chat-drawer.is-streaming .wsp-chat-drawer__form button[type="submit"] {
  opacity: 0.55;
  pointer-events: none;
}

/* ── Messages ─────────────────────────────────────────────────────────────── */
.wsp-chat-msg { display: flex; }
.wsp-chat-msg--q { justify-content: flex-end; }
.wsp-chat-msg--a { justify-content: flex-start; }
.wsp-chat-msg--a > .wsp-chat-answer:not(.wsp-chat-answer--thinking) { width: 100%; max-width: 100%; }

.wsp-chat-answer { min-width: 0; }
.wsp-chat-answer--thinking {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
}
.wsp-chat-answer__table {
  overflow-x: auto;
  max-width: 100%;
}
.wsp-chat-answer__table table { border-collapse: collapse; }
.wsp-chat-answer__inner img { max-width: 100%; height: auto; }
.wsp-chat-answer__inner pre { overflow-x: auto; }
.wsp-chat-answer__followups-list { display: flex; flex-wrap: wrap; }
.wsp-chat-answer__followup { cursor: pointer; }
.wsp-chat-task { list-style: none; }

/* Status line + thinking dots. */
.wsp-chat-status {
  display: inline-block;
  animation: wsp-chat-status-in 0.3s ease;
}
@keyframes wsp-chat-status-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

.wsp-chat-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  height: 1.3em;
}
.wsp-chat-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: wsp-chat-dot 1.2s infinite ease-in-out;
}
.wsp-chat-dots span:nth-child(2) { animation-delay: 0.2s; }
.wsp-chat-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes wsp-chat-dot { 0%, 80%, 100% { opacity: 0.35; transform: scale(0.85); } 40% { opacity: 1; transform: scale(1); } }

/* ── Inline section + launcher + trigger ──────────────────────────────────── */
.wsp-chat-section__form { display: flex; flex-direction: column; }
.wsp-chat-section.is-conversing .wsp-chat-section__input { cursor: pointer; }

.wsp-chat-launcher {
  position: fixed;
  bottom: 24px;
  z-index: calc(var(--wsp-chat-z, 99999) - 2);
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.wsp-chat-launcher--right { right: 24px; }
.wsp-chat-launcher--left { left: 24px; }
html.wsp-chat-drawer-open .wsp-chat-launcher { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  .wsp-chat-drawer { transition: none; }
  .wsp-chat-dots span { animation: none; opacity: 0.8; }
  .wsp-chat-drawer__thread { scroll-behavior: auto; }
}

/* Every clickable part of the chat shows the hand cursor, whatever the theme or design sets;
   a disabled button (e.g. Send while an answer streams) shows that it cannot be used. */
.wsp-chat-drawer a[href], .wsp-chat-drawer button:not(:disabled),
.wsp-chat-section a[href], .wsp-chat-section button:not(:disabled),
.wsp-chat-launcher, [data-wsp-chat-open] { cursor: pointer; }
.wsp-chat-drawer button:disabled, .wsp-chat-section button:disabled { cursor: not-allowed; }
