/* ========================================================
   Path: /assets/css/ai-edit-modal-form.css
   Purpose: AI編集モーダルの見た目を映画版と完全統一（ai-* セレクタ）
   Blocks: コンテナ / バックドロップ / 本体 / 閉じるボタン /
           セーフエリア対応 / 見出し / 入力UI / 行UI / エラー表示
======================================================== */

/* === モーダル全体（フルスクリーン固定・最前面） === */
.ai-edit-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;                /* 他の要素より上に */
  overscroll-behavior: contain;  /* iOS のゴムスク抑止 */
}

/* === 半透明の背景 === */
.ai-edit-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);   /* 半透明の黒 */
}

/* === モーダル本体（中央配置の箱） === */
.ai-edit-modal-content {
  position: absolute;
  top: 50%;                       /* 縦方向中央 */
  left: 50%;                      /* 横方向中央 */
  transform: translate(-50%, -50%); /* 正確な中央位置へ移動 */
  width: 90%;
  max-width: 700px;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  z-index: 10001;                 /* backdropよりも上に */
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

/* === セーフエリア配慮・スクロール安定化（映画と同等） === */
.ai-edit-modal-content {
  width: min(700px, calc(100% - 32px)); /* 端の安全余白を確保 */
  max-height: calc(100vh - 32px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
  scrollbar-gutter: stable;
  touch-action: auto;

  /* 既存 padding:20px をセーフエリア分だけ拡張 */
  padding-top:    calc(20px + env(safe-area-inset-top));
  padding-right:  calc(20px + env(safe-area-inset-right));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  padding-left:   calc(20px + env(safe-area-inset-left));
}
@supports (height: 100svh) {
  .ai-edit-modal-content { max-height: calc(100svh - 32px); }
}
@supports (height: 100dvh) {
  .ai-edit-modal-content { max-height: calc(100dvh - 32px); }
}

/* === 閉じるボタン（バツ印） === */
.ai-edit-modal-content .ai-modal-close-btn {
  position: absolute; /* 基準は .ai-edit-modal-content */
  top: 10px;          /* 上から10px */
  right: 10px;        /* 右から10px */
  background: none;
  border: none;
  font-size: 26px;
  cursor: pointer;
  color: #888;
  line-height: 1;
  padding: 0;
}
.ai-edit-modal-content .ai-modal-close-btn:hover {
  color: #333;
}

/* === ヘッダー（タイトル） === */
.ai-edit-modal-content .ai-modal-header {
  margin-bottom: 20px; /* タイトルとフォームの距離 */
  padding-right: 30px; /* ×ボタンとの重なり防止 */
}
.ai-edit-modal-content .ai-modal-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

/* === 入力UI（テキスト/セレクト/テキストエリア共通） === */
.ai-edit-modal-fields textarea,
.ai-edit-modal-fields input[type="text"],
.ai-edit-modal-fields select {
  width: 100%;                /* フォーム要素を幅いっぱいに */
  padding: 8px 10px;          /* 入力欄内の余白 */
  margin-bottom: 15px;        /* 各項目間の余白 */
  border-radius: 5px;         /* 角丸デザイン */
  border: 1px solid #ccc;     /* 境界線 */
  box-sizing: border-box;     /* padding込みのサイズ計算 */
  font-size: 14px;
  color: #333;
}

/* === セレクトの矢印を共通化 === */
.ai-edit-modal-fields select {
  appearance: none;
  background-color: #fff;
  background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="gray"><polygon points="0,0 20,0 10,10"/></svg>');
  background-repeat: no-repeat;
  background-position: right 10px top 50%;
  background-size: 8px 8px;
}

/* === 送信ボタン（保存する） === */
.ai-edit-modal-content .ai-modal-submit-btn {
  display: block;
  width: 100%;
  padding: 10px;
  background-color: #007BFF;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  margin-top: 10px;
}
.ai-edit-modal-content .ai-modal-submit-btn:hover {
  background-color: #0056b3;
}

/* === 行UI（人物などの可変行） === */
.ai-edit-modal-fields .ai-edit-row input[type="text"],
.ai-edit-modal-fields .ai-edit-row select {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  margin-bottom: 6px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
}

/* ドラッグハンドル */
.ai-edit-modal-fields .ai-row-drag-handle {
  cursor: move;
  font-size: 18px;
  color: #888;
  margin-right: 8px;
}

/* 詳細開閉ボタン */
.ai-edit-modal-fields .ai-row-toggle-btn {
  background-color: #f0f0f0;
  color: #555;
  border: none;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}
.ai-edit-modal-fields .ai-row-toggle-btn:hover {
  background-color: #e0e0e0;
}

/* 行の削除ボタン */
.ai-edit-modal-fields .ai-row-delete-btn {
  background-color: #ff4d4f;
  color: #fff;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 6px;
  transition: background-color 0.3s;
}
.ai-edit-modal-fields .ai-row-delete-btn:hover {
  background-color: #e33e41;
}

/* 行の追加ボタン */
.ai-edit-modal-fields .ai-row-add-btn {
  background-color: #28a745;
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
  margin-top: 8px;
}
.ai-edit-modal-fields .ai-row-add-btn:hover {
  background-color: #218838;
}

/* 主役チェック（主要人物の上位表示） */
.ai-edit-modal-fields .ai-main-role-check {
  margin-right: 4px;
}

/* エラーメッセージ */
.ai-edit-modal-fields .ai-field-error,
.ai-edit-modal-fields .ai-main-role-error {
  color: #ff4d4f;
  font-size: 12px;
  margin-top: 4px;
}
