/* ======================================
   SellSync — AI 도우미 (플로팅 채팅)
   우측 하단. 로그인 오버레이(z-index 100000) 아래에 두어 미로그인 시 가림.
   토스트(하단 우측)와 겹치지 않도록 FAB는 위쪽에 배치.
   ====================================== */

.ai-assistant-wrap {
  position: fixed;
  z-index: 99980;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(96px, calc(24px + env(safe-area-inset-bottom)));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: inherit;
  pointer-events: none;
}

.ai-assistant-wrap * {
  pointer-events: auto;
}

.ai-assistant-panel {
  display: none;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  max-height: min(520px, calc(100vh - 200px));
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  overflow: hidden;
  animation: ai-panel-in 0.22s ease;
}

.ai-assistant-wrap.is-open .ai-assistant-panel {
  display: flex;
}

@keyframes ai-panel-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ai-assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.ai-assistant-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.ai-assistant-title svg {
  flex-shrink: 0;
  color: var(--primary-light);
}

.ai-assistant-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--primary-alpha);
  color: var(--primary-light);
}

.ai-assistant-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.ai-assistant-close:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.ai-assistant-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
  max-height: 360px;
}

.ai-msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-primary);
}

.ai-msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg-bot {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
}

.ai-msg-bot strong {
  color: var(--primary-light);
  font-weight: 600;
}

.ai-assistant-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.ai-assistant-input {
  flex: 1;
  min-height: 40px;
  max-height: 100px;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  line-height: 1.45;
}

.ai-assistant-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-alpha);
}

.ai-assistant-send {
  flex-shrink: 0;
  align-self: flex-end;
  height: 40px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.ai-assistant-send:hover {
  background: var(--primary-dark);
}

.ai-assistant-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ai-assistant-fab {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: var(--radius-full);
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-md), 0 0 0 4px var(--primary-alpha);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.ai-assistant-fab:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-lg), 0 0 0 6px var(--primary-alpha-strong);
}

.ai-assistant-fab:active {
  transform: scale(0.98);
}

.ai-assistant-fab[aria-expanded="true"] {
  box-shadow: var(--shadow-md), 0 0 0 3px var(--border-strong);
}

.ai-assistant-hints {
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 0 4px 6px;
  line-height: 1.55;
}
.ai-assistant-hints .ai-hint-chip {
  display: inline-block;
  margin-right: 6px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(108, 99, 255, 0.14);
  border: 1px solid rgba(108, 99, 255, 0.35);
  color: var(--primary-light);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

/* 옮기기 · 숨기기 */
.ai-assistant-fab {
  touch-action: none;
}

.ai-assistant-wrap.is-dragging .ai-assistant-fab {
  cursor: grabbing;
  transform: scale(1.04);
}

.ai-assistant-wrap.is-hidden {
  display: none;
}

.ai-assistant-hide {
  position: absolute;
  right: -4px;
  bottom: 50px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 2;
}

.ai-assistant-wrap:hover .ai-assistant-hide,
.ai-assistant-hide:focus-visible {
  opacity: 1;
}

.ai-assistant-restore {
  position: fixed;
  right: 0;
  bottom: 120px;
  z-index: 99980;
  padding: 8px 6px;
  border: 1px solid var(--border-default);
  border-right: none;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  writing-mode: vertical-rl;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

@media (max-width: 768px) {
  .ai-assistant-wrap {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(88px, calc(16px + env(safe-area-inset-bottom)));
  }

  .ai-assistant-panel {
    width: calc(100vw - 24px);
    max-height: min(70vh, 560px);
  }
}
