/* Woo AI Assistant — Chat Widget
   "Gold on Black" brand theme, derived from the store logo:
   near-black surfaces (#0A0A0A), golden-amber accent (#FFC107),
   soft 18-22px rounding, a four-point sparkle motif, and restrained
   motion (one entrance, one typing bounce, subtle hovers).
   All custom properties are set on #wooai-widget-root so the admin's
   saved colors still override the defaults from settings. */

#wooai-widget-root {
  /* Isolate from the theme's cascade first... */
  all: initial;
  /* ...then apply the widget's own critical layout properties. Order
     matters here: these MUST come after "all: initial" in the same rule,
     otherwise the reset above wipes them back to static/auto and the
     whole widget drops into the page's normal flow instead of floating
     fixed in the corner. */
  display: block;
  position: fixed;
  z-index: 999999;
  bottom: 65px;
  font-family: var(--wooai-font);
  color: var(--wooai-ink);
  line-height: 1.5;
  /* "all: initial" above resets direction to LTR; this widget is Persian —
     restore RTL so punctuation, parentheses and mixed Latin/numbers sit on
     the correct side inside the bubbles. */
  direction: rtl;
  text-align: start;
  /* Brand palette: gold on black (logo-derived). The JS copies the
     admin-saved primary/accent onto --wooai-accent/--wooai-accent-soft,
     so these are just resilient defaults. */
  --wooai-black: #0A0A0A;
  --wooai-black-2: #141414;
  --wooai-surface-dark: #1B1B1B;
  --wooai-gold: #FFC107;
  --wooai-gold-bright: #FFD24A;
  --wooai-gold-deep: #E6A800;
  --wooai-primary: #FFC107;
  --wooai-primary-light: #FFD24A;
  --wooai-accent: #FFC107;
  --wooai-ink: #F5F5F5;
  --wooai-ink-soft: #9A9A9A;
  --wooai-paper: #FFFFFF;
  --wooai-surface: #0F0F0F;
  --wooai-border: rgba(255, 193, 7, 0.14);
  --wooai-border-faint: rgba(255, 255, 255, 0.07);
  --wooai-shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.55), 0 8px 20px rgba(0, 0, 0, 0.35);
  --wooai-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --wooai-radius: 20px;
  --wooai-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Vazirmatn", sans-serif;

  /* ===== STATE TOKENS (ui-ux-pro-max design-system: states-and-variants) ===== */
  --wooai-error: #DC3545;
  --wooai-error-fg: #FF8A93;
  --wooai-error-border: rgba(220, 53, 69, 0.35);
  --wooai-opacity-disabled: 0.4;
  /* Focus ring spec: 2px ring + 2px offset, primary color. */
  --wooai-ring-width: 2px;
  --wooai-ring-offset: 2px;

  /* ===== DURATION / EASING TOKENS ===== */
  --wooai-duration-fast: 150ms;
  --wooai-duration-normal: 200ms;
  --wooai-duration-slow: 240ms;
  --wooai-ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --wooai-ease-out: cubic-bezier(.2, .8, .2, 1);
}

#wooai-widget-root * {
  box-sizing: border-box;
  font-family: inherit;
}

#wooai-widget-root.wooai-pos-right { right: 24px; }
#wooai-widget-root.wooai-pos-left  { left: 24px; }

/* ---------- Launcher bubble ---------- */
.wooai-launcher {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: radial-gradient(120% 120% at 30% 25%, #232323 0%, var(--wooai-black) 60%, #000 100%);
  box-shadow: var(--wooai-shadow-lg), inset 0 0 0 1.5px rgba(255, 193, 7, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s cubic-bezier(.34,1.56,.64,1), box-shadow 0.2s ease;
  padding: 0;
}
.wooai-launcher:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 28px 68px rgba(0,0,0,0.6), 0 0 26px rgba(255,193,7,0.28), inset 0 0 0 1.5px rgba(255,193,7,0.85);
}
.wooai-launcher:active { transform: translateY(-1px) scale(0.97); }
.wooai-launcher svg { width: 30px; height: 30px; }
.wooai-launcher-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.wooai-launcher-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Icon + text pill variant, used when a launcher label is configured. */
.wooai-launcher-labeled {
  width: auto;
  height: 54px;
  border-radius: 999px;
  /* RTL: the icon (first in DOM) sits on the inline-start side. */
  padding-inline: 7px 22px;
  gap: 11px;
}
#wooai-widget-root.wooai-pos-left .wooai-launcher-labeled { padding-inline: 22px 7px; }
.wooai-launcher-labeled .wooai-launcher-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 193, 7, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 193, 7, 0.4);
}
.wooai-launcher-labeled .wooai-launcher-icon svg { width: 24px; height: 24px; }
.wooai-launcher-labeled .wooai-launcher-icon img { width: 100%; height: 100%; }
.wooai-launcher-label {
  color: var(--wooai-gold);
  font-family: var(--wooai-font);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1px;
  white-space: nowrap;
  max-width: 45vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wooai-launcher-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--wooai-gold);
  border: 2.5px solid #000;
  box-shadow: 0 0 10px rgba(255,193,7,0.7);
  animation: wooai-dot-pulse 2.4s infinite ease-in-out;
}
@keyframes wooai-dot-pulse {
  0%, 100% { box-shadow: 0 0 4px rgba(255,193,7,0.45); }
  50%      { box-shadow: 0 0 14px rgba(255,193,7,0.95); }
}
.wooai-launcher-labeled .wooai-launcher-dot { display: none; }

/* ---------- Panel ---------- */
.wooai-panel {
  position: absolute;
  bottom: 78px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: var(--wooai-surface);
  border-radius: var(--wooai-radius);
  box-shadow: var(--wooai-shadow-lg);
  border: 1px solid rgba(255, 193, 7, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  transform-origin: bottom;
  pointer-events: none;
  transition: opacity 0.22s cubic-bezier(.2,.8,.2,1), transform 0.22s cubic-bezier(.2,.8,.2,1);
}
.wooai-pos-right .wooai-panel { right: 0; }
.wooai-pos-left  .wooai-panel { left: 0; }

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

/* ---------- Header ---------- */
.wooai-header {
  position: relative;
  background: linear-gradient(160deg, #181818 0%, var(--wooai-black) 70%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  overflow: hidden;
  border-bottom: 1px solid rgba(255, 193, 7, 0.18);
}
.wooai-header::before {
  /* Golden glow sweeping the top corner — echoes the logo's sparkle. */
  content: "";
  position: absolute;
  top: -70%;
  inset-inline-end: -15%;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(255,193,7,0.18) 0%, rgba(255,193,7,0) 70%);
  pointer-events: none;
}
.wooai-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(150deg, #222 0%, #0D0D0D 100%);
  box-shadow: inset 0 0 0 1.5px rgba(255, 193, 7, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.wooai-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}
.wooai-header-avatar svg { width: 22px; height: 22px; }
.wooai-header-text { flex: 1; min-width: 0; position: relative; z-index: 1; }
.wooai-header-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.1px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
}
.wooai-header-status {
  font-size: 12px;
  color: rgba(255,255,255,0.72);
  margin: 3px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.wooai-header-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wooai-gold);
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.18);
  display: inline-block;
  animation: wooai-status-breathe 2.2s infinite ease-in-out;
}
@keyframes wooai-status-breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}
.wooai-close-btn {
  background: rgba(255, 193, 7, 0.08);
  border: none;
  color: var(--wooai-gold);
  cursor: pointer;
  padding: 7px;
  border-radius: 10px;
  display: flex;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}
.wooai-close-btn:hover { background: rgba(255, 193, 7, 0.2); transform: rotate(90deg); }
.wooai-close-btn svg { width: 17px; height: 17px; }

/* ---------- Messages ---------- */
.wooai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    radial-gradient(90% 60% at 50% 0%, rgba(255,193,7,0.05) 0%, rgba(255,193,7,0) 60%),
    var(--wooai-surface);
}
.wooai-messages::-webkit-scrollbar { width: 6px; }
.wooai-messages::-webkit-scrollbar-thumb { background: rgba(255,193,7,0.28); border-radius: 6px; }
.wooai-messages::-webkit-scrollbar-track { background: transparent; }

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

.wooai-msg {
  max-width: 86%;
  padding: 11px 15px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  animation: wooai-msg-in 0.22s cubic-bezier(.2,.8,.2,1) both;
}
.wooai-msg p { margin: 0 0 6px; }
.wooai-msg p:last-child { margin-bottom: 0; }
.wooai-msg a {
  color: var(--wooai-gold-bright);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(255,210,74,0.5);
}
.wooai-msg-user a { color: #0A0A0A; text-decoration-color: rgba(0,0,0,0.4); }
.wooai-msg strong { color: var(--wooai-gold); font-weight: 700; }
.wooai-msg-user strong { color: #0A0A0A; }

.wooai-msg-assistant {
  align-self: flex-start;
  background: var(--wooai-surface-dark);
  border: 1px solid var(--wooai-border-faint);
  box-shadow: var(--wooai-shadow-sm);
  /* RTL: assistant bubbles sit on the inline-start (right) side, so the
     tail corner is top-inline-start. */
  border-radius: 18px 4px 18px 18px;
  color: var(--wooai-ink);
}
.wooai-msg-user {
  align-self: flex-end;
  background: linear-gradient(150deg, var(--wooai-gold-bright) 0%, var(--wooai-gold-deep) 100%);
  color: #0A0A0A;
  /* RTL: user bubbles sit on the inline-end (left) side, tail top-inline-end. */
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 4px 14px rgba(255, 193, 7, 0.22);
  font-weight: 500;
}
.wooai-msg-error {
  align-self: flex-start;
  background: rgba(220, 53, 69, 0.12);
  color: var(--wooai-error-fg);
  border-radius: 18px 4px 18px 18px;
  border: 1px solid var(--wooai-error-border);
}

.wooai-typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 14px 16px;
  background: var(--wooai-surface-dark);
  border: 1px solid var(--wooai-border-faint);
  box-shadow: var(--wooai-shadow-sm);
  border-radius: 18px 4px 18px 18px;
}
.wooai-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wooai-gold);
  opacity: 0.35;
  animation: wooai-pulse 1.1s infinite ease-in-out;
}
.wooai-typing span:nth-child(2) { animation-delay: 0.15s; }
.wooai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes wooai-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0) scale(0.9); }
  40%           { opacity: 1;    transform: translateY(-3px) scale(1); }
}

/* ---------- Product cards ---------- */
.wooai-products {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
  max-width: 90%;
  align-self: flex-start;
}
.wooai-product-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--wooai-surface-dark);
  border: 1px solid var(--wooai-border-faint);
  border-inline-start: 3px solid var(--wooai-gold);
  border-radius: 13px;
  padding: 10px 13px;
  text-decoration: none;
  color: var(--wooai-ink);
  box-shadow: var(--wooai-shadow-sm);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.wooai-product-card:hover {
  border-color: rgba(255, 193, 7, 0.55);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(255, 193, 7, 0.14);
}
.wooai-product-name {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 2px;
  color: var(--wooai-ink);
}
.wooai-product-price {
  font-size: 12.5px;
  color: var(--wooai-gold);
  font-weight: 800;
  white-space: nowrap;
}

/* ---------- Input ---------- */
.wooai-input-row {
  display: flex;
  align-items: center;   /* was flex-end: on a single-line input the round
                            send button hung below the textarea's baseline
                            and looked vertically misaligned. Center keeps
                            button + field on one visual axis. */
  gap: 8px;
  padding: 12px 14px;
  background: var(--wooai-black-2);
  border-top: 1px solid rgba(255, 193, 7, 0.14);
  flex-shrink: 0;
}
.wooai-input {
  flex: 1;
  resize: none;
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  background: var(--wooai-surface-dark);
  padding: 11px 15px;
  font-size: 14px;
  font-family: inherit;
  color: var(--wooai-ink);
  max-height: 90px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.wooai-input::placeholder { color: rgba(255,255,255,0.38); }
.wooai-input:focus {
  border-color: var(--wooai-gold);
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.12);
}
.wooai-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(150deg, var(--wooai-gold-bright) 0%, var(--wooai-gold-deep) 100%);
  color: #0A0A0A;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  flex-shrink: 0;
  padding: 0;
  margin: auto 0;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(255, 193, 7, 0.3);
  transition: transform 0.15s cubic-bezier(.34,1.56,.64,1), box-shadow 0.15s ease, opacity 0.15s ease;
  cursor: pointer;
}
/* The SVG itself must also be dead-center: some themes set svg
   { vertical-align } or display rules that nudge icons off-axis inside
   buttons; pinning it with absolute centering removes any theme drift. */
.wooai-send-btn svg {
  width: 17px;
  height: 17px;
  display: block;
}
.wooai-send-btn:hover:not(:disabled) { transform: translateY(-2px) scale(1.05); box-shadow: 0 6px 18px rgba(255, 193, 7, 0.42); }
.wooai-send-btn:active:not(:disabled) { transform: scale(0.94); }
.wooai-send-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; }

.wooai-footer-note {
  font-size: 10.5px;
  text-align: center;
  color: rgba(255, 255, 255, 0.32);
  padding: 0 12px 11px;
  background: var(--wooai-black-2);
}

/* ---------- Accessibility ---------- */
.wooai-visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
#wooai-widget-root button:focus-visible, .wooai-input:focus-visible {
  outline: var(--wooai-ring-width) solid var(--wooai-gold);
  outline-offset: var(--wooai-ring-offset);
}

@media (prefers-reduced-motion: reduce) {
  .wooai-panel, .wooai-launcher, .wooai-typing span, .wooai-msg, .wooai-send-btn,
  .wooai-launcher-dot, .wooai-header-status::before { transition: none; animation: none; }
}

/* ---------- FiboSearch "light bridge" row ----------
   Injected into the FiboSearch results dropdown. Styled to match the
   gold-on-black brand but kept neutral enough to sit inside FiboSearch's
   own white dropdown: light surface, gold border, dark text. */
.wooai-fibo-bridge {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 8px;
  padding: 10px 13px;
  background: linear-gradient(150deg, #FFFBEF 0%, #FFF6DC 100%);
  border: 1px solid rgba(255, 193, 7, 0.55);
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.wooai-fibo-bridge:hover,
.wooai-fibo-bridge:focus-visible {
  border-color: var(--wooai-gold, #FFC107);
  box-shadow: 0 4px 14px rgba(255, 193, 7, 0.25);
  outline: none;
}
.wooai-fibo-bridge-icon { display: flex; flex-shrink: 0; }
.wooai-fibo-bridge-text {
  font-size: 13px;
  line-height: 1.5;
  color: #4A3B00;
}
.wooai-fibo-bridge-text strong {
  color: #0A0A0A;
  font-weight: 700;
}

/* ---------- State polish (ui-ux-pro-max design-system pass) ---------- */
.wooai-input-row { transition: border-color var(--wooai-duration-fast) ease-in-out; }
.wooai-input-row:focus-within { border-top-color: rgba(255, 193, 7, 0.45); }
@supports (scrollbar-width: thin) {
  .wooai-messages {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 193, 7, 0.28) transparent;
  }
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  /* Lifted well above typical mobile menu bars / sticky footers
     (usually 56-90px tall). bottom:120px keeps the launcher clickable
     instead of hiding behind them. */
  #wooai-widget-root { bottom: 120px; }
  #wooai-widget-root.wooai-pos-right { right: 16px; }
  #wooai-widget-root.wooai-pos-left  { left: 16px; }
  .wooai-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 190px);
    max-height: calc(100vh - 190px);
    bottom: 130px;
    border-radius: 20px;
  }
}
