/* ==========================================================================
   デザイントークン（CSSカスタムプロパティ：ライト／ダーク）
   ========================================================================== */

/*
 * 配色を変更する場所：ライトモード
 * 背景／境界線 → 文字 → メインアクセント → 警告アクセント → 重ね表示
 */
@font-face {
  font-family: "Nordica";
  src: url("Nordica.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg-base: #f9f9f9;
  --bg-surface: #fdfdff;
  --bg-subtle: #ebeef8;
  --border: #d3daeb;

  --text-primary: #311621;
  --text-muted: #6E627C;

  --accent-primary: #f33ba3;
  --accent-primary-hover: #ffb8e0;
  --accent-primary-soft: rgba(255, 59, 180, 0.12);

  /* 補充箇所の専用色（本文色・警告色とは独立） */
  --refill-color: #f33ba3;
  --on-refill: #ffffff;

  /* 在庫ありを示すタップ領域の専用色 */
  --stock-filled: #ffa7d7e8;

  --accent-alert: #b82f58;
  --accent-alert-soft: rgba(255, 187, 221, 0.34);

  --on-accent: #FFFFFF;
  --on-alert: #FFFFFF;
  --scrim: rgba(10, 10, 31, 0.38);

  --font-sans: "BIZ UDPGothic", "BIZ UDPゴシック", Meiryo, "メイリオ", "Hiragino Sans", sans-serif;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-ui: 13px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 20px;
  --fs-xl: 26px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;

  --sa-top: env(safe-area-inset-top, 0px);
  --sa: env(safe-area-inset-bottom, 0px);
  --sh: 24px;
  --tw: 56px;
  /* 縦スクロールバー幅（JSが実測して更新・左右余白の補正用） */
  --sbw: 0px;
}

/*
 * 配色を変更する場所：ダークモード
 * 上のライトモードと同じ変数名を上書きする
 */
.dark {
  --bg-base: #181818;
  --bg-surface: #292929;
  --bg-subtle: #4f4f4f;
  --border: #414141;

  --text-primary: #fbfbfb;
  --text-muted: #cfcfcf;

  --accent-primary: #6dd3c1;
  --accent-primary-hover: #b5e6de;
  --accent-primary-soft: rgba(129, 232, 217, 0.2);

  /* 補充箇所の専用色 */
  --refill-color: #09b39f;
  --on-refill: #f1f1f1;

  /* 在庫ありを示すタップ領域の専用色 */
  --stock-filled: #67f4e1ce;

  --accent-alert: #e367a3;
  --accent-alert-soft: rgba(255, 194, 224, 0.16);

  --on-accent: #0A0A1F;
  --on-alert: #0A0A1F;
  --scrim: rgba(2, 2, 12, 0.72);
}

/* 文字サイズ「小」の文字スケール上書き */
.fs-sm {
  --fs-xs: 10px;
  --fs-sm: 11px;
  --fs-ui: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 18px;
  --fs-xl: 24px;
}

/* 文字サイズ「大」の文字スケール上書き */
.fs-lg {
  --fs-xs: 13px;
  --fs-sm: 14px;
  --fs-ui: 15px;
  --fs-base: 16px;
  --fs-md: 17px;
  --fs-lg: 22px;
  --fs-xl: 30px;
}

/* ==========================================================================
   ベースレイアウト・共通リセット
   ========================================================================== */

/* 画面全体の背景とスクロール制御 */
html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg-subtle);
}

/* body自体のスクロールを無効化しアプリ内スクロールへ統一 */
body {
  overflow: hidden;
  font-family: var(--font-sans);
}

/* アプリ外枠（最大430pxの中央配置・縦フレックス） */
#app {
  position: relative;
  max-width: 430px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--text-primary);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  font: var(--fs-base)/1.5 var(--font-sans);
}

/* メインスクロール領域（右余白はスクロールバー幅の分を差し引いて左右を均等に） */
main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) max(var(--space-3) - var(--sbw), 0px) 24px var(--space-3);
  -webkit-overflow-scrolling: touch;
}

/* タップ誤操作防止とボックスサイズ統一 */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* スクロールバーを控えめに表示（細幅・透明トラック・低彩度サム） */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

/* ホバー時のみ少し濃くして操作位置を示す */
*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* SVGアイコンのデフォルト色（muted）とクリック透過設定 */
svg {
  color: var(--text-muted);
  pointer-events: none;
  flex: none;
}

/* フォーム要素のフォント継承 */
button,
input {
  font-family: inherit;
}

/* 共通ボタンスタイル（ニュートラルなセカンダリボタン） */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  min-height: 44px;
  cursor: pointer;
}

/* ボタン押下時のフィードバック */
button:active {
  background: var(--bg-subtle);
}

/* 無効状態ボタンの透過表示 */
button:disabled {
  opacity: 0.35;
  cursor: default;
}

/* 主要ボタン（バイオレットアクセント） */
.btn-primary {
  background: var(--accent-primary);
  color: var(--on-accent);
  border-color: var(--accent-primary);
  font-weight: 700;
}

/* 主要ボタン押下時のフィードバック */
.btn-primary:active {
  background: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}

/* 主要ボタン内のアイコン色を文字色に同期 */
.btn-primary svg {
  color: currentColor;
}

/* 共通テキスト入力スタイル（テキスト選択のみ許可） */
input {
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  min-height: 44px;
  min-width: 0;
  -webkit-user-select: text;
  user-select: text;
}

/* 入力欄プレースホルダーの控えめな文字色 */
input::placeholder {
  color: var(--text-muted);
}

/* キーボードフォーカス時のアウトライン */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   ヘッダー・下部ナビゲーション
   ========================================================================== */

/* 上部ヘッダーバー */
header {
  flex: none;
  padding: calc(var(--sa-top) + 8px) var(--space-3) 8px;
  background: var(--bg-surface);
  display: flex;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

/* ヘッダータイトル */
h1 {
  margin: 0;
  display: flex;
  align-items: center;
  color: var(--text-primary);
}

.logo-svg {
  display: block;
  width: 110px; /* 実際のロゴの横幅に合わせて調整 */
  height: 16px;
  background-color: var(--text-primary);
  -webkit-mask: url("HOJURIN.svg") no-repeat left center / contain;
  mask: url("HOJURIN.svg") no-repeat left center / contain;
}
/* ヘッダー右側のアクションボタン群 */
.hdr-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

/* ヘッダー・列交換ヘッダーのコンパクトボタン */
.icon-btn {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border-color: var(--border);
  color: var(--text-primary);
}

/* アイコンのみのスクエアボタン（テーマ切替用） */
.icon-btn.icon-only {
  width: 36px;
  padding: 0;
}

/* 下部タブナビゲーションバー */
nav {
  flex: none;
  display: flex;
  gap: var(--space-1);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 6px var(--space-2) calc(6px + var(--sa));
}

/* タブ切り替えボタン */
nav button {
  flex: 1;
  flex-direction: column;
  gap: 3px;
  border: 0;
  border-radius: var(--radius-lg);
  min-height: 48px;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
}

/* 選択中タブのアクティブ強調表示 */
nav .on {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
  font-weight: 700;
}

/* 選択中タブ内アイコン色の強調 */
nav .on svg {
  color: var(--accent-primary);
}

/* ==========================================================================
   棚ビュー（段カード・列タイル）
   ========================================================================== */

/* 補足説明テキスト */
.hint {
  font-size: var(--fs-sm);
  line-height: 1.5;
  color: var(--text-muted);
  margin: var(--space-1) 2px var(--space-3);
}

/* 棚・列交換上部の控えめな操作ガイド */
.hint-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 10px;
  margin: 0 0 var(--space-3);
  font-size: var(--fs-sm);
  line-height: 1.5;
  color: var(--text-muted);
}

/* 段ごとのカードコンテナ */
.shelf {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

/* 段ヘッダー（段名・補充小計・編集ボタン） */
.sh-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: var(--space-2);
}

/* 段名と状態テキストのグループ */
.sh-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  min-width: 0;
}

/* 段名の強調 */
.sh-head b {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

/* 段ごとの補充必要本数テキスト */
.sh-stat {
  font-size: var(--fs-sm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

/* 段内に補充対象がある場合の強調ウェイト */
.sh-stat.has-need {
  color: var(--refill-color);
  font-weight: 700;
}

/* 段ヘッダー右側のツールボタン群 */
.tools {
  display: flex;
  gap: 6px;
  flex: none;
}

/* 段ツールボタンのサイズ調整 */
.tools button {
  padding: 4px 10px;
  min-height: 34px;
  font-size: 12px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  color: var(--text-primary);
}

/* 列タイルを横に並べるスクロールコンテナ */
.grid {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

/* 1列分のタイルコンテナ */
.tile {
  flex: none;
  width: var(--tw);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 5px 4px 4px;
}

/* 列番号ラベル */
.cn {
  text-align: center;
  font-size: var(--fs-xs);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  line-height: 1.2;
  margin-bottom: 4px;
}

/* 在庫1本分を表すセグメント（空き状態） */
.seg {
  display: block;
  height: var(--sh);
  border-radius: var(--radius-md);
  margin-bottom: 3px;
  background: var(--bg-surface);
  border: 1px dashed var(--border);
}

/* 在庫あり状態のセグメント（専用の紫色で表示） */
.seg.on {
  background: var(--stock-filled);
  border: 1px solid var(--stock-filled);
}

/* 補充必要本数バッジ（0本＝満タン時） */
.ct {
  text-align: center;
  font-size: var(--fs-sm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 3px 0;
  margin-top: 4px;
  line-height: 1.2;
}

/* 補充が必要な列のピンク系ワンポイントバッジ（1本以上） */
.ct.z {
  background: var(--refill-color);
  color: var(--on-refill);
  border-color: var(--refill-color);
  font-weight: 700;
}

/* 列下部の商品名表示（最大2行） */
.nx {
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.25;
  height: 2.6em;
  overflow: hidden;
  word-break: break-all;
  text-align: center;
  padding-top: 4px;
  color: var(--text-primary);
}

/* 商品名未設定時の控えめな文字色 */
.nx.e {
  font-weight: 400;
  color: var(--text-muted);
  font-size: var(--nx-empty-size, 9px);
  letter-spacing: -0.04em;
  white-space: nowrap;
  word-break: keep-all;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   補充数ビュー・商品管理ビュー
   ========================================================================== */

/* 補充数タブ上部の合計補充本数サマリーカード */
.sum-hero {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* サマリーカード内の補足テキスト群 */
.sum-hero-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

/* サマリー見出しラベル */
.sum-hero-label {
  font-size: var(--fs-ui);
  font-weight: 700;
  color: var(--text-primary);
}

/* サマリー内訳サブテキスト */
.sum-hero-sub {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* サマリー合計本数の大型数値表示 */
.sum-hero-total {
  font-size: var(--fs-xl);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  white-space: nowrap;
}

/* サマリー合計本数の単位 */
.sum-hero-total small {
  font-size: var(--fs-ui);
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 2px;
}

/* 全幅アクションボタン（コピー・リセット等） */
.add {
  width: 100%;
  margin-top: var(--space-1);
}

/* リスト項目カード（補充数行・商品行） */
.row {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

/* リストカード上部（商品名と数値/削除ボタン） */
.row .top {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 補充本数の大型数値表示（0本時） */
.big {
  font-size: var(--fs-lg);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  color: var(--text-muted);
  white-space: nowrap;
}

/* 補充本数1本以上の強調表示（濃淡とウェイトで階層表現） */
.big.is-need {
  font-size: calc(var(--fs-lg) + 2px);
  font-weight: 700;
  color: var(--refill-color);
}

/* 補充本数の単位（「本」） */
.big small {
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--text-muted);
}

/* 商品名テキスト・入力欄の伸縮設定 */
.nm {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-base);
  font-weight: 700;
}

/* 在庫率プログレスバーの外枠 */
.meter {
  height: 6px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  margin: 10px 0 8px;
  overflow: hidden;
}

/* 在庫率プログレスバーの塗りつぶし部分 */
.meter i {
  display: block;
  height: 100%;
  border-radius: var(--radius-md);
  background: var(--text-primary);
}

/* 在庫数・容量・段別内訳のサブテキスト */
.sub {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   ボトムシート・中央ダイアログ
   ========================================================================== */

/* シート背景の半透明オーバーレイ */
.sbg {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  z-index: 8;
}

/* ボトムシート本体（段設定・列編集用） */
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  background: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-4) 14px calc(18px + var(--sa));
  max-height: 88%;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

/* 中央配置ダイアログ（商品名入力用） */
.sheet.dlg {
  left: var(--space-3);
  right: var(--space-3);
  bottom: auto;
  top: 38%;
  transform: translateY(-38%);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  border: 1px solid var(--border);
}

/* 段編集・アイコン説明パネルを画面中央に配置 */
.sheet.shelf-dialog,
.sheet.help-dialog {
  left: 14px;
  right: 14px;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  max-height: calc(100% - 32px);
  border: 1px solid var(--border);
}

/* シート内セクション見出し */
.sheet h3 {
  margin: 0 0 10px;
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--text-primary);
}

/* 段名見出しとUndoボタン */
.shelf-edit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: 10px;
}

.shelf-edit-head h3 {
  margin: 0;
}

.shelf-edit-head button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
}

/* アイコン説明の見出し行（タイトルと閉じるボタン） */
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: 4px;
}

.help-head h3 {
  margin: 0;
}

.help-head button {
  width: 36px;
  min-width: 36px;
  padding: 6px 0;
  font-size: 20px;
  line-height: 1;
}

/* アイコン説明の箇条書きリスト */
.help-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.help-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.help-list li:first-child {
  border-top: 0;
}

/* リスト左側のアイコン枠 */
.help-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.help-icon svg {
  color: var(--text-primary);
}

/* リスト右側の名称と説明文 */
.help-txt {
  font-size: var(--fs-sm);
  line-height: 1.5;
  color: var(--text-muted);
}

.help-txt b {
  display: block;
  font-size: var(--fs-ui);
  color: var(--text-primary);
}

/* シート内の2つ目以降のセクション見出し余白 */
.sheet h3.sh-sub {
  margin-top: 18px;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

/* 列編集見出しと列交換ページへの導線 */
.col-edit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  margin: 18px 0 10px;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.col-edit-head h3 {
  flex: 1;
  min-width: 0;
  margin: 0;
  white-space: nowrap;
}

.col-head-select {
  flex: 0 0 78px;
  width: 78px;
  min-width: 0;
  min-height: 36px;
  padding: 0 4px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font: 12px var(--font-sans);
}

.col-edit-actions {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: 6px;
  white-space: nowrap;
  flex: 0 0 auto;
}

/* 列交換ボタンを折り返さず、閉じるボタンと横並びにする */
.col-edit-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 8px;
  min-width: max-content;
  flex: 0 0 auto;
  white-space: nowrap;
}

.col-edit-actions button[aria-label="閉じる"] {
  width: 36px;
  min-width: 36px;
  padding: 6px 0;
  font-size: 20px;
  line-height: 1;
}


/* 2列均等ボタングループ（満タン／空） */
.two {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* 2列ボタンの均等伸縮 */
.two button {
  flex: 1;
}

/* 選択列の詳細編集ボックス */
.crow {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  margin-bottom: var(--space-2);
}

/* 数値増減ステッパー行 */
.stp {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: var(--space-2) 0;
}

/* 列数と新規列本数の設定を一行に並べる */
.shelf-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.shelf-controls .stp {
  min-width: 0;
  gap: 4px;
  margin: var(--space-2) 0;
}

.shelf-controls .stp span {
  flex: 1;
  white-space: nowrap;
}

.shelf-controls .stp button {
  flex: 0 0 32px;
  width: 32px;
  min-width: 32px;
}

.shelf-controls .stp b {
  min-width: 22px;
}

.shelf-controls .stp small {
  color: var(--text-muted);
}

/* 選択列ボックス内の余白を抑えたステッパー行 */
.stp.stp-compact {
  margin: 0;
}

/* ステッパーのラベル */
.stp span {
  flex: 1;
  font-size: var(--fs-ui);
  font-weight: 500;
  color: var(--text-muted);
}

/* 右寄せ指定のステッパーラベル */
.stp span.stp-label-r {
  text-align: right;
}

/* ステッパーの現在値表示 */
.stp b {
  min-width: 32px;
  text-align: center;
  font-size: var(--fs-md);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

/* ステッパーの増減ボタン */
.stp button {
  width: 44px;
  padding: 0;
}

/* 入力欄＋ボタンの横並びフォーム行 */
.f {
  display: flex;
  gap: var(--space-2);
  margin: 10px 0;
}

/* 選択列ボックス内のコンパクトなフォーム行 */
.f.f-compact {
  margin: var(--space-2) 0;
}

/* フォーム行内の入力欄伸縮 */
.f input {
  flex: 1;
}

/* 全幅ボタン */
.full {
  width: 100%;
  margin-top: var(--space-2);
}

/* 破壊的操作（削除・リセット）用の抑制スタイル */
.danger {
  color: var(--text-muted);
  border-color: var(--border);
  background: var(--bg-surface);
}

/* 破壊的操作ボタン押下時のフィードバック */
.danger:active {
  color: var(--accent-alert);
  background: var(--accent-alert-soft);
  border-color: var(--accent-alert);
}

/* 全データリセット用の破線境界 */
.add.danger {
  border-style: dashed;
}

/* ==========================================================================
   列交換モード（フルスクリーンオーバーレイ・ドラッグ＆ドロップ）
   ========================================================================== */

/* 列交換ダイアログの中央配置コンテナ */
#swap {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
}

/* 全段・段単位どちらも中央ダイアログとして表示 */
#swap.swap-modal {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.swap-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim);
}

.swap-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 430px;
  max-height: 100%;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.swap-modal .sw-h {
  padding: 8px var(--space-3);
}

.swap-modal .sw-b {
  flex: 1;
  min-height: 0;
}

/* 非アクティブ（空）時は非表示 */
#swap:empty {
  display: none;
}

/* 列交換画面の上部ヘッダー */
.sw-h {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--sa-top) + 8px) var(--space-3) 8px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

/* 列交換ヘッダーのタイトル */
.sw-h b {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

/* 列交換ヘッダー右側の操作ボタン群 */
.sw-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* 列交換画面のスクロール領域 */
.sw-b {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-3);
  -webkit-overflow-scrolling: touch;
}

/* 列交換ページ内の段名ラベル */
.sl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-subtle);
  padding: 6px 10px;
  margin-bottom: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* 列交換用の8列グリッド */
.sg {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
}

/* 列交換用の各列タイル */
.st {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-height: 52px;
  padding: 4px 2px;
  text-align: center;
  font-size: 10px;
  line-height: 1.25;
  overflow: hidden;
  word-break: break-all;
}

/* 列交換タイル内の列番号 */
.st b {
  display: block;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  margin-bottom: 2px;
}

/* 長押し対象要素でiOSコールアウトメニューを抑止 */
.st,
.sl,
.cn,
.nx,
.sh-title b {
  -webkit-touch-callout: none;
}

/* タップ交換で1つ目に選択された要素のアクティブ強調 */
.pick {
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
}

/* 選択要素内アイコン色の強調 */
.pick svg {
  color: var(--accent-primary);
}

/* ドラッグ中のドロップ先ハイライト */
.over {
  outline: 2px solid var(--accent-primary);
  outline-offset: 1px;
}

/* ドラッグ元要素の半透明化 */
.drag {
  opacity: 0.3;
}

/* ドラッグ中に指・カーソルへ追従するゴースト要素 */
.ghost {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: var(--bg-surface);
  border: 1px solid var(--accent-primary);
}

/* ==========================================================================
   トースト通知
   ========================================================================== */

/* 操作結果フィードバック用のトースト（ピンク系ワンポイント枠線） */
#toast {
  position: absolute;
  left: 50%;
  bottom: calc(80px + var(--sa));
  transform: translateX(-50%);
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--accent-alert);
  border-radius: var(--radius-lg);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

/* トースト表示状態 */
#toast.on {
  opacity: 1;
}
