/*
  OATHERA assistant — collapsible right-side chat panel.

  Layout model:
  - The panel is position:fixed on the right, 25% of viewport width (clamped).
  - When open, <html> gets .oathera-chat-open, which adds right padding equal
    to the panel width so the 75% site content reflows beside it (never hidden
    behind the panel).
  - When collapsed, the panel slides off the right edge; a small toggle tab
    stays docked to the right so it can be re-opened.
  - Colours come entirely from the existing theme tokens (--background,
    --foreground, --primary, --muted-foreground), so it themes automatically
    on oathera.ai (dark) and oathera.com (light).
*/

:root {
  --chat-width: clamp(320px, 25vw, 460px);
}

/* Reflow the whole site to the left 75% when the panel is open (desktop). */
@media (min-width: 861px) {
  html.oathera-chat-open body {
    padding-right: var(--chat-width);
  }
  html.oathera-chat-open .site-nav,
  html.oathera-chat-open .site-header {
    /* Fixed/sticky headers must shrink too so they don't slide under the panel. */
    right: var(--chat-width);
  }
}

/* ---- Toggle tab (collapsed state handle) ----------------------------------
   Icon-only handle: a tall double-left arrow (the chevron) with a vertical bar
   stuck to its right. The bar's height is 4x the arrow's height. */
:root {
  --chat-arrow-h: 20px;              /* height of the double-left arrow */
  --chat-bar-h: calc(var(--chat-arrow-h) * 4); /* vertical bar = 4x the arrow */
}
.oathera-chat-fab {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 6px 10px 8px;
  border: none;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease, filter 0.2s ease;
  filter: drop-shadow(0 0 10px color-mix(in oklab, var(--primary) 35%, transparent));
}
.oathera-chat-fab:hover,
.oathera-chat-fab:focus-visible {
  outline: none;
  filter: drop-shadow(0 0 16px color-mix(in oklab, var(--primary) 60%, transparent));
}
/* The arrow: tall and a bit lengthy in height, narrow in width. */
.oathera-chat-fab-arrow {
  display: block;
  height: var(--chat-arrow-h);
  width: auto;
  aspect-ratio: 24 / 48; /* matches the SVG viewBox so it stays tall + slim */
}
/* The vertical bar: hugs the right edge of the arrow, 4x the arrow's height. */
.oathera-chat-fab-bar {
  display: block;
  width: 3px;
  height: var(--chat-bar-h);
  border-radius: 2px;
  background: var(--primary);
}
/* Hover/focus tooltip: "ASK OATHERA" with a chat icon, floated to the LEFT of
   the tab so it doesn't run off the right edge of the screen. */
.oathera-chat-fab-tip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.75rem;
  white-space: nowrap;
  border-radius: 0.6rem;
  border: 1px solid color-mix(in oklab, var(--primary) 40%, transparent);
  background: color-mix(in oklab, var(--background) 92%, transparent);
  color: var(--primary);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 24px color-mix(in oklab, #000 30%, transparent);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.oathera-chat-fab-tip svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}
/* Little arrow pointing from the tooltip toward the tab. */
.oathera-chat-fab-tip::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: color-mix(in oklab, var(--primary) 40%, transparent);
}
.oathera-chat-fab:hover .oathera-chat-fab-tip,
.oathera-chat-fab:focus-visible .oathera-chat-fab-tip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}
/* Hide the tab while the panel is open. */
html.oathera-chat-open .oathera-chat-fab {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) translateX(100%);
}

/* ---- Panel ---------------------------------------------------------------- */
.oathera-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 61;
  width: var(--chat-width);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: color-mix(in oklab, var(--background) 92%, transparent);
  border-left: 1px solid color-mix(in oklab, var(--primary) 20%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: -12px 0 40px color-mix(in oklab, #000 25%, transparent);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
html.oathera-chat-open .oathera-chat-panel {
  transform: translateX(0);
}

/* Header */
.oathera-chat-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid color-mix(in oklab, var(--primary) 15%, transparent);
}
.oathera-chat-head img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}
.oathera-chat-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.oathera-chat-title strong {
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  color: var(--foreground);
}
.oathera-chat-title span {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--primary);
}
.oathera-chat-close {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  border: 1px solid color-mix(in oklab, var(--primary) 25%, transparent);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.oathera-chat-close:hover,
.oathera-chat-close:focus-visible {
  color: var(--primary);
  border-color: var(--primary);
  outline: none;
}
.oathera-chat-close svg {
  width: 18px;
  height: 18px;
}

/* Message list */
.oathera-chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
}
.oathera-msg {
  max-width: 92%;
  padding: 0.65rem 0.85rem;
  border-radius: 0.8rem;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.oathera-msg-bot {
  align-self: flex-start;
  background: color-mix(in oklab, var(--primary) 10%, transparent);
  border: 1px solid color-mix(in oklab, var(--primary) 18%, transparent);
  color: color-mix(in oklab, var(--foreground) 92%, transparent);
  border-bottom-left-radius: 0.2rem;
}
.oathera-msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: var(--background);
  border-bottom-right-radius: 0.2rem;
}
.oathera-msg a {
  color: inherit;
  text-decoration: underline;
}

/* Typing indicator */
.oathera-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.7rem 0.9rem;
  border-radius: 0.8rem;
  background: color-mix(in oklab, var(--primary) 10%, transparent);
}
.oathera-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.5;
  animation: oatheraTyping 1.2s infinite ease-in-out;
}
.oathera-typing span:nth-child(2) { animation-delay: 0.15s; }
.oathera-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes oatheraTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Composer */
.oathera-chat-form {
  border-top: 1px solid color-mix(in oklab, var(--primary) 15%, transparent);
  padding: 0.75rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.oathera-chat-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 7rem;
  min-height: 2.6rem;
  padding: 0.6rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid color-mix(in oklab, var(--primary) 25%, transparent);
  background: color-mix(in oklab, var(--background) 70%, transparent);
  color: var(--foreground);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
}
.oathera-chat-input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--primary) 30%, transparent);
}
.oathera-chat-send {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 0.6rem;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--background);
  cursor: pointer;
  transition: filter 0.2s ease, opacity 0.2s ease;
}
.oathera-chat-send:hover:not(:disabled) { filter: brightness(1.08); }
.oathera-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.oathera-chat-send svg { width: 18px; height: 18px; }
.oathera-chat-foot {
  padding: 0 0.75rem 0.6rem;
  font-size: 0.64rem;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
  text-align: center;
}

/* ---- Mobile: full-width overlay instead of a 25% split -------------------- */
@media (max-width: 860px) {
  :root { --chat-width: 100vw; }
  html.oathera-chat-open body { padding-right: 0; }
  .oathera-chat-panel { width: min(100vw, 420px); }
}

/* Respect reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .oathera-chat-panel,
  .oathera-chat-fab { transition: none; }
  .oathera-typing span { animation: none; }
}
