/* World Design — AI chat widget + float stack (WhatsApp below, AI above) */

:root {
  --wd-float-edge: 1.5rem;
  --wd-float-btn: 3.5rem;
  --wd-float-gap: 0.75rem;
  --wd-float-base: calc(var(--wd-float-edge) + env(safe-area-inset-bottom, 0px));
}

/* ── FAB (AI) — stacked above WhatsApp, same horizontal edge ── */
.wd-ai-chat-fab {
  position: fixed;
  z-index: 9002;
  bottom: calc(var(--wd-float-base) + var(--wd-float-btn) + var(--wd-float-gap));
  inset-inline-end: var(--wd-float-edge);
  width: var(--wd-float-btn);
  height: var(--wd-float-btn);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: linear-gradient(145deg, var(--color-primary) 0%, #0077b6 45%, var(--color-purple) 100%);
  color: #fff;
  box-shadow:
    0 4px 16px rgba(0, 150, 199, 0.35),
    0 8px 28px rgba(124, 58, 237, 0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wd-ai-chat-fab__icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.wd-ai-chat-fab__svg {
  width: 1.65rem;
  height: 1.65rem;
  display: block;
}

.wd-ai-chat-fab__badge {
  position: absolute;
  bottom: 0.15rem;
  inset-inline-end: 0.1rem;
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  padding: 0.12rem 0.22rem;
  border-radius: 0.25rem;
  background: rgba(255, 255, 255, 0.95);
  color: var(--color-purple);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.wd-ai-chat-fab:hover {
  transform: scale(1.06);
  box-shadow:
    0 6px 22px rgba(0, 150, 199, 0.45),
    0 10px 32px rgba(124, 58, 237, 0.35);
}

.wd-ai-chat-fab:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.wd-ai-chat-fab[aria-expanded="true"] {
  transform: scale(0.96);
}

/* Align WhatsApp with same corner + safe area when AI widget is active */
body.wd-has-ai-chat .whatsapp-float {
  bottom: var(--wd-float-base);
  z-index: 9000;
  width: var(--wd-float-btn);
  height: var(--wd-float-btn);
}

html[dir="ltr"] body.wd-has-ai-chat .whatsapp-float {
  right: var(--wd-float-edge);
  left: auto;
}

html[dir="rtl"] body.wd-has-ai-chat .whatsapp-float {
  left: var(--wd-float-edge);
  right: auto;
}

/* Scroll-to-top above AI + WhatsApp stack */
body.wd-has-ai-chat #scroll-top {
  z-index: 9003;
  bottom: calc(
    var(--wd-float-base) + var(--wd-float-btn) + var(--wd-float-gap) +
    var(--wd-float-btn) + var(--wd-float-gap) + 2.875rem
  );
}

html[dir="ltr"] body.wd-has-ai-chat #scroll-top {
  right: var(--wd-float-edge);
  left: auto;
}

html[dir="rtl"] body.wd-has-ai-chat #scroll-top {
  left: var(--wd-float-edge);
  right: auto;
}

/* ── Chat panel ── */
.wd-ai-chat-panel {
  position: fixed;
  z-index: 9001;
  bottom: calc(
    var(--wd-float-base) + var(--wd-float-btn) + var(--wd-float-gap) +
    var(--wd-float-btn) + var(--wd-float-gap)
  );
  inset-inline-end: var(--wd-float-edge);
  width: min(22rem, calc(100vw - var(--wd-float-edge) * 2));
  max-height: min(32rem, calc(100vh - 11rem - env(safe-area-inset-bottom, 0px)));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg, 1rem);
  overflow: hidden;
  background: var(--glass-bg, rgba(15, 23, 42, 0.92));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

.wd-ai-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.wd-ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, rgba(0, 150, 199, 0.25), rgba(124, 58, 237, 0.2));
  border-bottom: 1px solid var(--glass-border, rgba(255, 255, 255, 0.08));
}

.wd-ai-chat-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
}

.wd-ai-chat-title__icon {
  flex-shrink: 0;
  width: 1.15rem;
  height: 1.15rem;
  opacity: 0.95;
}

.wd-ai-chat-close {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  opacity: 0.75;
}

.wd-ai-chat-close:hover {
  opacity: 1;
}

.wd-ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 10rem;
}

.wd-ai-chat-msg {
  max-width: 92%;
  padding: 0.55rem 0.75rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.wd-ai-chat-msg--user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  border-end-end-radius: 0.2rem;
}

.wd-ai-chat-msg--bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border-end-start-radius: 0.2rem;
}

[data-theme="light"] .wd-ai-chat-msg--bot {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-primary);
}

.wd-ai-chat-msg--typing {
  opacity: 0.7;
  font-style: italic;
}

.wd-ai-chat-footer {
  padding: 0.65rem 0.75rem 0.75rem;
  border-top: 1px solid var(--glass-border, rgba(255, 255, 255, 0.08));
}

.wd-ai-chat-disclaimer {
  font-size: 0.68rem;
  opacity: 0.65;
  margin: 0 0 0.5rem;
  line-height: 1.35;
}

.wd-ai-chat-form {
  display: flex;
  gap: 0.5rem;
}

.wd-ai-chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-md, 0.5rem);
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.15));
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  font: inherit;
  font-size: 0.875rem;
}

[data-theme="light"] .wd-ai-chat-input {
  background: #fff;
}

.wd-ai-chat-send {
  flex-shrink: 0;
  padding: 0.5rem 0.85rem;
  border: none;
  border-radius: var(--radius-md, 0.5rem);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
}

.wd-ai-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.wd-ai-chat-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.wd-ai-chat-links a {
  font-size: 0.72rem;
  color: var(--color-primary);
}

/* ── Mobile: tighter edge + taller panel clearance ── */
@media (max-width: 1023px) {
  :root {
    --wd-float-edge: 1rem;
  }

  body.wd-has-ai-chat #scroll-top {
    bottom: calc(
      var(--wd-float-base) + var(--wd-float-btn) + var(--wd-float-gap) +
      var(--wd-float-btn) + var(--wd-float-gap) + 2.875rem
    );
  }

  /* mobile-cta-float stays on opposite side — no overlap with WA/AI stack */
}

@media (max-width: 480px) {
  .wd-ai-chat-panel {
    inset-inline-end: var(--wd-float-edge);
    width: calc(100vw - var(--wd-float-edge) * 2);
    max-height: min(28rem, calc(100vh - 12rem - env(safe-area-inset-bottom, 0px)));
  }
}

/* Panel open: lift scroll-top if visible */
body.wd-has-ai-chat.wd-ai-chat-open #scroll-top {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
