/* Kirihare 運営管理 — 追加 UI スタイル。
   既存の styles.css (基本レイアウト・指標・顧客別利用機能・データテーブル) を補い、
   個別操作ボタン群・行選択・作成編集モーダル・個別操作モーダル・コマンドパレットを定義する。
   配色は styles.css の CSS 変数 (--accent / --line / --panel 等) を流用し、ライトモードを維持する。 */

/* ----- コマンドパレット起動ボタン (サイドナビ上部) ----- */
.palette-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid var(--nav-line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #c7d2da;
  cursor: pointer;
  font-size: 13px;
}

.palette-trigger:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.palette-kbd {
  border: 1px solid var(--nav-line);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  color: #9fadb7;
}

/* ----- 個別操作ボタン群 ----- */
.operation-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
}

.text-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ----- データテーブル 行選択 ----- */
.data-table tr.row-selected td {
  background: #f3fbf9;
}

.data-table tr.row-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

/* ----- モーダル共通 ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(23, 32, 42, 0.42);
}

.modal-card {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: auto;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(26, 39, 51, 0.24);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h2 {
  font-size: 17px;
}

.modal-form {
  display: grid;
  gap: 12px;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

/* ----- フォーム部品 (構造化フォーム) ----- */
.form-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.form-field-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.form-field-type {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.form-control {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
}

textarea.form-control {
  min-height: 78px;
  line-height: 1.55;
  resize: vertical;
}

.form-control:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

/* ----- コマンドパレット ----- */
.palette-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 20px 20px;
  background: rgba(23, 32, 42, 0.42);
}

.palette-card {
  display: grid;
  gap: 0;
  width: 100%;
  max-width: 560px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(26, 39, 51, 0.24);
}

.palette-input {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  background: #ffffff;
  color: var(--ink);
  font-size: 15px;
}

.palette-input:focus {
  outline: none;
}

.palette-results {
  display: grid;
  max-height: 48vh;
  overflow: auto;
}

.palette-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 11px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.palette-item:last-child {
  border-bottom: 0;
}

.palette-item:hover,
.palette-item.active {
  background: #f3fbf9;
}

.palette-item-label {
  font-weight: 800;
}

.palette-item-desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.palette-empty {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 560px) {
  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .primary-button,
  .modal-actions .text-button {
    width: 100%;
  }
}

/* ----- 自前ログインフォーム (platform-admin 独自ログイン) ----- */
/* 枠 (.login-panel) は styles.css 側で定義済み。ここでは内部フォームの縦並び・余白・
   入力欄・送信ボタン・補助リンクのレイアウトのみを定義する。ライトモードを維持する。 */
.login-form {
  display: grid;
  /* styles.css 側の横 3 列グリッド (メール｜パスワード｜ボタン) を打ち消し、
     見出し・各入力欄・送信ボタンを縦 1 列・全幅で並べる。横 3 列のままだと
     パスワード欄が極端に細くなり入力できない。 */
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 14px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 28px 26px;
}

.login-form h2 {
  font-size: 19px;
  color: var(--ink);
}

.login-form .form-field {
  gap: 6px;
}

.login-form .form-control {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: #ffffff;
  color: var(--ink);
  font-size: 15px;
}

.login-form .form-control:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.login-form .primary-button {
  width: 100%;
  min-height: 44px;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 700;
}

.login-form .form-error {
  min-height: 18px;
  margin: 0;
}

.login-alt {
  margin: 0;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  text-align: center;
}

.login-alt a {
  color: var(--accent);
  font-weight: 600;
}

/* ----- 認証ゲート (未ログイン・未認可) ----- */
/* app-shell.auth-gate のときは運営コンソールの外枠 (サイドバー全体・ヘッダー全体) を
   一切描画せず、ログインフォーム / 権限不足パネルだけを画面中央に出す。これにより
   ログイン画面に機能検索・機能ナビ・指標・操作ボタン等が残るのを構造的に防ぐ。 */
.app-shell.auth-gate {
  grid-template-columns: 1fr;
}

.app-shell.auth-gate .sidebar,
.app-shell.auth-gate .topbar {
  display: none;
}

.app-shell.auth-gate .main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 100vh;
  padding: 24px;
}

.app-shell.auth-gate .login-panel,
.app-shell.auth-gate .guard-panel {
  width: 100%;
  max-width: 460px;
  margin: 0;
}

/* ----- 分類ナビ (大分類見出し + 機能ボタン) ----- */
.nav-group {
  display: grid;
  gap: 2px;
  margin-bottom: 12px;
}

.nav-group-label {
  margin: 6px 10px 4px;
  color: #8a99a4;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* ----- ビュー (概要 / 契約・利用機能 / 機能の作業領域 を 1 画面ずつ) ----- */
.view {
  display: block;
}

/* 機能の作業領域は 1 枚パネルを全幅で表示 (旧 3 ペインの中央カード列は廃止)。 */
.work-panel {
  width: 100%;
}

/* ----- screen 共通 (ハッシュルーター + screen レジストリ) ----- */
.workspace { width: 100%; }

.screen-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.screen-title { font-size: 20px; font-weight: 800; }
.screen-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.screen-body { display: grid; gap: 14px; }
.screen-loading { padding: 24px; }

/* ----- data-table ツールバー / 検索 / ページャ ----- */
.table-toolbar { margin-bottom: 10px; }
/* 幅は JS 側で placeholder 長に応じ inline 指定。ここでは下限と容器超過防止のみ。 */
.table-search { min-width: 220px; max-width: 100%; }
.data-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.data-table th.sortable:hover { color: var(--accent); }
.data-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 10px;
}

/* ----- フォーム部品 ----- */
.form-field .req { color: var(--red); font-style: normal; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; }
.modal-body { display: grid; gap: 12px; }

/* 動的行リピータ */
.repeater-list { display: grid; gap: 10px; }
.repeater-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-subtle, #fafbfc);
}
.repeater-row > :first-child { flex: 1; min-width: 0; }

/* 検索付きセレクト (Select2 相当) */
.search-select { position: relative; }
.search-select-list {
  position: absolute;
  z-index: 30;
  left: 0; right: 0;
  margin-top: 2px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(26, 39, 51, 0.18);
}
.search-select-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
.search-select-item:hover { background: #f3fbf9; }
.search-select-item small { display: block; color: var(--muted); font-size: 11px; }

/* 画像アップロード */
.image-preview { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.image-preview-img { max-width: 160px; max-height: 120px; border: 1px solid var(--line); border-radius: 6px; }
/* 保存済み画像のプレビューは「現在: <ファイル名>」の下の行に控えめに表示する */
.image-preview-current { flex-basis: 100%; }

/* 編集フォーム (法人編集など): ラベル付き入力を 2 列グリッド。textarea は全幅。 */
.edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  margin-bottom: 12px;
}
.edit-form .form-field textarea { width: 100%; }
.edit-form .form-field:has(textarea) { grid-column: 1 / -1; }
.edit-form .form-check { grid-column: 1 / -1; }
.save-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.save-msg.form-error { color: var(--red); }

@media (max-width: 720px) {
  .edit-form { grid-template-columns: 1fr; }
}

/* 心理テスト・割引のエディタ補助 */
.pt-block { margin: 14px 0; }
.section-row { align-items: center; }
.preview-msg { margin-top: 8px; }

/* 詳細モーダルの key-value 表示 */
.detail-kv { display: grid; gap: 6px; }
.kv-row { display: grid; grid-template-columns: 120px 1fr; gap: 10px; font-size: 13px; }
.kv-label { color: var(--muted); }
.kv-value { color: var(--ink); overflow-wrap: anywhere; }
