/* 部品：どの画面（モジュールを含む）でも同じ名前で使う。一覧は docs/ui.md */
@layer components {

  /* ---- ページの見出し：左に題名、右に主な操作 */
  .page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 4px 0 18px;
  }
  .page-title { margin: 0 0 18px; font-size: 24px; letter-spacing: .01em; }
  .page-head .page-title { margin: 0; }
  .page-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
  .page-pre { margin: 0 0 2px; color: var(--muted); font-size: 14px; }
  .page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .back-link {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    min-height: 36px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
  }
  .back-link svg.i { width: 18px; height: 18px; }
  .back-link:hover { color: var(--accent); }

  /* ---- 区切りの見出し（カードの外） */
  .section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 28px 2px 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: .04em;
  }
  .section-title a { font-weight: 600; text-decoration: none; }

  /* ---- ボタン */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: transform .12s, background .15s, border-color .15s, box-shadow .15s;
  }
  .btn:hover { background: var(--surface-2); }
  .btn:active { transform: scale(.97); }
  .btn:disabled { opacity: .45; cursor: default; transform: none; }
  .btn svg.i { width: 18px; height: 18px; }
  .btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
  .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn-danger { color: var(--danger); }
  .btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
  .btn-danger-fill { background: var(--danger); border-color: var(--danger); color: var(--danger-fg); }
  .btn-danger-fill:hover { background: var(--danger); filter: brightness(1.08); }
  .btn-ghost { border-color: transparent; background: none; }
  .btn-block { width: 100%; }
  .btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
  .btn-icon { width: 36px; padding: 0; }
  .icon-btn {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: none;
    color: var(--text);
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
  }
  .icon-btn:hover { background: var(--surface-2); }
  .actions-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

  /* ---- カード */
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
  }
  .card-title { font-size: 17px; margin: 0 0 12px; }
  .card > :last-child { margin-bottom: 0; }

  /* ---- お知らせ（画面の中に出す注意・結果） */
  .notice {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    flex-wrap: wrap;
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 15px;
  }
  .notice > svg.i { margin-top: 2px; }
  .notice-success { background: var(--success-soft); color: var(--success); }
  .notice-error { background: var(--danger-soft); color: var(--danger); }
  .notice-warning { background: var(--warning-soft); color: var(--warning); }
  .notice-info { background: var(--accent-soft); color: var(--accent); }
  .notice b, .notice strong { color: inherit; }
  .notice .notice-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
  .notice .notice-body p { margin: 2px 0 0; color: var(--muted); }

  /* ---- 状態の札 */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 22px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    background: var(--accent-soft);
    color: var(--accent);
    white-space: nowrap;
  }
  .badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
  .badge-published { background: var(--success-soft); color: var(--success); }
  .badge-scheduled { background: var(--accent-soft); color: var(--accent); }
  .badge-draft { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--border); }
  .badge-trash, .badge-off { background: var(--danger-soft); color: var(--danger); }
  .badge-wait { background: var(--warning-soft); color: var(--warning); }
  .badge-busy { background: var(--warning-soft); color: var(--warning); }

  /* ---- 一覧（カードの中に行を並べる） */
  .list {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .list-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    transition: background .15s;
  }
  .list-item:first-child { border-top: 0; }
  .list-item.is-link { cursor: pointer; flex-wrap: nowrap; }
  .list-item.is-link:hover { background: var(--surface-2); }
  .list-main { flex: 1 1 220px; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
  .list-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .list-actions form { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
  .list-thumb {
    width: 48px;
    height: 48px;
    flex: none;
    border-radius: 10px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: linear-gradient(135deg, var(--accent-soft), var(--surface-2));
    color: var(--faint);
  }
  .list-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .post-title {
    display: block;
    width: 100%;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  a.post-title:hover { color: var(--accent); }
  .post-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 12.5px; color: var(--muted); }
  .row-acts { display: flex; gap: 2px; flex: none; }
  .row-acts .icon-btn { width: 40px; height: 40px; color: var(--muted); }
  .row-acts .icon-btn:hover { color: var(--accent); background: var(--accent-soft); }
  .row-acts .icon-btn svg.i { width: 19px; height: 19px; }
  .chev { color: var(--faint); width: 18px; height: 18px; }

  /* ---- 設定の一覧（アイコン・題名・説明・右に短い状態） */
  .set-group { margin: 24px 2px 8px; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
  .set-group:first-child { margin-top: 0; }
  .set-list { padding: 0; overflow: hidden; }
  .set-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 4px 14px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    transition: background .15s;
  }
  .set-row > .chev { grid-column: -2; }
  .set-row .set-ic, .set-row > .chev { grid-row: 1 / span 2; }
  /* スマホ：右の状態は題名の下に（横に置くと題名と説明が細く潰れる） */
  @media (max-width: 599px) {
    .set-row { grid-template-columns: auto minmax(0, 1fr) auto; }
    .set-row .set-value { grid-column: 2; justify-self: start; white-space: normal; }
    .set-row > .chev { grid-column: 3; }
  }
  .set-row:first-child { border-top: 0; }
  a.set-row:hover, button.set-row:hover { background: var(--surface-2); }
  button.set-row { width: 100%; border-left: 0; border-right: 0; border-bottom: 0; background: none; text-align: left; cursor: pointer; font: inherit; }
  .set-row:first-child { border-top: 0; }
  .set-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
  .set-ic svg.i { width: 19px; height: 19px; }
  .set-text { flex: 1; min-width: 0; }
  .set-text b { display: block; font-weight: 600; line-height: 1.4; }
  .set-text small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
  .set-value { font-size: 13px; color: var(--muted); white-space: nowrap; }
  .set-value.is-warning { color: var(--warning); font-weight: 700; }
  .set-value.is-danger { color: var(--danger); font-weight: 700; }
  .set-row select { grid-column: 2 / -1; min-width: 0; min-height: 44px; }
  .set-list form { margin: 0; }
  .set-list form + .set-row, .set-row + form .set-row { border-top: 1px solid var(--border); }

  /* ---- 入力 */
  .form { display: grid; gap: 16px; }
  .field { display: grid; gap: 6px; margin: 0; }
  .field > span, .field > label:not(.switch):not(.check) > span { font-weight: 600; font-size: 14px; line-height: 1.4; }
  .hint { color: var(--muted); font-size: 12.5px; line-height: 1.55; overflow-wrap: anywhere; }
  .hint code { font-size: .95em; padding: 0 3px; border-radius: 4px; background: var(--surface-2); }
  .field-error { color: var(--danger); font-size: 13px; }
  .check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
  .check input { width: 20px; height: 20px; margin-top: 3px; flex: none; }
  .check span { display: grid; gap: 2px; }
  /* ON/OFF のスイッチ（中身は checkbox。記事のオプションの toggle） */
  .switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; min-height: 44px; }
  .switch > span { font-weight: 700; font-size: 14px; }
  .switch input { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 44px; height: 26px; margin: 0; border-radius: 13px; background: var(--faint); cursor: pointer; transition: background .15s; }
  .switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--knob); box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .15s; }
  .switch input:checked { background: var(--accent); }
  .switch input:checked::after { transform: translateX(18px); }
  .switch input:disabled { opacity: .5; cursor: default; }
  .switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  /* まとまり・繰り返し・表のマス（FieldForm）。行・列の操作は、表を触っているときだけ末尾に出る［⋯］（admin.js）。行番号などの飾りは出さない */
  .field-group, .field-list, .field-grid, .field-gallery { border: 0; padding: 0; margin: 0; min-width: 0; display: grid; gap: 10px; }
  .field-group > legend, .field-list > legend, .field-grid > legend, .field-gallery > legend {
    display: flex; align-items: center; gap: 8px;
    padding: 0; margin-bottom: 2px;
    font-weight: 700; font-size: 14px; line-height: 1.4;
  }
  .field-group > legend::before, .field-list > legend::before, .field-grid > legend::before, .field-gallery > legend::before {
    content: ""; flex: none; width: 3px; height: 14px; border-radius: 2px; background: var(--accent);
  }
  /* まとまり（group）：左に線を引いて、中の項目がひとまとまりだと分かるように */
  .field-group { padding: 2px 0 2px 14px; border-left: 3px solid color-mix(in srgb, var(--accent) 35%, var(--border)); }
  .field-group > legend { margin-left: -14px; }
  .field-group > legend::before { display: none; }
  .sheet-add { justify-self: start; }
  .field-list:not(.is-empty) > .sheet-add, .field-grid:not(.is-empty) > .sheet-add, .field-list.is-empty > .sheet-wrap, .field-list.is-empty > .field-rows, .field-grid.is-empty > .sheet-wrap { display: none; }
  /* 繰り返し（カードの形）：1行ずつのまとまり */
  .field-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
  .field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: 12px 20px;
    align-items: start;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-s);
    background: var(--surface-2);
  }
  .field-row > .field.is-wide, .field-row > fieldset.field { grid-column: 1 / -1; }
  .field-row.is-current { border-color: var(--accent); }
  .field-rows .field-row:not(:first-child) .hint { display: none; } /* 同じ説明が行ごとに並ばないように（1行目だけ） */
  /* 表（繰り返しの表の形・表のマス）：罫線の中のマスは枠のない入力、押したマスだけ青く囲み、触っている行は薄く色を付ける */
  .sheet-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface); }
  .sheet { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
  .sheet th, .sheet td { padding: 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
  .sheet tr > :last-child { border-right: 0; }
  .sheet tbody tr:last-child > * { border-bottom: 0; }
  .sheet thead th { padding: 6px 10px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 700; text-align: left; white-space: nowrap; }
  .sheet input.cell, .sheet select.cell { display: block; width: 100%; min-width: 7em; min-height: 42px; margin: 0; padding: 8px 10px; border: 0; border-radius: 0; background: transparent; box-shadow: none; font-size: 14px; color: var(--text); }
  .sheet input.cell:focus, .sheet select.cell:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--surface); }
  .sheet input.cell[readonly] { color: var(--muted); }
  .sheet tr.is-current > td { background: var(--accent-soft); }
  .switch-cell { min-height: 42px; justify-content: center; padding: 0 8px; }
  .field-grid[data-header-row] tbody tr:first-child input.cell, .field-grid[data-header-col] tbody td:first-child input.cell { font-weight: 700; }
  .field-grid[data-header-row] tbody tr:first-child > td, .field-grid[data-header-col] tbody td:first-child { background: var(--surface-2); }
  /* ［⋯］：触っているマスの右端（カードの形は行の右上）に1つだけ。表の外を押すまでと、メニューを開いている間だけ見える */
  .sheet td, .field-row { position: relative; }
  .sheet-more { display: none; position: absolute; top: 50%; right: 3px; z-index: 2; transform: translateY(-50%); align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 16px; line-height: 1; cursor: pointer; }
  .field-row > .sheet-more { top: 8px; transform: none; }
  .is-editing .is-current input.cell { padding-right: 44px; } /* 右端の［⋯］に文字が隠れないように */
  .field-list.is-editing .is-current .sheet-more, .field-grid.is-editing .is-current .sheet-more, .sheet-more[aria-expanded="true"] { display: inline-flex; }
  .sheet-more:hover, .sheet-more[aria-expanded="true"] { background: var(--surface-2); }
  .sheet-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  .sheet-menu { position: absolute; z-index: 70; display: grid; min-width: 190px; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface); box-shadow: var(--shadow-l); }
  .sheet-menu hr { margin: 4px 6px; border: 0; border-top: 1px solid var(--border); }
  .sheet-menu button { padding: 10px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: 14px; text-align: left; cursor: pointer; }
  .sheet-menu button:hover, .sheet-menu button:focus-visible { background: var(--surface-2); outline: none; }
  .sheet-menu .is-danger { color: var(--danger); }
  /* 管理者向け：編集者に制限している項目のまとめ（折りたたみ） */
  .field-perms { font-size: 13px; color: var(--muted); }
  .field-perms summary { cursor: pointer; }
  .field-perms ul { margin: 6px 0 0; padding-left: 1.2em; display: grid; gap: 2px; }
  .visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .inline-form { display: inline-flex; margin: 0; }

  /* ---- 情報の並び（見出しと値） */
  .info { margin: 0 0 16px; display: grid; gap: 10px; }
  .info > div { display: grid; gap: 2px; }
  .info dt { color: var(--muted); font-size: 13px; }
  .info dd { margin: 0; overflow-wrap: anywhere; }
  .info-compact > div { padding: 2px 0; }
  .big { font-size: 1.3rem; letter-spacing: .05em; }

  /* ---- 切り替え（状態・種類など） */
  .tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 1 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 40px; /* 指で押せる高さ（ui.md「スマホが先」） */
    padding: 4px 12px;
    border-radius: 9px;
    color: var(--muted);
    font-size: 13.5px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    transition: background .2s, color .2s;
  }
  .tab:hover { color: var(--text); }
  .tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  .tab-count { font-size: 12px; font-weight: 500; color: var(--faint); margin-left: 2px; }

  /* ---- 絞り込み・検索 */
  .filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
  .filter input[type="search"] { flex: 1 1 200px; width: auto; }
  .filter select { flex: 0 1 200px; width: auto; }
  .filter-link { font-size: 14px; margin-left: auto; }

  .pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 16px 0; }

  /* ---- 空のとき */
  .empty { padding: 36px 20px; text-align: center; color: var(--muted); }
  .empty svg.i { width: 36px; height: 36px; color: var(--faint); margin-bottom: 8px; }
  .empty p { margin: 0 0 14px; }

  /* ---- 選択中の操作（一覧でまとめて操作するとき） */
  .bulk-bar {
    position: sticky;
    top: calc(var(--topbar-h) + 8px);
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 8px 8px 16px;
    margin-bottom: 12px;
    border-radius: 14px;
    background: var(--text);
    color: var(--bg);
    box-shadow: var(--shadow-l);
    animation: kwe-enter .25s var(--ease) both;
  }
  .bulk-bar b { margin-right: auto; font-size: 14px; }
  .bulk-bar .btn { border-color: transparent; background: rgba(127, 127, 127, .22); color: inherit; min-height: 36px; }
  .bulk-bar .btn-danger-fill { background: var(--danger); color: var(--danger-fg); }
  .row-check { display: none; width: 22px; height: 22px; flex: none; margin: 0; }
  .is-selecting .row-check { display: block; }
  .is-selecting .row-acts { display: none; }
  .is-selecting .list-item { cursor: pointer; }

  /* ---- 確認ダイアログ（data-confirm で出る） */
  .kwe-dialog {
    border: 0;
    padding: 0;
    background: none;
    max-width: calc(100vw - 32px);
    width: 360px;
    color: var(--text);
  }
  .kwe-dialog::backdrop { background: var(--scrim); animation: kwe-fade .2s both; }
  .kwe-dialog-box {
    padding: 22px 20px 16px;
    border-radius: var(--radius-l);
    background: var(--surface);
    box-shadow: var(--shadow-l);
    animation: kwe-pop .25s var(--ease) both;
  }
  .kwe-dialog-box h2 { margin: 0 0 6px; font-size: 17px; }
  .kwe-dialog-box p { margin: 0 0 18px; color: var(--muted); font-size: 14px; white-space: pre-line; }
  .kwe-dialog-btns { display: flex; gap: 8px; }
  .kwe-dialog-btns .btn { flex: 1; }

  /* ---- トースト（保存しました 等） */
  .toast {
    position: fixed;
    left: 50%;
    top: 14px;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100vw - 32px);
    padding: 10px 18px 10px 12px;
    border-radius: 999px;
    background: var(--toast-bg);
    color: var(--toast-fg);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-l);
    transform: translate(-50%, calc(-100% - 24px)); /* 影も含めて画面の外へ（-120% では下の数ピクセルが上のバーに覗いていた） */
    visibility: hidden;
    transition: transform .4s var(--ease), visibility 0s .4s;
  }
  .toast.is-shown { transform: translate(-50%, 0); visibility: visible; transition: transform .4s var(--ease); }
  .toast-mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--toast-ok); }
  .toast-mark svg.i { width: 14px; height: 14px; stroke-width: 3; }
  .toast-error .toast-mark, .toast-warning .toast-mark { background: var(--toast-warn); }

  /* ---- 下から出るシート（スマホ） */
  .sheet-scrim {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
  }
  .sheet-scrim.is-open { opacity: 1; pointer-events: auto; }

  /* ---- アバター */
  .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex: none;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 14px;
    font-weight: 800;
  }
  .site-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex: none;
    object-fit: cover;
    display: grid;
    place-items: center;
    background: var(--hero);
    color: var(--hero-fg);
    font-size: 13px;
    font-weight: 800;
  }

  @keyframes kwe-enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  @keyframes kwe-fade { from { opacity: 0; } to { opacity: 1; } }
  @keyframes kwe-pop { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: none; } }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  }

  /* ---- メディアを選ぶダイアログ（views/_media_dialog.php・media-picker.js。本文への挿入・アイキャッチ・画像と PDF の欄で共用） */
  .media-dialog { width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); }
  .media-dialog::backdrop { background: rgba(0, 0, 0, .45); }
  .media-dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
  .media-dialog-tools { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 0; align-items: center; }
  .media-dialog-tools input[type="search"] { flex: 1 1 180px; width: auto; min-height: 40px; }
  .media-dialog .upload-status { padding: 0 16px; }
  .media-dialog-grid { list-style: none; margin: 0; padding: 8px 16px; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .media-dialog-grid button { display: block; width: 100%; padding: 0; border: 2px solid transparent; border-radius: 8px; background: var(--bg); cursor: pointer; overflow: hidden; }
  .media-dialog-grid button.is-selected { border-color: var(--accent); }
  .media-dialog-grid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
  .media-dialog-grid span { display: block; font-size: 11px; padding: 2px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
  .media-dialog-pager { text-align: center; padding: 0 16px 8px; }
  .media-dialog-pick { display: grid; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--border); background: var(--surface); }
  .media-dialog-pick img { max-height: 120px; max-width: 100%; object-fit: contain; justify-self: start; border-radius: 6px; }
  .media-dialog-pick-name { margin: 0; font-weight: 700; }
  .media-dialog-grid .pdf-badge { display: grid; place-items: center; aspect-ratio: 1; font-style: normal; font-weight: 700; color: var(--danger-fg); background: var(--danger); }
  .media-dialog-filter { display: flex; gap: 6px; padding: 8px 16px 0; }
  .media-dialog-filter button { font: inherit; font-size: 13px; padding: 4px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); cursor: pointer; }
  .media-dialog-filter button.is-active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
  /* 一覧の高さを固定して中だけスクロール（絞り込みを切り替えてもダイアログの大きさが変わらない） */
  .media-dialog-grid { height: clamp(160px, 40vh, 420px); overflow-y: auto; align-content: start; transition: opacity .15s; }
  .media-dialog-grid.is-loading { opacity: .5; }
  .media-dialog-pick { min-height: 190px; align-content: start; }
  .media-dialog-pick.is-empty > :not(.media-dialog-empty):not(#media-dialog-insert) { display: none; }
  .media-dialog-pick:not(.is-empty) .media-dialog-empty { display: none; }
  /* ---- 画像・PDF の欄（オプション・コンテンツ。FieldForm、操作は admin.js）。選んだものを小さく見せ、［選ぶ］［外す］ */
  .media-preview:empty { display: none; }
  .media-preview img { display: block; max-width: 100%; max-height: 160px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
  .media-preview .pdf-badge { display: inline-block; margin-right: 8px; padding: 2px 8px; border-radius: 4px; font-style: normal; font-weight: 700; font-size: 12px; color: var(--danger-fg); background: var(--danger); }

  /* ---- 写真の並び（gallery。FieldForm、操作は admin.js）。小さな写真を並べ、下に［←］［→］［×］ */
  .gallery-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .gallery-items:empty { display: none; }
  .gallery-item { position: relative; display: grid; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: grab; }
  .gallery-item.is-dragging { opacity: .4; }
  .gallery-item img, .gallery-missing { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
  .gallery-missing { display: grid; place-items: center; font-size: 11px; color: var(--muted); background: var(--bg); }
  .gallery-acts { display: flex; justify-content: space-between; }
  .gallery-acts button { min-width: 28px; min-height: 28px; padding: 0 4px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
  .gallery-acts [data-gallery-remove] { color: var(--danger); }
}
