/* augmora.org site chat (chat.js). Uses the tokens in styles.css; load after it. */

.chat-fab {
  position: fixed; left: 20px; bottom: 20px; z-index: 150;
  display: grid; place-items: center; width: 56px; height: 56px; padding: 0;
  border: 1px solid var(--ink); border-radius: 9999px;
  background: var(--ink); color: var(--on-ink);
  box-shadow: 0 6px 20px rgba(24, 27, 33, 0.18); cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease, transform 180ms ease;
}
.chat-fab:hover { background: var(--ink-hover); }
.chat-fab:active { transform: scale(0.96); }
.chat-fab.on-dark { background: var(--surface); color: var(--ink); border-color: var(--surface); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); }
.chat-fab.on-dark:hover { background: var(--pearl); }
.chat-fab.on-dark:focus-visible { outline-color: var(--pearl); }

.chat-panel {
  position: fixed; left: 20px; bottom: 88px; z-index: 150;
  display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100dvh - 112px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 18px 60px rgba(24, 27, 33, 0.18);
  overflow: hidden;
}
@media (prefers-reduced-motion: no-preference) {
  .chat-panel:not([hidden]) { animation: chat-in 200ms cubic-bezier(0.2, 0.8, 0.2, 1); transform-origin: bottom left; }
  @keyframes chat-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
}

.chat-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 14px 14px 18px; border-bottom: 1px solid var(--border);
}
.chat-title { font-family: var(--font-brand); font-size: 16px; font-weight: 600; line-height: 1.3; }
.chat-note { margin-top: 2px; font-size: 12px; line-height: 1.4; color: var(--muted); }
.chat-close {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 9999px; background: transparent; color: var(--muted); cursor: pointer;
}
.chat-close:hover { background: var(--soft); color: var(--text); }
.chat-close svg { width: 18px; height: 18px; }

.chat-log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 8px; padding: 16px;
  background: var(--alt); font-size: 15px; line-height: 1.45;
}
.chat-msg { max-width: 86%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-msg.in { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg.out { align-self: flex-end; background: var(--ink); color: var(--on-ink); border-bottom-right-radius: 4px; }
.chat-msg.error { color: var(--muted); }
.chat-msg a { text-decoration: underline; text-underline-offset: 2px; }
.chat-msg.typing::after { content: "…"; display: inline-block; min-width: 1.5em; color: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  .chat-msg.typing::after { animation: chat-dots 1s steps(4, end) infinite; overflow: hidden; vertical-align: bottom; }
  @keyframes chat-dots { from { width: 0; min-width: 0; } to { width: 1.2em; min-width: 0; } }
}

.chat-challenge { padding: 12px 16px 0; font-size: 13px; color: var(--muted); }
.chat-challenge p { margin-bottom: 8px; }

.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 12px 12px 8px 16px; border-top: 1px solid var(--border); }
.chat-input {
  flex: 1; min-width: 0; max-height: 120px; resize: none; margin: 0; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.35;
}
.chat-input:focus-visible { outline-offset: 0; }
.chat-send {
  display: grid; place-items: center; flex: none; width: 42px; height: 42px; padding: 0;
  border: 1px solid var(--ink); border-radius: 9999px; background: var(--ink); color: var(--on-ink); cursor: pointer;
}
.chat-send:hover { background: var(--ink-hover); }
.chat-send:disabled { opacity: 0.45; cursor: default; }
.chat-send svg { width: 18px; height: 18px; }

.chat-foot { display: flex; align-items: center; gap: 12px; padding: 4px 16px 14px; font-size: 12px; color: var(--muted); }
.chat-book {
  display: inline-flex; align-items: center; flex: none; min-height: 36px; padding: 0 16px; white-space: nowrap;
  border-radius: 9999px; background: var(--soft); border: 1px solid rgba(24, 27, 33, 0.15); color: var(--text);
  font-family: var(--font-brand); font-size: 12px; font-weight: 500; letter-spacing: 0.065em; text-transform: uppercase;
}
.chat-book:hover { opacity: 1; background: var(--border); }

@media (max-width: 520px) {
  .chat-fab { left: 16px; bottom: 16px; }
  .chat-panel { left: 16px; right: 16px; bottom: 84px; width: auto; height: min(560px, calc(100dvh - 104px)); }
}
@media print { .chat-fab, .chat-panel { display: none !important; } }
