/* ==========================================================================
   Content Reader — AI Support Chat widget
   ========================================================================== */

.cr-chat {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 90;
  font-family: var(--cr-font-sans);
}

/* ----- Launcher button --------------------------------------------- */
.cr-chat__launcher {
  position: relative;
  width: 60px; height: 60px;
  border: 0; border-radius: 50%;
  background: var(--cr-grad);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(79, 70, 229, 0.4);
  transition: transform 0.3s var(--cr-ease-bounce), box-shadow 0.3s var(--cr-ease);
}
.cr-chat__launcher:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 12px 28px rgba(79, 70, 229, 0.5);
}
.cr-chat__launcher-icon,
.cr-chat__launcher-close {
  grid-area: 1 / 1;
  display: inline-grid; place-items: center;
  transition: opacity 0.25s var(--cr-ease), transform 0.25s var(--cr-ease);
}
.cr-chat__launcher-close { opacity: 0; transform: scale(0.6); }
.cr-chat.is-open .cr-chat__launcher-icon { opacity: 0; transform: scale(0.6); }
.cr-chat.is-open .cr-chat__launcher-close { opacity: 1; transform: scale(1); }

.cr-chat__launcher-dot {
  position: absolute; top: 4px; right: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #06B6D4; border: 2px solid #fff;
  box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.5);
  animation: pulse 2.2s var(--cr-ease) infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.5); }
  70%  { box-shadow: 0 0 0 14px rgba(6, 182, 212, 0); }
  100% { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0); }
}
.cr-chat.is-open .cr-chat__launcher-dot { display: none; }

/* ----- Chat panel -------------------------------------------------- */
.cr-chat__panel {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 130px);
  background: var(--cr-bg-card);
  border: 1px solid var(--cr-border);
  border-radius: var(--cr-radius-lg);
  box-shadow: var(--cr-shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.25s var(--cr-ease), transform 0.25s var(--cr-ease-bounce);
}
.cr-chat.is-open .cr-chat__panel { opacity: 1; transform: translateY(0) scale(1); }
.cr-chat__panel[hidden] { display: none; }

/* ----- Panel header ------------------------------------------------ */
.cr-chat__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--cr-grad);
  color: #fff;
}
.cr-chat__head-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cr-chat__avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  flex-shrink: 0;
}
.cr-chat__avatar svg { display: block; }
.cr-chat__title { font-family: var(--cr-font-display); font-size: 15px; font-weight: 700; line-height: 1.1; }
.cr-chat__status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: rgba(255, 255, 255, 0.85); }
.cr-chat__status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #34D399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.3);
}
.cr-chat__close {
  background: transparent; border: 0; color: rgba(255, 255, 255, 0.85);
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  transition: background 0.2s var(--cr-ease);
}
.cr-chat__close:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }

/* ----- Panel body (messages) -------------------------------------- */
.cr-chat__body {
  flex: 1; min-height: 0;
  padding: 16px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  background:
    radial-gradient(circle at top right, rgba(79, 70, 229, 0.04), transparent 60%),
    var(--cr-bg-card);
  scroll-behavior: smooth;
}
.cr-chat__body::-webkit-scrollbar { width: 6px; }
.cr-chat__body::-webkit-scrollbar-track { background: transparent; }
.cr-chat__body::-webkit-scrollbar-thumb { background: var(--cr-border); border-radius: 3px; }
.cr-chat__body::-webkit-scrollbar-thumb:hover { background: var(--cr-text-faint); }

.cr-chat__msg {
  display: flex; gap: 8px;
  max-width: 85%;
  align-self: flex-start;
}
.cr-chat__msg--user { align-self: flex-end; flex-direction: row-reverse; }
.cr-chat__msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--cr-grad); color: #fff;
  display: grid; place-items: center;
  font-family: var(--cr-font-display); font-weight: 700; font-size: 11px;
  flex-shrink: 0;
}
.cr-chat__msg--user .cr-chat__msg-avatar {
  background: var(--cr-bg-soft); color: var(--cr-text-soft);
  border: 1px solid var(--cr-border);
}
.cr-chat__msg-bubble {
  padding: 10px 14px;
  border-radius: var(--cr-radius) var(--cr-radius) var(--cr-radius) 4px;
  background: var(--cr-bg-soft);
  border: 1px solid var(--cr-border);
  font-size: 14px; line-height: 1.5;
  color: var(--cr-text);
  word-wrap: break-word; word-break: break-word;
}
.cr-chat__msg--user .cr-chat__msg-bubble {
  background: var(--cr-grad); color: #fff;
  border-color: transparent;
  border-radius: var(--cr-radius) var(--cr-radius) 4px var(--cr-radius);
}
.cr-chat__msg-time {
  font-size: 11px; color: var(--cr-text-faint);
  margin-top: 4px;
}
.cr-chat__msg-bubble strong { font-weight: 700; }
.cr-chat__msg-bubble em { font-style: italic; }
.cr-chat__msg-bubble br + br { margin-top: 6px; }
.cr-chat__msg-bubble a { color: var(--cr-primary); text-decoration: underline; }

/* Suggested question chips */
.cr-chat__suggestions {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 4px;
}
.cr-chat__suggestion {
  display: inline-block;
  padding: 8px 12px;
  background: var(--cr-bg-card);
  border: 1px solid var(--cr-border);
  border-radius: var(--cr-radius-pill);
  font-size: 13px;
  color: var(--cr-text);
  cursor: pointer;
  transition: all 0.2s var(--cr-ease);
  text-align: left;
}
.cr-chat__suggestion:hover {
  background: var(--cr-grad-soft);
  border-color: var(--cr-primary);
  color: var(--cr-primary);
}

/* Typing indicator */
.cr-chat__typing {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 12px 16px;
  background: var(--cr-bg-soft);
  border: 1px solid var(--cr-border);
  border-radius: var(--cr-radius) var(--cr-radius) var(--cr-radius) 4px;
  align-self: flex-start;
}
.cr-chat__typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cr-text-faint);
  animation: typing 1.4s var(--cr-ease) infinite;
}
.cr-chat__typing span:nth-child(2) { animation-delay: 0.2s; }
.cr-chat__typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ----- Lead form (contact collection) ----------------------------- */
.cr-chat__lead {
  padding: 16px;
  border-top: 1px solid var(--cr-border-soft);
  display: flex; flex-direction: column; gap: 10px;
}
.cr-chat__lead-intro {
  font-size: 13px; color: var(--cr-text-soft);
  margin-bottom: 4px;
}
.cr-chat__lead-fields {
  display: flex; flex-direction: column; gap: 8px;
}
.cr-chat__lead-note {
  font-size: 11px; color: var(--cr-text-faint);
  text-align: center; margin: 4px 0 0;
}

/* ----- Composer (message input) ----------------------------------- */
.cr-chat__composer {
  display: flex; align-items: end; gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--cr-border-soft);
  background: var(--cr-bg-card);
}
.cr-chat__input {
  flex: 1;
  padding: 10px 14px;
  background: var(--cr-bg);
  border: 1px solid var(--cr-border);
  border-radius: var(--cr-radius-sm);
  font-family: inherit; font-size: 14px; color: var(--cr-text);
  transition: all 0.2s var(--cr-ease);
  width: 100%;
}
.cr-chat__input:focus {
  outline: none; border-color: var(--cr-primary);
  box-shadow: var(--cr-shadow-glow);
}
.cr-chat__input--area {
  resize: none; max-height: 100px; min-height: 40px;
  line-height: 1.4;
}
.cr-chat__send {
  width: 40px; height: 40px;
  background: var(--cr-grad); color: #fff;
  border: 0; border-radius: var(--cr-radius-sm);
  display: grid; place-items: center;
  cursor: pointer; flex-shrink: 0;
  transition: transform 0.2s var(--cr-ease);
}
.cr-chat__send:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4); }
.cr-chat__send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ----- Error / success banners ----------------------------------- */
.cr-chat__alert {
  padding: 10px 14px; margin: 0 16px 8px;
  border-radius: var(--cr-radius-sm);
  font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.cr-chat__alert--error { background: rgba(239, 68, 68, 0.1); color: #DC2626; }
.cr-chat__alert--success { background: rgba(16, 185, 129, 0.1); color: #10B981; }

/* ----- Social auth divider & button ------------------------------- */
.social-auth {
  margin-top: 20px;
}
.social-auth__divider {
  display: flex; align-items: center;
  margin: 12px 0 16px;
  color: var(--cr-text-faint);
  font-size: 13px;
}
.social-auth__divider::before,
.social-auth__divider::after {
  content: ''; flex: 1; height: 1px; background: var(--cr-border);
}
.social-auth__divider span { padding: 0 14px; }
.social-auth__btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%;
  padding: 12px 20px;
  background: var(--cr-bg-card);
  border: 1px solid var(--cr-border);
  border-radius: var(--cr-radius-sm);
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--cr-text);
  cursor: pointer;
  transition: all 0.2s var(--cr-ease);
}
.social-auth__btn:hover {
  border-color: var(--cr-primary);
  background: var(--cr-grad-soft);
  transform: translateY(-1px);
  box-shadow: var(--cr-shadow-sm);
}
.social-auth__btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }
.social-auth__icon { display: inline-grid; place-items: center; flex-shrink: 0; }
.social-auth__icon svg { display: block; }
.social-auth__note {
  text-align: center;
  font-size: 11px;
  color: var(--cr-text-faint);
  margin: 10px 0 0;
}

/* ----- Responsive ------------------------------------------------- */
@media (max-width: 480px) {
  .cr-chat { bottom: 16px; right: 16px; }
  .cr-chat__launcher { width: 56px; height: 56px; }
  .cr-chat__panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
    bottom: 76px;
    right: 0;
  }
}

/* ----- Reduced motion ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .cr-chat__launcher-dot,
  .cr-chat__typing span { animation: none; }
}
