/*
 * e_Brand.css — enjiro soft 共通スタイルシート
 *
 * 【テーマカラー指定】 <html> の style 属性で上書き
 *   <html style="--primary:#4caf50; --primary-dark:#388e3c;">
 *   ※ テキストは常に白（--on-primary は定義不要）
 *
 * 【アクセントカラー指定】 data-accent 属性をプリセット名で指定
 *   <html data-accent="sage">
 *   ライトモード：白文字 / ダークモード：黒文字（自動切替）
 *
 * 【ダークモード】
 *   <html data-theme="dark">
 */

/* ===================================================================
   CSS カスタムプロパティ
=================================================================== */
:root {
  /* ── テーマカラー（ボタン・トグル・スライダー・フォーカスリング） ── */
  /* デフォルト：ウォームオーカー（黄土色系ブラウン）*/
  --primary:       #a07030;
  --primary-dark:  #7a5020;
  --on-primary:    #ffffff; /* 全テーマ共通・変更不要 */

  /* ── アクセントカラー（ヘッダー・モーダルヘッダー・FAB） ── */
  /* data-accent 未指定時はテーマカラーにフォールバック */
  --accent:      var(--primary);
  --accent-dark: var(--primary-dark);
  /* アクセント文字色：ライトモード=白 / ダークモード=黒（下記で切替） */
  --accent-text: #ffffff;

  /* ── 構造 ── */
  --header-h:  64px;
  --radius:    8px;
  --radius-sm: 4px;
  --radius-lg: 16px;
  --danger:    #d32f2f;
  --success:   #388e3c;

  /* ── 影 ── */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow:    0 2px 6px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.18);

  /* ── ライトモード背景（テーマカラーを微量ブレンド） ── */
  --bg:       color-mix(in srgb, var(--primary)  5%, #f5f7fa);
  --surface:  color-mix(in srgb, var(--primary)  3%, #ffffff);
  --surface2: color-mix(in srgb, var(--primary)  7%, #efefef);
  --border:   color-mix(in srgb, var(--primary)  8%, #e0e0e0);
  --text:     #212121;
  --text-sub: #757575;
}

@supports not (color: color-mix(in srgb, red, blue)) {
  :root { --bg:#f5f7fa; --surface:#ffffff; --surface2:#efefef; --border:#e0e0e0; }
}

/* ===================================================================
   アクセントカラー プリセット（data-accent="xxx" で指定）
   背景色のみ定義。文字色はモードごとに自動切替（下記ダークモードで上書き）。
=================================================================== */
[data-accent="sand-gold"]  { --accent:#c8a050; --accent-dark:#a07a30; }
[data-accent="sage"]       { --accent:#7aa87a; --accent-dark:#5a885a; }
[data-accent="smoky-blue"] { --accent:#6898b8; --accent-dark:#4878a0; }
[data-accent="lavender"]   { --accent:#9880c8; --accent-dark:#7860a8; }
[data-accent="terracotta"] { --accent:#c87858; --accent-dark:#a85838; }
[data-accent="soft-mint"]  { --accent:#60b090; --accent-dark:#408870; }

/* ===================================================================
   ダークモード
=================================================================== */
[data-theme="dark"] {
  --bg:       color-mix(in srgb, var(--primary)  8%, #121212);
  --surface:  color-mix(in srgb, var(--primary)  5%, #1e1e1e);
  --surface2: color-mix(in srgb, var(--primary)  8%, #2c2c2c);
  --border:   color-mix(in srgb, var(--primary) 10%, #444444);
  --text:     #e0e0e0;
  --text-sub: #9e9e9e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow:    0 2px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  /* ダークモードではアクセント文字色を黒系に固定 */
  --accent-text: #212121;
}
@supports not (color: color-mix(in srgb, red, blue)) {
  [data-theme="dark"] {
    --bg:#121212; --surface:#1e1e1e; --surface2:#2c2c2c; --border:#444444;
  }
}


/* ===================================================================
   リセット & ベース
=================================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', -apple-system,
               BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  transition: background 0.3s, color 0.3s;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}


/* ===================================================================
   ヘッダー（固定・64px・アクセントカラー）
=================================================================== */
header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h); padding: 0 12px;
  background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; justify-content: space-between;
  z-index: 100; box-shadow: var(--shadow);
}
header h1 {
  font-size: 20px; font-weight: 600; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-icons { display: flex; gap: 8px; flex-shrink: 0; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: none; border: none; color: var(--accent-text);
  font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s; -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: rgba(128,128,128,0.20); }
.icon-btn:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }


/* ===================================================================
   メインコンテンツ領域
=================================================================== */
.main { margin-top: var(--header-h); padding: 16px; min-height: calc(100vh - var(--header-h)); }
.main-fab-pad { padding-bottom: 104px; }


/* ===================================================================
   ボタン（5種類）
=================================================================== */
button { cursor: pointer; font-family: inherit; font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: var(--radius);
  font-size: 15px; font-weight: 500;
  transition: background 0.2s, box-shadow 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* ボタン1：テーマカラー塗り（文字は常に白） */
.btn-1 { background: var(--primary); color: #ffffff; }
.btn-1:hover { background: var(--primary-dark); }

/* ボタン2：テーマカラー枠線 */
.btn-2 {
  background: transparent; color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-2:hover { background: color-mix(in srgb, var(--primary) 10%, transparent); }
@supports not (color: color-mix(in srgb, red, blue)) {
  .btn-2:hover { background: rgba(0,0,0,0.06); }
}

/* モーダルヘッダー小ボタン */
.btn-modal {
  padding: 4px 12px; font-size: 13px; font-weight: 600;
  border-radius: var(--radius-sm);
  background: rgba(128,128,128,0.20); color: var(--accent-text);
  border: 1px solid rgba(128,128,128,0.35); transition: background 0.2s;
}
.btn-modal:hover { background: rgba(128,128,128,0.35); }
.btn-modal:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.btn-modal-danger { background: rgba(211,47,47,0.40); border-color: rgba(211,47,47,0.60); }
.btn-modal-danger:hover { background: rgba(211,47,47,0.60); }

/* 閉じるボタン（モーダルヘッダー内） */
.close-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(128,128,128,0.18); border: none;
  font-size: 20px; font-weight: bold; cursor: pointer; color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s; flex-shrink: 0;
}
.close-btn:hover { background: rgba(128,128,128,0.32); }
.close-btn:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* 初期化ボタン（赤・設定モーダル最下部） */
.btn-init { background: var(--danger); color: #fff; }
.btn-init:hover { filter: brightness(0.9); }
.btn-init:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }


/* ===================================================================
   カード
=================================================================== */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 20px; margin-bottom: 12px;
}
/* 長押し・ドラッグ操作を伴うカード（掴む手カーソル） */
.card-tap {
  cursor: grab;
  -webkit-touch-callout: none; /* iOS 長押しメニュー抑制 */
  user-select: none;           /* テキスト選択抑制 */
  touch-action: pan-y;         /* 縦スクロールは許可、横ジェスチャーはJS制御 */
}
.card-tap:hover { box-shadow: var(--shadow); }
.card-tap:active { cursor: grabbing; opacity: 0.88; }

/* EB.card.swipable / sortable が付与するクラス */
.card-held { box-shadow: var(--shadow-lg); opacity: 0.92; }
/* 削除閾値到達（左スワイプ60px超） */
.card-swipe-ready { background: color-mix(in srgb, var(--danger) 18%, var(--surface)); }
@supports not (color: color-mix(in srgb, red, blue)) {
  .card-swipe-ready { background: rgba(211,47,47,0.12); }
}
/* ドラッグ並び替え：挿入位置インジケーター */
.card-drop-indicator {
  height: 3px; border-radius: 2px;
  background: var(--primary); margin-bottom: 12px;
  pointer-events: none;
}


/* ===================================================================
   モーダル
=================================================================== */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 200;
  align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 600px; max-height: 90vh;
  overflow-y: auto; position: relative; box-shadow: var(--shadow-lg);
}

/* モーダルヘッダー（アクセントカラー） */
.modal-header {
  background: var(--accent); color: var(--accent-text);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px; min-height: 52px;
}
.modal-header h2 { font-size: 18px; font-weight: 600; flex: 1; color: var(--accent-text); }
.modal-header-actions { display: flex; align-items: center; gap: 8px; }
/* 閉じるボタン前のマージン（誤操作防止） */
.modal-header-actions > .close-btn { margin-left: 12px; }

.modal-body { padding: 20px 24px 24px; }
.modal-byline { font-size: 11px; color: var(--text-sub); text-align: right; margin-bottom: 12px; }


/* ===================================================================
   設定行
=================================================================== */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border); gap: 12px;
}
.setting-label { font-size: 14px; flex: 1; color: var(--text); }
/* 現在値はスライダーの左側（右端にスライダーが来てトグルと揃う） */
.slider-val { font-size: 13px; min-width: 24px; text-align: right; color: var(--text-sub); flex-shrink: 0; }


/* ===================================================================
   トグルスイッチ
=================================================================== */
.toggle-wrap { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.toggle-wrap input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute; inset: 0; background: #bdbdbd;
  border-radius: 26px; cursor: pointer; transition: background 0.2s;
}
.toggle-track::before {
  content: ''; position: absolute;
  width: 20px; height: 20px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-wrap input:checked + .toggle-track { background: var(--primary); }
.toggle-wrap input:checked + .toggle-track::before { transform: translateX(22px); }
.toggle-wrap input:focus-visible + .toggle-track { outline: 2px solid var(--primary); outline-offset: 2px; }


/* ===================================================================
   スライダー（input[type=range]）
   HTML構成: <span class="slider-val"> → <input type="range">
=================================================================== */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 120px; height: 6px; border-radius: 3px;
  background: var(--border); cursor: pointer; outline: none; flex-shrink: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,0.3); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--primary); border: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3); cursor: pointer;
}
input[type="range"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }


/* ===================================================================
   FAB（全て72px統一・アクセントカラー2色構成）
   ※ アイコンは --accent 背景色・--accent-text 文字色のみで構成すること
=================================================================== */
.fab-group {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: row; gap: 12px; align-items: center; z-index: 50;
}
.fab {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  border: none; font-size: 30px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.30); cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.fab:hover  { transform: scale(1.07); box-shadow: 0 6px 20px rgba(0,0,0,0.35); }
.fab:active { transform: scale(0.93); }
.fab:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
/* バックアップ通知FAB（左下・変更検出時のみ表示） */
.fab-backup { position: fixed; bottom: 20px; left: 20px; width: 72px; height: 72px; }


/* ===================================================================
   アコーディオン（▼▽切替・回転なし）
=================================================================== */
details.accordion { border-bottom: 1px solid var(--border); }
details.accordion > summary {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; cursor: pointer; list-style: none;
  font-size: 0.95rem; font-weight: 600; color: var(--text); user-select: none;
}
details.accordion > summary::-webkit-details-marker { display: none; }
.acc-arrow::before { content: '▼'; font-size: 0.72rem; color: var(--text-sub); }
details.accordion[open] > summary .acc-arrow::before { content: '▽'; }
details.accordion > .acc-body { padding-left: 16px; padding-bottom: 8px; }


/* ===================================================================
   トースト通知
=================================================================== */
.toast-stack {
  position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 800; pointer-events: none; width: 90%; max-width: 360px;
}
.toast {
  background: rgba(30,30,30,0.92); color: #f0f0f0;
  padding: 12px 20px; border-radius: 12px; font-size: 0.9rem;
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(16px);
  transition: opacity 0.25s, transform 0.25s; pointer-events: auto; text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: rgba(127,29,29,0.95); }


/* ===================================================================
   フォーム要素
=================================================================== */
input[type="text"], input[type="number"], input[type="email"],
input[type="search"], textarea, select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 15px; font-family: inherit;
  background: var(--surface); color: var(--text); transition: border-color 0.2s; width: 100%;
}
input[type="text"]:focus, input[type="number"]:focus, textarea:focus, select:focus {
  outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary);
}
textarea { resize: vertical; min-height: 80px; }


/* ===================================================================
   テーマカラーピッカー
=================================================================== */
.theme-picker-wrap { position: relative; }

.theme-picker-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 6px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 0.85rem; cursor: pointer; white-space: nowrap;
  transition: background 0.15s;
}
.theme-picker-btn:hover { background: var(--surface2); }

.theme-picker-dot {
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.18);
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.25);
}

.theme-picker-chev { font-size: 0.68rem; color: var(--text-sub); }

.theme-picker-panel {
  display: none;
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 8px; z-index: 300; width: 256px;
}
.theme-picker-panel.open { display: block; }

.theme-picker-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
}

.theme-picker-opt {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 2px; border: 2px solid transparent;
  border-radius: var(--radius-sm); background: transparent; cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.theme-picker-opt:hover { background: var(--surface2); border-color: var(--border); }
.theme-picker-opt.active { border-color: var(--primary); }
.theme-picker-opt .theme-picker-dot { width: 22px; height: 22px; }

.theme-picker-lbl {
  font-size: 0.55rem; color: var(--text-sub); line-height: 1.2;
  text-align: center; word-break: keep-all;
  max-width: 34px; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* ===================================================================
   レスポンシブ
=================================================================== */
@media (max-width: 480px) {
  .btn { padding: 10px 14px; font-size: 14px; }
  .modal-body { padding: 16px; }
  .fab { width: 64px; height: 64px; font-size: 26px; }
}
