/* =========================================================
   Chatbot UI — "paper & forest" editorial style
   Matches the portfolio's cream · forest · terracotta palette
   ========================================================= */

/* ---------- chatbot root ---------- */
#chatbot {
  position: fixed;
  bottom: 1.6rem;
  right: 1.6rem;
  z-index: 200;
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- FAB (floating action button) ---------- */
.cb-fab {
  position: relative;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1f3d2e 0%, #2d5a43 100%);
  color: #f8f2e4;
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow:
    0 6px 24px -6px rgba(31, 61, 46, 0.5),
    0 0 0 0 rgba(31, 61, 46, 0.3);
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.4s;
  z-index: 10;
}
.cb-fab:hover {
  transform: scale(1.08);
  box-shadow:
    0 10px 36px -8px rgba(31, 61, 46, 0.55),
    0 0 0 0 rgba(31, 61, 46, 0);
}
.cb-fab:active { transform: scale(0.95); }

.cb-fab-icon {
  position: absolute;
  width: 26px;
  height: 26px;
  transition: opacity 0.3s, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.cb-fab-close { opacity: 0; transform: rotate(-90deg) scale(0.5); }
.cb-open .cb-fab-chat { opacity: 0; transform: rotate(90deg) scale(0.5); }
.cb-open .cb-fab-close { opacity: 1; transform: rotate(0) scale(1); }

/* pulse ring */
.cb-fab-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid #1f3d2e;
  animation: cb-pulse 2.5s ease-out infinite;
}
.cb-open .cb-fab-pulse { animation: none; opacity: 0; }
@keyframes cb-pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ---------- chat window ---------- */
.cb-window {
  position: absolute;
  bottom: calc(100% + 14px);
  right: 0;
  width: 380px;
  max-height: min(600px, calc(100dvh - 140px));
  display: flex;
  flex-direction: column;
  border-radius: 24px;
  background: #f4eddf;
  overflow: hidden;
  box-shadow:
    0 30px 70px -20px rgba(21, 19, 15, 0.35),
    0 0 0 1px rgba(21, 19, 15, 0.08);
  opacity: 0;
  transform: translateY(20px) scale(0.92);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
              transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.cb-open .cb-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- header ---------- */
.cb-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, #1f3d2e 0%, #2d5a43 100%);
  color: #f8f2e4;
  flex-shrink: 0;
}
.cb-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(248, 242, 228, 0.15);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.cb-avatar svg { width: 20px; height: 20px; }
.cb-header-info { flex: 1; min-width: 0; }
.cb-header-name {
  display: block;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.cb-header-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.8;
}
.cb-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7ee2a8;
  display: inline-block;
  animation: cb-blink 2s ease-in-out infinite;
}
@keyframes cb-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.cb-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.cb-header-close,
.cb-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(248, 242, 228, 0.1);
  border: none;
  color: #f8f2e4;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.3s;
  flex-shrink: 0;
}
.cb-header-close:hover,
.cb-header-btn:hover { background: rgba(248, 242, 228, 0.2); }
.cb-header-close svg,
.cb-header-btn svg { width: 16px; height: 16px; }

/* ---------- body ---------- */
.cb-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}
.cb-body::-webkit-scrollbar { width: 5px; }
.cb-body::-webkit-scrollbar-track { background: transparent; }
.cb-body::-webkit-scrollbar-thumb { background: rgba(21, 19, 15, 0.15); border-radius: 99px; }

/* ---------- setup screen ---------- */
.cb-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2.5rem 1.8rem;
  gap: 0.8rem;
}
.cb-setup-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, #1f3d2e 0%, #2d5a43 100%);
  color: #f8f2e4;
  display: grid;
  place-items: center;
  margin-bottom: 0.4rem;
}
.cb-setup-icon svg { width: 28px; height: 28px; }
.cb-setup h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 450;
  font-size: 1.5rem;
  letter-spacing: -0.03em;
  color: #15130f;
}
.cb-setup p {
  color: #15130f;
  opacity: 0.75;
  font-size: 0.88rem;
  max-width: 32ch;
  line-height: 1.55;
}
.cb-setup-note {
  margin-top: 0.4rem;
  font-size: 0.8rem !important;
  opacity: 0.55 !important;
}
.cb-setup-note a {
  color: #b8432c;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.cb-setup-note a:hover { text-decoration-thickness: 2px; }

/* key form */
.cb-key-form {
  display: flex;
  width: 100%;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.cb-key-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.82rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 1.5px solid rgba(21, 19, 15, 0.18);
  background: rgba(255, 255, 255, 0.6);
  color: #15130f;
  outline: none;
  transition: border-color 0.3s;
}
.cb-key-form input:focus { border-color: #1f3d2e; }
.cb-key-form input::placeholder { color: rgba(21, 19, 15, 0.4); }
.cb-key-form button {
  padding: 0.7rem 1.2rem;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #1f3d2e 0%, #2d5a43 100%);
  color: #f8f2e4;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
}
.cb-key-form button:hover { opacity: 0.85; transform: translateY(-1px); }

/* ---------- messages area ---------- */
.cb-messages {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.2rem 1rem 0.6rem;
  min-height: 200px;
}

/* single message */
.cb-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.35s, transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.cb-msg-in { opacity: 1; transform: none; }
.cb-msg-user { align-self: flex-end; align-items: flex-end; }
.cb-msg-ai { align-self: flex-start; align-items: flex-start; }

.cb-bubble {
  padding: 0.7rem 1rem;
  border-radius: 18px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
}
.cb-msg-user .cb-bubble {
  background: linear-gradient(135deg, #1f3d2e 0%, #2d5a43 100%);
  color: #f8f2e4;
  border-bottom-right-radius: 6px;
}
.cb-msg-ai .cb-bubble {
  background: #e8dcc4;
  color: #15130f;
  border-bottom-left-radius: 6px;
}
.cb-msg-error .cb-bubble {
  background: #fce8e4;
  color: #b8432c;
}

/* bubble content styling */
.cb-bubble strong { font-weight: 600; }
.cb-bubble em { font-style: italic; }
.cb-bubble code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8em;
  background: rgba(21, 19, 15, 0.08);
  padding: 0.15em 0.35em;
  border-radius: 5px;
}
.cb-bubble pre {
  margin: 0.5rem 0;
  padding: 0.7rem;
  background: #15130f;
  color: #f8f2e4;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.78rem;
}
.cb-bubble pre code { background: none; padding: 0; color: inherit; }
.cb-bubble a {
  color: #b8432c;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.cb-bubble a:hover { text-decoration-thickness: 2px; }

.cb-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.62rem;
  letter-spacing: 0.03em;
  opacity: 0.45;
  margin: 0.2rem 0.3rem 0;
}

/* ---------- typing indicator ---------- */
.cb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.85rem 1.1rem;
  min-height: 0;
}
.cb-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #15130f;
  opacity: 0.35;
  animation: cb-dot-bounce 1.4s ease-in-out infinite;
}
.cb-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.cb-typing-dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes cb-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-5px); opacity: 0.9; }
}

/* ---------- footer ---------- */
.cb-footer {
  flex-shrink: 0;
  padding: 0.5rem 0.8rem 0.8rem;
  background: #f4eddf;
  border-top: 1px solid rgba(21, 19, 15, 0.08);
}

/* suggestions */
.cb-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}
.cb-sug {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  padding: 0.4rem 0.7rem;
  border-radius: 99px;
  border: 1.5px solid rgba(21, 19, 15, 0.18);
  background: rgba(255, 255, 255, 0.5);
  color: #15130f;
  cursor: pointer;
  transition: background 0.3s, border-color 0.3s, transform 0.2s;
  white-space: nowrap;
}
.cb-sug:hover {
  background: #1f3d2e;
  color: #f8f2e4;
  border-color: #1f3d2e;
  transform: translateY(-1px);
}

/* input row */
.cb-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.cb-input-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.88rem;
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  border: 1.5px solid rgba(21, 19, 15, 0.15);
  background: rgba(255, 255, 255, 0.6);
  color: #15130f;
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.cb-input-row input:focus {
  border-color: #1f3d2e;
  box-shadow: 0 0 0 3px rgba(31, 61, 46, 0.1);
}
.cb-input-row input::placeholder { color: rgba(21, 19, 15, 0.4); }

.cb-input-row button[type="submit"] {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #1f3d2e 0%, #2d5a43 100%);
  color: #f8f2e4;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: opacity 0.3s, transform 0.3s;
}
.cb-input-row button[type="submit"]:hover:not(:disabled) {
  transform: scale(1.08);
}
.cb-input-row button[type="submit"]:disabled {
  opacity: 0.4;
  cursor: default;
}
.cb-input-row button svg { width: 18px; height: 18px; }

/* ---------- responsive ---------- */
@media (max-width: 480px) {
  #chatbot {
    bottom: 1rem;
    right: 1rem;
  }
  .cb-window {
    width: calc(100vw - 2rem);
    right: 0;
    bottom: calc(100% + 10px);
    max-height: calc(100dvh - 100px);
    border-radius: 20px;
  }
  .cb-fab {
    width: 54px;
    height: 54px;
  }
  .cb-fab-icon {
    width: 22px;
    height: 22px;
  }
}

/* ---------- respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .cb-window,
  .cb-msg,
  .cb-fab,
  .cb-fab-icon {
    transition-duration: 0.01ms !important;
  }
  .cb-fab-pulse,
  .cb-dot,
  .cb-typing-dot {
    animation: none !important;
  }
}
