/* =========================================================================
   AIチャットボット (ai_chat.php / ai_faq.php)
   見た目は チャット画面に寄せる — 左に会話の一覧、 右にやりとり。
   狭い画面では 片方ずつ出す (data-view で切り替え)。
   ========================================================================= */
.aib-app {
  display: flex;
  flex-direction: column;
  gap: 0;
  /* 100vh は **仮想キーボードが出ても縮まない**。 そのままだと 画面より中身が高くなり、
     入力欄を見せようとブラウザが巻き上げて ヘッダが上へ飛ぶ。
     dvh は キーボードのぶん縮むので 巻き上げが起きない。 古い端末向けに vh も残す。 */
  height: calc(100vh - 116px);
  height: calc(100dvh - 116px);
  min-height: 380px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

/* ── やりとり ── */
.aib-main-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fff;
}
/* 見出しのロゴ (images/ai_icon.webp 1067x150)。 高さで揃えて 幅は比率なり */
.aib-logo { height: 22px; width: auto; max-width: 100%; display: block; flex: 0 1 auto; min-width: 0; }
.aib-faq-btn { flex: 0 0 auto; margin-left: auto; white-space: nowrap; }
@media (max-width: 420px) {
  .aib-logo { height: 18px; }
  .aib-faq-btn { padding: 4px 8px; font-size: 0.78rem; }
}

.aib-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px; }
.aib-msg { display: flex; margin-bottom: 10px; }
.aib-msg.is-user { justify-content: flex-end; }
.aib-bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.65;
  word-break: break-word;
  white-space: normal;
}
.aib-msg.is-user .aib-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.aib-msg.is-assistant .aib-bubble { background: #f0f3f6; color: var(--text); border-bottom-left-radius: 4px; }
/* 待っている間。 点滅させて 止まっていないことを見せる */
.aib-msg.is-waiting .aib-bubble { color: var(--text-muted); animation: aibBlink 1.2s ease-in-out infinite; }
@keyframes aibBlink { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) {
  .aib-msg.is-waiting .aib-bubble { animation: none; }
}

.aib-intro { max-width: 560px; margin: 10px auto; text-align: center; }
.aib-lead { margin: 0 0 6px; font-size: 1rem; }
.aib-note { margin: 0 0 18px; font-size: 0.82rem; color: var(--text-muted); line-height: 1.6; }
/* よくある質問のモーダル。 数が多いので 中だけ縦に送る */
.aib-faq-inner { max-width: 560px; display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.aib-faq-title { margin: 0 0 2px; font-size: 1.05rem; }
.aib-faq-lead2 { margin: 0 0 10px; font-size: 0.82rem; }
.aib-faq-body { overflow-y: auto; overscroll-behavior: contain; margin: 0 -4px; padding: 0 4px; }
.aib-faq-g {
  margin: 12px 0 6px; font-size: 0.78rem; font-weight: 700; color: #8a5a14;
  border-bottom: 1px solid var(--border); padding-bottom: 4px;
}
.aib-faq-g:first-child { margin-top: 0; }
/* 質問1つ。 押すとそのまま投げるので、 押せることが分かる形にする */
.aib-q {
  display: block; width: 100%; text-align: left;
  border: 1px solid var(--border); background: #fff; border-radius: 8px;
  padding: 9px 12px; margin-bottom: 5px;
  font-size: 0.86rem; font-family: inherit; line-height: 1.5; color: var(--text); cursor: pointer;
}
.aib-q:hover { background: #eef4fb; border-color: #bcd4ee; }
.aib-empty { max-width: 460px; margin: 30px auto; text-align: center; font-size: 0.9rem; line-height: 1.8; color: var(--text-muted); }

/* 入力欄は中身に合わせて伸びるが、 **ボタンは伸ばさない**。
   align-items:center にしないと ボタンが入力欄の高さまで引き伸ばされる */
.aib-form {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-top: 1px solid var(--border); background: #fff;
}
.aib-form textarea {
  flex: 1 1 auto; min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 0.92rem; line-height: 1.5;
  resize: none; max-height: 160px;
  /* 長い質問で上限に当たると 縦のバーが出る。
     Windows の Chrome/Edge は そこに ▲▼ のボタンを付けるので、
     細いつまみだけにして ボタンは出さない */
  overflow-y: auto;
  scrollbar-width: thin;                 /* Firefox */
  scrollbar-color: #c8ccd0 transparent;
}
.aib-form textarea::-webkit-scrollbar { width: 6px; }
.aib-form textarea::-webkit-scrollbar-button { display: none; height: 0; width: 0; }
.aib-form textarea::-webkit-scrollbar-track { background: transparent; }
.aib-form textarea::-webkit-scrollbar-thumb { background: #c8ccd0; border-radius: 3px; }
.aib-form textarea::-webkit-scrollbar-thumb:hover { background: #aeb4ba; }
/* チャット画面の送信ボタンと同じ形 (丸 + 紙飛行機)。 こちらは緑 */
.aib-send {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: #1b9e4b; color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.aib-send:hover { background: #17853f; }
.aib-send svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round;
}
.aib-send:disabled { background: #e8eaed; color: #9aa0a6; cursor: default; }
.aib-err { margin: 0 12px 10px; font-size: 0.85rem; }

@media (max-width: 760px) {
  .aib-app {
    height: calc(100vh - 104px);
    height: calc(100dvh - 104px);
    /* 最低の高さを外す。 残しておくと キーボードで画面が狭くなったとき
       ページが画面より高くなり、 ブラウザが入力欄を見せようと巻き上げて
       ヘッダが上へ飛ぶ。 低くなったら 会話のところが縮めばよい */
    min-height: 0;
    border-radius: 0; border-left: 0; border-right: 0;
  }
  .aib-bubble { max-width: 86%; }
}

/* ── よくある質問 (ai_faq.php) ── */
.aib-faq-item { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: #fff; }
.aib-faq-q {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  padding: 12px 14px; background: none; border: 0; cursor: pointer;
  font-family: inherit; font-size: 0.92rem; font-weight: 600; color: var(--text);
}
.aib-faq-q::after { content: '＋'; margin-left: auto; color: var(--text-muted); font-weight: normal; }
.aib-faq-item.is-open .aib-faq-q::after { content: '−'; }
.aib-faq-a { padding: 0 14px 14px; font-size: 0.88rem; line-height: 1.75; white-space: pre-wrap; }
.aib-faq-count {
  font-size: 0.72rem; font-weight: 700; color: #8a5a14;
  background: #fff4e0; border-radius: 9px; padding: 1px 7px;
}

/* 答えの中のリンク。 吹き出しの色に合わせる */
.aib-link { color: #1a56b0; text-decoration: underline; word-break: break-all; }
.aib-msg.is-assistant .aib-link:hover { color: #0d3b80; }
