/* =========================================================
   FAQチャットボット（js/chat-faq.js）の見た目

   ・文言は一切持ちません。表示する語はすべて js/chat-faq-data.js 側です。
   ・色はサイトに合わせて 紺（#08234a）／青（#1160c7）／白 の3色です。

   位置について
   ・起動ボタンとパネルは、どちらも position: fixed で別々に置いています。
     ひとつの入れ物にまとめて置くと、起動ボタンを左へ寄せたときに
     パネルまで一緒に左へ動き、狭い画面で画面外にはみ出すためです。
   ・ai-samurai.html には右下に「TOPへ戻る」（.ai-lp-totop）があります。
     そのページでは本体が .chat-faq-beside-totop を付けるので、
     起動ボタンを **その左どなりに、縦位置をそろえて** 置きます。
   ========================================================= */

/* 入れ物そのものは位置を持ちません（中の2つが個別に fixed です） */
.chat-faq {
  font-family: inherit;
}

/* ---------- 起動ボタン ---------- */

.chat-faq-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 61;
  width: 54px;
  height: 54px;
  border: none;
  border-radius: 50%;
  background: #1160c7;
  box-shadow: 0 8px 20px rgba(17, 96, 199, 0.3), 0 2px 6px rgba(8, 35, 74, 0.16);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background-color 0.15s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

/* chat-faq-data.js に launchLabel（例：チャットQ&A）があるときは、
   角丸の横長ボタンになります。すぐ右の「TOPへ戻る」は紺色の丸なので、
   形（角丸の横長 ↔ 丸）と色（青 ↔ 紺）の両方で見分けが付きます。 */
.chat-faq-launcher.is-labeled {
  width: auto;
  height: 36px;
  padding: 0 11px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid #08234a;
}

.chat-faq-launcher-text {
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  color: #fff;
  white-space: nowrap;
}

.chat-faq-launcher:hover {
  background: #0d4d9e;
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(17, 96, 199, 0.38);
}

.chat-faq-launcher:focus-visible {
  outline: 3px solid #5fa8f2;
  outline-offset: 2px;
}

/* 吹き出しのアイコン。文字ではなく図形なので、文言には数えません。 */
.chat-faq-launcher-icon {
  flex: none;
  width: 26px;
  height: 22px;
  border-radius: 8px 8px 8px 2px;
  background: #fff;
  position: relative;
}

.chat-faq-launcher-icon::before,
.chat-faq-launcher-icon::after {
  content: "";
  position: absolute;
  left: 6px;
  height: 2px;
  border-radius: 1px;
  background: #1160c7;
}

.chat-faq-launcher-icon::before { top: 7px; width: 14px; }
.chat-faq-launcher-icon::after  { top: 12px; width: 9px; }

/* 横長のときは、文字に合わせてアイコンも小さくします */
.chat-faq-launcher.is-labeled .chat-faq-launcher-icon {
  width: 15px;
  height: 13px;
  border-radius: 5px 5px 5px 2px;
}

.chat-faq-launcher.is-labeled .chat-faq-launcher-icon::before,
.chat-faq-launcher.is-labeled .chat-faq-launcher-icon::after {
  left: 3px;
  height: 1.5px;
}

.chat-faq-launcher.is-labeled .chat-faq-launcher-icon::before { top: 4px; width: 9px; }
.chat-faq-launcher.is-labeled .chat-faq-launcher-icon::after  { top: 7px; width: 6px; }

.chat-faq-launcher[aria-expanded="true"] .chat-faq-launcher-icon {
  border-radius: 50%;
}

.chat-faq-launcher.is-labeled[aria-expanded="true"] .chat-faq-launcher-icon {
  border-radius: 5px 5px 5px 2px;
}

/* ---------- パネル ---------- */

.chat-faq-panel {
  position: fixed;
  right: 20px;
  bottom: 68px;          /* 起動ボタン（20 + 36）の上に12px空けて置きます */
  z-index: 62;
  width: min(360px, calc(100vw - 40px));
  max-height: min(560px, calc(100vh - 92px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border: 1px solid #e2e7ec;
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(8, 35, 74, 0.22);
}

.chat-faq-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  /* ヘッダーは低く抑えます（会話の場所を優先） */
  padding: 6px 12px;
  background: #1160c7;
  color: #fff;
}

.chat-faq-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.chat-faq-close {
  flex: none;
  margin-left: auto;   /* データに title が無いときは×だけを右端に置きます */
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.chat-faq-close:hover { background: rgba(255, 255, 255, 0.3); }

/* ---------- 吹き出し ---------- */

.chat-faq-log {
  flex: 1 1 auto;
  min-height: 210px;
  overflow-y: auto;
  /* 中を最後までスクロールしても、背後のページに送りません */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* 新しい吹き出しの位置まで送る計算（js側の offsetTop）の基準になります */
  position: relative;
  padding: 14px 16px;
  background: #f4f7f9;
}

.chat-faq-bubble {
  max-width: 85%;
  margin: 0 0 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.7;
  border-radius: 14px;
  white-space: pre-wrap;   /* データ側の改行をそのまま活かします */
  overflow-wrap: anywhere;
}

.chat-faq-bubble-left {
  margin-right: auto;
  background: #fff;
  border: 1px solid #e2e7ec;
  border-bottom-left-radius: 4px;
  color: #1c2530;
}

.chat-faq-bubble-right {
  margin-left: auto;
  background: #1160c7;
  border-bottom-right-radius: 4px;
  color: #fff;
}

/* ---------- 選択肢 ---------- */

.chat-faq-choices {
  flex: 0 0 auto;
  max-height: 150px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  border-top: 1px solid #e2e7ec;
}

.chat-faq-choice {
  padding: 8px 12px;
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
  color: #123f7d;
  background: #fff;
  border: 1.5px solid #c6dbf5;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chat-faq-choice:hover {
  background: #eef5fd;
  border-color: #1160c7;
}

/* ---------- 足まわり（メール導線・最初に戻る） ---------- */

.chat-faq-foot {
  flex: 0 0 auto;
  padding: 8px 12px 10px;
  border-top: 1px solid #e2e7ec;
  background: #fff;
}

/* 説明文は折りたたみ。閉じているあいだは見出し1行ぶんしか場所を取りません。 */
.chat-faq-fallback-note {
  margin: 0 0 6px;
}

.chat-faq-fallback-note > summary {
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 700;
  color: #5b6675;
  list-style: none;
}

.chat-faq-fallback-note > summary::-webkit-details-marker {
  display: none;
}

.chat-faq-fallback-note > summary::before {
  content: "▸";
  margin-right: 4px;
  font-size: 10px;
}

.chat-faq-fallback-note[open] > summary::before {
  content: "▾";
}

.chat-faq-fallback-note > p {
  margin: 4px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: #5b6675;
}

.chat-faq-fallback-label {
  margin: 0 0 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: #5b6675;
}

/* ボタン2つは横並びにして、縦の場所を1段ぶんに抑えます */
.chat-faq-foot-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-faq-fallback-btn {
  flex: 1 1 auto;
  display: block;
  padding: 9px 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #1160c7;
  border-radius: 10px;
  text-decoration: none;
}

.chat-faq-fallback-btn:hover {
  background: #0d4d9e;
  text-decoration: none;
}

.chat-faq-back-btn {
  flex: 0 0 auto;
  display: block;
  padding: 8px 2px;
  font-size: 11.5px;
  white-space: nowrap;
  color: #5b6675;
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
}

.chat-faq-back-btn:hover { color: #1160c7; }

/* チャットが開いているあいだ、背後のページは動かしません。
   位置は js 側が body の top に入れて覚えます（iOS Safari 対策）。 */
body.chat-faq-locked {
  overflow: hidden;
}

/* ---------- スマートフォン ---------- */

@media (max-width: 480px) {
  .chat-faq-launcher {
    right: 12px;
    bottom: 12px;
    width: 46px;
    height: 46px;
  }

  .chat-faq-launcher.is-labeled {
    width: auto;
    height: 32px;
    padding: 0 9px;
    gap: 5px;
    border-radius: 9px;
  }

  .chat-faq-launcher.is-labeled .chat-faq-launcher-text {
    font-size: 11.5px;
  }

  .chat-faq-panel {
    right: 12px;
    bottom: 56px;
    width: min(360px, calc(100vw - 24px));
    max-height: calc(100vh - 80px);
  }
}

/* ---------- 「TOPへ戻る」ボタンがあるページ ----------

   ai-samurai.html だけにある .ai-lp-totop の **左どなり** に、
   縦位置をそろえて置きます（本体が .chat-faq-beside-totop を付けます）。
   ・701px以上：TOPは right:18px・bottom:24px・54px角
   ・700px以下：TOPは right:12px・bottom:86px・46px角
     （下部の固定ボタン .ai-lp-sticky を避けた位置）                     */

.chat-faq-beside-totop .chat-faq-launcher.is-labeled {
  /* 18(TOPの右余白) + 54(TOPの幅) + 12(すき間) */
  right: 84px;
  /* 24(TOPの下余白) + (54 - 36)/2 → 中心の高さをそろえます */
  bottom: 33px;
}

.chat-faq-beside-totop .chat-faq-panel {
  right: 18px;
  bottom: 81px;
  max-height: min(560px, calc(100vh - 105px));
}

@media (max-width: 700px) {
  .chat-faq-beside-totop .chat-faq-launcher.is-labeled {
    /* 12 + 46 + 10 */
    right: 68px;
    /* 86 + (46 - 32)/2 */
    bottom: 93px;
    height: 32px;
    padding: 0 9px;
    gap: 5px;
    border-radius: 9px;
  }

  .chat-faq-beside-totop .chat-faq-launcher.is-labeled .chat-faq-launcher-text {
    font-size: 11.5px;
  }

  .chat-faq-beside-totop .chat-faq-panel {
    right: 12px;
    bottom: 137px;
    width: min(360px, calc(100vw - 24px));
    max-height: calc(100vh - 161px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-faq-launcher,
  .chat-faq-launcher:hover { transition: none; transform: none; }
}
