/* =========================================================
   申し込みモーダル（STEP1 内容確認 → STEP2 入力 → STEP3 同意）

   ・対象は ai-samurai / ai-apply / 士業別5ページの相談・申し込みボタンです。
   ・マークアップは js/ai-modal.js がページ読み込み時に1つだけ生成します
     （7ページに同じHTMLを貼らずに済むようにしています）。
   ・色や角丸は既存の変数（css/ai-lp.css の :root）をそのまま使います。
     このファイルは ai-lp.css の後に読み込んでください。
   ========================================================= */

/* ---------- 配色（ダークテーマ） ----------
   2026-08-29：モーダルだけ黒背景に変更しました。サイト本体は白基調のままです。
   色をここでまとめて変数にしているので、明るい配色に戻したいときは
   この5行を差し替えるだけで済みます。 */
.ai-modal-overlay {
  --m-bg: #101a2c;          /* パネルの地。真っ黒ではなく紺寄りの黒 */
  --m-bg-soft: #1a2740;     /* カード・入力欄などの一段明るい地 */
  --m-line: #2c3b57;        /* 罫線 */
  --m-text: #f2f6fb;        /* 本文 */
  --m-text-mute: #a9b7cc;   /* 補助的な文字 */
}

/* モーダルの中のリンクは、サイト共通のリンク色（濃紺 #123f7d）だと
   黒い地の上でコントラストが1.4:1しか出ず読めません。
   ここでまとめて明るい色に上書きし、下線でリンクだと分かるようにしています。
   OSの配色設定（ライト／ダーク）には依存させず、常にこの色です。 */
.ai-modal-overlay a {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.ai-modal-overlay a:hover {
  color: var(--lp-sky, #7ccaff);
}

/* ---------- 背景の覆い ---------- */

.ai-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 10, 20, 0.72);
  overflow-y: auto;
}

/* hidden 属性が付いているあいだは出しません（display:flex に負けないよう明示） */
.ai-modal-overlay[hidden] {
  display: none;
}

/* ---------- ダイアログ本体 ---------- */

.ai-modal {
  width: 100%;
  max-width: 620px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  border-radius: var(--lp-r-l, 20px);
  background: var(--m-bg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.ai-modal-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 22px 12px;
  border-bottom: 1px solid var(--m-line);
}

.ai-modal-title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.4;
  color: var(--m-text);
}

.ai-modal-close {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--m-line);
  border-radius: 8px;
  background: var(--m-bg-soft);
  font-size: 18px;
  line-height: 1;
  color: var(--m-text);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.ai-modal-close:hover {
  border-color: var(--lp-sky, #7ccaff);
  background: rgba(124, 202, 255, 0.16);
}

/* ---------- 中身（ここだけスクロールします） ---------- */

.ai-modal-body {
  flex: 1;
  padding: 12px 22px 14px;
  overflow-y: auto;
}

.ai-modal-lead {
  margin: 0 0 14px;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--ink, #1c2530);
}

/* ---------- 1画面の中の3ブロック ---------- */

/* 2026-08-29：ステップ送りをやめ、1画面に3ブロックを縦に並べる形にしました。 */
.ai-modal-block + .ai-modal-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--m-line);
}

.ai-modal-h {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.4;
  color: var(--m-text);
}

/* 見出しの丸番号。ステップバーの代わりに順番を示します。 */
.ai-modal-h-no {
  flex: none;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--lp-blue, #1777f2);
  font-family: var(--mono, monospace);
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.ai-modal-note {
  margin: 0 0 6px;
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--m-text-mute);
}

.ai-modal-note.is-warn {
  font-weight: 700;
  color: #c0392b;
}

/* ---------- 選択中の内容カード ---------- */

.ai-modal-summary {
  display: grid;
  gap: 10px;
  margin: 0 0 10px;
  padding: 13px 14px;
  border: 1px solid var(--m-line);
  border-radius: var(--lp-r-m, 16px);
  background: var(--m-bg-soft);
}

.ai-modal-summary dl {
  display: grid;
  grid-template-columns: 5.5em minmax(0, 1fr);
  gap: 6px 12px;
  margin: 0;
}

.ai-modal-summary dt {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.9;
  color: var(--lp-sky, #7ccaff);
}

.ai-modal-summary dd {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.9;
  color: var(--m-text);
}

.ai-modal-summary dd.is-empty {
  font-weight: 400;
  color: var(--m-text-mute);
}

/* 選んだ士業ごとに「士業 ― プラン」を1行ずつ並べる一覧。
   2026-08-29：士業は複数選べるので、確認画面は1行1士業にしています。 */
.ai-modal-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.ai-modal-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--m-line);
}

.ai-modal-list li:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.ai-modal-list b {
  flex: none;
  min-width: 6.5em;
  font-size: 14px;
  font-weight: 700;
  color: var(--m-text);
}

/* 士業とプランのあいだの区切り。文字ではなく擬似要素で入れています。 */
.ai-modal-list b::after {
  content: "―";
  margin-left: 10px;
  color: var(--lp-sky, #7ccaff);
}

.ai-modal-list span {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--lp-sky, #7ccaff);
}

.ai-modal-list span.is-undecided {
  font-weight: 400;
  color: var(--m-text-mute);
}

/* 一覧の下に会社名などを続けるときの区切り */
.ai-modal-summary .ai-modal-list + dl {
  padding-top: 12px;
  border-top: 1px solid var(--m-line);
}

/* 士業ごとのプラン欄。士業チップの下に、選んだぶんだけ並びます。 */
.ai-modal-plans {
  display: grid;
  gap: 12px;
}

/* 確認表示のまま出すプラン欄は、一覧カードとの間に少し余白を取ります。 */
.ai-modal-summary + .ai-modal-note {
  margin-top: 12px;
}

.ai-modal-note + .ai-modal-plans {
  margin-bottom: 14px;
}

.ai-modal-pick-plan {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--m-line);
  border-radius: var(--lp-r-m, 16px);
  background: rgba(255, 255, 255, 0.04);
}

.ai-modal-pick-plan legend {
  margin-bottom: 7px;
  color: var(--lp-sky, #7ccaff);
}

/* 「内容を変更する」は文字幅ぶんだけにします（下部の主ボタンとは別扱い）。
   モーダルを低くするため、下部の主ボタンより一回り小さくしています。 */
.ai-modal-btn-edit {
  flex: none;
  padding: 9px 14px;
  font-size: 13px;
}

.ai-modal-lead.is-warn {
  font-weight: 700;
  color: #c0392b;
}

/* ---------- 選択チップ（比較表のものと同じ見た目） ---------- */

.ai-modal-pick {
  margin: 0 0 10px;
  padding: 0;
  border: 0;
}

.ai-modal-pick legend {
  width: 100%;
  padding: 0;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--m-text);
}

/* 2026-08-29：選択肢が6つになり2行に折り返すので、行間も gap で確保します
   （flex-wrap の折り返しは row-gap を指定しないと行が詰まって見えます）。
   長いラベルでも枠からはみ出さないよう、チップ側で折り返しを許可しています。 */
.ai-modal-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 6px;
  align-items: flex-start;
}

.ai-modal-chips label {
  margin: 0;
  cursor: pointer;
}

/* 画面には出さないが、キーボードでは選べるようにします（display:none は不可） */
.ai-modal-chips input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.ai-modal-chips span {
  display: inline-block;
  max-width: 100%;
  padding: 6px 13px;
  border: 1px solid #3a5a86;
  border-radius: 999px;
  background: rgba(124, 202, 255, 0.10);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.5;
  color: var(--m-text);
  transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.ai-modal-chips label:hover span {
  border-color: var(--lp-sky, #7ccaff);
  background: rgba(124, 202, 255, 0.20);
  color: #fff;
}

.ai-modal-chips input:checked + span {
  border-color: var(--lp-blue, #1777f2);
  background: var(--lp-blue, #1777f2);
  color: #fff;
}

.ai-modal-chips input:focus-visible + span {
  outline: 2px solid var(--lp-blue, #1777f2);
  outline-offset: 2px;
}

/* ---------- STEP2：入力欄 ---------- */

/* 2026-09-01：「その他」を選んだときだけ出る業種名の欄。
   チップの下に少し離して置きます（.ai-modal-field の見た目をそのまま使います）。 */
.ai-modal-otherind {
  margin: 10px 0 0;
}

.ai-modal-field {
  margin: 0 0 8px;
}

.ai-modal-field > label {
  display: block;
  margin-bottom: 4px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--m-text);
}

.ai-modal-req,
.ai-modal-any {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  vertical-align: 1px;
}

.ai-modal-req {
  background: #c0392b;
  color: #fff;
}

.ai-modal-any {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--m-line);
  color: var(--m-text-mute);
}

/* 入力欄の包み。右端のチェック印（::after）の位置の基準になります。 */
.ai-modal-input-wrap {
  position: relative;
}

/* 入力が完了した欄に出すチェック印。
   1行の入力欄は上下中央、テキストエリアは1行目の高さに合わせます。 */
.ai-modal-input-wrap::after {
  content: "✓";
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  color: #6fe3b8;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.ai-modal-input-wrap.is-textarea::after {
  top: 14px;
  transform: none;
}

.ai-modal-field.is-done .ai-modal-input-wrap::after {
  opacity: 1;
}

/* 入力済みの欄。薄い緑の地と緑の枠線で、完了したことが一目でわかるようにします。 */
.ai-modal-field.is-done input,
.ai-modal-field.is-done textarea {
  border-color: rgba(111, 227, 184, 0.55);
  background: rgba(83, 208, 170, 0.16);
}

/* チェック印と文字が重ならないよう、右の余白を空けます。 */
.ai-modal-field input,
.ai-modal-field textarea {
  width: 100%;
  /* 2026-08-29：モーダル全体を低くするため 11px/13px → 8px/12px。
     高さは約47px → 約41pxで、指でも押しやすい大きさは保っています。 */
  padding: 7px 12px;
  border: 1px solid var(--m-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--m-text);
}

/* 入力例の文字。暗い地でも読める明るさにしています。 */
.ai-modal-field input::placeholder,
.ai-modal-field textarea::placeholder {
  color: rgba(242, 246, 251, 0.42);
}

.ai-modal-field.is-done input,
.ai-modal-field.is-done textarea {
  padding-right: 34px;
}

/* 2026-08-29：初期の高さを半分ほど（96px → 50px）に。
   足りなければ利用者が右下のつまみで広げられます。 */
.ai-modal-field textarea {
  min-height: 44px;
  resize: vertical;
}

.ai-modal-field input:focus,
.ai-modal-field textarea:focus {
  outline: 2px solid var(--lp-sky, #7ccaff);
  outline-offset: 1px;
  border-color: var(--lp-sky, #7ccaff);
}

.ai-modal-field.is-error input,
.ai-modal-field.is-error textarea {
  border-color: #ff8f83;
  background: rgba(192, 57, 43, 0.18);
}

.ai-modal-error {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  font-weight: 700;
  color: #ff8f83;
}

/* ---------- STEP3：同意 ---------- */

.ai-modal-agree {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--m-line);
  border-radius: var(--lp-r-m, 16px);
  background: var(--m-bg-soft);
  font-size: 13.5px;
  line-height: 1.8;
  color: var(--m-text);
  cursor: pointer;
}

/* 「利用規約」＋「に同意する」。どちらも白ではっきり読めるようにします。 */
.ai-modal-agree span {
  color: var(--m-text);
}

.ai-modal-agree a {
  color: #fff;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-modal-agree a:hover {
  color: var(--lp-sky, #7ccaff);
}

.ai-modal-agree input {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--lp-sky, #7ccaff);
}

/* ---------- 送信前の最終確認ポップアップ ---------- */

/* モーダルの上にもう1枚重ねます。overlay（z-index 1000）の中なので、
   ここでは absolute で覆うだけで足ります。 */
.ai-modal-confirm {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 35, 74, 0.45);
}

.ai-modal-confirm[hidden] {
  display: none;
}

.ai-modal-confirm-panel {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  padding: 22px;
  border-radius: var(--lp-r-l, 20px);
  background: var(--m-bg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  overflow-y: auto;
}

.ai-modal-confirm-title {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.5;
  color: var(--m-text);
}

.ai-modal-confirm-body .ai-modal-summary {
  margin-bottom: 0;
}

.ai-modal-confirm-foot {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.ai-modal-confirm-foot .ai-modal-btn-main {
  flex: 1;
}

/* 「戻って修正する」は文字が長いので、最小幅を広げて折り返さないようにします。 */
.ai-modal-confirm-foot .ai-modal-btn-sub {
  min-width: 132px;
  padding-left: 12px;
  padding-right: 12px;
}

@media (max-width: 560px) {
  .ai-modal-confirm {
    padding: 16px;
  }

  .ai-modal-confirm-panel {
    padding: 18px 16px;
  }
}

/* ---------- 利用規約ビューアー ---------- */

/* 確認ポップアップ（z-index 1）より上に出します。
   背景クリックでは閉じません（閉じるのは × のみ）。 */
.ai-modal-terms {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 10, 20, 0.65);
}

.ai-modal-terms[hidden] {
  display: none;
}

/* 高さは画面に収まる範囲で頭打ちにし、本文だけ内部スクロールさせます。 */
.ai-modal-terms-panel {
  width: 100%;
  max-width: 680px;
  max-height: min(760px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  border-radius: var(--lp-r-l, 20px);
  background: var(--m-bg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.ai-modal-terms-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--m-line);
}

.ai-modal-terms-title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.4;
  color: var(--m-text);
}

.ai-modal-terms-body {
  flex: 1;
  min-height: 0;
  padding: 4px 20px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 規約本文。ページ側の .policy より一段小さく・詰めて、
   モーダルの中でも読みやすい行送りにしています。 */
.ai-modal-terms-body .policy > * {
  max-width: none;
}

.ai-modal-terms-body .policy p,
.ai-modal-terms-body .policy li {
  font-size: 13px;
  line-height: 1.85;
  color: var(--m-text);
}

/* 規約内のリンクも暗い地で見えるようにします。 */
.ai-modal-terms-body .policy a {
  color: var(--lp-sky, #7ccaff);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-modal-terms-body .policy h2 {
  margin: 20px 0 6px;
  font-size: 14.5px;
  font-weight: 800;
  color: var(--m-text);
}

.ai-modal-terms-body .policy ul {
  margin: 6px 0 0;
  padding-left: 1.3em;
}

@media (max-width: 560px) {
  .ai-modal-terms {
    padding: 0;
    align-items: flex-end;
  }

  .ai-modal-terms-panel {
    max-width: none;
    max-height: 88vh;
    border-radius: var(--lp-r-l, 20px) var(--lp-r-l, 20px) 0 0;
  }

  .ai-modal-terms-head,
  .ai-modal-terms-body {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ---------- 完了表示 ---------- */

.ai-modal-done {
  padding: 18px 0 6px;
  text-align: center;
}

.ai-modal-done-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(124, 202, 255, 0.16);
  font-size: 26px;
  font-weight: 700;
  color: var(--lp-sky, #7ccaff);
}

.ai-modal-done h3 {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 800;
  color: var(--m-text);
}

.ai-modal-done p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.85;
  color: var(--m-text-mute);
}

/* ---------- 下部のボタン ---------- */

.ai-modal-foot {
  display: flex;
  gap: 10px;
  padding: 12px 22px 16px;
  border-top: 1px solid var(--m-line);
}

.ai-modal-foot .ai-modal-btn:only-child {
  margin-left: auto;
}

.ai-modal-btn {
  flex: 1;
  padding: 13px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

/* 2026-08-30：申し込みまわりの青を統一しました。
   ヒーローの「今すぐ相談する」・プラン比較の「この内容で相談(申し込む)」と同じ
   濃い青（#1160c7）、ホバーはさらに一段濃い #0d4d9e です。
   白文字とのコントラストは 4.24:1 → 5.96:1（ホバー時 8.16:1）。 */
.ai-modal-btn-main {
  background: var(--lp-blue-dark, #1160c7);
  color: #fff;
}

.ai-modal-btn-main:hover {
  background: #0d4d9e;
}

/* 利用規約のチェックが入るまでは押せません。 */
.ai-modal-btn[disabled] {
  background: #35455f;
  color: rgba(242, 246, 251, 0.5);
  cursor: not-allowed;
}

.ai-modal-btn[disabled]:hover {
  background: #35455f;
}

.ai-modal-btn-sub {
  flex: none;
  min-width: 96px;
  border-color: var(--m-line);
  background: transparent;
  color: var(--m-text);
}

.ai-modal-btn-sub:hover {
  border-color: var(--lp-sky, #7ccaff);
  color: var(--lp-sky, #7ccaff);
}

/* ---------- 狭い画面 ---------- */

@media (max-width: 560px) {
  .ai-modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .ai-modal {
    max-width: none;
    max-height: 92vh;
    border-radius: var(--lp-r-l, 20px) var(--lp-r-l, 20px) 0 0;
  }

  .ai-modal-head,
  .ai-modal-steps,
  .ai-modal-body,
  .ai-modal-foot {
    padding-left: 16px;
    padding-right: 16px;
  }

  .ai-modal-summary dl {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
}

/* ---------- 動きを減らす設定への対応 ---------- */

@media (prefers-reduced-motion: reduce) {
  .ai-modal-btn,
  .ai-modal-close,
  .ai-modal-chips span {
    transition: none;
  }
}
