/* ============================================================
   BOOKSBYAMA — livechat.css
   Floating live-chat button + slide-in chat panel.
   Depends on: variables.css (loaded before this file)
============================================================ */

/* ── FLOATING TRIGGER BUTTON ─────────────────────────────── */
.lc-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: calc(var(--z-modal) + 10);   /* always on top */

  width: 58px;
  height: 58px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  outline: none;

  background: var(--color-purple);
  color: #fff;
  box-shadow: 0 4px 24px rgba(99, 93, 169, 0.45);

  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform var(--duration-base) var(--ease-bounce),
    background var(--duration-base) var(--ease-default),
    box-shadow var(--duration-base) var(--ease-default);
}

.lc-fab:hover,
.lc-fab:focus-visible {
  background: var(--color-purple-dark);
  transform: scale(1.08);
  box-shadow: 0 8px 32px rgba(99, 93, 169, 0.55);
}

.lc-fab:active {
  transform: scale(0.96);
}

/* Icon swap — chat icon shows by default, × shows when open */
.lc-fab__icon-chat,
.lc-fab__icon-close {
  position: absolute;
  transition:
    opacity var(--duration-base) var(--ease-default),
    transform var(--duration-base) var(--ease-bounce);
}

.lc-fab__icon-chat  { opacity: 1; transform: rotate(0deg) scale(1); }
.lc-fab__icon-close { opacity: 0; transform: rotate(-90deg) scale(0.6); }

.lc-fab--open .lc-fab__icon-chat  { opacity: 0; transform: rotate(90deg) scale(0.6); }
.lc-fab--open .lc-fab__icon-close { opacity: 1; transform: rotate(0deg) scale(1); }

/* Pulse ring (idle, disappears once panel opens) */
.lc-fab::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: var(--radius-full);
  border: 2px solid rgba(99, 93, 169, 0.45);
  animation: lc-pulse 2.4s var(--ease-out) infinite;
}

.lc-fab--open::before {
  animation: none;
  opacity: 0;
}

@keyframes lc-pulse {
  0%   { transform: scale(1);   opacity: 0.9; }
  70%  { transform: scale(1.5); opacity: 0;   }
  100% { transform: scale(1.5); opacity: 0;   }
}

/* Unread badge */
.lc-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--color-coral);
  color: #fff;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);

  transform: scale(0);
  transition: transform var(--duration-base) var(--ease-bounce);
}

.lc-badge--visible {
  transform: scale(1);
}

/* ── CHAT PANEL ──────────────────────────────────────────── */
.lc-panel {
  position: fixed;
  bottom: 100px;       /* sits just above the FAB */
  right: 28px;
  z-index: calc(var(--z-modal) + 9);

  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 130px);

  background: var(--color-surface);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  border: 1px solid var(--color-border);
  overflow: hidden;

  display: flex;
  flex-direction: column;

  /* Hidden state */
  opacity: 0;
  transform: translateY(24px) scale(0.96);
  pointer-events: none;
  transition:
    opacity var(--duration-slow) var(--ease-out),
    transform var(--duration-slow) var(--ease-bounce);
  transform-origin: bottom right;
}

.lc-panel--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── PANEL HEADER ────────────────────────────────────────── */
.lc-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--color-purple);
  color: #fff;
}

.lc-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.lc-header__info {
  flex: 1;
  min-width: 0;
}

.lc-header__name {
  font-family: var(--font-head);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lc-header__status {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  opacity: 0.75;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.lc-header__status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--color-green);
  box-shadow: 0 0 0 2px rgba(81,187,121,.35);
  flex-shrink: 0;
}

.lc-header__close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.75);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default);
  flex-shrink: 0;
}

.lc-header__close:hover,
.lc-header__close:focus-visible {
  color: #fff;
  background: rgba(255,255,255,.15);
  outline: none;
}

/* ── INTRO BANNER (shown before first message) ───────────── */
.lc-intro {
  flex-shrink: 0;
  padding: var(--space-4) var(--space-5);
  background: var(--color-purple-soft);
  border-bottom: 1px solid var(--color-border);
  text-align: center;
}

.lc-intro__title {
  font-family: var(--font-head);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 4px;
}

.lc-intro__sub {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  color: var(--color-muted);
  margin: 0;
  line-height: var(--leading-relaxed);
}

/* ── MESSAGE LIST ────────────────────────────────────────── */
.lc-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
}

/* Scrollbar */
.lc-messages::-webkit-scrollbar        { width: 4px; }
.lc-messages::-webkit-scrollbar-track  { background: transparent; }
.lc-messages::-webkit-scrollbar-thumb  { background: var(--color-border); border-radius: 2px; }

/* Date divider */
.lc-divider {
  text-align: center;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  color: var(--color-light);
  position: relative;
  margin: var(--space-2) 0;
}

.lc-divider::before,
.lc-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 40px);
  height: 1px;
  background: var(--color-border);
}

.lc-divider::before { left: 0; }
.lc-divider::after  { right: 0; }

/* Bubble row */
.lc-msg {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  max-width: 100%;
}

/* Admin (incoming) — left-aligned */
.lc-msg--admin {
  align-self: flex-start;
}

.lc-msg--admin .lc-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--color-purple-tint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.lc-msg--admin .lc-msg__bubble {
  background: var(--color-purple-soft);
  color: var(--color-text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-xs);
}

/* User (outgoing) — right-aligned */
.lc-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.lc-msg--user .lc-msg__bubble {
  background: var(--color-purple);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-xs) var(--radius-lg);
}

/* Bubble shared */
.lc-msg__bubble {
  max-width: 240px;
  padding: 9px 13px;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  word-break: break-word;
  box-shadow: var(--shadow-xs);
}

.lc-msg__time {
  font-family: var(--font-body);
  font-size: 10px;
  color: var(--color-light);
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 2px;
  white-space: nowrap;
}

.lc-msg--user .lc-msg__time {
  /* time on left side for user messages */
  order: 1;
}

/* Fade-in new messages */
.lc-msg {
  animation: lc-msg-in 0.22s var(--ease-out) both;
}

@keyframes lc-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* Typing indicator */
.lc-typing {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  align-self: flex-start;
}

.lc-typing__avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--color-purple-tint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.lc-typing__dots {
  background: var(--color-purple-soft);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-xs);
  padding: 10px 14px;
  display: flex;
  gap: 4px;
  align-items: center;
  box-shadow: var(--shadow-xs);
}

.lc-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--color-purple);
  opacity: 0.5;
  animation: lc-dot 1.2s var(--ease-default) infinite;
}

.lc-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.lc-typing__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes lc-dot {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1;   }
}

/* ── INPUT AREA ──────────────────────────────────────────── */
.lc-footer {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.lc-form {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

.lc-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface);
  line-height: var(--leading-normal);
  max-height: 100px;
  overflow-y: auto;
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
}

.lc-input::placeholder {
  color: var(--color-light);
}

.lc-input:focus {
  border-color: var(--color-purple);
  box-shadow: 0 0 0 3px rgba(99, 93, 169, 0.12);
}

.lc-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-purple);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease-default),
              transform var(--duration-fast) var(--ease-bounce);
}

.lc-send:hover,
.lc-send:focus-visible {
  background: var(--color-purple-dark);
  transform: scale(1.08);
  outline: none;
}

.lc-send:active {
  transform: scale(0.94);
}

.lc-send:disabled {
  background: var(--color-border);
  cursor: not-allowed;
  transform: none;
}

/* "Powered by" footer note */
.lc-powered {
  text-align: center;
  font-family: var(--font-body);
  font-size: 10px;
  color: var(--color-light);
  margin-top: var(--space-2);
}

.lc-powered a {
  color: var(--color-purple);
  text-decoration: none;
}

.lc-powered a:hover {
  text-decoration: underline;
}

/* ── CUSTOMER FORM / CLOSED STATE ─────────────────────────── */
.lc-intro__btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-top: 16px;
  background: var(--color-primary, #8b5cf6);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg, 10px);
  font-weight: 600;
  cursor: pointer;
}

.lc-intro__btn:hover {
  filter: brightness(1.05);
}

.lc-customer-form {
  display: none;
  padding: 12px 16px;
}

.lc-customer-form--active {
  display: block;
}

.lc-form__field {
  margin-bottom: 12px;
}

.lc-form__field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--color-text, #1f2937);
}

.lc-form__field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-lg, 10px);
  background: var(--color-surface, #fff);
  color: var(--color-text, #1f2937);
  font: inherit;
  outline: none;
}

.lc-form__field input:focus {
  border-color: var(--color-primary, #8b5cf6);
}

.lc-form__error {
  color: #dc2626;
  font-size: 12px;
  margin-top: 8px;
  min-height: 18px;
}

.lc-closed,
.lc-composer {
  display: none;
}

.lc-closed--active,
.lc-composer--active {
  display: block;
}

.lc-closed__title {
  font-weight: 600;
  margin-bottom: 8px;
  text-align: center;
  color: var(--color-text, #1f2937);
}

.lc-closed__subtitle {
  font-size: 13px;
  text-align: center;
  color: var(--color-muted, #6b7280);
  margin-bottom: 16px;
}

/* ── RESPONSIVE — small phones ───────────────────────────── */
@media (max-width: 480px) {
  .lc-fab {
    bottom: 20px;
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .lc-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    height: 92dvh;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    border-bottom: none;
  }
}

/* ── QUICK REPLIES / FAQ / ESCALATE (Phase 15C-7) ────────── */
.lc-quick-replies {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
  padding: 0 4px;
}

.lc-quick-reply,
.lc-escalate-btn {
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg, 10px);
  background: var(--color-surface, #fff);
  color: var(--color-text, #1f2937);
  font-family: var(--font-body);
  font-size: var(--text-sm, 14px);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default),
              border-color var(--duration-fast) var(--ease-default);
}

.lc-quick-reply:hover,
.lc-quick-reply:focus-visible,
.lc-escalate-btn:hover,
.lc-escalate-btn:focus-visible {
  background: var(--color-purple-soft, rgba(99,93,169,.08));
  border-color: var(--color-purple, #635DA9);
  outline: none;
}

.lc-escalate-btn {
  background: var(--color-purple, #635DA9);
  color: #fff;
  border-color: var(--color-purple, #635DA9);
  font-weight: 600;
  text-align: center;
  margin-top: 8px;
}

.lc-escalate-btn:hover,
.lc-escalate-btn:focus-visible {
  background: var(--color-purple-dark, #4E4890);
}

/* ── STATUS MESSAGES ─────────────────────────────────────── */
.lc-status {
  text-align: center;
  padding: 8px 12px;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--color-muted, #6b7280);
  margin: 6px 0;
}

/* ── ADMIN META ──────────────────────────────────────────── */
.lc-msg__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 240px;
}

.lc-msg__name {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-muted, #6b7280);
  margin-left: 2px;
}

/* ── REDUCED MOTION ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .lc-fab,
  .lc-panel,
  .lc-msg,
  .lc-typing__dot,
  .lc-fab__icon-chat,
  .lc-fab__icon-close {
    transition: none !important;
    animation: none !important;
  }
}
