/*
 * セイシル /chatbot/（page-chatbot.php）。元は THC の受け渡し（chatbot_handoff_seicil_20261120）の見本。
 * 相談チャットのページ（見本）。THC の /chatbot-b/pe/（第24弾 24-144・修正①〜③）と同じ見た目を、ふつうの CSS にしたもの。
 * 色はいちばん上の変数だけ替えれば、サイトの色に合わせられる。
 * ヘッダーの高さ（--header-h-sp / --header-h-pc）は、使うサイトのヘッダーの実際の高さに合わせる。
 */
:root {
  --chat-main: #3ba5b9; /* テーマの色（帯・自分の吹き出し・送信ボタン・線） */
  --chat-main-2: #3bb99c; /* 帯のグラデーションの右端 */
  --chat-soft: #eef8fa; /* 会話の背景 */
  --chat-link: #2f8a9c; /* 返事の中のリンク */
  --ink: #333; /* 文字 */
  --ink-sub: #777; /* 時刻・注意書き・パンくず */
  --ink-mute: #8a9293; /* 入力欄のヒント */
  --line: #cfd6d6; /* 線 */
  --fill: #f3f5f9; /* 入力欄の背景 */
  --page: #f4fafb; /* ページの背景 */
  --header-h-sp: 65px;
  --header-h-pc: 141px;
}

.chatbot-page {
  position: relative;
  overflow: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", sans-serif;
  letter-spacing: 0.04em;
}
.chatbot-page *,
.chatbot-page *::before,
.chatbot-page *::after {
  box-sizing: border-box;
}

/* 飾りの円（PC だけ） */
.chatbot-deco {
  position: absolute;
  pointer-events: none;
  display: none;
}

/* ---------- 並び ---------- */
/* SP・タブレット（1023px まで）：チャットの窓だけ。ページ名・パンくずは読み上げ用に残す */
.chatbot-side .chatbot-title-block {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.chatbot-intro {
  display: none;
}

/* ---------- チャットの窓 ---------- */
.chat-window {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: max(480px, calc(100dvh - var(--header-h-sp)));
  overflow: hidden;
  background: #fff;
}
@media (min-width: 768px) {
  .chat-window {
    height: max(480px, calc(100dvh - var(--header-h-pc)));
  }
}

.chat-head {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 12px;
  padding: 14px 20px 14px 18px;
  background: linear-gradient(to right, var(--chat-main), var(--chat-main-2));
}
.chat-head-icon {
  flex-shrink: 0;
  overflow: hidden;
  padding: 3px;
  border-radius: 50%;
  background: #fff;
}
.chat-head-icon img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
}
.chat-head-name {
  margin: 0;
  min-width: 0;
  font-size: 15px;
  line-height: 1.4;
  font-weight: 700;
  color: #fff;
}

.messages-container {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 14px;
  background: var(--chat-soft);
}
.chat-day {
  flex-shrink: 0;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 11px;
  line-height: 1.4;
  font-weight: 500;
  color: var(--ink-sub);
}
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.chat-input-row {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 8px;
  border-top: 1px solid var(--line);
}
.message-input {
  flex: 1;
  min-width: 0;
  padding: 12px 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--fill);
  font: inherit;
  font-size: 16px; /* SP で 16px 未満だと iPhone が拡大するため */
  line-height: 1.4;
  color: var(--ink);
}
.message-input::placeholder {
  color: var(--ink-mute);
}
.message-input:focus {
  border-color: var(--chat-main);
  outline: none;
}
.send-button {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--chat-main);
  cursor: pointer;
  transition: opacity 0.2s;
}
.send-button:hover {
  opacity: 0.8;
}
.send-button:disabled {
  cursor: default;
  opacity: 0.4;
}
.send-button img {
  display: block;
  width: 20px;
  height: 20px;
}
.chat-note {
  flex-shrink: 0;
  margin: 0;
  padding: 0 20px 12px;
  text-align: center;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-sub);
}

/* ---------- 吹き出し（chatMessage.js が作る） ---------- */
/* .message-item（.bot / .user）> .message-avatar ＋ .message-content（.message-bubble ＋ .message-timestamp） */
.chatbot-page .message-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.chatbot-page .message-item.user {
  justify-content: flex-end;
}
.chatbot-page .message-avatar.user {
  display: none; /* 自分のアイコン（「U」の丸）は出さない */
}
.chatbot-page .message-avatar.bot {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}
.chatbot-page .message-avatar-img {
  display: block;
  width: 100%;
  height: 100%;
}
.chatbot-page .message-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  max-width: calc(100% - 38px);
}
.chatbot-page .message-item.user .message-content {
  align-items: flex-end;
  max-width: 82%;
}
.chatbot-page .message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  /* text-wrap: pretty は使わない（iPhone の Safari で行が短く折れ、吹き出しの右に空白ができるため） */
}
.chatbot-page .message-bubble.bot {
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
  background: #fff;
  color: var(--ink);
}
.chatbot-page .message-bubble.user {
  border-top-right-radius: 4px;
  background: var(--chat-main);
  color: #fff;
}
.chatbot-page .message-bubble a {
  color: var(--chat-link);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.chatbot-page .message-timestamp {
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-sub);
}

/* 返事を待っている間：「回答を生成中」の文字の代わりに点を 3 つ */
.chatbot-page .streaming-text {
  position: relative;
  display: block;
  width: 36px;
  height: 8px;
  font-size: 0;
  animation: chatbot-typing 1.2s infinite ease-in-out;
}
.chatbot-page .streaming-text::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chat-main);
  box-shadow:
    14px 0 0 color-mix(in srgb, var(--chat-main) 60%, transparent),
    28px 0 0 color-mix(in srgb, var(--chat-main) 30%, transparent);
}
.chatbot-page .message-content:has(.streaming-text) .message-timestamp {
  display: none;
}
@keyframes chatbot-typing {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}
@media (prefers-reduced-motion: reduce) {
  .chatbot-page .streaming-text {
    animation: none;
  }
}

/* ---------- PC（1024px から） ---------- */
@media (min-width: 1024px) {
  .chatbot-deco {
    display: block;
  }
  .chatbot-deco.r {
    top: -50px;
    right: calc(50% - 840px);
    width: 520px;
    height: 520px;
  }
  .chatbot-deco.l {
    top: 480px;
    left: calc(50% - 860px);
    width: 360px;
    height: 360px;
  }
  /* 左：ページ名・パンくず・紹介（幅 420）／右：チャットの窓（幅 720）。ヘッダーのすぐ下から並べる */
  .chatbot-inner {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 40px;
    max-width: 1256px;
    margin: 0 auto;
    padding: 24px 20px 140px;
  }
  .chatbot-side {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 420px;
    padding-top: 40px;
  }
  .chatbot-side .chatbot-title-block {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
    display: flex;
    flex-direction: column;
    gap: 24px;
  }
  .chatbot-title {
    display: flex;
    flex-direction: column;
    gap: 20px;
  }
  .chatbot-title h1 {
    margin: 0;
    font-size: 38px;
    line-height: 1.2;
    font-weight: 400;
  }
  .chatbot-title .bar {
    display: block;
    width: 90px;
    height: 6px;
    background: var(--chat-main);
  }
  .chatbot-breadcrumb {
    display: flex;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 14px;
    line-height: 1.2;
  }
  .chatbot-breadcrumb a {
    color: var(--ink);
    text-decoration: none;
  }
  .chatbot-breadcrumb li + li::before {
    content: "›";
    margin-right: 10px;
    color: var(--ink);
  }
  .chatbot-breadcrumb [aria-current] {
    color: var(--ink-sub);
  }
  .chatbot-intro {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 22px;
    margin-top: 56px;
  }
  .chatbot-catch {
    margin: 0;
    font-size: 26px;
    line-height: 1.5;
    font-weight: 700;
  }
  .chatbot-lead {
    margin: 0;
    font-size: 16px;
    line-height: 1.8;
  }
  .chatbot-uses {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: #fff;
  }
  .chatbot-uses p {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
    font-weight: 700;
    color: var(--chat-main);
  }
  .chatbot-uses ul {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .chatbot-uses li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    line-height: 1.6;
  }
  .chatbot-uses li::before {
    content: "";
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chat-main);
  }

  /* 窓：ヘッダーの 24px 下から。高さ＝画面の高さ − ヘッダー − 上下 24px（520〜900px）。開いたときに窓全体が見える */
  .chat-window {
    flex: 1;
    max-width: 720px;
    height: clamp(520px, calc(100dvh - var(--header-h-pc) - 48px), 900px);
    border: 1px solid var(--line);
    border-radius: 26px;
    box-shadow: 0 8px 28px rgba(0, 51, 51, 0.14);
  }
  .chat-head {
    padding: 20px 28px;
  }
  .chat-head-icon img {
    width: 44px;
    height: 44px;
  }
  .chat-head-name {
    font-size: 19px;
  }
  .messages-container {
    padding: 28px;
  }
  .chat-input-row {
    padding: 16px 24px 10px;
  }
  .message-input {
    font-size: 14px;
  }
  .chatbot-page .message-avatar.bot {
    width: 34px;
    height: 34px;
  }
  .chatbot-page .message-content {
    max-width: min(552px, calc(100% - 44px));
  }
  .chatbot-page .message-item.user .message-content {
    max-width: 452px;
  }
  .chatbot-page .message-bubble {
    font-size: 15px;
  }
}

/* ---------- ヘッダー：下へスクロールで消え、上へスクロールで戻る（任意。THC 24-145 と同じ動き） ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  transition: transform 0.3s ease;
}
.site-header.is-hidden {
  transform: translateY(-100%);
}
@media (prefers-reduced-motion: reduce) {
  .site-header {
    transition: none;
  }
}
