/**
 * YOOAi — promotional floating assistant + modal
 */

:root {
  --yooai-fab-size: 56px;
  --yooai-brand: var(--yooadmin-brand-source, var(--yp-primary, var(--yooadmin-primary, #eda934)));
  --yooai-surface: #ffffff;
  --yooai-surface-2: #f8fafc;
  --yooai-border: rgba(15, 23, 42, 0.1);
  --yooai-text: #1f2937;
  --yooai-muted: #6b7280;
  --yooai-assistant-bg: color-mix(in srgb, var(--yooai-surface) 92%, var(--yooai-text) 8%);
  --yooai-user-bg: color-mix(in srgb, var(--yooai-brand) 11%, var(--yooai-surface));
  --yooai-shadow: 0 14px 40px rgba(15, 23, 42, 0.18);
}

html[data-yooadmin-studio-color-mode-effective='dark'],
html.yooadmin-studio-hub-html[data-yooadmin-studio-color-mode-effective='dark'] {
  --yooai-surface: #1a1d23;
  --yooai-surface-2: #1a1d23;
  --yooai-border: rgba(255, 255, 255, 0.08);
  --yooai-text: #e8edf4;
  --yooai-muted: #9aa3b2;
  --yooai-assistant-bg: color-mix(in srgb, var(--yooai-surface) 88%, #ffffff 12%);
  --yooai-user-bg: color-mix(in srgb, var(--yooai-brand) 14%, var(--yooai-surface));
  --yooai-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

/* —— Floating button —— */
.yooai-fab {
  position: fixed;
  inset-inline-end: 22px;
  inset-block-end: 22px;
  z-index: 1000100;
  width: var(--yooai-fab-size);
  height: var(--yooai-fab-size);
}

/* Per-user Arabic admin UI can flip before html[dir] is updated on first paint. */
html:not([dir="rtl"]) body.yooadmin-arabic-ui .yooai-fab {
  inset-inline-end: auto;
  inset-inline-start: 22px;
}

.yooai-fab.is-hidden,
.yooai-fab[hidden] {
  display: none !important;
}

.yooai-fab__trigger {
  position: relative;
  width: var(--yooai-fab-size);
  height: var(--yooai-fab-size);
  border: none;
  border-radius: 999px;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--yooai-brand) 72%, #fff) 0%,
    var(--yooai-brand) 55%,
    color-mix(in srgb, var(--yooai-brand) 82%, #000) 100%
  );
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--yooai-brand) 42%, transparent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.yooai-fab__trigger:hover,
.yooai-fab__trigger:focus {
  transform: translateY(-2px) scale(1.03);
  filter: brightness(1.04);
  outline: none;
  box-shadow: 0 14px 32px color-mix(in srgb, var(--yooai-brand) 50%, transparent);
}

.yooai-fab__trigger:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.yooai-fab__label {
  position: relative;
  z-index: 2;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  color: #fff;
}

.yooai-fab__pulse {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--yooai-brand);
  opacity: 0.45;
  animation: yooai-fab-pulse 2.2s ease-out infinite;
  z-index: 1;
  pointer-events: none;
}

@keyframes yooai-fab-pulse {
  0% {
    transform: scale(1);
    opacity: 0.5;
  }
  70% {
    transform: scale(1.55);
    opacity: 0;
  }
  100% {
    transform: scale(1.55);
    opacity: 0;
  }
}

.yooai-fab__dismiss {
  position: absolute;
  top: -6px;
  inset-inline-end: -6px;
  z-index: 3;
  width: 22px;
  height: 22px;
  border: 1px solid var(--yooai-border);
  border-radius: 999px;
  background: var(--yooai-surface);
  color: var(--yooai-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.yooai-fab__dismiss:hover,
.yooai-fab__dismiss:focus {
  color: var(--yooai-text);
  border-color: color-mix(in srgb, var(--yooai-brand) 45%, transparent);
  outline: none;
}

/* —— Modal —— */
.yooai-modal {
  position: fixed;
  inset: 0;
  z-index: 1000110;
  display: none;
  align-items: flex-end;
  justify-content: flex-start;
  padding-inline: 18px;
  padding-block-end: 92px;
  box-sizing: border-box;
}

.yooai-modal.is-open {
  display: flex;
}

.yooai-modal[hidden] {
  display: none !important;
}

.yooai-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 22, 0.42);
  backdrop-filter: blur(2px);
}

.yooai-modal__panel {
  position: relative;
  margin-inline-start: auto;
  width: min(420px, calc(100vw - 36px));
  max-height: min(640px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--yooai-surface);
  color: var(--yooai-text);
  border: 1px solid var(--yooai-border);
  border-radius: 16px;
  box-shadow: var(--yooai-shadow);
  overflow: hidden;
  animation: yooai-modal-in 0.28s ease;
}

@keyframes yooai-modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.yooai-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--yooai-border);
  background: var(--yooai-surface-2);
}

.yooai-modal__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.yooai-modal__logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #1a1a1a;
  background: linear-gradient(145deg, color-mix(in srgb, var(--yooai-brand) 72%, #fff) 0%, var(--yooai-brand) 100%);
  flex-shrink: 0;
}

.yooai-modal__title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.yooai-modal__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--yooai-text);
}

.yooai-modal__badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--yooai-brand);
  background: color-mix(in srgb, var(--yooai-brand) 12%, var(--yooai-surface));
  border: 1px solid color-mix(in srgb, var(--yooai-brand) 28%, transparent);
}

.yooai-modal__close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--yooai-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.yooai-modal__close:hover,
.yooai-modal__close:focus {
  background: color-mix(in srgb, var(--yooai-brand) 12%, var(--yooai-surface));
  color: var(--yooai-brand);
  outline: none;
}

.yooai-modal__close .dashicons {
  width: 18px;
  height: 18px;
  font-size: 18px;
}

.yooai-modal__messages {
  flex: 1;
  min-height: 220px;
  max-height: min(480px, calc(100vh - 200px));
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--yooai-surface);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--ysh-sidebar-scroll-thumb, rgba(15, 23, 42, 0.22)) transparent;
}

.yooai-modal__messages::-webkit-scrollbar {
  width: 8px;
}

.yooai-modal__messages::-webkit-scrollbar-track {
  background: transparent;
}

.yooai-modal__messages::-webkit-scrollbar-thumb {
  background-color: var(--ysh-sidebar-scroll-thumb, rgba(15, 23, 42, 0.22));
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

.yooai-modal__messages::-webkit-scrollbar-thumb:hover {
  background-color: var(--ysh-sidebar-scroll-thumb-hover, rgba(15, 23, 42, 0.32));
}

html[data-yooadmin-studio-color-mode-effective='dark'] .yooai-modal__messages,
html.yooadmin-studio-hub-html[data-yooadmin-studio-color-mode-effective='dark'] .yooai-modal__messages {
  scrollbar-color: var(--ysh-sidebar-scroll-thumb, rgba(255, 255, 255, 0.2)) transparent;
}

.yooai-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 92%;
}

.yooai-msg--assistant {
  align-self: flex-start;
}

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

.yooai-msg--system {
  align-self: center;
  max-width: 100%;
}

.yooai-msg__bubble {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--yooai-text);
}

.yooai-msg__bubble a.yooai-msg__link {
  color: var(--yooai-brand);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.18s ease;
}

.yooai-msg__bubble a.yooai-msg__link:hover,
.yooai-msg__bubble a.yooai-msg__link:focus {
  color: color-mix(in srgb, var(--yooai-brand) 72%, #fff 28%);
  outline: none;
}

.yooai-msg--assistant .yooai-msg__bubble {
  background: var(--yooai-assistant-bg);
  border: 1px solid var(--yooai-border);
  border-bottom-left-radius: 4px;
}

.yooai-msg--typing .yooai-msg__bubble {
  min-width: 52px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.yooai-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 10px;
}

.yooai-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--yooai-muted);
  animation: yooai-typing-dot 1.1s ease-in-out infinite;
}

.yooai-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.yooai-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes yooai-typing-dot {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.yooai-msg--user .yooai-msg__bubble {
  background: var(--yooai-user-bg);
  border: 1px solid color-mix(in srgb, var(--yooai-brand) 22%, transparent);
  border-bottom-right-radius: 4px;
}

.yooai-msg--system .yooai-msg__bubble {
  background: transparent;
  border: 1px dashed color-mix(in srgb, var(--yooai-brand) 35%, transparent);
  color: var(--yooai-muted);
  font-size: 12px;
  text-align: center;
}

.yooai-msg__meta {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--yooai-muted);
}

.yooai-msg--user .yooai-msg__meta {
  text-align: end;
}

body.yooai-modal-open {
  overflow: hidden;
}

@media (max-width: 600px) {
  .yooai-modal {
    padding-inline: 10px;
    padding-block-end: 84px;
    align-items: flex-end;
    justify-content: center;
  }

  .yooai-modal__panel {
    width: 100%;
    max-height: min(78vh, 640px);
    margin-inline: 0;
  }

  .yooai-fab {
    inset-inline-end: 14px;
    inset-block-end: 14px;
  }

  html:not([dir="rtl"]) body.yooadmin-arabic-ui .yooai-fab {
    inset-inline-end: auto;
    inset-inline-start: 14px;
  }
}

/* YOOAdmin standard toast (top-right) — used when FAB is hidden */
body.wp-admin .yp-toast-message.yooai-fab-hidden-toast:not(.ysh-layout-saved-toast) {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #fff;
  border-left: 4px solid var(--yp-brand, #eda934);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 12px 16px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  max-width: min(500px, calc(100vw - 40px));
  z-index: 100050;
  opacity: 0;
  transform: translateX(400px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  box-sizing: border-box;
  pointer-events: none;
}

body.wp-admin .yp-toast-message.yooai-fab-hidden-toast:not(.ysh-layout-saved-toast).yp-toast-show {
  opacity: 1;
  transform: translateX(0);
}

body.wp-admin .yp-toast-message.yooai-fab-hidden-toast:not(.ysh-layout-saved-toast) .yp-toast-icon {
  font-size: 18px;
  font-weight: bold;
  flex-shrink: 0;
  line-height: 1;
  color: var(--yp-brand, #eda934);
}

body.wp-admin .yp-toast-message.yooai-fab-hidden-toast:not(.ysh-layout-saved-toast) .yp-toast-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.4;
  color: #333;
}

html[data-yooadmin-studio-color-mode-effective='dark'] body.wp-admin .yp-toast-message.yooai-fab-hidden-toast:not(.ysh-layout-saved-toast),
html.yooadmin-studio-hub-html[data-yooadmin-studio-color-mode-effective='dark'] body.wp-admin .yp-toast-message.yooai-fab-hidden-toast:not(.ysh-layout-saved-toast) {
  background: var(--ysh-card, #1a1d23);
  color: var(--ysh-text, #e8edf4);
  box-shadow: var(--ysh-elev-2, 0 4px 16px rgba(0, 0, 0, 0.35));
}

html[data-yooadmin-studio-color-mode-effective='dark'] body.wp-admin .yp-toast-message.yooai-fab-hidden-toast:not(.ysh-layout-saved-toast) .yp-toast-text,
html.yooadmin-studio-hub-html[data-yooadmin-studio-color-mode-effective='dark'] body.wp-admin .yp-toast-message.yooai-fab-hidden-toast:not(.ysh-layout-saved-toast) .yp-toast-text {
  color: var(--ysh-text, #e8edf4);
}
