/* ============================================================
   業務整理・AI活用診断Bot 専用CSS
   ------------------------------------------------------------
   すべてのルールを #diagnosisBotRoot 配下にスコープし、
   本番LP側の lp.css / style.css と競合しないようにしています。
   @keyframes 名も diagBot プレフィックスを付けて衝突を避けています。

   本番LPのHTML側では、診断Bot一式を以下のように
   ルート要素で囲ってから、このCSSを読み込んでください。

     <div id="diagnosisBotRoot" class="diagnosis-bot-root">
       ... (診断BotのHTMLブロック) ...
     </div>

   アバター画像は、CSSファイルの配置場所に依存するurl()の相対パス問題を
   避けるため、CSS背景画像ではなく<img>タグのsrc属性で表示します
   （diagnosis-bot.js が window.DIAGNOSIS_BOT_CONFIG.BOT_AVATAR_URL を
   HTMLドキュメント基準の相対パスとしてimg.srcに設定します）。
   このCSSでは <img class="bot-launcher-avatar/header-avatar/bot-avatar">
   の見た目（サイズ・円形・枠線など）のみを定義しています。
   ============================================================ */

/* === 右下固定Botアイコン ======================================= */
#diagnosisBotRoot .bot-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999990;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px 9px 9px;
  background: linear-gradient(135deg, #2563eb, #0891b2);
  border: none;
  border-radius: 999px;
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(37,99,235,.45), 0 0 0 1px rgba(255,255,255,.08) inset;
  transition: transform .18s ease, box-shadow .18s ease;
  animation: diagBotLauncherPulse 2.4s ease-in-out infinite;
}
#diagnosisBotRoot .bot-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 34px rgba(37,99,235,.55); }
@keyframes diagBotLauncherPulse {
  0%,100% { box-shadow: 0 8px 28px rgba(37,99,235,.45), 0 0 0 1px rgba(255,255,255,.08) inset; }
  50%      { box-shadow: 0 8px 28px rgba(37,99,235,.45), 0 0 0 8px rgba(37,99,235,.10); }
}
#diagnosisBotRoot .bot-launcher-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.5);
  flex-shrink: 0;
  box-sizing: border-box;
  background-color: rgba(255,255,255,.18);
  object-fit: cover;
  display: block;
}

/* === 初回吹き出し ============================================== */
#diagnosisBotRoot .bot-bubble {
  position: fixed;
  right: 20px;
  bottom: 88px;
  z-index: 999989;
  max-width: 220px;
  background: rgba(255,255,255,.97);
  color: #1e293b;
  padding: 12px 30px 12px 14px;
  border-radius: 16px 16px 4px 16px;
  font-size: 12.5px;
  line-height: 1.6;
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
#diagnosisBotRoot .bot-bubble.active { opacity: 1; transform: none; pointer-events: auto; cursor: pointer; }
#diagnosisBotRoot .bot-bubble-close {
  position: absolute;
  top: 2px; right: 4px;
  width: 22px; height: 22px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

/* === モーダルオーバーレイ ======================================= */
#diagnosisBotRoot .bot-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999995;
  background: rgba(2,6,20,.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#diagnosisBotRoot .bot-modal-overlay.active { display: flex; }

#diagnosisBotRoot .modal-close-btn {
  position: absolute;
  top: 10px; right: 12px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.14);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
#diagnosisBotRoot .modal-close-btn:hover { background: rgba(255,255,255,.26); }

/* === チャットカード (Glassmorphism) ============================= */
#diagnosisBotRoot .chat-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 448px;
  height: 92svh;
  max-height: 700px;
  display: flex;
  flex-direction: column;
  background: rgba(8, 16, 40, 0.80);
  backdrop-filter: blur(28px) saturate(1.5);
  -webkit-backdrop-filter: blur(28px) saturate(1.5);
  border: 1px solid rgba(59,130,246,.22);
  border-radius: 24px;
  overflow: hidden;
  animation: diagBotCardGlow 5s ease-in-out infinite;
}
@keyframes diagBotCardGlow {
  0%,100% { box-shadow: 0 40px 80px rgba(0,0,0,.55), 0 0 44px rgba(59,130,246,.12), 0 0 0 1px rgba(255,255,255,.05) inset; }
  50%      { box-shadow: 0 40px 80px rgba(0,0,0,.55), 0 0 70px rgba(59,130,246,.22), 0 0 0 1px rgba(255,255,255,.05) inset; }
}

/* === ヘッダー ================================================== */
#diagnosisBotRoot .chat-header {
  flex-shrink: 0;
  padding: 14px 40px 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, rgba(30,58,138,.92) 0%, rgba(7,89,133,.92) 100%);
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: relative;
}
#diagnosisBotRoot .chat-header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 3px,
    rgba(255,255,255,.012) 3px, rgba(255,255,255,.012) 6px
  );
  pointer-events: none;
}
#diagnosisBotRoot .header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.28);
  flex-shrink: 0;
  box-shadow: 0 0 20px rgba(59,130,246,.5);
  box-sizing: border-box;
  background-color: rgba(255,255,255,.15);
  object-fit: cover;
  display: block;
}
#diagnosisBotRoot .header-info { flex: 1; min-width: 0; }
#diagnosisBotRoot .header-title {
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
  letter-spacing: .04em;
  text-shadow: 0 0 18px rgba(96,165,250,.35);
}
#diagnosisBotRoot .header-sub {
  color: rgba(186,230,253,.82);
  font-size: 11px;
  margin-top: 2px;
}
#diagnosisBotRoot .header-right { flex-shrink: 0; text-align: right; }
#diagnosisBotRoot .status-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin-bottom: 6px;
}
#diagnosisBotRoot .status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 7px #34d399;
  animation: diagBotStatusPulse 2.2s ease-in-out infinite;
}
@keyframes diagBotStatusPulse { 0%,100%{opacity:1;} 50%{opacity:.45;} }
#diagnosisBotRoot .status-label { color: #86efac; font-size: 10px; font-weight: 500; }
#diagnosisBotRoot .prog-label { color: rgba(186,230,253,.65); font-size: 10px; margin-bottom: 3px; }
#diagnosisBotRoot .prog-track {
  width: 64px; height: 4px;
  background: rgba(255,255,255,.15);
  border-radius: 99px;
  overflow: hidden;
}
#diagnosisBotRoot .prog-fill {
  height: 100%;
  background: linear-gradient(90deg, #60a5fa, #22d3ee);
  border-radius: 99px;
  width: 0%;
  transition: width .5s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 0 8px rgba(34,211,238,.6);
}

/* === メッセージエリア ========================================== */
#diagnosisBotRoot .chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
}
#diagnosisBotRoot .chat-body::-webkit-scrollbar { width: 3px; }
#diagnosisBotRoot .chat-body::-webkit-scrollbar-thumb { background: rgba(96,165,250,.28); border-radius: 99px; }

#diagnosisBotRoot .msg-row-in {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: diagBotSlideL .38s cubic-bezier(.22,1,.36,1) both;
}
#diagnosisBotRoot .msg-row-out {
  display: flex;
  justify-content: flex-end;
  animation: diagBotSlideR .38s cubic-bezier(.22,1,.36,1) both;
}

@keyframes diagBotSlideL { from{opacity:0;transform:translateX(-18px);} to{opacity:1;transform:none;} }
@keyframes diagBotSlideR { from{opacity:0;transform:translateX(18px);}  to{opacity:1;transform:none;} }
@keyframes diagBotFadeUp { from{opacity:0;transform:translateY(10px);}  to{opacity:1;transform:none;} }

#diagnosisBotRoot .bot-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid rgba(59,130,246,.45);
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(59,130,246,.3);
  box-sizing: border-box;
  background-color: rgba(37,99,235,.55);
  object-fit: cover;
  display: block;
}

#diagnosisBotRoot .bubble-in {
  background: rgba(255,255,255,.97);
  color: #1e293b;
  border-radius: 18px 18px 18px 4px;
  padding: 11px 15px;
  font-size: 13.5px;
  line-height: 1.7;
  max-width: 78%;
  box-shadow: 0 3px 16px rgba(0,0,0,.18);
}
#diagnosisBotRoot .bubble-in strong { color: #1e40af; }

#diagnosisBotRoot .bubble-out {
  background: linear-gradient(135deg, #2563eb, #0891b2);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 11px 15px;
  font-size: 13.5px;
  line-height: 1.7;
  max-width: 78%;
  box-shadow: 0 3px 20px rgba(37,99,235,.4);
}

#diagnosisBotRoot .typing-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#diagnosisBotRoot .typing-bubble {
  background: rgba(255,255,255,.97);
  border-radius: 18px 18px 18px 4px;
  padding: 12px 16px;
  box-shadow: 0 3px 16px rgba(0,0,0,.18);
}
#diagnosisBotRoot .dots-wrap { display: flex; gap: 5px; align-items: center; height: 18px; }
#diagnosisBotRoot .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  animation: diagBotDotBounce .9s infinite ease-in-out;
}
#diagnosisBotRoot .dot:nth-child(1) { background: #93c5fd; }
#diagnosisBotRoot .dot:nth-child(2) { background: #60a5fa; animation-delay: .15s; }
#diagnosisBotRoot .dot:nth-child(3) { background: #3b82f6; animation-delay: .30s; }
@keyframes diagBotDotBounce { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-6px);} }

/* === フッター ================================================== */
#diagnosisBotRoot .chat-footer {
  flex-shrink: 0;
  padding: 12px 14px;
  background: rgba(4, 10, 28, 0.72);
  border-top: 1px solid rgba(59,130,246,.15);
  min-height: 56px;
  max-height: 46svh;
  overflow-y: auto;
}

#diagnosisBotRoot .choices-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: diagBotFadeUp .3s ease-out both;
}
#diagnosisBotRoot .choice-btn {
  width: 100%;
  text-align: left;
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: rgba(226,232,240,.90);
  background: rgba(30,58,138,.22);
  border: 1.5px solid rgba(59,130,246,.28);
  border-radius: 12px;
  cursor: pointer;
  transition: all .18s ease;
  position: relative;
  overflow: hidden;
}
#diagnosisBotRoot .choice-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(59,130,246,.12), rgba(34,211,238,.06));
  opacity: 0;
  transition: opacity .18s;
}
#diagnosisBotRoot .choice-btn:hover {
  background: rgba(37,99,235,.38);
  border-color: rgba(96,165,250,.55);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 5px 20px rgba(37,99,235,.25);
}
#diagnosisBotRoot .choice-btn:hover::before { opacity: 1; }
#diagnosisBotRoot .choice-btn:active { transform: translateY(0); }
#diagnosisBotRoot .choice-btn:disabled { opacity: .32; cursor: not-allowed; transform: none; box-shadow: none; }

/* 戻るボタン */
#diagnosisBotRoot .back-btn {
  width: 100%;
  padding: 10px;
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  color: rgba(226,232,240,.75);
  background: transparent;
  border: 1px solid rgba(148,163,184,.3);
  border-radius: 10px;
  cursor: pointer;
  transition: all .18s ease;
}
#diagnosisBotRoot .back-btn:hover { background: rgba(255,255,255,.06); color: #fff; }
#diagnosisBotRoot .back-btn:disabled { opacity: .4; cursor: not-allowed; }

/* フォーム */
#diagnosisBotRoot .form-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: diagBotFadeUp .3s ease-out both;
}
#diagnosisBotRoot .diagnosis-bot-input {
  width: 100%;
  padding: 11px 15px;
  font-size: 13px;
  font-family: inherit;
  color: #e2e8f0;
  background: rgba(12, 22, 50, 0.75);
  border: 1.5px solid rgba(59,130,246,.28);
  border-radius: 12px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
#diagnosisBotRoot .diagnosis-bot-input::placeholder { color: rgba(148,163,184,.45); }
#diagnosisBotRoot .diagnosis-bot-input:focus {
  border-color: rgba(96,165,250,.65);
  box-shadow: 0 0 0 3px rgba(59,130,246,.14);
}
#diagnosisBotRoot .form-textarea { resize: none; min-height: 60px; font-family: inherit; }

/* honeypot: 人間には見えない項目（スパムBot対策） */
#diagnosisBotRoot .hp-field { position: absolute; left: -9999px; top: -9999px; opacity: 0; height: 0; overflow: hidden; }

/* 個人情報に関する注意文 */
#diagnosisBotRoot .privacy-notice {
  font-size: 10.5px;
  color: rgba(251,191,36,.9);
  line-height: 1.6;
  background: rgba(251,191,36,.08);
  border: 1px solid rgba(251,191,36,.25);
  border-radius: 8px;
  padding: 8px 10px;
}
#diagnosisBotRoot .privacy-link { font-size: 11px; text-align: center; }
#diagnosisBotRoot .privacy-link a { color: #7dd3fc; text-decoration: underline; }

/* 同意チェックボックス */
#diagnosisBotRoot .consent-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11.5px;
  color: rgba(226,232,240,.85);
  line-height: 1.5;
  cursor: pointer;
}
#diagnosisBotRoot .consent-row input { margin-top: 2px; flex-shrink: 0; }

#diagnosisBotRoot .submit-btn {
  width: 100%;
  padding: 13px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: .04em;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0891b2);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all .2s ease;
  box-shadow: 0 4px 22px rgba(37,99,235,.38);
}
#diagnosisBotRoot .submit-btn:hover {
  background: linear-gradient(135deg, #1d4ed8, #0e7490);
  transform: translateY(-1px);
  box-shadow: 0 7px 28px rgba(37,99,235,.55);
}
#diagnosisBotRoot .submit-btn:active { transform: translateY(0); }
#diagnosisBotRoot .submit-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
#diagnosisBotRoot .form-error {
  color: #f87171;
  font-size: 11px;
  text-align: center;
  display: none;
  margin-top: 2px;
}

/* 送信前確認画面 */
#diagnosisBotRoot .confirm-wrap { display:flex; flex-direction:column; gap:10px; animation: diagBotFadeUp .3s ease-out both; }
#diagnosisBotRoot .confirm-title { font-size: 12.5px; color: rgba(226,232,240,.85); font-weight: 700; }
#diagnosisBotRoot .confirm-list { display:grid; grid-template-columns: 86px 1fr; gap: 6px 10px; font-size: 12px; color: rgba(226,232,240,.9); }
#diagnosisBotRoot .confirm-list dt { color: rgba(148,163,184,.75); }
#diagnosisBotRoot .confirm-list dd { word-break: break-word; }

/* 結果画面CTA */
#diagnosisBotRoot .result-cta-wrap { animation: diagBotFadeUp .3s ease-out both; }

/* === 送信中オーバーレイ ======================================== */
#diagnosisBotRoot .send-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#diagnosisBotRoot .send-overlay.active { display: flex; }
#diagnosisBotRoot .send-card {
  background: rgba(8, 18, 48, 0.94);
  border: 1px solid rgba(59,130,246,.32);
  border-radius: 22px;
  padding: 40px 44px;
  text-align: center;
  box-shadow: 0 0 70px rgba(37,99,235,.25), 0 24px 64px rgba(0,0,0,.45);
  width: 100%;
  max-width: 300px;
}
#diagnosisBotRoot .spinner-ring {
  position: relative;
  width: 64px; height: 64px;
  margin: 0 auto 20px;
}
#diagnosisBotRoot .spin         { animation: diagBotSpin .9s linear infinite; }
#diagnosisBotRoot .spin-reverse { animation: diagBotSpin .65s linear infinite reverse; }
@keyframes diagBotSpin { to { transform: rotate(360deg); } }
#diagnosisBotRoot .send-title { font-weight: 700; color: #e2e8f0; font-size: 15px; }
#diagnosisBotRoot .send-sub { color: rgba(148,163,184,.7); font-size: 11px; margin-top: 4px; }
#diagnosisBotRoot .send-dots { display: flex; justify-content: center; gap: 7px; margin-top: 18px; }
#diagnosisBotRoot .send-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  animation: diagBotDotBounce .9s infinite ease-in-out;
}
#diagnosisBotRoot .send-dot:nth-child(1) { background: #60a5fa; }
#diagnosisBotRoot .send-dot:nth-child(2) { background: #3b82f6; animation-delay:.15s; }
#diagnosisBotRoot .send-dot:nth-child(3) { background: #2563eb; animation-delay:.30s; }

/* === レスポンシブ (モバイル ≤768px) ==============================
   ★ キーボード対応の設計思想（既存ロジックを踏襲し、対象を
      document.body → .bot-modal-overlay に変更）:
      - モーダル表示中は .bot-modal-overlay をページ全体のスクロールコンテナとする
      - .chat-card の overflow を visible にして scrollIntoView() がオーバーレイまで届くようにする
      - input focus 時に overlay へ巨大な padding-bottom を付与 → 高さ増加 → スクロール可能
      - setTimeout で 150ms 待機後に scrollIntoView() → キーボード上に入力欄が表示される
      - blur 時に padding-bottom を除去してトップへ戻す
   ==============================================================*/
@media (max-width: 768px) {
  #diagnosisBotRoot .bot-modal-overlay.active {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #diagnosisBotRoot .chat-card {
    width: 100%;
    max-width: 100%;
    height: 100svh;
    max-height: none;
    border-radius: 0;
    border: none;
    animation: none;
    box-shadow: none;
    overflow: visible;
    transition: none;
  }
  #diagnosisBotRoot .chat-body { min-height: 0; }
  #diagnosisBotRoot .bubble-in, #diagnosisBotRoot .bubble-out { max-width: 85%; }
  #diagnosisBotRoot .form-wrap { padding-bottom: 20px; }
  /*
    ★ iOS Safari 自動ズーム防止: font-size < 16px の input にフォーカスすると
    ブラウザが拡大し、ビューポートが横にずれて横スクロールが発生する。
    16px にすることでズーム自体を抑止する（横スクロール解消の根本対策）。
  */
  #diagnosisBotRoot .diagnosis-bot-input { font-size: 16px; }

  #diagnosisBotRoot .bot-launcher { right: 12px; bottom: 12px; padding: 8px 14px 8px 8px; font-size: 12px; }
  #diagnosisBotRoot .bot-launcher-avatar { width: 30px; height: 30px; background-size: 30px 30px !important; }
  #diagnosisBotRoot .bot-bubble { right: 12px; bottom: 66px; max-width: 62vw; }
}
