/*
 * Mount anchor: viewport-fixed so inner UI is never clipped by page overflow.
 */
#stq-ai-assistant-root {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 0;
  height: 0;
  overflow: visible;
  z-index: 2147483000;
  pointer-events: none;
}

#stq-ai-assistant-root .stq-ai {
  pointer-events: auto;
  z-index: 10050 !important;
}

.stq-ai {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  z-index: 10040;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

/* --- Floating FAB (robot mascot) --- */
.stq-ai__fab {
  position: relative;
  width: 3.35rem;
  height: 3.35rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  background: linear-gradient(145deg, #fff 0%, #f0f4ff 38%, #e8f0ff 100%);
  box-shadow:
    0 4px 6px rgba(15, 23, 42, 0.06),
    0 14px 28px rgba(230, 138, 78, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.65) inset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s ease;
}

.stq-ai__fab:hover,
.stq-ai__fab:focus-visible {
  transform: translateY(-2px) scale(1.03);
  box-shadow:
    0 6px 10px rgba(15, 23, 42, 0.08),
    0 18px 36px rgba(230, 138, 78, 0.42),
    0 0 0 1px rgba(255, 255, 255, 0.8) inset;
}

.stq-ai__fab:active {
  transform: translateY(0) scale(0.96);
}

.stq-ai__fab:focus-visible,
.stq-ai__panel button:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 3px;
}

.stq-ai__fab-ring {
  position: absolute;
  inset: -5px;
  border-radius: inherit;
  border: 2px solid rgba(230, 138, 78, 0.35);
  opacity: 0;
  pointer-events: none;
  animation: stq-ai-fab-pulse 2.4s ease-out infinite;
}

.stq-ai__fab:hover .stq-ai__fab-ring,
.stq-ai__fab:focus-visible .stq-ai__fab-ring {
  opacity: 1;
}

.stq-ai__fab-face {
  position: relative;
  z-index: 1;
  width: 2.65rem;
  height: 2.65rem;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(180deg, #dbeafe 0%, #eff6ff 100%);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.12) inset;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: stq-ai-fab-breathe 3.2s ease-in-out infinite;
}

.stq-ai__fab-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 15%;
  pointer-events: none;
  display: none;
}

.stq-ai__fab-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  line-height: 1;
  pointer-events: none;
}

@keyframes stq-ai-fab-breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.035);
  }
}

@keyframes stq-ai-fab-pulse {
  0% {
    transform: scale(1);
    opacity: 0.55;
  }
  70%,
  100% {
    transform: scale(1.22);
    opacity: 0;
  }
}

/* --- Compact glass panel (desktop defaults) --- */
.stq-ai__panel {
  --stq-ai-kb: 0px;
  --stq-ai-vvh: 100vh;
  position: absolute;
  right: 0;
  bottom: calc(3.55rem + env(safe-area-inset-bottom, 0px) + var(--stq-ai-kb));
  width: min(18.5rem, calc(100vw - 1.5rem));
  max-height: min(38dvh, calc(var(--stq-ai-vvh, 100vh) * 0.42 - 2rem));
  display: flex;
  flex-direction: column;
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  background: rgba(255, 253, 251, 0.92);
  backdrop-filter: blur(16px) saturate(1.15);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
  border: 1px solid rgba(241, 223, 211, 0.78);
  border-radius: 1.1rem;
  box-shadow:
    0 2px 12px rgba(31, 20, 12, 0.06),
    0 14px 36px rgba(31, 20, 12, 0.1);
  overflow: hidden;
  transform-origin: bottom right;
  transform: translateY(12px) scale(0.94);
  filter: saturate(1.02);
  transition:
    opacity 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.26s ease,
    visibility 0s linear 0.26s;
}

.stq-ai__panel--open {
  visibility: visible;
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition:
    opacity 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.26s ease,
    visibility 0s;
}

.stq-ai__head {
  flex-shrink: 0;
  background: linear-gradient(135deg, rgba(255, 248, 242, 0.95) 0%, rgba(255, 255, 255, 0.88) 100%);
  border-bottom: 1px solid rgba(243, 229, 220, 0.9);
  padding: 0.55rem 0.65rem 0.55rem 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.stq-ai__head-main {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.stq-ai__avatar-wrap {
  position: relative;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
  background: linear-gradient(180deg, #dbeafe 0%, #eff6ff 100%);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.stq-ai__avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 15%;
  display: none;
}

.stq-ai__avatar-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.stq-ai__head-text {
  min-width: 0;
}

.stq-ai__title-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.stq-ai__title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: #4a2c18;
  letter-spacing: -0.01em;
}

.stq-ai__online {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.95);
  flex-shrink: 0;
}

.stq-ai__sub {
  margin: 0.08rem 0 0;
  font-size: 0.68rem;
  color: #8f715f;
  line-height: 1.25;
}

.stq-ai__close {
  border: 0;
  background: rgba(255, 255, 255, 0.75);
  color: #6b5346;
  border-radius: 999px;
  width: 1.85rem;
  height: 1.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.stq-ai__close:hover {
  background: #fff;
  color: #4a2c18;
}

/* Scroll region: grows; composer stays pinned for keyboard */
.stq-ai__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stq-ai__messages {
  flex: 1;
  min-height: 0;
  padding: 0.55rem 0.65rem 0.6rem;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  background: linear-gradient(180deg, rgba(255, 254, 252, 0.98) 0%, rgba(255, 250, 246, 0.95) 100%);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.stq-ai__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-bottom: 0.15rem;
}

.stq-ai__chip {
  border: 1px solid rgba(230, 200, 180, 0.95);
  background: rgba(255, 255, 255, 0.92);
  color: #5c3824;
  border-radius: 999px;
  padding: 0.32rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.stq-ai__chip:active {
  transform: scale(0.97);
}

.stq-ai__chip:hover {
  background: #fff8f2;
  border-color: #e68a4e;
  transform: translateY(-1px);
}

.stq-ai__msg {
  max-width: 88%;
  border-radius: 0.85rem;
  padding: 0.48rem 0.62rem;
  font-size: 0.82rem;
  line-height: 1.38;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.stq-ai__msg--welcome {
  max-width: 100%;
  padding: 0.55rem 0.68rem;
  background: linear-gradient(135deg, rgba(239, 246, 255, 0.9) 0%, rgba(255, 248, 242, 0.95) 100%);
  border: 1px solid rgba(219, 234, 254, 0.65);
  color: #3f2a1f;
}

.stq-ai__msg--assistant {
  align-self: flex-start;
  background: #f9efe8;
  color: #4d2f1d;
}

.stq-ai__msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, #e68a4e 0%, #d4783e 100%);
  color: #fff;
}

.stq-ai__typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.76rem;
  color: #7a6558;
  padding: 0.2rem 0;
}

.stq-ai__typing-label {
  font-weight: 500;
}

.stq-ai__typing-dots {
  display: inline-flex;
  gap: 0.12rem;
}

.stq-ai__typing-dots span {
  width: 0.28rem;
  height: 0.28rem;
  border-radius: 999px;
  background: #e68a4e;
  opacity: 0.35;
  animation: stq-ai-dot 1.14s ease-in-out infinite;
}

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

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

@keyframes stq-ai-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.stq-ai__row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.15rem;
  flex-wrap: wrap;
}

.stq-ai__choice {
  border: 1px solid #eed3c2;
  background: #fff;
  color: #72462b;
  border-radius: 0.55rem;
  padding: 0.38rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.stq-ai__choice--primary {
  background: linear-gradient(135deg, #e68a4e 0%, #d4783e 100%);
  border-color: #e68a4e;
  color: #fff;
}

.stq-ai__composer {
  flex-shrink: 0;
  border-top: 1px solid rgba(243, 229, 220, 0.95);
  background: rgba(255, 255, 255, 0.96);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.stq-ai__form {
  padding: 0.5rem 0.55rem;
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
}

.stq-ai__input {
  flex: 1;
  border: 1px solid #ead6c8;
  border-radius: 0.6rem;
  padding: 0.48rem 0.58rem;
  font-size: 0.8rem;
  min-width: 0;
  background: #fff;
}

.stq-ai__send {
  border: 0;
  border-radius: 0.6rem;
  background: linear-gradient(135deg, #e68a4e 0%, #d4783e 100%);
  color: #fff;
  padding: 0.48rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.stq-ai__send:active:not([disabled]) {
  transform: scale(0.97);
}

.stq-ai__send[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.stq-ai__note {
  font-size: 0.68rem;
  color: #8f715f;
  padding: 0 0.65rem 0.5rem;
  margin: 0;
  line-height: 1.35;
}

/* Hidden by default; desktop-only resize grip (see min-width: 641px) */
.stq-ai__resize {
  display: none;
}

@media (max-width: 640px) {
  .stq-ai {
    right: max(0.5rem, env(safe-area-inset-right, 0px));
    bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px));
  }

  .stq-ai__fab {
    width: 3.05rem;
    height: 3.05rem;
  }

  .stq-ai__fab-face {
    width: 2.35rem;
    height: 2.35rem;
  }

  /* Floating card: not edge-to-edge; sits above FAB with breathing room */
  .stq-ai__panel {
    --stq-ai-fab-stack: 3.45rem;
    width: min(22rem, 88vw, calc(100vw - 1.25rem));
    max-width: 90vw;
    right: 0;
    bottom: calc(var(--stq-ai-fab-stack) + 0.35rem + env(safe-area-inset-bottom, 0px) + var(--stq-ai-kb));
    max-height: min(
      44dvh,
      max(
        9.5rem,
        calc(var(--stq-ai-vvh, 100dvh) * 0.54 - var(--stq-ai-fab-stack) - env(safe-area-inset-bottom, 0px) - 0.65rem)
      )
    );
    border-radius: 1.05rem;
    box-shadow:
      0 2px 10px rgba(31, 20, 12, 0.05),
      0 10px 28px rgba(31, 20, 12, 0.09);
    background: rgba(255, 253, 251, 0.9);
  }

  .stq-ai__head {
    padding: 0.38rem 0.45rem 0.38rem 0.5rem;
    gap: 0.35rem;
  }

  .stq-ai__head-main {
    gap: 0.42rem;
  }

  .stq-ai__avatar-wrap {
    width: 2.05rem;
    height: 2.05rem;
  }

  .stq-ai__avatar-fallback {
    font-size: 0.95rem;
  }

  .stq-ai__title {
    font-size: 0.8rem;
  }

  .stq-ai__sub {
    margin: 0.04rem 0 0;
    font-size: 0.62rem;
    line-height: 1.2;
  }

  .stq-ai__online {
    width: 0.4rem;
    height: 0.4rem;
  }

  .stq-ai__close {
    width: 1.65rem;
    height: 1.65rem;
    font-size: 0.78rem;
  }

  .stq-ai__messages {
    padding: 0.38rem 0.45rem 0.42rem;
    gap: 0.3rem;
  }

  .stq-ai__chips {
    gap: 0.28rem;
    padding-bottom: 0.05rem;
  }

  .stq-ai__chip {
    padding: 0.24rem 0.45rem;
    font-size: 0.66rem;
  }

  .stq-ai__msg {
    font-size: 0.74rem;
    line-height: 1.32;
    padding: 0.34rem 0.48rem;
    border-radius: 0.75rem;
  }

  .stq-ai__typing {
    font-size: 0.68rem;
    gap: 0.28rem;
    padding: 0.12rem 0;
  }

  .stq-ai__choice {
    padding: 0.3rem 0.48rem;
    font-size: 0.7rem;
    border-radius: 0.48rem;
  }

  .stq-ai__composer {
    padding-bottom: max(0.2rem, env(safe-area-inset-bottom, 0px));
  }

  .stq-ai__form {
    padding: 0.32rem 0.4rem;
    gap: 0.32rem;
    align-items: center;
  }

  .stq-ai__input {
    border-radius: 999px;
    padding: 0.34rem 0.65rem;
    font-size: 0.78rem;
    min-height: 2.25rem;
    box-sizing: border-box;
  }

  .stq-ai__input::placeholder {
    color: #a8988c;
    opacity: 1;
  }

  .stq-ai__send {
    border-radius: 999px;
    padding: 0.32rem 0.52rem;
    font-size: 0.72rem;
    min-height: 2.25rem;
    box-sizing: border-box;
  }

  .stq-ai__note {
    font-size: 0.58rem;
    padding: 0 0.45rem 0.32rem;
    line-height: 1.28;
    opacity: 0.92;
  }

  .stq-ai__resize {
    display: none !important;
  }
}

@media (min-width: 641px) {
  .stq-ai__panel {
    max-height: min(48vh, calc(var(--stq-ai-vvh, 100vh) * 0.46 - 2rem));
  }

  .stq-ai__resize {
    display: block;
    position: absolute;
    right: 1px;
    bottom: 1px;
    width: 18px;
    height: 18px;
    z-index: 8;
    cursor: nwse-resize;
    touch-action: none;
    border-radius: 0.35rem 0 0.95rem 0;
    background: linear-gradient(
      135deg,
      transparent 0%,
      transparent 48%,
      rgba(230, 138, 78, 0.22) 48%,
      rgba(230, 138, 78, 0.22) 100%
    );
    box-shadow: -1px -1px 0 rgba(255, 255, 255, 0.5) inset;
  }

  .stq-ai__resize:hover {
    background: linear-gradient(
      135deg,
      transparent 0%,
      transparent 44%,
      rgba(230, 138, 78, 0.35) 44%,
      rgba(230, 138, 78, 0.35) 100%
    );
  }

  .stq-ai__panel--open .stq-ai__head {
    cursor: grab;
    user-select: none;
  }

  .stq-ai__panel--dragging .stq-ai__head {
    cursor: grabbing;
  }

  .stq-ai__panel--user-placed {
    transform-origin: top left;
  }

  .stq-ai__panel--user-placed.stq-ai__panel--open {
    transform: translate(0, 0) scale(1);
  }

  .stq-ai__panel--dragging {
    transition: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stq-ai__fab,
  .stq-ai__fab-face,
  .stq-ai__fab-ring {
    animation: none !important;
  }

  .stq-ai__panel {
    transform: translateY(6px);
    transition: opacity 0.16s ease, visibility 0s linear 0.16s;
  }

  .stq-ai__panel--open {
    transform: translateY(0);
    transition: opacity 0.16s ease, visibility 0s;
  }

  .stq-ai__panel--user-placed.stq-ai__panel--open {
    transform: translate(0, 0);
  }
}