/* ============================================================
   SWD Smart Chat — v10.0
   Clean, scoped, no !important spam
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── 1. Isolation wrapper ------------------------------------ */
#swd-chat {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 2147483600;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #111827;
}

/* Hard-reset every child so theme styles can't bleed in */
#swd-chat *,
#swd-chat *::before,
#swd-chat *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 1px;
  border: 0;
  outline: 0;
  font: inherit;
  color: inherit;
  /* NOTE: background intentionally NOT reset here — bubble/panel colours must survive */
  text-decoration: none;
  list-style: none;
  line-height: inherit;
  -webkit-tap-highlight-color: transparent;
}

/* ── 2. Design tokens ---------------------------------------- */
#swd-chat {
  --brand:        #fc1d55;
  --brand-dark:   #d4153f;
  --brand-light:  #ff6b90;
  --brand-alpha:  rgba(252, 29, 85, 0.12);
  --brand-glow:   rgba(252, 29, 85, 0.40);

  --white:        #ffffff;
  --off-white:    #f8f9fb;
  --gray-50:      #f3f4f6;
  --gray-100:     #e5e7eb;
  --gray-300:     #d1d5db;
  --gray-500:     #6b7280;
  --gray-900:     #111827;

  --panel-bg:     rgba(255, 255, 255, 0.92);
  --msg-bg:       #f3f4f6;
  --bot-bubble:   #ffffff;
  --user-bubble:  var(--brand);

  --radius-panel: 20px;
  --radius-bub:   16px;
  --shadow-panel:
    0 0 0 1px rgba(0,0,0,0.06),
    0 4px 6px rgba(0,0,0,0.04),
    0 12px 28px rgba(0,0,0,0.10),
    0 36px 72px rgba(0,0,0,0.12);
  --shadow-bub:   0 1px 2px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.06);

  --ease-spring:  cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:     cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── 3. FAB launcher ----------------------------------------- */
#swd-fab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--brand-light), var(--brand-dark));
  box-shadow: 0 4px 20px var(--brand-glow), 0 2px 6px rgba(0,0,0,0.16);
  cursor: pointer;
  border: none;
  padding: 0;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s ease;
  animation: fabIdle 3.5s ease-in-out infinite;
}
@keyframes fabIdle {
  0%, 100% { box-shadow: 0 4px 20px var(--brand-glow), 0 2px 6px rgba(0,0,0,0.16); }
  50%       { box-shadow: 0 4px 20px var(--brand-glow), 0 0 0 10px rgba(252,29,85,0), 0 2px 6px rgba(0,0,0,0.16); }
}
#swd-fab:hover  { transform: scale(1.07) translateY(-2px); box-shadow: 0 8px 28px var(--brand-glow); }
#swd-fab:active { transform: scale(0.94); }
#swd-fab.open   { animation: none; background: linear-gradient(145deg, #e8104a, #b50e35); }

#swd-fab svg {
  position: absolute;
  display: block;
  transition: opacity 0.22s ease, transform 0.30s var(--ease-spring);
}
.swd-ico-chat  { width: 26px; height: 26px; opacity: 1; transform: scale(1) rotate(0); }
.swd-ico-close { width: 22px; height: 22px; opacity: 0; transform: scale(0.4) rotate(-80deg); }
#swd-fab.open .swd-ico-chat  { opacity: 0; transform: scale(0.4) rotate(80deg); }
#swd-fab.open .swd-ico-close { opacity: 1; transform: scale(1) rotate(0); }

/* Notification badge */
.swd-notif {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #ffffff;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2.5px solid var(--brand);
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  transition: transform 0.22s var(--ease-spring), opacity 0.18s ease;
  line-height: 1;
}
#swd-fab.open .swd-notif { transform: scale(0); opacity: 0; }

/* Pulse ring */
#swd-fab::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(252,29,85,0.3);
  animation: fabRing 2.5s ease-out infinite;
  pointer-events: none;
}
#swd-fab.open::after { display: none; }
@keyframes fabRing {
  0%   { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* ── 4. Panel ------------------------------------------------- */
#swd-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 372px;
  max-width: calc(100vw - 20px);
  height: 588px;
  max-height: calc(100dvh - 112px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius-panel);
  background: var(--panel-bg);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  box-shadow: var(--shadow-panel);
  border: 1px solid rgba(255,255,255,0.75);

  /* entry / exit */
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  pointer-events: none;
  visibility: hidden;
  transition:
    opacity 0.28s var(--ease-out),
    transform 0.32s var(--ease-spring),
    visibility 0s linear 0.32s;
}
#swd-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
  transition:
    opacity 0.28s var(--ease-out),
    transform 0.32s var(--ease-spring),
    visibility 0s linear 0s;
}

/* ── 5. Header ----------------------------------------------- */
#swd-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(135deg, #fc1d55 0%, #c8123e 100%);
  position: relative;
  overflow: hidden;
}
/* Moving light sweep on header */
#swd-header::before {
  content: '';
  position: absolute;
  top: 0; left: -75%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.14), transparent);
  animation: headerSweep 5s linear infinite;
  pointer-events: none;
}
@keyframes headerSweep {
  to { left: 130%; }
}

.swd-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
}
.swd-avatar-wrap svg {
  width: 42px;
  height: 42px;
  display: block;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.40);
  background: rgba(255,255,255,0.15);
}
.swd-status {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid #c8123e;
  animation: statusPulse 2.2s ease-in-out infinite;
}
@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  55%       { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

.swd-header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.swd-name {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.3px;
}
.swd-live {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  gap: 5px;
}
.swd-live i {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: #4ade80;
  border-radius: 50%;
  animation: statusPulse 2.2s ease-in-out infinite;
}

#swd-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.18s ease, transform 0.18s ease;
}
#swd-close:hover  { background: rgba(255,255,255,0.28); transform: scale(1.08); }
#swd-close:active { transform: scale(0.92); }
#swd-close svg    { width: 14px; height: 14px; display: block; }

/* ── 6. Service tags bar ------------------------------------- */
#swd-tags {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(252,29,85,0.04);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  overflow-x: auto;
  scrollbar-width: none;
}
#swd-tags::-webkit-scrollbar { display: none; }
#swd-tags span {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  background: rgba(252,29,85,0.08);
  border: 1px solid rgba(252,29,85,0.18);
  color: var(--brand);
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}

/* ── 7. Messages scroll area --------------------------------- */
#swd-msgs {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--msg-bg);
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.12) transparent;
}
#swd-msgs::-webkit-scrollbar       { width: 4px; }
#swd-msgs::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 2px; }

/* Timestamp divider */
.swd-ts {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--gray-500);
  letter-spacing: 0.3px;
  margin: 2px 0;
}
.swd-ts::before,
.swd-ts::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-100);
}

/* Message rows */
.swd-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgIn 0.28s var(--ease-spring) both;
}
.swd-row.bot { justify-content: flex-start; }
.swd-row.usr { justify-content: flex-end; min-width: 0; width: 100%; }
.swd-row.usr .swd-bub { max-width: 78%; min-width: 0; flex-shrink: 1; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: none; }
}

/* Bot avatar (small) */
.swd-av {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-light), var(--brand-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
  box-shadow: 0 2px 6px rgba(252,29,85,0.25);
}
.swd-av svg { width: 14px; height: 14px; display: block; fill: white; }

/* Bubbles */
.swd-bub {
  max-width: 78%;
  padding: 8px 8px!important;
  font-size: 12px;
  line-height: 1.6;
  word-break: break-all;
  overflow-wrap: anywhere;
  white-space: normal;
  overflow: hidden;
  min-width: 0;
  display: block;
}
.swd-bub.bot {
  background: var(--bot-bubble);
  color: var(--gray-900);
  border-radius: 4px var(--radius-bub) var(--radius-bub) var(--radius-bub);
  box-shadow: var(--shadow-bub);
  border: 1px solid var(--gray-100);
}
.swd-bub.usr {
  background: linear-gradient(135deg, var(--brand-light), var(--brand-dark));
  color: #ffffff;
  border-radius: var(--radius-bub) 4px var(--radius-bub) var(--radius-bub);
  box-shadow: 0 3px 12px rgba(252,29,85,0.30);
  padding: 11px 18px;
}
.swd-bub a { color: inherit; text-decoration: underline; }

/* Typing indicator */
.swd-row.typing .swd-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bot-bubble);
  border-radius: 4px var(--radius-bub) var(--radius-bub) var(--radius-bub);
  box-shadow: var(--shadow-bub);
  border: 1px solid var(--gray-100);
}
.swd-dots span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  animation: dotBounce 1.2s ease-in-out infinite both;
}
.swd-dots span:nth-child(2) { animation-delay: 0.16s; }
.swd-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%            { transform: translateY(-7px); opacity: 1; }
}

/* ── 8. Quick reply chips ------------------------------------ */
#swd-chips {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 16px 12px;
  background: var(--msg-bg);
  animation: msgIn 0.24s var(--ease-spring) both;
}
#swd-chips:empty { padding: 0; }

.swd-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 100px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--gray-300);
  background: var(--white);
  color: var(--gray-900);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  transition: all 0.18s var(--ease-spring);
  white-space: nowrap;
}
.swd-chip:hover {
  border-color: var(--brand);
  color: var(--brand);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(252,29,85,0.14);
}
.swd-chip:active { transform: scale(0.95); }
.swd-chip.primary {
  background: linear-gradient(135deg, var(--brand-light), var(--brand-dark));
  color: white;
  border-color: transparent;
  box-shadow: 0 3px 10px rgba(252,29,85,0.28);
}
.swd-chip.primary:hover { filter: brightness(1.08); }
.swd-chip.green {
  background: #16a34a;
  color: white;
  border-color: transparent;
  box-shadow: 0 3px 10px rgba(22,163,74,0.22);
}

/* ── 9. Footer / input --------------------------------------- */
#swd-footer {
  flex-shrink: 0;
  padding: 12px 16px 16px;
  background: var(--white);
  border-top: 1px solid var(--gray-100);
}

#swd-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--off-white);
  border: 1.5px solid var(--gray-200, #e5e7eb);
  border-radius: 14px;
  padding: 6px 6px 6px 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
#swd-input-row:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(252,29,85,0.10);
  background: var(--white);
}

#swd-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--gray-900);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  padding: 6px 0;
  max-height: 96px;
  min-height: 32px;
  display: block;
  width: 100%;
}
#swd-input::placeholder { color: var(--gray-500); }
#swd-input:disabled { opacity: 0.45; cursor: not-allowed; }

#swd-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-light), var(--brand-dark));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 2px 8px rgba(252,29,85,0.35);
  transition: transform 0.18s var(--ease-spring), box-shadow 0.18s ease, filter 0.15s ease;
}
#swd-send:hover  { transform: scale(1.07); box-shadow: 0 4px 16px rgba(252,29,85,0.45); }
#swd-send:active { transform: scale(0.9); }
#swd-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
#swd-send svg { width: 15px; height: 15px; display: block; }

#swd-hint {
  margin-top: 8px;
  padding: 0 2px;
  min-height: 16px;
  font-size: 11px;
  color: var(--gray-500);
  line-height: 1.4;
  display: block;
}
#swd-hint.err { color: #dc2626; }
#swd-hint.ok  { color: #16a34a; }

/* ── 10. Action buttons (WhatsApp / Email) ------------------- */
.swd-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  animation: msgIn 0.28s var(--ease-spring) both;
}
.swd-act-btn {
  flex: 1;
  min-width: 100px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 12px;
  border-radius: 12px;
  border: none;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.18s var(--ease-spring), filter 0.15s ease;
}
.swd-act-btn:hover  { filter: brightness(1.07); transform: translateY(-2px); }
.swd-act-btn:active { transform: scale(0.95); }
.swd-act-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.swd-act-btn.wa { background: #25D366; color: white; box-shadow: 0 3px 12px rgba(37,211,102,0.25); }
.swd-act-btn.em { background: linear-gradient(135deg, var(--brand-light), var(--brand-dark)); color: white; box-shadow: 0 3px 12px rgba(252,29,85,0.28); }

/* System note */
.swd-note {
  align-self: center;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-500);
  background: rgba(0,0,0,0.04);
  animation: msgIn 0.24s var(--ease-spring) both;
}

/* ── 11. Responsive ------------------------------------------ */
@media (max-width: 480px) {
  #swd-chat {
    right: 16px;
    bottom: 20px;
  }
  #swd-panel {
    position: fixed;
    inset: 12px 12px auto 12px;
    bottom: 82px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    max-height: calc(100dvh - 100px);
    border-radius: 18px;
  }
}
@media (max-height: 640px) {
  #swd-panel { max-height: calc(100dvh - 96px); }
}
