/**
 * 山本楽器 チャットボット - フロントエンドCSS
 * ユーザー向けチャットUI
 */

/* ============================================
   チャットボットラッパー
============================================ */
.yg-chatbot-wrapper {
  position: fixed;
  bottom: 80px;
  right: 10px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  @media screen and (min-width: 1280.1px) {
    bottom: 10px;
    right: 80px;
  }
}

/* ============================================
   チャットトリガーボタン（フローティング）
============================================ */
.yg-chatbot-trigger {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0066cc 0%, #0052a3 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(0, 102, 204, 0.4), 0 2px 4px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.yg-chatbot-trigger:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 102, 204, 0.5), 0 3px 6px rgba(0, 0, 0, 0.15);
}

.yg-chatbot-trigger:active {
  transform: scale(0.95);
}

.yg-chatbot-trigger-icon,
.yg-chatbot-trigger-close {
  width: 28px;
  height: 28px;
  color: white;
  transition: all 0.3s;
  position: absolute;
}

.yg-chatbot-trigger-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.yg-chatbot-trigger-close {
  opacity: 0;
  transform: rotate(90deg) scale(0);
}

/* チャット開いている時 */
.yg-chatbot-wrapper.is-open .yg-chatbot-trigger-icon {
  opacity: 0;
  transform: rotate(-90deg) scale(0);
}

.yg-chatbot-wrapper.is-open .yg-chatbot-trigger-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* ============================================
   チャットウィンドウ
============================================ */
.yg-chatbot-window {
  position: fixed;
  bottom: 100px;
  right: 20px;
  width: 400px;
  max-width: calc(100vw - 40px);
  height: 600px;
  max-height: calc(100vh - 140px);
  background: white;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.yg-chatbot-wrapper.is-open .yg-chatbot-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ============================================
   ヘッダー
============================================ */
.yg-chatbot-header {
  background: linear-gradient(135deg, #0066cc 0%, #0052a3 100%);
  color: white;
  padding: 16px 20px;
  border-radius: 16px 16px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.yg-chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.yg-chatbot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  padding: 4px;
  object-fit: cover;
}

.yg-chatbot-header-text {
  flex: 1;
}

.yg-chatbot-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.yg-chatbot-status {
  margin: 2px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}

.yg-chatbot-status-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.yg-chatbot-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.yg-chatbot-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.yg-chatbot-close svg {
  width: 18px;
  height: 18px;
  color: white;
}

/* ============================================
   メッセージエリア
============================================ */
.yg-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: linear-gradient(180deg, #f8fafb 0%, #ffffff 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.yg-chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.yg-chatbot-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.yg-chatbot-messages::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

.yg-chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

/* ============================================
   メッセージ
============================================ */
.yg-chatbot-message {
  display: flex;
  gap: 10px;
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ボットのメッセージ */
.yg-chatbot-message-bot {
  align-items: flex-start;
}

.yg-chatbot-message-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.yg-chatbot-message-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: white;
  padding: 3px;
  object-fit: cover;
}

.yg-chatbot-message-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.yg-chatbot-message-bubble {
  background: white;
  padding: 12px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  font-size: 14px;
  line-height: 1.6;
  color: #1e293b;
  max-width: 100%;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* ユーザーのメッセージ */
.yg-chatbot-message-user {
  justify-content: flex-end;
}

.yg-chatbot-message-user .yg-chatbot-message-bubble {
  background: linear-gradient(135deg, #0066cc 0%, #0052a3 100%);
  color: white;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
  margin-left: 42px;
}

/* エラーメッセージ */
.yg-chatbot-message-error .yg-chatbot-message-bubble {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  color: #991b1b;
  border: 1px solid #f87171;
}

/* ============================================
   提案質問（Quick Replies）
============================================ */
.yg-chatbot-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.yg-chatbot-quick-reply {
  background: white;
  border: 1px solid #e2e8f0;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: #0066cc;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.yg-chatbot-quick-reply:hover {
  background: linear-gradient(135deg, #ffd700 0%, #ffc300 100%);
  color: #1e293b;
  border-color: #ffd700;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(255, 215, 0, 0.3);
}

.yg-chatbot-quick-reply:active {
  transform: translateY(0);
}

/* ============================================
   参考URL
============================================ */
.yg-chatbot-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
}

.yg-chatbot-sources-title {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.yg-chatbot-sources-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.yg-chatbot-source-link {
  display: block;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.2s;
  font-size: 12px;
}

.yg-chatbot-source-link:hover {
  background: #fef3c7;
  border-color: #ffd700;
  transform: translateX(4px);
}

.yg-chatbot-source-title {
  font-weight: 600;
  color: #1e293b;
  display: block;
  margin-bottom: 2px;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
}

.yg-chatbot-source-url {
  color: #64748b;
  font-family: monospace;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

/* ============================================
   ローディング
============================================ */
.yg-chatbot-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: white;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  width: fit-content;
}

.yg-chatbot-loading-text {
  font-size: 14px;
  color: #64748b;
}

.yg-chatbot-loading-dots {
  display: flex;
  gap: 4px;
}

.yg-chatbot-loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #0066cc;
  animation: bounce 1.4s infinite ease-in-out both;
}

.yg-chatbot-loading-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.yg-chatbot-loading-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* ============================================
   入力エリア
============================================ */
.yg-chatbot-input-area {
  border-top: 1px solid #e2e8f0;
  padding: 16px;
  background: white;
  border-radius: 0 0 16px 16px;
  flex-shrink: 0;
}

.yg-chatbot-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.yg-chatbot-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
  font-family: inherit;
}

.yg-chatbot-input:focus {
  border-color: #0066cc;
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

.yg-chatbot-input:disabled {
  background: #f8fafc;
  cursor: not-allowed;
  opacity: 0.6;
}

.yg-chatbot-submit {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0066cc 0%, #0052a3 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.yg-chatbot-submit:hover:not(:disabled) {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
}

.yg-chatbot-submit:active:not(:disabled) {
  transform: scale(0.95);
}

.yg-chatbot-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.yg-chatbot-submit svg {
  width: 20px;
  height: 20px;
  color: white;
}

.yg-chatbot-hint {
  margin-top: 8px;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
}

/* ============================================
   レスポンシブ
============================================ */
@media (max-width: 480px) {
  .yg-chatbot-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .yg-chatbot-header {
    border-radius: 0;
  }

  .yg-chatbot-input-area {
    border-radius: 0;
  }

  .yg-chatbot-trigger {
    bottom: 16px;
    right: 16px;
  }
}

/* ============================================
   アクセシビリティ
============================================ */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
