/* ==========================================================================
   MSWP Chat Lead AI — Frontend Chat Widget
   Trigger balloon + Full-screen AI chat
   ========================================================================== */

.mswp-root {
  --mswp-primary: #3d9e4a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #1a1a1a;
}

/* ==========================================================================
   AVATARS
   ========================================================================== */

.mswp-avatar {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.mswp-avatar--xs { width: 32px;  height: 32px; }
.mswp-avatar--sm { width: 36px;  height: 36px; }
.mswp-avatar--md { width: 48px;  height: 48px; }
.mswp-avatar--lg { width: 62px;  height: 62px; }

.mswp-avatar--default {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
}

.mswp-avatar--xs.mswp-avatar--default { font-size: 12px; }
.mswp-avatar--sm.mswp-avatar--default { font-size: 14px; }
.mswp-avatar--md.mswp-avatar--default { font-size: 18px; }
.mswp-avatar--lg.mswp-avatar--default { font-size: 24px; }

/* ==========================================================================
   TRIGGER BALLOON
   ========================================================================== */

@keyframes mswp-trigger-in {
  from { opacity: 0; transform: translateY(18px) scale(.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.mswp-trigger {
  position: fixed;
  bottom: 28px;
  right: 24px;
  z-index: 999990;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: mswp-trigger-in .42s cubic-bezier(.34,1.56,.64,1) both;
}

/* Speech bubble with tail pointing right toward avatar */
.mswp-trigger__balloon {
  position: relative;
  background: #fff;
  border: none;
  border-radius: 18px;
  padding: 14px 20px;
  cursor: pointer;
  text-align: left;
  max-width: 250px;
  filter: drop-shadow(0 4px 18px rgba(0,0,0,.15)) drop-shadow(0 1px 4px rgba(0,0,0,.07));
  transition: filter .18s, transform .15s;
}

.mswp-trigger__balloon:hover {
  filter: drop-shadow(0 6px 26px rgba(0,0,0,.2)) drop-shadow(0 1px 6px rgba(0,0,0,.09));
  transform: translateY(-2px);
}

/* Tail pointing right */
.mswp-trigger__balloon::after {
  content: '';
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  border: 8px solid transparent;
  border-left-color: #fff;
  border-right-width: 0;
}

.mswp-trigger__text {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: #1a1a1a;
  line-height: 1.45;
}

/* Agent circle: avatar + online dot + dismiss */
.mswp-trigger__agent {
  position: relative;
  flex-shrink: 0;
}

/* Online dot */
.mswp-online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #44d662;
  border: 2.5px solid #fff;
  animation: mswp-pulse 2.4s ease-in-out infinite;
}

.mswp-online-dot--mini {
  width: 12px;
  height: 12px;
  bottom: 1px;
  right: 1px;
}

@keyframes mswp-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .6; transform: scale(.82); }
}

/* Dismiss × button */
.mswp-trigger__dismiss {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #e0e0e0;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1;
  padding: 0;
  line-height: 1;
  transition: background .15s, color .15s, border-color .15s;
}

.mswp-trigger__dismiss:hover {
  background: #f5f5f5;
  color: #555;
  border-color: #bbb;
}

/* ==========================================================================
   LEFT POSITION VARIANT
   ========================================================================== */

.mswp-root[data-position="left"] .mswp-trigger {
  right: auto;
  left: 24px;
  flex-direction: row-reverse;
}

/* Tail points LEFT when widget is on the left side */
.mswp-root[data-position="left"] .mswp-trigger__balloon::after {
  right: auto;
  left: -8px;
  border-left-color: transparent;
  border-right-color: #fff;
  border-left-width: 0;
  border-right-width: 8px;
}

.mswp-root[data-position="left"] .mswp-mini-bubble {
  right: auto;
  left: 24px;
}

/* ==========================================================================
   MINI BUBBLE (after trigger dismiss)
   ========================================================================== */

.mswp-mini-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999990;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--mswp-primary);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,.24);
  transition: transform .18s, box-shadow .18s;
  overflow: hidden;
}

.mswp-mini-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0,0,0,.3);
}

.mswp-mini-bubble .mswp-avatar {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ==========================================================================
   FULL-SCREEN CHAT
   ========================================================================== */

@keyframes mswp-fs-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.mswp-fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999999;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  animation: mswp-fs-in .22s ease both;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ── Header ── */
.mswp-fs-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  background: #fff;
  border-bottom: 1px solid #efefef;
  flex-shrink: 0;
}

.mswp-fs-back {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}

.mswp-fs-back:hover {
  background: #f5f5f5;
  color: #1a1a1a;
}

.mswp-fs-agent {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.mswp-fs-agent-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.mswp-fs-name {
  font-weight: 700;
  font-size: 15px;
  color: #1a1a1a;
}

.mswp-fs-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: #777;
}

.mswp-status-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #44d662;
  flex-shrink: 0;
  animation: mswp-pulse 2.4s ease-in-out infinite;
}

/* ── Messages ── */
.mswp-chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 28px max(20px, calc((100% - 680px) / 2));
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.mswp-chat-messages::-webkit-scrollbar { width: 4px; }
.mswp-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* Message rows */
.mswp-msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.mswp-msg-row--bot  { justify-content: flex-start; }
.mswp-msg-row--user { justify-content: flex-end; }

/* Mini avatar inside bot messages */
.mswp-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  margin-top: 4px;
}

.mswp-msg-avatar--default {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  background: var(--mswp-primary);
}

/* Spacer to align consecutive bot messages without repeating avatar */
.mswp-msg-avatar-spacer {
  width: 32px;
  flex-shrink: 0;
}

/* Bubbles */
.mswp-msg-bubble {
  max-width: 78%;
  padding: 12px 16px;
  font-size: 14.5px;
  line-height: 1.6;
  word-break: break-word;
}

/* Bot: light gray bubble */
.mswp-msg-row--bot .mswp-msg-bubble {
  background: #f0f0f0;
  color: #1a1a1a;
  border-radius: 18px 18px 18px 5px;
}

/* User: primary color bubble, white text */
.mswp-msg-row--user .mswp-msg-bubble {
  background: var(--mswp-primary);
  color: #fff;
  border-radius: 18px 18px 5px 18px;
}

.mswp-msg-bubble--error {
  background: #fff4f4 !important;
  color: #c62828 !important;
  border: 1px solid #ffcdd2;
  border-radius: 12px !important;
  padding: 10px 16px !important;
  box-shadow: none !important;
}

/* ==========================================================================
   TYPING INDICATOR
   ========================================================================== */

.mswp-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: #f0f0f0;
  border-radius: 18px 18px 18px 5px;
}

.mswp-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #bbb;
  animation: mswp-dot 1.2s ease-in-out infinite;
}

.mswp-typing span:nth-child(2) { animation-delay: .2s; }
.mswp-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes mswp-dot {
  0%, 80%, 100% { transform: scale(1);    opacity: .45; }
  40%            { transform: scale(1.35); opacity: 1; }
}

/* ==========================================================================
   CHOICE BUTTONS
   ========================================================================== */

.mswp-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  padding: 4px 0 6px;
  padding-left: 42px;
}

.mswp-choice-btn {
  padding: 9px 18px;
  border: 1.5px solid #e0e0e0;
  background: #fff;
  border-radius: 24px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  color: #444;
  transition: border-color .15s, background .15s, color .15s;
}

.mswp-choice-btn:hover      { border-color: var(--mswp-primary); color: var(--mswp-primary); }
.mswp-choice-btn--selected  { background: var(--mswp-primary); border-color: var(--mswp-primary); color: #fff; }
.mswp-choice-btn:disabled   { opacity: .55; cursor: default; }

.mswp-confirm-area {
  padding-left: 42px;
  margin-top: 8px;
}

.mswp-confirm-btn {
  padding: 10px 22px;
  background: var(--mswp-primary);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .15s, transform .12s;
}

.mswp-confirm-btn:hover    { opacity: .88; transform: scale(1.02); }
.mswp-confirm-btn:disabled { opacity: .5;  cursor: default; transform: none; }

/* ==========================================================================
   INPUT AREA
   ========================================================================== */

.mswp-fs-input-area {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid #efefef;
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
}

.mswp-fs-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 680px;
  margin: 0 auto;
  background: #f5f5f5;
  border: 1.5px solid #e8e8e8;
  border-radius: 30px;
  padding: 4px 4px 4px 16px;
  transition: border-color .15s, background .15s;
  box-sizing: border-box;
  width: 100%;
}

.mswp-fs-input-wrap:focus-within {
  border-color: var(--mswp-primary);
  background: #fff;
}

.mswp-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  color: #1a1a1a;
  padding: 7px 0;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}

.mswp-chat-input:disabled       { opacity: .55; }
.mswp-chat-input::placeholder   { color: #b8b8b8; }

.mswp-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--mswp-primary);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .15s, transform .12s;
  -webkit-tap-highlight-color: transparent;
}

.mswp-chat-send:hover    { opacity: .88; transform: scale(1.06); }
.mswp-chat-send:disabled { opacity: .4;  cursor: default; transform: none; }

/* ==========================================================================
   WHATSAPP BUTTON
   ========================================================================== */

.mswp-wa-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 12px 24px;
  background: #25d366;
  color: #fff;
  border-radius: 28px;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  transition: background .15s;
}

.mswp-wa-btn:hover { background: #1ebe57; color: #fff; }

/* ==========================================================================
   SIDEBAR MODE — compact floating chat widget
   ========================================================================== */

.mswp-fullscreen.mswp-sidebar-mode {
  position: fixed;
  top: auto;
  bottom: 24px;
  right: 24px;
  left: auto;
  width: 400px;
  height: 580px;
  max-height: calc(100vh - 48px);
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,.18), 0 2px 12px rgba(0,0,0,.08);
  overflow: hidden;
  animation: mswp-sidebar-in .28s cubic-bezier(.34,1.2,.64,1) both;
}

.mswp-root[data-position="left"] .mswp-fullscreen.mswp-sidebar-mode {
  right: auto;
  left: 24px;
}

@keyframes mswp-sidebar-in {
  from { opacity: 0; transform: translateY(24px) scale(.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Sidebar header — slightly more compact */
.mswp-sidebar-mode .mswp-fs-header {
  padding: 12px 16px;
  border-radius: 20px 20px 0 0;
}

/* Sidebar messages area */
.mswp-sidebar-mode .mswp-chat-messages {
  padding: 20px 16px;
}

/* Sidebar input area */
.mswp-sidebar-mode .mswp-fs-input-area {
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  border-radius: 0 0 20px 20px;
}

.mswp-sidebar-mode .mswp-fs-input-wrap {
  padding: 3px 3px 3px 14px;
}

.mswp-sidebar-mode .mswp-chat-input {
  font-size: 14px;
  padding: 6px 0;
}

.mswp-sidebar-mode .mswp-chat-send {
  width: 34px;
  height: 34px;
}

/* Sidebar doesn't need dvh/vw overrides */
.mswp-sidebar-mode {
  height: 580px !important;
  width: 400px !important;
}

/* On tablets (481px-768px), slightly narrower sidebar */
@media (max-width: 768px) {
  .mswp-fullscreen.mswp-sidebar-mode {
    width: 360px;
    height: 520px;
    bottom: 16px;
    right: 16px;
  }
  .mswp-sidebar-mode {
    width: 360px !important;
    height: 520px !important;
  }
  .mswp-root[data-position="left"] .mswp-fullscreen.mswp-sidebar-mode {
    left: 16px;
  }
}

/* On small mobile (<=480px), sidebar mode is forced to fullscreen by JS,
   but just in case, override it here too */
@media (max-width: 480px) {
  .mswp-fullscreen.mswp-sidebar-mode {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  .mswp-sidebar-mode .mswp-fs-header {
    border-radius: 0;
  }
  .mswp-sidebar-mode .mswp-fs-input-area {
    border-radius: 0;
  }
}
