/* CRVITAE — chat.css · the "Ask CRVITAE" widget (born in Chapter 05)
   Logical properties throughout: the widget docks to the inline-end corner, so
   under dir=rtl it docks bottom-left with no override. The one exception is
   the birth keyframe, whose translate() has no logical form. */

.chat { position: fixed; inset-inline-end: clamp(14px, 3vw, 34px); inset-block-end: clamp(14px, 3vh, 30px); z-index: 120; font-family: var(--sans); }
.chat__launch[hidden], .chat__panel[hidden] { display: none !important; }

.chat__launch {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 22px; border: 0; border-radius: 999px;
  /* 14.4px/700 white measured 3.27:1 on the old #8b7cff stop. --grad-cta
     holds >=4.70:1 across its whole span. */
  font: 700 var(--t-14)/1 var(--sans); color: #fff;
  background: var(--grad-cta);
  box-shadow: 0 10px 34px rgba(124,111,246,0.45), 0 0 0 1px rgba(255,255,255,0.12) inset;
  transition: transform var(--dur-move) var(--ease-out), box-shadow var(--dur-move);
}
.chat__launch:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 14px 44px rgba(124,111,246,0.6); }
.chat__launch.is-born { animation: chat-born 0.9s cubic-bezier(0.16,1,0.3,1) both; }
.chat__launch.is-here { animation: chat-here 0.4s ease-out both; }
@keyframes chat-born {
  0% { transform: translate(-40vw, -40vh) scale(0.3); opacity: 0; }
  60% { opacity: 1; }
  80% { transform: translate(0,0) scale(1.08); }
  100% { transform: translate(0,0) scale(1); opacity: 1; }
}
/* translate() has no logical form: in RTL the widget flies in from the other
   side of the page, so the keyframe mirrors rather than the layout. */
@keyframes chat-born-rtl {
  0% { transform: translate(40vw, -40vh) scale(0.3); opacity: 0; }
  60% { opacity: 1; }
  80% { transform: translate(0,0) scale(1.08); }
  100% { transform: translate(0,0) scale(1); opacity: 1; }
}
[dir="rtl"] .chat__launch.is-born { animation-name: chat-born-rtl; }
@keyframes chat-here { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.chat__panel {
  position: absolute; inset-inline-end: 0; inset-block-end: calc(100% + 14px);
  width: min(392px, calc(100vw - 28px));
  display: flex; flex-direction: column;
  max-height: min(600px, calc(100vh - 120px)); min-height: 320px;
  border-radius: var(--r-lg); overflow: hidden;
  background: linear-gradient(165deg, rgba(34,21,64,0.94), rgba(21,9,42,0.97));
  border: 1px solid rgba(255,255,255,0.14);
  backdrop-filter: blur(20px) saturate(1.2);
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(124,111,246,0.15);
  opacity: 0; transform: translateY(14px) scale(0.98);
  transition: opacity var(--dur-move) ease, transform var(--dur-move) var(--ease-out);
}
.chat__panel.is-open { opacity: 1; transform: none; }

.chat__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-block-end: 1px solid rgba(255,255,255,0.07);
}
.chat__head b { color: var(--fg-1); font-size: var(--t-16); display: block; }
/* The panel floats over arbitrary page content, so every ratio below is
   measured against the worst case: a pure-white backdrop showing through the
   panel's 6% transparency. --fg-3 = 4.62:1 there, --fg-2 = 6.83:1. */
.chat__mode { display: block; margin-block-start: 3px; font: 600 var(--t-11)/1 var(--mono); letter-spacing: 0.16em; color: var(--fg-3); }
.chat__mode[data-mode="llm"] { color: var(--mint); }
.chat__close { background: none; border: 0; color: var(--fg-2); font-size: var(--t-16); padding: 6px 8px; border-radius: var(--r-xs); }
.chat__close:hover { color: var(--fg-1); background: rgba(255,255,255,0.06); }

.chat__log { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: grid; gap: 10px; align-content: start; scrollbar-width: thin; }
.chat__msg { max-width: 88%; padding: 11px 14px; border-radius: var(--r-md); font-size: var(--t-14); line-height: 1.6; }
.chat__msg p { margin: 0; }
/* Logical tails: the bubbles point the right way in an Arabic thread. */
.chat__msg--bot { justify-self: start; background: rgba(255,255,255,0.055); border: 1px solid rgba(255,255,255,0.09); color: var(--fg-1); border-end-start-radius: var(--r-xs); }
.chat__msg--user { justify-self: end; background: linear-gradient(135deg, rgba(124,111,246,0.4), rgba(107,91,224,0.5)); border: 1px solid rgba(124,111,246,0.4); color: #fff; border-end-end-radius: var(--r-xs); }
.chat__anchor { display: inline-block; margin-block-start: 8px; font: 600 var(--t-12)/1 var(--mono); color: var(--mint); }
.chat__anchor:hover { text-decoration: underline; }

.chat__typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.chat__typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-3); animation: chat-blink 1.2s infinite; }
.chat__typing i:nth-child(2) { animation-delay: 0.2s; }
.chat__typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

.chat__chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 16px 12px; }
.chat__chip {
  border: 1px solid rgba(124,111,246,0.4); background: rgba(124,111,246,0.1);
  color: var(--violet-300); border-radius: 999px; padding: 8px 13px;
  font: 600 var(--t-12)/1.3 var(--sans); text-align: start;
  transition: background var(--dur-tap), color var(--dur-tap);
}
.chat__chip:hover { background: rgba(124,111,246,0.22); color: #fff; }

.chat__form { display: flex; gap: 10px; padding: 12px 14px 14px; border-block-start: 1px solid rgba(255,255,255,0.07); }
.chat__form input {
  flex: 1; min-width: 0; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--r-sm); padding: 12px 14px; color: var(--fg-1); font: 500 var(--t-14)/1.3 var(--sans);
}
/* DESIGN.md:268 — a placeholder meets the same 4.5:1 as body text. --fg-3
   measured 3.60:1 on the field (3.86:1 worst case); --fg-2 gives 5.71:1. */
.chat__form input::placeholder { color: var(--fg-2); }
.chat__form input:focus { outline: none; border-color: var(--violet-400); box-shadow: 0 0 0 3px rgba(124,111,246,0.25); }
.chat__form button {
  width: 46px; border: 0; border-radius: var(--r-sm); font-size: var(--t-18); color: #fff;
  background: var(--grad-cta);
}
.chat__form button:hover { filter: brightness(1.12); }

@media (max-width: 480px) {
  .chat__panel { position: fixed; inset-block: auto 84px; inset-inline: 10px; width: auto; max-height: 68vh; }
}
@media (prefers-reduced-motion: reduce) {
  .chat__launch.is-born, .chat__launch.is-here { animation: none; }
  .chat__panel { transition: opacity var(--dur-tap); transform: none; }
}
