:root {
  --ai-dock-width: clamp(320px, 28vw, 420px);
  --ai-dock-height: min(52dvh, 440px);
}
body.ai-docked { margin-inline-end: var(--ai-dock-width); }
.ai-launcher {
  position: fixed;
  z-index: 130;
  right: max(20px, env(safe-area-inset-right));
  top: max(18px, calc(env(safe-area-inset-top) + 12px));
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  margin: 0;
  padding: 0;
  appearance: none;
  border: 0;
  border-radius: 18px;
  background: transparent;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.ai-launcher img {
  display: block;
  width: 92px;
  height: 92px;
  pointer-events: none;
  filter: drop-shadow(0 3px 4px #2d18394d);
}

.ai-launcher.is-dragging { cursor: grabbing; }
.ai-docked .ai-launcher { visibility: hidden; }

.ai-welcome {
  position: fixed;
  z-index: 129;
  box-sizing: border-box;
  width: min(286px, calc(100% - 24px));
  padding: 13px 38px 13px 15px;
  border: 1px solid #dacbe5;
  border-radius: 13px;
  background: #fff;
  color: #352244;
  box-shadow: 0 6px 20px #321d4826;
}

.ai-welcome[hidden] { display: none; }

.ai-welcome::before {
  position: absolute;
  left: var(--ai-welcome-pointer);
  top: -5px;
  width: 9px;
  height: 9px;
  border: solid #dacbe5;
  border-width: 1px 0 0 1px;
  background: #fff;
  transform: translateX(-50%) rotate(45deg);
  content: "";
}

.ai-welcome[data-side="above"]::before {
  top: auto;
  bottom: -5px;
  transform: translateX(-50%) rotate(225deg);
}

.ai-welcome h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
}

.ai-welcome p {
  margin: 5px 0 10px;
  color: #53465f;
  font-size: 13px;
  line-height: 1.45;
}

.ai-welcome button {
  border: 0;
  cursor: pointer;
}

#ai-welcome-open {
  min-height: 34px;
  padding: 4px 11px;
  border-radius: 7px;
  background: #f0e6f4;
  color: #442a58;
  font-size: 13px;
  font-weight: 650;
}

#ai-welcome-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 7px;
  background: transparent;
  color: #554464;
  font-size: 21px;
  line-height: 1;
}

#ai-welcome-open:hover,
#ai-welcome-close:hover { background: #e9dbf0; }

@media (max-width: 1100px) {
  .ai-launcher {
    top: auto;
    right: max(14px, env(safe-area-inset-right));
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
    width: 84px;
    height: 84px;
  }
  .ai-launcher img { width: 80px; height: 80px; }
}

.ai-pet-launcher {
  --ai-pet-cycle: 40s;
  --ai-pet-range: 32px;
  --ai-pet-size: 92px;
  width: calc(var(--ai-pet-size) + 2 * var(--ai-pet-range) + 4px);
  pointer-events: none;
}

.ai-pet {
  position: relative;
  display: block;
  width: var(--ai-pet-size);
  height: var(--ai-pet-size);
  transform: translateX(var(--ai-pet-range));
  pointer-events: auto;
}

.ai-pet img,
.ai-pet-pose {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ai-pet-pose { opacity: 0; }

@media (max-width: 1100px) {
  .ai-pet-launcher {
    --ai-pet-range: 24px;
    --ai-pet-size: 80px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .ai-pet {
    animation: ai-pet-walk-route var(--ai-pet-cycle) linear infinite;
  }

  .ai-pet .ai-pet-sitting {
    transform-origin: 56% 94%;
    animation: ai-pet-seated var(--ai-pet-cycle) step-end infinite, ai-pet-breathe 3.2s ease-in-out infinite;
  }

  .ai-pet-pose {
    background: url("./assets/andrology-assistant-poses-20261118.png") no-repeat 0% 0%;
    background-size: 400% 100%;
    filter: drop-shadow(0 3px 4px #2d18394d);
    animation: ai-pet-poses var(--ai-pet-cycle) step-end infinite;
  }

  .ai-launcher:is(:hover, :focus-visible, .is-dragging)
  :is(.ai-pet, .ai-pet-sitting, .ai-pet-pose) {
    animation-play-state: paused;
  }

  @keyframes ai-pet-walk-route {
    0%, 70%, 90%, 100% { transform: translateX(var(--ai-pet-range)); }
    75%, 85% { transform: translateX(calc(-1 * var(--ai-pet-range))); }
  }

  @keyframes ai-pet-seated {
    0%, 90%, 100% { opacity: 1; }
    70% { opacity: 0; }
  }

  @keyframes ai-pet-breathe {
    0%, 100% { transform: rotate(-1.5deg) scaleY(.99); }
    50% { transform: translateY(-3px) rotate(1.5deg) scaleY(1.02); }
  }

  @keyframes ai-pet-poses {
    0%, 90%, 100% { opacity: 0; }
    70%, 73%, 85%, 88% { opacity: 1; background-position-x: 0%; }
    70.75%, 72.25%, 73.75%, 85.75%, 87.25%, 88.75% { background-position-x: 33.333333%; }
    71.5%, 74.5%, 86.5%, 89.5% { background-position-x: 66.666667%; }
    75% { background-position-x: 100%; }
    70%, 75% { transform: scaleX(1); }
    85% { transform: scaleX(-1); }
  }
}

.ai-pet-eyes-closed { opacity: 0; }

.ai-pet-sitting,
.ai-pet-drag {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ai-pet-drag {
  --drag-frame-a: 0%;
  --drag-frame-b: 33.333333%;
  --drag-frame-c: 66.666667%;
  --drag-frame-d: 33.333333%;
  visibility: hidden;
  background: url("./assets/andrology-assistant-poses-20261118.png") no-repeat var(--drag-frame-a) 0%;
  background-size: 400% 100%;
  filter: drop-shadow(0 3px 4px #2d18394d);
}

.ai-launcher.is-dragging[data-drag-direction] :is(.ai-pet-sitting, .ai-pet-pose) { visibility: hidden; }
.ai-launcher.is-dragging[data-drag-direction] .ai-pet-drag { visibility: visible; }
.ai-launcher[data-drag-direction="right"] .ai-pet-drag { transform: scaleX(-1); }

.ai-launcher:is([data-drag-direction="down"], [data-drag-direction="up"]) .ai-pet-drag {
  background-image: url("./assets/andrology-assistant-vertical-walk-20261119.png");
  --drag-frame-c: var(--drag-frame-a);
  --drag-frame-d: var(--drag-frame-b);
}

.ai-launcher[data-drag-direction="up"] .ai-pet-drag {
  --drag-frame-a: 66.666667%;
  --drag-frame-b: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  .ai-pet-eyes-open {
    --eyes-open-opacity: 1;
    --eyes-closed-opacity: 0;
  }

  .ai-pet-eyes-closed {
    --eyes-open-opacity: 0;
    --eyes-closed-opacity: 1;
  }

  .ai-pet :is(.ai-pet-eyes-open, .ai-pet-eyes-closed) {
    animation: ai-pet-blink 20s step-end infinite;
  }

  .ai-launcher.is-dragging[data-drag-direction] .ai-pet-drag {
    animation: ai-pet-drag-step 480ms step-end infinite;
  }

  @keyframes ai-pet-blink {
    0%, 19.7%, 37.7%, 69.7%, 95.7%, 100% { opacity: var(--eyes-open-opacity); }
    19%, 37%, 69%, 95% { opacity: var(--eyes-closed-opacity); }
  }

  @keyframes ai-pet-drag-step {
    0%, 100% { background-position-x: var(--drag-frame-a); }
    25% { background-position-x: var(--drag-frame-b); }
    50% { background-position-x: var(--drag-frame-c); }
    75% { background-position-x: var(--drag-frame-d); }
  }
}

.ai-drawer {
  position: fixed;
  z-index: 130;
  inset: 0 0 0 auto;
  margin: 0;
  padding: 0;
  width: var(--ai-dock-width);
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  border: 0;
  border-left: 1px solid #e3d8eb;
  border-radius: 0;
  background: #fff;
  color: #2c2037;
}
.ai-drawer-layout { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; height: 100%; }
.ai-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 13px 16px;
  background: #fff;
  border-bottom: 1px solid #e8dfee;
}
.ai-drawer-header h2 { margin: 0; font-size: 19px; }
.ai-drawer-header h2 span { display: block; }
.ai-drawer-header h2 span:last-child { margin-top: 2px; font-size: 14px; }
.ai-drawer-header > div { display: flex; align-items: center; gap: 8px; }
.ai-drawer-header button, .ai-form button, #ai-unlock {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 7px;
  background: #e7daef;
  color: #3f2551;
  font-weight: 600;
}
#ai-close { min-width: 36px; font-size: 22px; line-height: 1; }
.ai-access { grid-row: 2; margin: 0; padding: 12px 16px; background: #f8f4fa; color: #60536d; font-size: 13px; }
#ai-login-status { margin: 0 0 8px; }
#ai-login { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 8px; }
#ai-login[hidden] { display: none; }
#ai-login label { grid-column: 1 / -1; }
.ai-form textarea, #ai-password {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid #d6c8e0;
  border-radius: 7px;
  color: #2c2037;
  background: #fff;
  font: inherit;
}
#ai-empty, #ai-status { margin: 7px 0; font-size: 13px; color: #60536d; line-height: 1.5; }
.ai-conversation { grid-row: 3; display: flex; flex-direction: column; min-height: 0; padding: 0 16px; }
#ai-empty { margin-top: 16px; }
.ai-messages { overflow-y: auto; overscroll-behavior: contain; flex: 1; margin: 0; padding: 12px 0; list-style: none; }
.ai-bubble { width: fit-content; max-width: 93%; margin: 0 0 10px; padding: 8px 11px; border-radius: 10px; background: #f2edf6; }
.ai-bubble.ai-user { margin-left: auto; background: #e6d9f0; }
.ai-bubble strong { font-size: 12px; }
.ai-bubble p { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-size: 14px; }
.ai-form { grid-row: 4; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; padding: 10px 16px max(14px, env(safe-area-inset-bottom)); border-top: 1px solid #eee6f2; }
#ai-status { grid-column: 1 / -1; margin: 0; }
#ai-status:empty { display: none; }
.ai-context { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; font-size: 13px; color: #60536d; }
.ai-context input { margin: 0; accent-color: #442a58; }
.ai-form textarea { resize: vertical; max-height: 160px; }
.ai-form button, #ai-unlock { background: #442a58; color: #fff; }
.ai-form button:disabled, #ai-unlock:disabled { opacity: .55; }
@media (max-width: 1020px) {
  body.ai-docked { margin-inline-end: 0; padding-bottom: var(--ai-dock-height); }
  .ai-drawer {
    inset: auto 0 0 0;
    width: 100%;
    height: var(--ai-dock-height);
    border-top: 1px solid #e3d8eb;
    border-left: 0;
  }
  .ai-form textarea, #ai-password { font-size: 16px; }
}

#ai-context-state { grid-column: 1 / -1; color: #60536d; line-height: 1.4; }
#ai-context-state:empty { display: none; }

.ai-action-links { margin: 9px 0 0; padding-inline-start: 17px; }
.ai-action-links li + li { margin-block-start: 5px; }
.ai-action-links a { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
