/**
 * Bushari Chatbot — Styles
 *
 * Covers: sidebar panel, welcome card, listing sidebar, mobile panel,
 * message bubbles, buttons, lead form, email capture, consent card,
 * typing indicator, and the mobile trigger.
 *
 * Uses CSS custom property --bushari-primary (set by JS from plugin settings).
 */

/* ── CSS Variables (defaults) ─────────────────────────────────────── */

:root {
  --bushari-primary: #7C3AED;
  --bushari-header-bg: #000000;
  --bushari-header-text: #FFFFFF;
  --bushari-bg: #FFFFFF;
  --bushari-bot-bg: #F3F4F6;
  --bushari-text: #1F2937;
  --bushari-text-light: #6B7280;
  --bushari-border: #E5E7EB;
  --bushari-radius-panel: 12px;
  --bushari-radius-bubble: 18px;
  --bushari-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --bushari-font: inherit;
}

/* ── Chat Panel (shared across modes) ─────────────────────────────── */

.bushari-chat {
  display: flex;
  flex-direction: column;
  background: var(--bushari-bg);
  border-radius: var(--bushari-radius-panel);
  box-shadow: var(--bushari-shadow);
  border: 1px solid var(--bushari-border);
  font-family: var(--bushari-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--bushari-text);
  overflow: hidden;
  max-width: 100%;
}

.bushari-chat--hidden {
  display: none !important;
}

/* Sidebar mode: fixed height in sidebar widget area */
.bushari-chat--sidebar,
.bushari-chat--listing {
  height: 520px;
  min-height: 400px;
}

/* Welcome mode: starts compact, expands */
.bushari-chat--welcome {
  height: 450px;
}

/* ── Header ───────────────────────────────────────────────────────── */

.bushari-chat__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bushari-header-bg);
  color: var(--bushari-header-text);
  flex-shrink: 0;
}

.bushari-chat__header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
}

.bushari-chat__header-title {
  font-weight: 600;
  font-size: 14px;
}

.bushari-chat__header-status {
  font-size: 11px;
  opacity: 0.7;
  display: flex;
  align-items: center;
  gap: 4px;
}

.bushari-chat__header-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34D399;
}

.bushari-chat__close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--bushari-header-text);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.bushari-chat__close:hover {
  opacity: 1;
}

/* ── Messages Area ────────────────────────────────────────────────── */

.bushari-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.bushari-chat__messages::-webkit-scrollbar {
  width: 4px;
}
.bushari-chat__messages::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 2px;
}

/* ── Message Bubbles ──────────────────────────────────────────────── */

.bushari-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: bushariMsgIn 0.2s ease-out;
}

.bushari-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

.bushari-msg--bot {
  align-self: flex-start;
  align-items: flex-start;
}

.bushari-msg__bubble {
  padding: 10px 14px;
  border-radius: var(--bushari-radius-bubble);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.bushari-msg--user .bushari-msg__bubble {
  background: var(--bushari-primary);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}

.bushari-msg--bot .bushari-msg__bubble {
  background: var(--bushari-bot-bg);
  color: var(--bushari-text);
  border-bottom-left-radius: 4px;
}

.bushari-msg__bubble a {
  color: var(--bushari-primary);
  text-decoration: underline;
}

.bushari-msg--user .bushari-msg__bubble a {
  color: #E0D4FF;
}

.bushari-msg__time {
  font-size: 10px;
  color: var(--bushari-text-light);
  margin-top: 2px;
  padding: 0 4px;
}

@keyframes bushariMsgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Quick-Reply Buttons ──────────────────────────────────────────── */

.bushari-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  padding: 0 2px;
}

.bushari-btn {
  background: var(--bushari-bg);
  color: var(--bushari-primary);
  border: 1.5px solid var(--bushari-primary);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 13px;
  font-family: var(--bushari-font);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.3s;
  line-height: 1.3;
  white-space: nowrap;
}

.bushari-btn:hover:not(:disabled) {
  background: var(--bushari-primary);
  color: #FFFFFF;
}

.bushari-btn--selected {
  background: var(--bushari-primary) !important;
  color: #FFFFFF !important;
  border-color: var(--bushari-primary) !important;
}

.bushari-btn--faded {
  opacity: 0.35;
  pointer-events: none;
}

/* Mobile: stack buttons full width */
@media (max-width: 767px) {
  .bushari-buttons {
    flex-direction: column;
  }
  .bushari-btn {
    white-space: normal;
    text-align: center;
  }
}

/* ── Cards (Lead Form, Email Capture, Consent) ────────────────────── */

.bushari-card {
  margin-top: 8px;
  border: 1px solid var(--bushari-border);
  border-radius: var(--bushari-radius-panel);
  padding: 16px;
  background: var(--bushari-bg);
  animation: bushariMsgIn 0.2s ease-out;
}

.bushari-card__submit {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: var(--bushari-primary);
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--bushari-font);
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 12px;
}

.bushari-card__submit:hover:not(:disabled) {
  opacity: 0.9;
}

.bushari-card__submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.bushari-card__error {
  color: #EF4444;
  font-size: 12px;
  margin-top: 6px;
}

.bushari-card__confirmed {
  text-align: center;
  padding: 12px;
  color: #059669;
  font-weight: 600;
  font-size: 14px;
}

.bushari-card__confirmed::before {
  content: '\2714  ';
}

/* ── Lead Form ────────────────────────────────────────────────────── */

.bushari-lead-form__field {
  margin-bottom: 10px;
}

.bushari-lead-form__field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--bushari-text-light);
  margin-bottom: 3px;
}

.bushari-lead-form__field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--bushari-border);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--bushari-font);
  color: var(--bushari-text);
  background: var(--bushari-bg);
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.bushari-lead-form__field input:focus {
  outline: none;
  border-color: var(--bushari-primary);
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.15);
}

/* ── Email Capture ────────────────────────────────────────────────── */

.bushari-email-form__row {
  display: flex;
  gap: 8px;
}

.bushari-email-form__row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--bushari-border);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--bushari-font);
  color: var(--bushari-text);
  min-width: 0;
  box-sizing: border-box;
}

.bushari-email-form__row input:focus {
  outline: none;
  border-color: var(--bushari-primary);
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.15);
}

.bushari-email-form__row .bushari-card__submit {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
  padding: 8px 16px;
  flex-shrink: 0;
}

/* ── Lead Form Consent Text ───────────────────────────────────────── */

.bushari-lead-form__consent-text {
  font-size: 11px;
  color: #999;
  text-align: center;
  margin: 8px 0 0;
  line-height: 1.4;
}

/* ── Input Area ───────────────────────────────────────────────────── */

.bushari-chat__input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--bushari-border);
  flex-shrink: 0;
  background: var(--bushari-bg);
}

.bushari-chat__form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.bushari-chat__input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--bushari-border);
  border-radius: 20px;
  font-size: 14px;
  font-family: var(--bushari-font);
  color: var(--bushari-text);
  background: var(--bushari-bg);
  min-width: 0;
}

.bushari-chat__input:focus {
  outline: none;
  border-color: var(--bushari-primary);
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.1);
}

.bushari-chat__send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bushari-primary);
  color: #FFFFFF;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.bushari-chat__send:hover {
  opacity: 0.85;
}

.bushari-chat__send svg {
  display: block;
}

/* ── Typing Indicator ─────────────────────────────────────────────── */

.bushari-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bushari-bot-bg);
  border-radius: var(--bushari-radius-bubble);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  animation: bushariMsgIn 0.2s ease-out;
}

.bushari-typing span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9CA3AF;
  animation: bushariDot 1.4s infinite;
}

.bushari-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.bushari-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bushariDot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ── Welcome Card ─────────────────────────────────────────────────── */

.bushari-chat-welcome {
  border-radius: var(--bushari-radius-panel);
  box-shadow: var(--bushari-shadow);
  border: 1px solid var(--bushari-border);
  overflow: hidden;
  background: var(--bushari-bg);
}

.bushari-chat-welcome__inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
}

.bushari-chat-welcome__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bushari-primary);
  color: #FFFFFF;
  flex-shrink: 0;
}

.bushari-chat-welcome__text {
  flex: 1;
  min-width: 0;
}

.bushari-chat-welcome__title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 2px;
  color: var(--bushari-text);
}

.bushari-chat-welcome__subtitle {
  font-size: 13px;
  color: var(--bushari-text-light);
  margin: 0;
}

.bushari-chat-welcome__btn {
  padding: 10px 20px;
  background: var(--bushari-primary);
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--bushari-font);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.bushari-chat-welcome__btn:hover {
  opacity: 0.9;
}

/* Expanded state: hide the card header, show the chat */
.bushari-chat-welcome--expanded .bushari-chat-welcome__inner {
  display: none;
}

.bushari-chat-welcome--expanded .bushari-chat--welcome {
  display: flex !important;
}

/* ── Mobile Header Trigger ────────────────────────────────────────── */

.bushari-mobile-trigger {
  display: none; /* Hidden on desktop */
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99998;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--bushari-primary);
  color: #FFFFFF;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--bushari-font);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s, box-shadow 0.15s;
}

.bushari-mobile-trigger:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.bushari-mobile-trigger svg {
  display: block;
}

@media (max-width: 767px) {
  .bushari-mobile-trigger {
    display: flex;
  }

  /* Hide sidebar shortcodes on mobile — mobile panel takes over */
  .bushari-chat--sidebar,
  .bushari-chat--listing {
    display: none !important;
  }
}

/* ── Mobile Overlay ───────────────────────────────────────────────── */

.bushari-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99999;
  transition: opacity 0.3s;
}

.bushari-mobile-overlay[aria-hidden="false"] {
  display: block;
}

/* ── Mobile Slide-Up Panel ────────────────────────────────────────── */

.bushari-mobile-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100000;
  background: var(--bushari-bg);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.bushari-mobile-panel[aria-hidden="false"] {
  transform: translateY(0);
}

.bushari-mobile-panel__handle {
  display: flex;
  justify-content: center;
  padding: 8px;
  cursor: grab;
  flex-shrink: 0;
}

.bushari-mobile-panel__handle::after {
  content: '';
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #D1D5DB;
}

.bushari-mobile-panel .bushari-chat--mobile {
  flex: 1;
  height: auto;
  min-height: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

/* Prevent background scroll when mobile panel is open */
body.bushari-mobile-open {
  overflow: hidden;
}

/* ── Noscript Fallback ────────────────────────────────────────────── */

.bushari-chat__fallback {
  padding: 20px;
  text-align: center;
  color: var(--bushari-text-light);
  font-size: 13px;
}

.bushari-chat__fallback a {
  color: var(--bushari-primary);
}
