/**
 * JDSL チャットボット スタイルシート
 * 
 * 責任：
 * - チャットUIのスタイリング
 * - レスポンシブ対応
 * - アニメーション
 * 
 * 原則：
 * - すべてのセレクターに chatbot- プレフィックス必須
 * - 既存CSSとの競合を完全回避
 * - z-index: 9999 で最前面表示
 * - KISS: シンプルな実装
 * 
 * 競合回避：
 * - .form-*, .step-*, .faq-* 等の既存クラスと競合しない
 * 
 * @version 1.0.0
 */

/* ========================================
   コンテナ（右下固定）
   ======================================== */

.chatbot-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
}

/* ========================================
   トグルボタン
   ======================================== */

.chatbot-toggle-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e3a8a, #4c1d95);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(30, 58, 138, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-toggle-button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(30, 58, 138, 0.4);
}

.chatbot-toggle-button:active {
  transform: scale(0.95);
}

.chatbot-icon {
  width: 28px;
  height: 28px;
}

/* ========================================
   チャットウィンドウ
   ======================================== */

.chatbot-window {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 1;
  transform: translateY(0);
}

.chatbot-window.chatbot-hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

/* ========================================
   ヘッダー
   ======================================== */

.chatbot-header {
  background: linear-gradient(135deg, #1e3a8a, #4c1d95);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chatbot-header-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chatbot-header-title strong {
  font-size: 16px;
  font-weight: 600;
}

.chatbot-status {
  font-size: 11px;
  opacity: 0.9;
  line-height: 1.3;
}

.chatbot-close-button {
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.chatbot-close-button:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* ========================================
   メッセージエリア
   ======================================== */

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #f9fafb;
}

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

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

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

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* ========================================
   メッセージバブル
   ======================================== */

.chatbot-message {
  display: flex;
  margin-bottom: 8px;
}

.chatbot-message-bot {
  justify-content: flex-start;
}

.chatbot-message-user {
  justify-content: flex-end;
}

.chatbot-message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-line;
}

.chatbot-message-bot .chatbot-message-bubble {
  background-color: #f3f4f6;
  color: #111827;
  border-bottom-left-radius: 4px;
}

.chatbot-message-user .chatbot-message-bubble {
  background-color: #1e3a8a;
  color: white;
  border-bottom-right-radius: 4px;
}

/* ========================================
   選択肢ボタン
   ======================================== */

.chatbot-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.chatbot-option-button {
  background: white;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: #111827;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.chatbot-option-button:hover {
  background: #f9fafb;
  border-color: #1e3a8a;
  transform: translateX(4px);
}

.chatbot-option-button:active {
  transform: translateX(2px);
}

.chatbot-back-option {
  background: white;
  border-color: #d1d5db;
  color: #6b7280;
  font-weight: 500;
}

.chatbot-back-option:hover {
  background: #f9fafb;
  border-color: #9ca3af;
  color: #374151;
  transform: translateX(-4px);
}

/* ========================================
   入力エリア
   ======================================== */

.chatbot-input-area {
  padding: 16px 20px;
  background: white;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
  /* フォームが長い場合でも下部が隠れないようスクロール可能にする */
  max-height: 55%;
  overflow-y: auto;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* ========================================
   質問フォーム
   ======================================== */

.chatbot-question-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chatbot-question-form.chatbot-message-enter {
  opacity: 0;
  transform: translateY(10px);
}

.chatbot-question-form.chatbot-message-visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.chatbot-question {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chatbot-question-label {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

.chatbot-select {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 16px;
  color: #111827;
  background: white;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.chatbot-select:hover {
  border-color: #d1d5db;
}

.chatbot-select:focus {
  outline: none;
  border-color: #1e3a8a;
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

.chatbot-select.chatbot-error {
  border-color: #ef4444;
}

/* ========================================
   最終フォーム
   ======================================== */

.chatbot-final-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chatbot-final-form.chatbot-message-enter {
  opacity: 0;
  transform: translateY(10px);
}

.chatbot-final-form.chatbot-message-visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.chatbot-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chatbot-form-label {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

.chatbot-required {
  color: #ef4444;
}

.chatbot-form-input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 16px;
  color: #111827;
  transition: border-color 0.2s ease;
}

.chatbot-form-input:hover {
  border-color: #d1d5db;
}

.chatbot-form-input:focus {
  outline: none;
  border-color: #1e3a8a;
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

.chatbot-form-input::placeholder {
  color: #9ca3af;
}

/* ========================================
   プライバシー同意
   ======================================== */

.chatbot-privacy {
  margin-top: 4px;
}

.chatbot-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: #6b7280;
  cursor: pointer;
}

.chatbot-checkbox-label input[type="checkbox"] {
  margin-top: 2px;
  cursor: pointer;
}

/* ========================================
   ボタンコンテナ
   ======================================== */

.chatbot-button-container {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  opacity: 1 !important;
  transform: none !important;
  /* 入力エリア内の最下部に常に表示 */
  position: sticky;
  bottom: 0;
  background: #fff;
  padding-top: 8px;
}

/* ========================================
   戻るボタン
   ======================================== */

.chatbot-back-button {
  flex: 1;
  padding: 12px 20px;
  background: white;
  color: #6b7280;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chatbot-back-button:hover {
  background: #f9fafb;
  border-color: #d1d5db;
  color: #374151;
}

.chatbot-back-button:active {
  transform: scale(0.98);
}

/* ========================================
   リダイレクトコンテナ
   ======================================== */

.chatbot-redirect-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chatbot-redirect-container.chatbot-message-enter {
  opacity: 0;
  transform: translateY(10px);
}

.chatbot-redirect-container.chatbot-message-visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* ========================================
   Pricingページへのリダイレクトボタン
   ======================================== */

.chatbot-redirect-button {
  width: 100%;
  padding: 16px 20px;
  background: linear-gradient(135deg, #059669, #10b981);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: block;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}

.chatbot-redirect-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(5, 150, 105, 0.4);
}

.chatbot-redirect-button:active {
  transform: translateY(0);
}

/* ========================================
   代替ボタン
   ======================================== */

.chatbot-alt-button {
  width: 100%;
  padding: 12px 20px;
  background: white;
  color: #6b7280;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chatbot-alt-button:hover {
  background: #f9fafb;
  border-color: #d1d5db;
  color: #374151;
}

.chatbot-alt-button:active {
  transform: scale(0.98);
}

/* ========================================
   送信ボタン
   ======================================== */

.chatbot-submit-button {
  flex: 2;
  padding: 12px 20px;
  background: linear-gradient(135deg, #1e3a8a, #4c1d95);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.2);
}

.chatbot-submit-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(30, 58, 138, 0.3);
}

.chatbot-submit-button:active {
  transform: translateY(0);
}

.chatbot-submit-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ========================================
   レスポンシブ対応（スマートフォン）
   ======================================== */

@media (max-width: 768px) {
  .chatbot-container {
    bottom: 0;
    right: 0;
    left: 0;
  }
  
  .chatbot-toggle-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
  }
  
  .chatbot-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  
  .chatbot-window.chatbot-hidden {
    transform: translateY(100vh);
  }
  
  .chatbot-message-bubble {
    max-width: 85%;
  }

  /* スマホ全画面時：入力エリアの高さを制御（ヘッダー+メッセージ分を差し引く） */
  .chatbot-input-area {
    max-height: 50vh;
  }
}

/* ========================================
   アニメーション
   ======================================== */

@keyframes chatbot-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-message-enter,
.chatbot-options.chatbot-message-enter {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.chatbot-message-visible {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

/* ========================================
   アクセシビリティ
   ======================================== */

.chatbot-toggle-button:focus,
.chatbot-close-button:focus,
.chatbot-option-button:focus,
.chatbot-submit-button:focus,
.chatbot-select:focus,
.chatbot-form-input:focus {
  outline: 2px solid #1e3a8a;
  outline-offset: 2px;
}

/* 高コントラストモード対応 */
@media (prefers-contrast: high) {
  .chatbot-toggle-button,
  .chatbot-submit-button {
    border: 2px solid white;
  }
  
  .chatbot-option-button {
    border-width: 3px;
  }
}

/* ダークモード対応（将来的な拡張用） */
@media (prefers-color-scheme: dark) {
  /* 必要に応じて実装 */
}

