/* ── AFL Chatbot ─────────────────────────────────────────────── */

/* Bubble — pill with portrait */
#afl-chat-bubble {
  position: fixed;
  bottom: 28px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 0;
  background: #E8614A;
  border: none;
  border-radius: 40px;
  box-shadow: 0 4px 22px rgba(232,97,74,0.45);
  cursor: pointer;
  z-index: 100000;
  padding: 0;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
}
#afl-chat-bubble:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(232,97,74,0.55); }
#afl-chat-bubble.afl-hidden { opacity: 0; pointer-events: none; transform: translateY(12px); }
.afl-bubble-img {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}
.afl-bubble-label {
  color: #fff;
  font-family: 'Lato', system-ui, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
  padding: 0 14px 0 10px;
  white-space: nowrap;
}

/* Window */
#afl-chat-window {
  position: fixed;
  bottom: 100px;
  right: 20px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 99998;
}
#afl-chat-window.afl-open {
  display: flex;
  animation: afl-slide-up 0.22s ease forwards;
}
@keyframes afl-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
#afl-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #E8614A;
  color: #fff;
  flex-shrink: 0;
}
.afl-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.afl-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.5);
  flex-shrink: 0;
}
#afl-chat-header strong { display: block; font-size: 0.9rem; }
.afl-chat-status { font-size: 0.7rem; opacity: 0.85; }
#afl-chat-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
  line-height: 1;
}
#afl-chat-close:hover { background: rgba(255,255,255,0.2); }

/* Messages */
#afl-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
#afl-chat-messages::-webkit-scrollbar { width: 4px; }
#afl-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.afl-msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-break: break-word;
}
.afl-msg.afl-bot {
  background: #F9EDE8;
  color: #2C2C2C;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.afl-msg.afl-user {
  background: #E8614A;
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.afl-msg.afl-system {
  background: #fff8e1;
  color: #7a5c00;
  border: 1px solid #f0d980;
  font-size: 0.8rem;
  align-self: flex-start;
}
.afl-msg.afl-error { background: #fde8e8; color: #c0392b; }
.afl-msg a { color: #E8614A; word-break: break-all; }
.afl-msg.afl-user a { color: #ffe0d8; }
.afl-msg p { margin: 0 0 0.4rem; }
.afl-msg p:last-child { margin: 0; }

/* Quick buttons */
.afl-quick-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.afl-quick-btn {
  background: #fff;
  border: 1.5px solid #E8614A;
  color: #E8614A;
  border-radius: 20px;
  padding: 7px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.afl-quick-btn:hover { background: #E8614A; color: #fff; }

/* Typing indicator */
.afl-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 14px;
}
.afl-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #E8614A;
  opacity: 0.4;
  animation: afl-bounce 1.2s infinite;
}
.afl-typing span:nth-child(2) { animation-delay: 0.2s; }
.afl-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes afl-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* Input */
#afl-chat-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #f0e8e4;
  background: #fff;
  flex-shrink: 0;
}
#afl-chat-input {
  flex: 1;
  border: 1.5px solid #e0d4cf;
  border-radius: 24px;
  padding: 9px 14px;
  font-size: 0.88rem;
  color: #2C2C2C;
  outline: none;
  transition: border-color 0.2s;
  background: #faf7f5;
}
#afl-chat-input:focus { border-color: #E8614A; }
#afl-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #E8614A;
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}
#afl-chat-send:hover { background: #b5532f; transform: scale(1.07); }
#afl-chat-send:disabled { background: #ddd; cursor: default; transform: none; }

/* Mobile */
@media (max-width: 480px) {
  #afl-chat-window {
    bottom: 0; right: 0;
    width: 100vw; max-width: 100vw;
    height: 90vh; max-height: 90vh;
    border-radius: 18px 18px 0 0;
  }
  #afl-chat-bubble { bottom: 18px; right: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  #afl-chat-bubble, #afl-chat-window, .afl-quick-btn, #afl-chat-send { transition: none; }
  .afl-typing span { animation: none; opacity: 0.6; }
}
