/* =================================================================
   基本スタイル
   ================================================================= */
body {
    font-family: 'Kaisei Opti', Georgia, 'Times New Roman', serif;
    margin: 0;
    background: #fafafa;
    color: #222;
}

main {
    margin-top: 300px;
}

/* =================================================================
   ヘッダー
   ================================================================= */
header {
    background: #fff;
    padding: 5px 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    display: flex;
    gap: 12px;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

header h1 {
    margin: 0 0 3px 0;
    font-size: 14px;
}

header input {
    display: none;
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 15px;
    font-size: 11px;
}

.mode-toggle {
    padding: 4px 8px;
    background: transparent;
    color: #666;
    border: 1px solid #ddd;
    border-radius: 3px;
    cursor: pointer;
    font-family: 'Kaisei Opti', serif;
    font-size: 11px;
    white-space: nowrap;
    margin-left: auto;
    flex-shrink: 0;
    transition: background 0.2s ease, color 0.2s ease;
}

.mode-toggle:hover {
    background: #f5f5f5;
    color: #333;
}

/* =================================================================
   編集モード制御
   ================================================================= */
/* 閲覧モード時の非表示設定 */
body:not(.edit-mode) .select-chk,
body:not(.edit-mode) .bulk,
body:not(.edit-mode) #export-btn,
body:not(.edit-mode) #import-btn,
body:not(.edit-mode) .modal .actions,
body:not(.edit-mode) #modal-save,
body:not(.edit-mode) .selection {
    display: none;
}

body:not(.edit-mode) .edit-only {
    display: none;
}

body.edit-mode .view-only {
    display: none;
}

.view-only {
    display: inline;
    color: white;
    font-size: 14px;
}

/* =================================================================
   コントロールパネル
   ================================================================= */

/* =================================================================
   コントロールパネル
   ================================================================= */
#controls {
    position: fixed;
    top: 35px;
    left: 0;
    right: 0;
    z-index: 99;
    background: #fff;
    border-bottom: 1px solid #e8eef5;
    max-height: calc(100vh - 54px);
    overflow-y: auto;
    overflow-x: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

#controls.collapsed {
    max-height: 35px;
}

#controls.collapsed .controls-content {
    opacity: 0;
    pointer-events: none;
}

#controls.collapsed .controls-header {
    border-bottom: 1px solid #e8eef5;
}

.controls-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    border-bottom: 1px solid #e8eef5;
    background: #fff;
    gap: 20px;
}

.controls-toggle {
    width: auto;
    flex-shrink: 0;
    padding: 8px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: 'Kaisei Opti', serif;
    color: #666;
    text-align: left;
    transition: background 0.2s ease;
}

.controls-toggle:hover {
    background: #f0f4f9;
}

.reset-filters {
    width: auto;
    flex-shrink: 0;
    padding: 4px 8px;
    border: 1px solid #ddd;
    background: #fff;
    cursor: pointer;
    font-size: 10px;
    font-weight: 500;
    font-family: 'Kaisei Opti', serif;
    color: #666;
    border-radius: 20px;
    transition: all 0.2s ease;
}

.reset-filters:hover {
    font-size: 10px;
    border-color: #999;
    color: #333;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 20px;
    padding: 4px 8px;
}

.controls-content {
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    opacity: 1;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.info-row {
    display: flex;
    flex-direction: row;
    gap: 16px;
    align-items: center;
    white-space: nowrap;
    padding-top: 0;
    font-size: 12px;
}

#count {
    padding: 4px 2px;
    color: #555;
    font-size: 12px;
    font-weight: 500;
}

.selection {
    padding: 4px 2px;
    color: #444;
    font-size: 12px;
    font-weight: 500;
}

/* フィルターセクション */
.filters-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 2px;
}

.filter-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-title {
    margin: 0;
    padding: 0 2px;
    font-size: 11px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 64px;
    flex-shrink: 0;
}

/* フィルターチップ */
.types,
.collections {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 0;
}

.type-chip {
    padding: 4px 8px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid #eceff3;
    cursor: pointer;
    font-family: 'Kaisei Opti', Georgia, 'Times New Roman', serif;
    font-size: 9px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.type-chip.active {
    background: linear-gradient(180deg, #3b82f6, #2563eb);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.18);
}

.type-chip.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.chip-icon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    display: inline-block;
}

/* 一括編集 */
.bulk {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 0;
    padding: 8px 10px;
    background: linear-gradient(180deg, #f8fbff, #f0f5fb);
    border-radius: 6px;
    border: 1px solid #e0e8f0;
    flex-wrap: wrap;
}

.bulk select {
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid #d0dce8;
    background: #fff;
    font-family: 'Kaisei Opti', Georgia, 'Times New Roman', serif;
    font-size: 12px;
}

.small-select {
    width: 96px;
}

#bulk-collection {
    width: 160px;
    max-height: 80px;
}

.bulk button {
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #d0dce8;
    background: #fff;
    cursor: pointer;
    font-family: 'Kaisei Opti', Georgia, 'Times New Roman', serif;
    font-size: 12px;
    font-weight: 500;
    transition: all .2s ease;
}

.bulk button:hover {
    background: #f0f5fb;
    border-color: #3b82f6;
    color: #3b82f6;
}

.actions {
    margin-left: 0;
    padding: 8px 4px;
}

.actions button {
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #d0dce8;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all .2s ease;
}

.actions button:hover {
    background: #f0f5fb;
    border-color: #3b82f6;
    color: #3b82f6;
}

/* =================================================================
   グリッド / カード
   ================================================================= */

/* =================================================================
   グリッド / カード
   ================================================================= */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    padding: 12px;
}

.no-results {
    padding: 24px;
    text-align: center;
    color: #888;
}

.card {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    transition: transform .18s ease, box-shadow .18s ease;
    box-shadow: 0 1px 6px rgba(16, 24, 40, 0.04);
    position: relative;
    text-decoration: none;
    color: inherit;
}

.card:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 12px 30px rgba(16, 24, 40, 0.12);
}

.card.selected {
    outline: 3px solid rgba(99, 102, 241, 0.12);
    box-shadow: 0 12px 30px rgba(37, 99, 235, 0.06);
}

/* サムネイル */
.thumb {
    width: 100%;
    aspect-ratio: 5/7;
    background: linear-gradient(180deg, #fbfdff, #f7f9fb);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: saturate(1.02);
}

.thumb .select-chk {
    position: absolute;
    left: 10px;
    bottom: 10px;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: #fff;
    border: 1px solid #cbd5e1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5;
    -webkit-appearance: none;
    appearance: none;
}

.thumb .select-chk::after {
    content: '';
    color: transparent;
    font-size: 12px;
    line-height: 1;
}

.thumb .select-chk:checked {
    background: linear-gradient(180deg, #2563eb, #1e40af);
    border-color: transparent;
}

.thumb .select-chk:checked::after {
    content: '✔';
    color: #fff;
    font-size: 13px;
}

/* メタデータ */
.meta {
    padding: 10px 12px;
    font-size: 13px;
    color: #222;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fafafa);
    border-top: 1px solid #f1f1f1;
}

.meta .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.type-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    margin-right: 8px;
    display: inline-block;
}

.badge {
    display: inline-block;
    background: rgba(0, 0, 0, 0.06);
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    margin-left: 8px;
}

.badge.type {
    background: linear-gradient(180deg, #fff, #f3f6fb);
    border: 1px solid #eef3ff;
    color: #0f172a;
    font-weight: 600;
}

.badge.collection {
    background: linear-gradient(180deg, #fff7ed, #fff1e6);
    border: 1px solid #ffe9d5;
    color: #92400e;
    font-weight: 600;
}

/* =================================================================
   モーダル
   ================================================================= */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(2, 6, 23, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
    z-index: 1000;
}

.modal.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-inner {
    width: 90vw;
    max-width: 450px;
    max-height: 90vh;
    background: rgb(0 0 0 / 50%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    box-sizing: border-box;
    z-index: 1001;
    padding: 16px;
}

body.edit-mode .modal-inner {
    overflow-y: auto;
}

.modal img {
    width: 100%;
    max-height: 70vh;
    height: auto;
    object-fit: contain;
    border-radius: 22px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background: #fff;
    display: block;
    margin: 0 auto;
}

.modal-caption {
    color: #fff;
    text-align: center;
    font-size: 16px;
}

.modal-close {
    position: relative;
    background: rgba(255, 255, 255, 0.12);
    border: 0;
    color: #fff;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    z-index: 1002;
    align-self: center;
    margin-top: 8px;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.18);
}

.modal-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.modal-controls label {
    color: white;
}

.modal-controls select {
    padding: 6px;
    border-radius: 8px;
}

.modal-controls button {
    padding: 8px 16px;
    border-radius: 8px;
}

.collection-highlight {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    justify-content: center;
    padding: 12px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    margin-bottom: 8px;
}

body:not(.edit-mode) .collection-highlight {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.collection-highlight label {
    font-weight: 600;
    font-size: 16px;
    text-align: center;
}

body:not(.edit-mode) .collection-highlight label {
    text-align: center;
    flex-shrink: 0;
}

.collection-highlight select[multiple] {
    width: 100%;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    padding: 4px;
    font-family: 'Kaisei Opti', Georgia, 'Times New Roman', serif;
    font-size: 13px;
}

.collection-highlight .view-only {
    font-weight: 600;
    font-size: 16px;
    text-align: center;
}

body:not(.edit-mode) .collection-highlight .view-only {
    text-align: center;
}

/* =================================================================
   レスポンシブ
   ================================================================= */
@media (min-width: 768px) {
    #controls {
        top: 42px;
    }

    header h1 {
        font-size: 20px;
    }

    .filter-section {
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }

    .filter-title {
        min-width: 52px;
        margin-right: 4px;
    }

    .filter-section>.types,
    .filter-section>.collections {
        flex: 1;
    }
}