/* ==========================================================================
   Folio — Arthur, the chatbot (js/chatbot.js): a button bottom right that
   opens a small chat window.

   Its own file, because pages use different stylesheets (the editor and the
   sign-in pages don't load components.css). The --color-* variables come
   from pages.css; elsewhere the fallbacks from colors.css are used.
   ========================================================================== */

.chatbot {
  --chat-surface: var(--color-surface, var(--bg-surface));
  --chat-soft: var(--color-surface-soft, var(--bg-selected));
  --chat-ink: var(--color-ink, var(--text-primary));
  --chat-muted: var(--color-muted, var(--text-secondary));
  --chat-line: var(--color-line, var(--border-decorative));
  --chat-primary: var(--color-primary, var(--action-primary));

  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

/* Room at the bottom of the page, so the last button (like "Next" in the
   editor) can always be scrolled above Arthur's button. */
body.has-chatbot {
  padding-bottom: 96px;
}

.chatbot [hidden] {
  display: none !important;
}

.chatbot .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.chatbot-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 22px 10px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--action-gradient);
  color: var(--text-on-action);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-action);
}

.chatbot-toggle img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
}

.chatbot-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  display: grid;
  width: min(360px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid var(--chat-line);
  border-radius: 16px;
  background: var(--chat-surface);
  color: var(--chat-ink);
  box-shadow: 0 24px 64px -16px rgba(14, 24, 48, 0.45);
}

.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--chat-line);
  background: var(--chat-soft);
}

.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot-header-info div {
  display: grid;
  gap: 2px;
}

.chatbot-header-info span {
  color: var(--chat-muted);
  font-size: 0.85rem;
}

.chatbot-avatar {
  width: 52px;
  height: 52px;
  border: 2px solid var(--chat-surface);
  border-radius: 50%;
  background: var(--chat-surface);
  object-fit: cover;
}

.chatbot-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--chat-line);
  border-radius: 10px;
  background: var(--chat-surface);
  color: var(--chat-ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.chatbot-messages {
  display: grid;
  align-content: start;
  gap: 10px;
  max-height: min(320px, 50vh);
  overflow-y: auto;
  padding: 16px;
}

.chat-message {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-line; /* keep the line breaks in Arthur's answers */
  overflow-wrap: anywhere;
}

.chat-message.bot {
  justify-self: start;
  background: var(--chat-soft);
  color: var(--chat-ink);
}

.chat-message.user {
  justify-self: end;
  background: var(--action-primary);
  color: var(--text-on-action);
}

.chat-message.is-thinking {
  color: var(--chat-muted);
  font-style: italic;
}

.chatbot-note {
  margin: 0;
  padding: 0 16px 8px;
  color: var(--chat-muted);
  font-size: 0.78rem;
}

.chatbot-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--chat-line);
}

.chatbot-form input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--color-control, var(--border-control));
  border-radius: 10px;
  background: var(--chat-surface);
  color: var(--chat-ink);
  font: inherit;
}

.chatbot-form button {
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--action-primary);
  color: var(--text-on-action);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.chatbot-form button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.chatbot button:focus-visible,
.chatbot input:focus-visible {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

/* Phones: a smaller round button, so it covers less of the page */
@media (max-width: 600px) {
  .chatbot {
    right: 16px;
    bottom: 16px;
  }

  .chatbot-toggle {
    min-height: 56px;
    padding: 7px;
  }

  .chatbot-toggle span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .chatbot-panel {
    bottom: 68px;
  }
}

/* Never on a printed CV or PDF */
@media print {
  .chatbot {
    display: none !important;
  }

  body.has-chatbot {
    padding-bottom: 0;
  }
}
