/* ============================================================
   RESCUER EDUSKILLS — CHATBOT WIDGET
   Pure CSS + JS. No external libraries.
   ============================================================ */

/* ── Floating Trigger Button ─────────────────────────────────── */
#re-chat-trigger {
  position: fixed;
  bottom: 28px;
  right: 24px;
  z-index: 9998;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6C3FC5 0%, #4299E1 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 28px rgba(108,63,197,.45), 0 2px 8px rgba(0,0,0,.15);
  transition: transform 0.3s cubic-bezier(.4,0,.2,1), box-shadow 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  /* iOS safe area */
  bottom: max(28px, calc(28px + env(safe-area-inset-bottom, 0px)));
  right: max(24px, calc(24px + env(safe-area-inset-right, 0px)));
}
#re-chat-trigger:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 12px 36px rgba(108,63,197,.55);
}
#re-chat-trigger:active { transform: scale(0.96); }

/* Icon inside trigger */
#re-chat-trigger .ct-icon {
  width: 28px; height: 28px;
  fill: #fff;
  transition: transform 0.35s cubic-bezier(.4,0,.2,1), opacity 0.25s;
}
#re-chat-trigger .ct-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}
.re-chat-open #re-chat-trigger .ct-chat  { opacity: 0; transform: rotate(90deg) scale(0.6); }
.re-chat-open #re-chat-trigger .ct-close { opacity: 1; transform: rotate(0deg) scale(1); }

/* Pulse ring */
#re-chat-trigger::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2.5px solid rgba(108,63,197,.45);
  animation: re-pulse 2.4s ease-out infinite;
}
@keyframes re-pulse {
  0%   { transform: scale(1); opacity: .7; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { opacity: 0; }
}
.re-chat-open #re-chat-trigger::before { animation: none; opacity: 0; }

/* Notification badge */
#re-chat-badge {
  position: absolute;
  top: -4px; right: -4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #E53E3E;
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.re-chat-open #re-chat-badge { transform: scale(0); opacity: 0; }

/* ── Chat Window ─────────────────────────────────────────────── */
#re-chat-window {
  position: fixed;
  bottom: max(100px, calc(100px + env(safe-area-inset-bottom, 0px)));
  right: max(24px, calc(24px + env(safe-area-inset-right, 0px)));
  z-index: 9999;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 130px));
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 24px 72px rgba(26,20,51,.22), 0 4px 16px rgba(108,63,197,.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  /* Closed state */
  transform: scale(0.85) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(.34,1.56,.64,1), opacity 0.28s ease;
}
.re-chat-open #re-chat-window {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ──────────────────────────────────────────────────── */
.re-chat-header {
  background: linear-gradient(135deg, #4B28A0 0%, #2B6CB0 55%, #319795 100%);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.re-chat-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  border: 2px solid rgba(255,255,255,.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  position: relative;
}
.re-chat-avatar::after {
  content: '';
  position: absolute;
  bottom: 1px; right: 1px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #48BB78;
  border: 2px solid #fff;
}

.re-chat-header-info { flex: 1; min-width: 0; }
.re-chat-header-info strong {
  display: block;
  color: #fff;
  font-size: .93rem;
  font-weight: 700;
  font-family: 'Outfit', sans-serif;
}
.re-chat-header-info span {
  font-size: .74rem;
  color: rgba(255,255,255,.75);
  font-family: 'Outfit', sans-serif;
}

.re-chat-header-actions { display: flex; gap: 6px; }
.re-chat-header-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.15);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.re-chat-header-btn:hover { background: rgba(255,255,255,.28); }

/* ── Messages Area ───────────────────────────────────────────── */
.re-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: #F7F6FF;
  -webkit-overflow-scrolling: touch;
}
.re-chat-messages::-webkit-scrollbar { width: 4px; }
.re-chat-messages::-webkit-scrollbar-track { background: transparent; }
.re-chat-messages::-webkit-scrollbar-thumb { background: rgba(108,63,197,.25); border-radius: 10px; }

/* ── Message Bubbles ─────────────────────────────────────────── */
.re-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 88%;
  animation: re-msg-in 0.3s cubic-bezier(.4,0,.2,1) both;
}
@keyframes re-msg-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Bot message — left */
.re-msg.bot { align-self: flex-start; flex-direction: row; }
.re-msg.bot .re-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg,#6C3FC5,#4299E1);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; flex-shrink: 0;
}
.re-msg.bot .re-msg-bubble {
  background: #fff;
  color: #2D2850;
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 2px 8px rgba(108,63,197,.10);
  border: 1px solid rgba(108,63,197,.10);
}

/* User message — right */
.re-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.re-msg.user .re-msg-bubble {
  background: linear-gradient(135deg,#6C3FC5,#4299E1);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 4px 14px rgba(108,63,197,.28);
}

.re-msg-bubble {
  padding: 10px 14px;
  font-family: 'Outfit', sans-serif;
  font-size: .875rem;
  line-height: 1.55;
  word-break: break-word;
}
.re-msg-bubble a {
  color: inherit;
  text-decoration: underline;
  opacity: .85;
}
.re-msg-bubble strong { font-weight: 700; }

/* Timestamp */
.re-msg-time {
  font-size: .65rem;
  color: rgba(90,84,117,.55);
  margin-top: 3px;
  padding: 0 4px;
  font-family: 'Outfit', sans-serif;
}
.re-msg.user .re-msg-time { text-align: right; align-self: flex-end; }

/* ── Typing Indicator ────────────────────────────────────────── */
.re-typing {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
  animation: re-msg-in 0.3s ease both;
}
.re-typing .re-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg,#6C3FC5,#4299E1);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; flex-shrink: 0;
}
.re-typing-dots {
  background: #fff;
  border: 1px solid rgba(108,63,197,.10);
  border-radius: 18px 18px 18px 4px;
  padding: 12px 16px;
  display: flex; gap: 5px; align-items: center;
  box-shadow: 0 2px 8px rgba(108,63,197,.10);
}
.re-typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg,#6C3FC5,#4299E1);
  animation: re-dot 1.3s ease-in-out infinite;
}
.re-typing-dots span:nth-child(2) { animation-delay: .18s; }
.re-typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes re-dot {
  0%, 80%, 100% { transform: scale(1); opacity: .5; }
  40%            { transform: scale(1.3); opacity: 1; }
}

/* ── Quick Reply Chips ───────────────────────────────────────── */
.re-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 6px 14px 10px;
  background: #F7F6FF;
  border-top: 1px solid rgba(108,63,197,.08);
  flex-shrink: 0;
}
.re-chip {
  padding: 7px 13px;
  border-radius: 100px;
  font-size: .79rem;
  font-weight: 600;
  color: #6C3FC5;
  background: rgba(108,63,197,.08);
  border: 1.5px solid rgba(108,63,197,.22);
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Outfit', sans-serif;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.re-chip:hover  { background: #6C3FC5; color: #fff; border-color: #6C3FC5; }
.re-chip:active { transform: scale(0.95); }

/* ── Input Area ──────────────────────────────────────────────── */
.re-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(108,63,197,.10);
  background: #fff;
  flex-shrink: 0;
  /* iOS safe area bottom */
  padding-bottom: max(10px, calc(10px + env(safe-area-inset-bottom, 0px)));
}

#re-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid rgba(108,63,197,.18);
  border-radius: 100px;
  font-size: .875rem;
  font-family: 'Outfit', sans-serif;
  color: #2D2850;
  background: #F7F6FF;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 42px;
}
#re-chat-input:focus {
  border-color: #6C3FC5;
  box-shadow: 0 0 0 3px rgba(108,63,197,.10);
  background: #fff;
}
#re-chat-input::placeholder { color: rgba(90,84,117,.45); }

#re-chat-send {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg,#6C3FC5,#4299E1);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 14px rgba(108,63,197,.35);
  -webkit-tap-highlight-color: transparent;
}
#re-chat-send:hover  { transform: scale(1.08); box-shadow: 0 6px 18px rgba(108,63,197,.45); }
#re-chat-send:active { transform: scale(0.94); }
#re-chat-send svg    { fill: #fff; width: 18px; height: 18px; }
#re-chat-send:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* ── Date separator ─────────────────────────────────────────── */
.re-date-sep {
  display: flex; align-items: center; gap: 8px;
  font-size: .70rem; color: rgba(90,84,117,.55);
  font-family: 'Outfit', sans-serif;
  margin: 4px 0;
}
.re-date-sep::before, .re-date-sep::after {
  content: ''; flex: 1; height: 1px;
  background: rgba(108,63,197,.12);
}

/* ── Mobile full-screen chat on tiny screens ─────────────────── */
@media (max-width: 430px) {
  #re-chat-window {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100dvh;
    border-radius: 0;
    transform-origin: bottom center;
  }
  .re-chat-header { padding-top: calc(16px + env(safe-area-inset-top, 0px)); }
  .re-chat-input-row { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  #re-chat-trigger { bottom: max(20px, env(safe-area-inset-bottom, 20px)); right: 20px; }
}

/* ── Animations ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #re-chat-trigger::before { animation: none; }
  .re-typing-dots span { animation: none; opacity: 1; }
}
