/* ============================================================
   lib/components.css — yuto's dev tools 共通コンポーネント

   全ツール共通のレイアウト・コンポーネントスタイル。
   各ツールはこのファイルを <link> で読み込んで、自分の style.css
   ではツール固有のスタイルだけ書く。

   トークン（色・shadow・radius・spacing・font）は lib/theme.css で
   定義済み。このファイルではトークンを var() で参照するだけ。

   このファイルを編集すると全ツールに即時反映されることに注意。
   ============================================================ */

/* ============================================================
   Reset / Base
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   View switching
   <body data-view="list|editor"> で .app-view-* を切り替え
   ============================================================ */
.app-view { display: none; }
body[data-view="list"]   .app-view-list   { display: block; }
body[data-view="editor"] .app-view-editor { display: block; }

/* ============================================================
   Layout — max-width 1280px の中央寄せコンテナ
   ============================================================ */
.app-inner {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-10) var(--space-10);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* ============================================================
   Header
   左: [← 戻る] [アイコン] タイトル
   右: テーマ切替ボタン + sync UI
   下端に区切り線でメイン領域と分離
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-strong);
  box-shadow: 0 1px 0 var(--shadow-light);
}
.app-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}
.app-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ---- 戻るボタン（pill 型ニューモフィズム） ---- */
.app-back-btn {
  height: 34px;
  padding: 0 var(--space-3);
  border: none;
  border-radius: var(--radius-full);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-sans);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow-out-sm);
  transition: box-shadow .15s, color .15s, transform .1s;
  flex-shrink: 0;
  text-decoration: none;
  line-height: 1;
  margin-right: var(--space-2);
}
.app-back-btn:hover { color: var(--accent); }
.app-back-btn:active {
  box-shadow: var(--shadow-in-sm);
  transform: scale(.96);
}
/* 広い画面では戻るボタンを左余白に配置（ネガティブマージンで引き出し） */
/* ※ editor ビューは max-width:none なので適用しない */
@media (min-width: 1500px) {
  body[data-view="list"] .app-header-left > .app-back-btn:first-child {
    margin-left: calc(-1 * (var(--space-10) + 70px));
  }
}

/* ---- タイトルアイコン ---- */
.app-title-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1;
}

/* ---- タイトルテキスト ---- */
.app-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  line-height: 1.2;
  letter-spacing: -.02em;
}

/* ---- ヘッダーアクション（編集画面の保存・読込・書出） ---- */
.app-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  justify-content: flex-end;
  padding: 0 var(--space-4);
}
.app-header-actions .btn {
  font-size: 12px;
  padding: 8px 14px;
  gap: 6px;
}
.app-header-actions .dropdown {
  position: relative;
}
.app-header-actions .dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 4px;
  min-width: 140px;
  z-index: 100;
  display: none;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.app-header-actions .dropdown.open .dropdown-menu {
  display: flex;
}
.app-header-actions .dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-dim);
  white-space: nowrap;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.app-header-actions .dropdown-item:hover {
  background: var(--bg);
  color: var(--text);
}


/* ---- Drive 同期プログレスバー ---- */
.drive-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 9999; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 200% 100%; animation: driveBar .9s ease-in-out infinite; }
@keyframes driveBar { 0% { background-position: 100% 0 } 100% { background-position: -100% 0 } }

/* ---- 同期状態ドット（エディタ画面用） ---- */
.sync-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--muted); transition: background .2s, box-shadow .2s;
}
.sync-dot[data-status="synced"] { background: var(--success); box-shadow: 0 0 6px rgba(33,168,125,.55); }
.sync-dot[data-status="syncing"] { background: var(--accent); animation: syncPulse 1.2s ease-in-out infinite; }
.sync-dot[data-status="error"] { background: var(--danger); box-shadow: 0 0 6px rgba(255,114,114,.55); }
@keyframes syncPulse { 0%,100%{opacity:.4;transform:scale(.85)} 50%{opacity:1;transform:scale(1.1)} }

/* ---- 保存ボタン状態変化 ---- */
#save-btn { min-width: 80px; justify-content: center; }
.app-header-actions .btn-icon { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; }
.btn-save-done { background: var(--success); }
.btn-save-error { background: var(--danger); }

/* ---- 編集可能タイトル ---- */
.app-title-editable {
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  transition: background .15s;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 60px;
}
.app-title-editable:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}
.app-title-editable.editing {
  cursor: text;
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  outline: none;
}

/* ---- 旧 back-link（後方互換 — 新規では使わない） ---- */
.app-back-link {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: .04em;
  margin-top: 6px;
  width: fit-content;
  transition: color .15s;
  line-height: 1;
}
.app-back-link:hover { color: var(--accent); }

/* ============================================================
   Toolbar — セクションタイトル + アクション行
   ============================================================ */
.app-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.app-section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

/* ============================================================
   Main area
   ============================================================ */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Gallery grid — 標準規則：左上から流し込み
   ============================================================ */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-5);
}

/* ============================================================
   Card（ニューモフィズム）
   ============================================================ */
.app-card {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius);
  padding: var(--space-4);
  cursor: pointer;
  transition: box-shadow .18s, transform .18s;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: var(--shadow-out);
  text-decoration: none;
  color: inherit;
}
.app-card:hover {
  box-shadow: var(--shadow-out-lg);
  transform: translateY(-2px);
}
.app-card-thumb {
  height: 140px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 36px;
  opacity: .55;
  overflow: hidden;
}
.app-card-thumb svg { width: 100%; height: 100%; display: block; opacity: 1; }
.app-card-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: 0 var(--space-1);
}
.app-card-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-card-meta {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  gap: var(--space-3);
  align-items: center;
}
.app-card-actions {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  display: flex;
  gap: var(--space-1);
  opacity: 0;
  transition: opacity .15s;
}
.app-card:hover .app-card-actions { opacity: 1; }
.app-card-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  box-shadow: var(--shadow-out-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color .12s, box-shadow .12s;
  font-family: inherit;
}
.app-card-btn:hover { color: var(--accent); }
.app-card-btn.danger:hover { color: var(--danger); }
.app-card-btn:active { box-shadow: var(--shadow-in-sm); }
@media (pointer: coarse) { .app-card-actions { opacity: 1; } }

/* ============================================================
   Empty state — 件数 0 のときの表示
   ============================================================ */
.app-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 80px var(--space-5);
  color: var(--muted);
}
.app-empty-icon { font-size: 56px; opacity: .3; margin-bottom: var(--space-3); }
.app-empty-text { font-size: 14px; font-weight: 700; color: var(--text-dim); }
.app-empty-sub { font-size: 11px; }

/* ============================================================
   Editor body — ツール固有の編集 UI を入れる箱
   ============================================================ */
.app-editor-body {
  flex: 1;
  background: var(--bg);
  border-radius: var(--radius);
  padding: var(--space-8);
  min-height: 400px;
  box-shadow: var(--shadow-in-sm);
}

/* ============================================================
   Editor view 全幅オーバーライド
   一覧画面と違って編集画面は max-width 解除・左右 padding 0
   ============================================================ */
body[data-view="editor"] .app-inner {
  max-width: none;
  min-height: 100vh;
  padding: 0;
  gap: 0;
}
body[data-view="editor"] .app-header {
  padding: var(--space-5) var(--space-5) var(--space-4);
}
body[data-view="editor"] .app-editor-body {
  flex: 1;
  border-radius: 0;
  box-shadow: none;
  background: var(--bg);
  padding: var(--space-5);
  min-height: 0;
}

/* ============================================================
   Buttons — .btn / .btn-primary / .btn-ghost / .btn-danger
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-out-sm);
  transition: box-shadow .15s, color .15s, background .15s, transform .1s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { color: var(--accent); }
.btn:active {
  box-shadow: var(--shadow-in-sm);
  transform: scale(.98);
}
.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
}
.btn-ghost {
  color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); }
.btn-danger {
  color: var(--danger);
}
.btn-danger:hover { color: var(--danger); }
.btn-orange {
  background: var(--orange);
  color: #fff;
}
.btn-orange:hover { opacity: .85; color: #fff; }
.btn-teal {
  background: var(--teal);
  color: #fff;
}
.btn-teal:hover { opacity: .85; color: #fff; }

/* ============================================================
   Forms — .form-row / .form-label / .form-input
   ============================================================ */
.form-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.form-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: .04em;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  box-shadow: var(--shadow-in-sm);
  transition: box-shadow .15s;
}
.form-input:focus { box-shadow: var(--shadow-in); }
.form-input::placeholder { color: var(--muted); }
textarea.form-input { resize: vertical; min-height: 80px; font-family: inherit; }

/* ============================================================
   Modal — .modal-overlay / .modal / .modal-* 各領域
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-out-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg);
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  box-shadow: var(--shadow-out-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.modal-close:hover { color: var(--accent); }
.modal-close:active { box-shadow: var(--shadow-in-sm); }
.modal-body { padding: var(--space-2) var(--space-6) var(--space-6); overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: var(--space-2);
}

/* ============================================================
   Radio button — .radio + 中の <input type="radio">
   ============================================================ */
.radio {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  user-select: none;
}
.radio input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  cursor: pointer;
  position: relative;
  transition: box-shadow .15s;
  flex-shrink: 0;
  margin: 0;
}
.radio input[type="radio"]:hover {
  box-shadow: var(--shadow-in);
}
.radio input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.radio input[type="radio"]:disabled {
  cursor: not-allowed;
  opacity: .5;
}

/* ============================================================
   Checkbox — .checkbox + 中の <input type="checkbox">
   ============================================================ */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  user-select: none;
}
.checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  cursor: pointer;
  position: relative;
  transition: box-shadow .15s, background .15s;
  flex-shrink: 0;
  margin: 0;
}
.checkbox input[type="checkbox"]:hover {
  box-shadow: var(--shadow-in);
}
.checkbox input[type="checkbox"]:checked {
  background: var(--accent);
  box-shadow: var(--shadow-in-sm);
}
.checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 3px;
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.checkbox input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: .5;
}

/* ============================================================
   Select — .select（ネイティブ <select> をスタイル）
   ============================================================ */
.select {
  width: 100%;
  padding: 12px 36px 12px 16px;
  background: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  box-shadow: var(--shadow-in-sm);
  transition: box-shadow .15s;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238C94A0' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  cursor: pointer;
}
.select:focus { box-shadow: var(--shadow-in); }
.select:disabled {
  cursor: not-allowed;
  opacity: .5;
}

/* ============================================================
   Switch — iOS 風 ON/OFF
   <label class="switch">
     <input type="checkbox">
     <span class="switch-track"><span class="switch-thumb"></span></span>
   </label>
   ============================================================ */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}
.switch-track {
  display: inline-block;
  width: 44px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  position: relative;
  transition: background .25s;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  transition: transform .25s, background .25s;
}
.switch input:checked + .switch-track {
  background: var(--accent);
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(18px);
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.switch input:disabled + .switch-track {
  opacity: .5;
  cursor: not-allowed;
}

/* ============================================================
   Slider — ネイティブ <input type="range"> をスタイル

   thumb の左側を accent で塗るには、JS で --slider-fill を
   セットする必要がある（CSS 単体では range 値を取得できない）。
   Firefox は ::-moz-range-progress でネイティブ対応。

   JS 初期化例（全 .slider に適用）:
     document.querySelectorAll('.slider').forEach(function(s){
       function u(){ s.style.setProperty('--slider-fill',
         ((s.value-s.min)/(s.max-s.min)*100)+'%'); }
       s.addEventListener('input', u); u();
     });
   ============================================================ */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: var(--radius-full);
  background: linear-gradient(to right,
    var(--accent) 0%,
    var(--accent) var(--slider-fill, 0%),
    var(--bg) var(--slider-fill, 0%));
  box-shadow: var(--shadow-in-sm);
  outline: none;
  cursor: pointer;
  margin: 10px 0;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  cursor: pointer;
  border: none;
  transition: box-shadow .15s, background .15s;
}
.slider::-webkit-slider-thumb:hover {
  box-shadow: var(--shadow-out);
}
.slider::-webkit-slider-thumb:active {
  box-shadow: var(--shadow-in-sm);
}
/* Firefox: ネイティブで progress（左側）を塗れる */
.slider::-moz-range-track {
  background: var(--bg);
  border-radius: var(--radius-full);
  height: 8px;
  box-shadow: var(--shadow-in-sm);
}
.slider::-moz-range-progress {
  background: var(--accent);
  border-radius: var(--radius-full);
  height: 100%;
}
.slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  cursor: pointer;
  border: none;
}

/* ============================================================
   Tab bar / Segmented control
   どちらも同じ視覚言語（pill コンテナ + active が浮き上がる）
   ============================================================ */
.tab-bar,
.segmented {
  display: inline-flex;
  background: var(--bg);
  border-radius: var(--radius-full);
  padding: 4px;
  box-shadow: var(--shadow-in-sm);
  gap: 2px;
}
.tab,
.segmented-item {
  padding: 8px 18px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-full);
  transition: color .15s, box-shadow .15s, background .15s;
  white-space: nowrap;
}
.tab:hover,
.segmented-item:hover { color: var(--text); }
.tab.active,
.segmented-item.active {
  color: var(--accent);
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
}

/* ============================================================
   Badge — 小さな inline ラベル
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--bg);
  color: var(--text-dim);
  box-shadow: var(--shadow-out-sm);
}
/* semantic */
.badge-primary { color: var(--accent); }
.badge-success { color: var(--success); }
.badge-danger  { color: var(--danger); }
.badge-warning { color: var(--warning); }
.badge-info    { color: var(--info); }
/* utility palette */
.badge-purple  { color: var(--purple); }
.badge-pink    { color: var(--pink); }
.badge-orange  { color: var(--orange); }
.badge-teal    { color: var(--teal); }
.badge-indigo  { color: var(--indigo); }

/* ============================================================
   Progress — 線形進捗バー
   ============================================================ */
.progress {
  width: 100%;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  overflow: hidden;
  position: relative;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width .3s ease;
}
.progress-bar.success { background: var(--success); }
.progress-bar.danger  { background: var(--danger); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.info    { background: var(--info); }

/* indeterminate（読み込み中） */
.progress.indeterminate .progress-bar {
  width: 30% !important;
  animation: progress-indeterminate 1.4s ease-in-out infinite;
}
@keyframes progress-indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(380%); }
}

/* ============================================================
   Spinner — ローディングインジケーター
   ============================================================ */
.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--bg);
  border-top-color: var(--accent);
  box-shadow: var(--shadow-out-sm);
  animation: spinner-spin 0.8s linear infinite;
  vertical-align: middle;
}
.spinner-sm {
  width: 18px;
  height: 18px;
  border-width: 2px;
}
.spinner-lg {
  width: 48px;
  height: 48px;
  border-width: 4px;
}
@keyframes spinner-spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Divider — 水平・垂直の区切り線（neumorphism 彫り込み）
   ============================================================ */
.divider {
  border: none;
  height: 1px;
  background: var(--border-strong);
  box-shadow: 0 1px 0 var(--shadow-light);
  margin: var(--space-4) 0;
}
.divider-vertical {
  display: inline-block;
  width: 1px;
  height: 100%;
  min-height: 20px;
  background: var(--border-strong);
  box-shadow: 1px 0 0 var(--shadow-light);
  margin: 0 var(--space-4);
  vertical-align: middle;
}
/* ラベル付き divider */
.divider-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-4) 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.divider-label::before,
.divider-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-strong);
  box-shadow: 0 1px 0 var(--shadow-light);
}

/* ============================================================
   Alert / Banner — ページ内の固定メッセージ
   toast は消えるが alert は消えない（明示的に閉じるまで残る）
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.alert-icon {
  flex-shrink: 0;
  font-size: 16px;
  margin-top: 1px;
}
.alert-body { flex: 1; }
.alert-title {
  font-weight: 700;
  margin-bottom: 2px;
}
.alert-text {
  font-size: 12px;
  color: var(--text-dim);
}
.alert-close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px;
  transition: color .15s;
}
.alert-close:hover { color: var(--text); }
/* semantic variants */
.alert-success { border-left: 3px solid var(--success); }
.alert-success .alert-icon { color: var(--success); }
.alert-danger  { border-left: 3px solid var(--danger); }
.alert-danger  .alert-icon { color: var(--danger); }
.alert-warning { border-left: 3px solid var(--warning); }
.alert-warning .alert-icon { color: var(--warning); }
.alert-info    { border-left: 3px solid var(--info); }
.alert-info    .alert-icon { color: var(--info); }

/* ============================================================
   Tooltip — data-tooltip 属性で hover 時にヒント表示
   <button class="btn tooltip-parent" data-tooltip="保存します">💾</button>
   ============================================================ */
.tooltip-parent {
  position: relative;
}
.tooltip-parent::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(.92);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-out);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s, transform .15s;
  z-index: 50;
}
.tooltip-parent:hover::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
/* 下方向 */
.tooltip-parent.tooltip-bottom::after {
  bottom: auto;
  top: calc(100% + 8px);
}

/* ============================================================
   Custom Dropdown menu
   <div class="dropdown">
     <button class="dropdown-trigger">選択 ▾</button>
     <div class="dropdown-menu">
       <button class="dropdown-item">Item A</button>
       <div class="dropdown-divider"></div>
       <button class="dropdown-item">Item B</button>
     </div>
   </div>
   JS で .dropdown に .open を付けると menu が表示される
   ============================================================ */
.dropdown {
  position: relative;
  display: inline-flex;
}
.dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-out-sm);
  transition: box-shadow .15s, color .15s;
  white-space: nowrap;
}
.dropdown-trigger:hover { color: var(--accent); }
.dropdown-trigger:active { box-shadow: var(--shadow-in-sm); }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 180px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: var(--shadow-out-lg);
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 100;
}
.dropdown.open .dropdown-trigger { box-shadow: var(--shadow-in-sm); color: var(--accent); }
.dropdown.open .dropdown-menu { display: flex; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-dim);
  border: none;
  background: transparent;
  white-space: nowrap;
  width: 100%;
  text-align: left;
  transition: background .12s, color .12s;
}
.dropdown-item:hover {
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  color: var(--text);
}
.dropdown-item.active { color: var(--accent); font-weight: 700; }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { color: var(--danger); }
.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

/* ============================================================
   Picker — ネイティブ input を neumorphism スタイルに
   color / date / time / datetime-local
   ============================================================ */
.picker {
  padding: 10px 16px;
  background: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  box-shadow: var(--shadow-in-sm);
  cursor: pointer;
  transition: box-shadow .15s;
}
.picker:focus { box-shadow: var(--shadow-in); }
.picker::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: .6;
  filter: var(--picker-icon-filter, none);
}
.picker:hover::-webkit-calendar-picker-indicator { opacity: 1; }
/* color picker は正方形のほうが自然 */
input[type="color"].picker {
  width: 48px;
  height: 48px;
  padding: 6px;
  border-radius: var(--radius);
  overflow: hidden;
}
input[type="color"].picker::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"].picker::-webkit-color-swatch {
  border: none;
  border-radius: calc(var(--radius) - 4px);
}

/* カラーフィールド（swatch + hex テキスト入力のセット）
   <div class="color-field">
     <input type="color" class="color-field-swatch" value="#489CC1">
     <input type="text" class="color-field-hex" value="#489CC1" maxlength="7">
   </div>
   JS で swatch ↔ hex を同期させる。 */
.color-field {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  overflow: hidden;
  transition: box-shadow .15s;
}
.color-field:focus-within { box-shadow: var(--shadow-in); }
.color-field-swatch {
  width: 40px;
  height: 40px;
  border: none;
  cursor: pointer;
  padding: 5px;
  background: transparent;
  flex-shrink: 0;
}
.color-field-swatch::-webkit-color-swatch-wrapper { padding: 0; }
.color-field-swatch::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}
.color-field-swatch::-moz-color-swatch {
  border: none;
  border-radius: 6px;
}
.color-field-hex {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 12px 10px 4px;
  width: 90px;
  outline: none;
  text-transform: uppercase;
  letter-spacing: .04em;
}
/* dark テーマでアイコンを明るくする */
[data-theme="dark"] .picker::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

/* ============================================================
   Knob — 円形ダイヤル（静的ビジュアルのみ、JS 操作なし）
   <div class="knob">
     <div class="knob-track"></div>
     <div class="knob-indicator" style="--knob-angle:135deg"></div>
     <div class="knob-label">75</div>
   </div>
   ============================================================ */
.knob {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-out);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.knob-track {
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
}
.knob-indicator {
  position: absolute;
  width: 4px;
  height: 20px;
  background: var(--accent);
  border-radius: 2px;
  top: 10px;
  left: 50%;
  margin-left: -2px;
  transform-origin: center calc(100% + 10px);
  transform: rotate(var(--knob-angle, 0deg));
  transition: transform .3s;
}
.knob-label {
  position: relative;
  z-index: 1;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  font-family: var(--font-mono);
}
.knob-sm { width: 56px; height: 56px; }
.knob-sm .knob-track { inset: 4px; }
.knob-sm .knob-indicator { height: 14px; top: 6px; transform-origin: center calc(100% + 7px); }
.knob-sm .knob-label { font-size: 11px; }
.knob-lg { width: 110px; height: 110px; }
.knob-lg .knob-track { inset: 8px; }
.knob-lg .knob-indicator { height: 28px; top: 12px; transform-origin: center calc(100% + 14px); }
.knob-lg .knob-label { font-size: 18px; }

/* ============================================================
   Range control（2-handle）
   <div class="range-control">
     <div class="range-control-track">
       <div class="range-control-fill" style="left:20%;right:30%"></div>
     </div>
     <div class="range-control-thumb" style="left:20%"></div>
     <div class="range-control-thumb" style="left:70%"></div>
   </div>
   left / right / left% は JS で制御する。
   ============================================================ */
.range-control {
  position: relative;
  width: 100%;
  height: 8px;
  margin: 16px 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.range-control-track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-full);
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  overflow: hidden;
}
.range-control-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: left .05s, right .05s;
}
.range-control-thumb {
  position: absolute;
  top: 50%;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  transform: translate(-50%, -50%);
  cursor: grab;
  z-index: 2;
  transition: box-shadow .15s;
}
.range-control-thumb:hover { box-shadow: var(--shadow-out); }
.range-control-thumb:active {
  cursor: grabbing;
  box-shadow: var(--shadow-in-sm);
}
.range-control-values {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-top: 8px;
}

/* ============================================================
   Toast — .toast (.show / .success / .error)
   ============================================================ */
.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px 24px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  z-index: 2000;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
  box-shadow: var(--shadow-out-lg);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { color: var(--success); }
.toast.error { color: var(--danger); }

/* ============================================================
   Skeleton — 読み込み中のプレースホルダー
   <div class="skeleton skeleton-title"></div>
   <div class="skeleton skeleton-text"></div>
   ============================================================ */
.skeleton {
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--shadow-light) 50%,
    transparent 100%);
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.skeleton-title { height: 22px; width: 50%; margin-bottom: var(--space-3); }
.skeleton-text  { height: 14px; margin-bottom: var(--space-2); }
.skeleton-text:last-child { width: 70%; }
.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}
.skeleton-thumb {
  height: 140px;
  border-radius: var(--radius-sm);
}
.skeleton-btn {
  height: 40px;
  width: 120px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   Avatar — ユーザーアイコン
   <div class="avatar">Y</div>
   <div class="avatar"><img src="..."></div>
   ============================================================ */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-sans);
  user-select: none;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 48px; height: 48px; font-size: 20px; }
.avatar-xl { width: 64px; height: 64px; font-size: 26px; }
/* color variants */
.avatar-purple  { color: var(--purple); }
.avatar-pink    { color: var(--pink); }
.avatar-orange  { color: var(--orange); }
.avatar-teal    { color: var(--teal); }
.avatar-success { color: var(--success); }

/* ============================================================
   Chip — removable tag（badge は表示のみ、chip は × で消せる）
   <span class="chip">React <button class="chip-remove">×</button></span>
   ============================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 12px;
  border-radius: var(--radius-full);
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  transition: box-shadow var(--transition-fast);
}
.chip-remove {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.chip-remove:hover {
  color: var(--danger);
  background: var(--bg);
  box-shadow: var(--shadow-in-sm);
}
.chip-primary { color: var(--accent); }
.chip-success { color: var(--success); }
.chip-danger  { color: var(--danger); }

/* ============================================================
   Table — スタイル付きデータテーブル
   ============================================================ */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  font-family: inherit;
}
.table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-strong);
  box-shadow: 0 1px 0 var(--shadow-light);
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.table tbody tr {
  transition: background var(--transition-fast);
}
.table tbody tr:hover td {
  background: var(--bg-elevated);
}
.table td:first-child { font-weight: 600; }
/* compact */
.table-compact th,
.table-compact td { padding: 6px 10px; }
/* rounded card wrapper */
.table-card {
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-out-sm);
  overflow: hidden;
}

/* ============================================================
   Accordion — 折りたたみセクション
   JS で .accordion-item に .open を付け外しする
   ============================================================ */
.accordion {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.accordion-item {
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow-out-sm);
  overflow: hidden;
}
.accordion-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: color var(--transition-fast);
}
.accordion-trigger:hover { color: var(--accent); }
.accordion-trigger::after {
  content: '▾';
  font-size: 11px;
  color: var(--muted);
  transition: transform var(--transition-normal);
  flex-shrink: 0;
}
.accordion-item.open .accordion-trigger::after {
  transform: rotate(180deg);
}
.accordion-body {
  display: none;
  padding: 0 16px 14px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.7;
}
.accordion-item.open .accordion-body {
  display: block;
}

/* ============================================================
   Focus ring — アクセシビリティ（Tab キーフォーカス時）
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* neumorphism のボタン等は outline ではなく shadow で示す */
.btn:focus-visible,
.app-card-btn:focus-visible,
.theme-toggle-btn:focus-visible,
.modal-close:focus-visible {
  outline: none;
  box-shadow: var(--shadow-out-sm), 0 0 0 2px var(--accent);
}

/* ============================================================
   Scrollbar — neumorphism テーマに合わせたカスタムスクロールバー
   ============================================================ */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}
/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) var(--bg);
}

/* ============================================================
   List Chip — アイコン付き選択リスト項目
   ON/OFF トグル式。エフェクト選択・機能選択等に使う。
   <div class="list-chip-group">
     <button class="list-chip active">
       <span class="list-chip-icon">✨</span>
       <span class="list-chip-text">
         <span class="list-chip-name">グロウ</span>
         <span class="list-chip-desc">テキストに光る発光エフェクト</span>
       </span>
       <span class="list-chip-check">✓</span>
     </button>
   </div>
   ============================================================ */
.list-chip-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.list-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s, transform .15s;
  box-shadow: var(--shadow-out-sm);
  font-family: inherit;
  text-align: left;
  width: 100%;
}
.list-chip:hover:not(.active) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-out);
}
.list-chip.active {
  border-color: var(--accent);
  box-shadow: var(--shadow-out-sm), 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}
.list-chip-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow-out-sm);
}
.list-chip.active .list-chip-icon {
  box-shadow: var(--shadow-in-sm);
}
.list-chip-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.list-chip-name {
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
}
.list-chip-desc {
  font-size: 10px;
  color: var(--text-dim);
}
.list-chip-check {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: transparent;
  transition: .15s;
  flex-shrink: 0;
}
.list-chip.active .list-chip-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 767px) {
  .app-inner {
    padding: var(--space-5) var(--space-5) var(--space-6);
    gap: var(--space-4);
  }
  .app-title { font-size: 18px; }
  .app-header-left { flex: none; }
  .app-back-btn { height: 30px; font-size: 11px; padding: 0 var(--space-2); margin-right: var(--space-1); }
  .app-title-icon { width: 32px; height: 32px; font-size: 16px; }
  .app-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-3);
  }
  .app-card-thumb { height: 110px; }
}
@media (max-width: 479px) {
  .app-inner { padding: var(--space-4) var(--space-3) var(--space-6); }
  .app-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }
  .app-card-thumb { height: 90px; }
}
