/* ===========================================================
   Scholar Chat Widget
   Uses the site's existing design tokens (defined in styles.css):
   --ink, --surface, --elevated, --rule, --muted, --body, --heading,
   --accent, --accent-soft, plus Fraunces (serif) and Inter (sans).
   Dark, editorial, to match the rest of the page.
   =========================================================== */

.chat-launcher {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.1rem 0.6rem 0.6rem;
  min-height: 52px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--elevated);
  color: var(--heading);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.7);
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}
.chat-launcher:hover {
  border-color: var(--accent);
  color: var(--accent-soft);
  transform: translateY(-1px);
}
.chat-launcher[aria-expanded="true"] {
  display: none;
}

/* Eva avatar (used in launcher and header). Initials fallback, no image dep. */
.chat-avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(150deg, var(--accent-soft), var(--accent));
  border-radius: 50%;
  letter-spacing: 0.01em;
}
.chat-launcher .chat-avatar {
  width: 38px;
  height: 38px;
  font-size: 1rem;
  position: relative;
}
/* Online dot on the launcher avatar */
.chat-launcher .chat-avatar::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #57c97a;
  border: 2px solid var(--elevated);
}
.chat-launcher-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}
.chat-launcher-text small {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

/* Proactive teaser bubble that pops up shortly after load */
.chat-teaser {
  position: fixed;
  right: 1.5rem;
  bottom: 5.5rem;
  z-index: 60;
  max-width: 270px;
  background: var(--surface);
  color: var(--body);
  border: 1px solid var(--rule);
  border-radius: 12px;
  border-bottom-right-radius: 4px;
  padding: 0.85rem 2.1rem 0.85rem 0.95rem;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.9rem;
  line-height: 1.5;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.75);
  cursor: pointer;
  transform-origin: bottom right;
  animation: chat-teaser-in 0.35s ease both;
}
.chat-teaser[hidden] {
  display: none;
}
.chat-teaser strong {
  color: var(--heading);
  font-weight: 600;
}
.chat-teaser-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}
.chat-teaser-close:hover {
  color: var(--heading);
  background: rgba(255, 255, 255, 0.05);
}

@keyframes chat-teaser-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Panel ---- */
.chat-panel {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 61;
  display: flex;
  flex-direction: column;
  width: 380px;
  max-width: calc(100vw - 3rem);
  height: 560px;
  max-height: calc(100vh - 3rem);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.8);
}
.chat-panel[hidden] {
  display: none;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--elevated);
}
.chat-header .chat-avatar {
  width: 40px;
  height: 40px;
  font-size: 1.05rem;
}
.chat-header-title {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex: 1;
}
.chat-header-title strong {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  color: var(--heading);
  font-size: 1.02rem;
  line-height: 1.2;
}
.chat-header-title span {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.chat-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background 0.15s ease;
}
.chat-close:hover {
  color: var(--heading);
  background: rgba(255, 255, 255, 0.05);
}

/* ---- Messages ---- */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}
.chat-msg {
  max-width: 85%;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--ink);
  border-bottom-right-radius: 3px;
}
.chat-msg-bot {
  align-self: flex-start;
  background: var(--elevated);
  color: var(--body);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 3px;
}
.chat-msg-bot strong {
  color: var(--heading);
  font-weight: 600;
}
.chat-msg-error {
  align-self: flex-start;
  background: rgba(180, 90, 90, 0.12);
  border: 1px solid rgba(180, 90, 90, 0.4);
  color: #e8b7b7;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 0.3rem;
  padding: 0.8rem 0.9rem;
  background: var(--elevated);
  border: 1px solid var(--rule);
  border-radius: 10px;
  border-bottom-left-radius: 3px;
}
.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-bounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---- Composer ---- */
.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.85rem;
  border-top: 1px solid var(--rule);
  background: var(--elevated);
}
.chat-input {
  flex: 1;
  resize: none;
  background: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 8px;
  color: var(--body);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.4;
  padding: 0.6rem 0.7rem;
  max-height: 120px;
}
.chat-input:focus {
  outline: none;
  border-color: var(--accent);
}
.chat-input::placeholder {
  color: var(--muted);
}
.chat-send {
  appearance: none;
  border: none;
  background: var(--accent);
  color: var(--ink);
  font-weight: 600;
  border-radius: 8px;
  padding: 0 1rem;
  min-width: 64px;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.chat-send:hover:not(:disabled) {
  background: var(--accent-soft);
}
.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
  .chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .chat-launcher {
    right: 1rem;
    bottom: 1rem;
  }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .chat-launcher,
  .chat-log,
  .chat-typing span,
  .chat-teaser {
    transition: none;
    animation: none;
    scroll-behavior: auto;
  }
}
