/* ============================================================
   chat.css — チャット型査定フォーム UI(LLM不使用)

   参考にした構造(store.tamagokichi.com のチャットLP):
     1. 挨拶の吹き出しが順に流れ、その続きに選択タイルが出る
     2. 操作エリアを画面下部に固定しない。通常フローに置き、
        その下に大きな余白を作る
        → キーボード・ブラウザUI・ホームバーと物理的に被りようがない。
          これが最も堅牢な解決策なので visualViewport 制御はしていない
     3. 入力欄は白いカードの中。ラベル + 入力の組を縦に積む
     4. 「次へ」は未入力のあいだ非活性色。押せるかどうかが色で分かる

   弊社仕様:
     - 枠は max-width 480px(既存 .lp と同一)。PCでもスマホ幅で中央に出る
     - 緑は既存LPのCTAと同じ #3ecb5e→#1caf41(--chat-green-1/2)
     - 緑地の白文字はコントラストが 3:1 に届かないため text-shadow で
       輪郭を補う(docs/marketing/lp/design_principles.md §4 視認性最優先)
     - 文字は18px以上、タップ領域は最低48px
       (同 §4「60-70代の視認性最優先」)
   ============================================================ */

/* ── オーバーレイ(スクロールはここが担当) ───────────── */
.chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;

  /* contain だと iOS Safari で下端到達時に背景へスクロールが伝播し、
     その拍子に fixed のこの要素がずれて下端からLPが覗く(2026-08-12 実機)。
     none で伝播を完全に切る。JS側の背景ロックとの二重防御。 */
  overscroll-behavior: none;

  /* iOS はアドレスバーの伸縮で visual viewport が縮むが、fixed の
     inset:0 は縮まない側(レイアウトビューポート)基準で描画がずれる。
     dvh で実表示領域に追従させる。未対応ブラウザは上の 100% を使う。 */
  height: 100%;
  height: 100dvh;

  background: #f5f5f5; /* 既存 body と同色 */
  font-family: inherit;

  /* ヘッダーと物件種別タイルの緑。既存LPのCTAと同じ #3ecb5e→#1caf41。
     2026-07-30、柔らかめの緑を2案比較したが締まりが無くなるため元の緑で確定。
     変えるときはこの4つだけ差し替えれば全体に効く。 */
  --chat-green-1: #3ecb5e;
  --chat-green-2: #1caf41;
  --chat-green-ink: #1caf41;
  --chat-green-glow: rgba(28, 175, 65, 0.32);
}

.chat-overlay[hidden] {
  display: none;
}

/* PCでもスマホ幅を維持。既存 .lp と同じ 480px / 白 / 影 */
.chat-frame {
  width: 100%;
  max-width: 480px;
  min-height: 100%;
  margin: 0 auto;
  background: #eef1f4;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* ── ヘッダー(枠内で sticky) ───────────────────── */
.chat-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(
    180deg,
    var(--chat-green-1) 0%,
    var(--chat-green-2) 100%
  );
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

/* 「戻る」ボタンを置かないので左寄せ(右の × とのバランスを取る) */
.chat-header-title {
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 2px;
}

.chat-header-name {
  display: block;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.3;
}

.chat-header-sub {
  display: block;
  margin-top: 1px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  opacity: 0.92;
}

.chat-iconbtn {
  flex: 0 0 auto;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.16);
  border: 0;
  border-radius: 22px;
  color: #ffffff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chat-iconbtn--close {
  font-size: 22px;
  font-weight: 700;
}

.chat-iconbtn:active {
  background: rgba(255, 255, 255, 0.32);
}

.chat-iconbtn[hidden] {
  display: none;
}

/* 残り項目数。参考LPは進捗バーを持たないので細い帯にはせず文字だけ */
.chat-remain {
  display: block;
  padding: 7px 14px;
  background: #ffffff;
  border-bottom: 1px solid #e2e6e9;
  color: var(--chat-green-ink);
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  letter-spacing: 0.02em;
}

.chat-remain[hidden] {
  display: none;
}

/* ── 物件種別タイル ────────────────────────────
   挨拶の吹き出しから地続きに見せたいので、第1問を全面ブランドカラーには
   しない。背景はチャットのグレーのまま、ボタンだけを緑にする。 */
.chat-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin: 4px 0 16px;
}

/* タイルは「押せるボタン」に見せる。下辺に厚みを持たせ、押すと沈ませる。 */
.chat-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 112px;
  padding: 16px 8px;
  background: linear-gradient(
    180deg,
    var(--chat-green-1) 0%,
    var(--chat-green-2) 100%
  );
  border: 0;
  border-bottom: 4px solid rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  color: #ffffff;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--chat-green-glow);
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.1s ease,
    border-bottom-width 0.1s ease,
    box-shadow 0.1s ease;
}

.chat-tile:active {
  transform: translateY(3px);
  border-bottom-width: 1px;
  box-shadow: 0 1px 4px var(--chat-green-glow);
}

/* 押せることを示す矢印(参考LPの「その他 ›」と同じ記号を流用) */
.chat-tile::after {
  content: "›";
  position: absolute;
  right: 11px;
  bottom: 4px;
  color: rgba(255, 255, 255, 0.88);
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

/* アイコンは白い丸地に載せる。緑のボタン上でも輪郭が立つ */
.chat-tile-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.chat-tile-icon svg {
  width: 27px;
  height: 27px;
  fill: var(--chat-green-2);
}

.chat-tile span {
  font-size: 21px;
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: 0.01em;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.26);
}

/* 白地に落ちた未選択タイルは影が不要(むしろ読みにくくなる) */
.chat-tiles.is-decided .chat-tile span {
  text-shadow: none;
}

.chat-tiles.is-decided .chat-tile.is-selected span {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.26);
}

/* 「その他」は性質が違うので横幅いっぱいの1枚にする */
.chat-tile--wide {
  grid-column: 1 / -1;
  flex-direction: row;
  gap: 12px;
  min-height: 72px;
  padding: 12px 16px;
}

.chat-tile--wide .chat-tile-icon {
  width: 40px;
  height: 40px;
}

.chat-tile--wide .chat-tile-icon svg {
  width: 22px;
  height: 22px;
}

/* 選択後もタイルは消さない。選択中だけを緑のまま残し、他は白地に落とす。
   押し直せばその場で選び直せる(あとから直せることを見た目で示す)。 */
.chat-tiles.is-decided .chat-tile {
  background: #ffffff;
  border-bottom-color: rgba(0, 0, 0, 0.1);
  color: #46544b;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.chat-tiles.is-decided .chat-tile-icon {
  background: #eaf9ee;
}

.chat-tiles.is-decided .chat-tile::after {
  color: #a6b8ac;
}

.chat-tiles.is-decided .chat-tile.is-selected {
  background: linear-gradient(
    180deg,
    var(--chat-green-1) 0%,
    var(--chat-green-2) 100%
  );
  border-bottom-color: rgba(0, 0, 0, 0.18);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--chat-green-glow);
}

.chat-tiles.is-decided .chat-tile.is-selected .chat-tile-icon {
  background: #ffffff;
}

.chat-tiles.is-decided .chat-tile.is-selected::after {
  content: "✓";
  color: #ffffff;
  font-size: 15px;
  bottom: 6px;
}

/* ── 冒頭の買取実績(チャット用に組み直したもの) ─────────────
   LPのセクションをそのまま貼るとチャットの中で異物になるため、
   中身だけをLP本体から読み取ってここで組み直している。
   ・縦を食わないよう横スワイプ(1件140px)にして件数を出す
   ・情報は 地域 / 築年数 / 買取価格 の3つに絞る(駅徒歩は落とす)
   ・カードの質感は入力カード(.chat-card)と揃えて会話に馴染ませる
   狙い: LP封印モード(chatf)では利用者がLPの信頼要素を一切見ないため、
         「実在する会社が実際に買っている」を会話の最初に置いて穴を埋める。 */
.chat-record {
  margin: -2px 0 16px;
}

/* 見出しは画像1枚(chat-record-banner.webp)。
   キラキラ・白縁・オレンジ強調はCSSでは再現しきれないため、
   既存LPの見出しと同じく画像化している。文言を変えるときは
   買取再販/ops/creative-src/prompts/image-prompts.ts の
   chat-record-banner を直して再生成する。 */
.chat-record-label {
  margin: 0 0 8px;
}

.chat-record-label img {
  display: block;
  width: 100%;
  height: auto;
}

/* 横スワイプ。右端に次のカードを覗かせてスワイプできることを伝える */
.chat-record-track {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding: 2px 12px 6px 0;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chat-record-track::-webkit-scrollbar {
  display: none;
}

.chat-record-card {
  flex: 0 0 140px;
  scroll-snap-align: start;
  overflow: hidden;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.chat-record-figure {
  position: relative;
  line-height: 0;
}

.chat-record-figure img {
  display: block;
  width: 100%;
  height: 94px;
  object-fit: cover;
}

.chat-record-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 3px 7px;
  background: #d32f2f;
  border-radius: 4px;
  color: #ffffff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

.chat-record-place {
  margin: 9px 0 0;
  color: #6b7a83;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
}

.chat-record-place strong {
  display: block;
  margin-top: 1px;
  color: #1e5a8e;
  font-size: 16px;
  font-weight: 900;
}

.chat-record-age {
  margin: 5px 0 0;
  color: #6b7a83;
  font-size: 12px;
  font-weight: 700;
}

.chat-record-price {
  margin: 6px 0 11px;
  color: #4a5a63;
  font-size: 12px;
  font-weight: 700;
}

.chat-record-price strong {
  color: #d32f2f;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.chat-record-hint {
  margin: 2px 0 0;
  color: #8b979e;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* ── 吹き出し ──────────────────────────────── */
.chat-messages {
  padding: 16px 12px 4px;
}

.chat-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
  animation: chat-in 0.26s ease both;
}

.chat-row--me {
  flex-direction: row-reverse;
}

@keyframes chat-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-row {
    animation: none;
  }
  .chat-next--pulse {
    animation: none;
  }
}

/* 担当者アイコン。既存 sec5 の女性スタッフと同一人物の顔アップを使う
   (LPを読んだ人が「さっきの人だ」と認識できるほうが信頼が積み上がる)。
   background-size / position で顔が円の中心に大きく収まるよう調整している。
   2026-07-30、ヘッドセットあり/なしを比較して「あり」を採用
   (44pxでもマイクが視認でき、いま応対している感が出る)。
   生成プロンプトは 買取再販/ops/creative-src/prompts/image-prompts.ts の
   chat-operator-a / -b に記録済み。 */
.chat-avatar {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background-color: #d9f0e1;
  background-image: url("images/chat-operator.webp");
  background-repeat: no-repeat;
  background-position: center 29%;
  background-size: 160%;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

/* 写真を使うので SVG は隠す(画像を外したいときの保険として残しておく) */
.chat-avatar svg {
  display: none;
  width: 30px;
  height: 30px;
  fill: #14853a;
}

.chat-row--me .chat-avatar {
  visibility: hidden;
}

.chat-bubble {
  max-width: 82%;
  padding: 14px 16px;
  border-radius: 13px;
  font-size: 20px;
  line-height: 1.6;
  word-break: break-word;
}

/* 参考LPは「白」ではなく地色のついた吹き出し + 黒文字。その質感を
   ブランドカラーの淡色で再現する(ベージュそのままだと緑のLPで浮くため)。 */
.chat-row--bot .chat-bubble {
  background: #dcefe1;
  border-top-left-radius: 4px;
  color: #26332a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
}

.chat-row--me .chat-bubble {
  background: linear-gradient(180deg, #3ecb5e 0%, #1caf41 100%);
  border-top-right-radius: 4px;
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 2px 6px rgba(28, 175, 65, 0.28);
}

.chat-bubble strong {
  color: #0f7a2c;
  font-weight: 900;
}

.chat-row--me .chat-bubble strong {
  color: #ffffff;
}

.chat-bubble-note {
  display: block;
  margin-top: 6px;
  color: #4a5a4e;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.6;
}

.chat-echo {
  display: block;
  margin: 9px 0 3px;
  padding: 10px 12px;
  background: #f2faf4;
  border: 2px dashed #1caf41;
  border-radius: 10px;
  color: #0f7a2c;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-align: center;
}

/* タイピング演出 */
.chat-typing {
  display: flex;
  gap: 5px;
  padding: 4px 2px;
}

.chat-typing span {
  width: 9px;
  height: 9px;
  background: #b3bfc7;
  border-radius: 50%;
  animation: chat-dot 1s ease-in-out infinite;
}

.chat-typing span:nth-child(2) {
  animation-delay: 0.16s;
}

.chat-typing span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes chat-dot {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* ── 入力カード ────────────────────────────────
   カードは回答後も消さず履歴として積む(上へスクロールすればどの項目でも
   その場で直せる)。並ぶので下に余白を持たせる。 */
.chat-card {
  margin: 4px 0 16px;
  padding: 15px 14px 14px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* 最終ブロック(備考 + 同意 + 送信) */
.chat-final {
  margin: 4px 0 16px;
}

.chat-final .chat-card {
  margin: 0;
}

/* 2カラム(ラベル左・入力右)。項目数が多い住所・連絡先で使う */
.chat-field {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.chat-field-label {
  color: #333333;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.35;
}

.chat-req,
.chat-opt {
  display: inline-block;
  margin-left: 3px;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 900;
  vertical-align: 1px;
}

.chat-req {
  background: #d32f2f;
  color: #ffffff;
}

.chat-opt {
  background: #eceff1;
  color: #6b7a83;
}

/* 1カラム(お名前のように単独項目のとき。参考LPと同じ大きめ表示) */
.chat-card-label {
  display: block;
  margin-bottom: 9px;
  color: #333333;
  font-size: 18px;
  font-weight: 900;
}

/* 入力欄。font-size は16px以上でないとiOSが自動ズームする */
.chat-input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  background: #fffdf0; /* 参考LPのクリーム地 */
  border: 1px solid #b9b9b9;
  border-radius: 8px;
  color: #222222;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.5;
  -webkit-appearance: none;
  appearance: none;
}

.chat-input--lg {
  min-height: 56px;
  padding: 13px 14px;
  font-size: 19px;
}

.chat-input::placeholder {
  color: #a9aeb2;
}

.chat-input:focus {
  background: #ffffff;
  border-color: #1caf41;
  outline: 0;
  box-shadow: 0 0 0 3px rgba(28, 175, 65, 0.22);
}

.chat-input--error {
  border-color: #d32f2f;
  background: #fff5f5;
}

select.chat-input {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%23555' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  padding-right: 32px;
}

textarea.chat-input {
  min-height: 84px;
  resize: vertical;
}

.chat-error {
  margin: -4px 0 10px;
  color: #c62828;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.5;
}

.chat-error[hidden] {
  display: none;
}

/* ── 次へ / 送信ボタン ─────────────────────────
   参考LPと同じく pill 形状。未入力のあいだは非活性色にして
   「押せる状態になった」ことを色で伝える。 */
.chat-next {
  display: block;
  width: 100%;
  min-height: 62px;
  margin: 14px 0 0;
  padding: 15px 20px;
  background: linear-gradient(180deg, #3ecb5e 0%, #1caf41 100%);
  border: 0;
  border-radius: 32px;
  color: #ffffff;
  font-family: inherit;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.3;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(28, 175, 65, 0.38);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.chat-next:active {
  transform: scale(0.985);
}

.chat-next:disabled {
  background: #c9cfd4;
  box-shadow: none;
  cursor: default;
}

/* 送信ボタンのぷよぷよ。LPのCTAボタン(.cta-form-btn)と動きを完全に揃えるため、
   keyframes は style.css の cta-form-btn-puyo をそのまま借りている
   (squash-and-stretch でゼリー感 / 1.4s ease-in-out)。
   ここで値を複製するとLP側を調整したときにズレるので、あえて共有する。
   ※ style.css 側の keyframes 名を変えるとこの動きも止まる(相互参照)
   同意チェックが入って押せる状態になったときだけ chat.js が付与する。 */
.chat-next--pulse {
  transform-origin: center;
  will-change: transform;
  animation: cta-form-btn-puyo 1.4s ease-in-out infinite;
}
/* タップ中は動きを止める(LP側の .cta-form-btn:active と同じ挙動) */
.chat-next--pulse:active {
  animation-play-state: paused;
  transform: scale(0.985);
}

/* ── 同意チェック(既存フォームの consent と同じ形式) ────────
   送信ボタンの直上に置く。label 全体をタップ領域にし、
   チェックボックス自体も 24px 確保する(指で外しやすい/入れやすい)。 */
.chat-consent-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  padding: 13px 14px;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chat-consent-check {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin: 1px 0 0;
  cursor: pointer;
  /* 既存フォームの .consent-checkbox と同色 */
  accent-color: #1e5a8e;
}

.chat-consent-text {
  color: #333333;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
}

/* プライバシーポリシー:リンクに見せず地の文に馴染ませる
   (「押して読む」導線に見えると同意チェックの手前で離脱するため)
   ※ リンク機能自体は残しているので、タップすれば従来どおり別タブで開く。
   既存フォームの .consent-label a と同じ扱いに揃えている。 */
.chat-consent-text a {
  color: inherit;
  font-weight: inherit;
  text-decoration: none;
}

/* ── 下部の余白 ───────────────────────────────
   参考LPと同じ狙い。ボタンの下に十分な空白を確保して、
   どのデバイス・ブラウザのUI(アドレスバー / ツールバー / ホームバー /
   ソフトキーボード)とも被らないようにする。
   固定配置に頼らないので、環境ごとの例外処理が不要になる。 */
.chat-tail {
  /* vh はアドレスバー非表示時の高さ基準なので実機では余白が過剰になる。
     dvh で実表示領域基準に。未対応ブラウザは上の vh を使う。 */
  height: 46vh;
  height: 46dvh;
  min-height: 260px;
}

/* ── 起動ボタン(必要になった場合用) ───────────────── */
.chat-launch {
  display: block;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  min-height: 66px;
  padding: 16px 20px;
  background: linear-gradient(180deg, #3ecb5e 0%, #1caf41 100%);
  border: 0;
  border-radius: 33px;
  color: #ffffff;
  font-family: inherit;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(28, 175, 65, 0.42);
}

/* ── ローカル確認モードの帯(本番では出ない) ───────────── */
.chat-devnote {
  padding: 6px 12px;
  background: #fff3cd;
  border-bottom: 1px solid #ffe08a;
  color: #7a5b00;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}
