:root {
    --dark: #1e1e2e;
    --panel: #2a2a3e;
    --gold: #d4a843;
    --white: #e0e0e0;
    --muted: #888;
    --danger: #c0392b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--dark);
    color: var(--white);
    font-family: "微軟正黑體", "Segoe UI", sans-serif;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--panel);
    padding: 14px 24px;
    border-bottom: 2px solid var(--gold);
}
.brand { color: var(--gold); font-weight: bold; font-size: 1.2em; text-decoration: none; }
.topbar nav a {
    color: var(--white);
    text-decoration: none;
    margin-left: 18px;
    font-size: 0.95em;
}
.topbar nav a:hover { color: var(--gold); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

.flash { background: #4a2020; color: #ffb3b3; padding: 10px 16px; margin: 12px 24px; border-radius: 6px; }

h1 { color: var(--gold); }
h2 { color: var(--gold); font-size: 1.1em; }

.filter-bar {
    background: var(--panel);
    padding: 16px;
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 20px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 0.85em; color: var(--muted); }

.searchable-select { position: relative; }
.searchable-select .ss-input {
    width: 100%; box-sizing: border-box; background: #3a3a4e; color: var(--white);
    border: 1px solid #4a4a5e; border-radius: 6px; padding: 7px 10px; font-size: 0.95em;
}
.searchable-select .ss-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
    background: #26263a; border: 1px solid #4a4a5e; border-radius: 6px; margin-top: 2px;
    max-height: 280px; overflow-y: auto; box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}
.searchable-select .ss-option { padding: 8px 12px; cursor: pointer; font-size: 0.9em; }
.searchable-select .ss-option:hover { background: var(--gold); color: var(--dark); }
.searchable-select .ss-option-empty { color: var(--muted); cursor: default; }
.searchable-select .ss-option-empty:hover { background: transparent; color: var(--muted); }
.tags-filter { flex-basis: 100%; }
.tags-filter summary { font-size: 0.85em; color: var(--muted); cursor: pointer; user-select: none; list-style: none; }
.tags-filter summary::-webkit-details-marker { display: none; }
.tags-filter summary::before { content: "▸ "; }
.tags-filter[open] summary::before { content: "▾ "; }
.tags-filter summary:hover { color: var(--white); }
.tags-filter > *:not(summary) { margin-top: 6px; }
.search-group { flex-basis: 100%; }
.search-group input[type=text] { width: 100%; padding: 8px 10px; font-size: 1em; }
.tag-checkboxes { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-group-block { flex-basis: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.tag-group-name { color: var(--gold); font-size: 0.85em; min-width: 70px; }
.medal-card-meta { padding: 0 10px; color: var(--muted); font-size: 0.8em; }

.filter-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.view-active { background: var(--gold); color: var(--dark); }

.medal-list { display: flex; flex-direction: column; gap: 10px; }
.medal-row {
    display: flex; align-items: center; gap: 16px;
    background: var(--panel); border-radius: 8px; padding: 10px 16px;
    text-decoration: none; color: var(--white); min-height: 120px;
}
.medal-row:hover { background: #33334a; }
.medal-row img { width: 200px; height: auto; aspect-ratio: 2/1; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.no-image.small { width: 200px; aspect-ratio: 2/1; display: flex; align-items: center; justify-content: center; background: #3a3a4e; color: var(--muted); font-size: 0.7em; border-radius: 6px; flex-shrink: 0; }
.medal-row-info { flex: 1; min-width: 0; }
.medal-row-title { font-weight: bold; font-size: 1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.medal-row-breadcrumb { font-size: 0.85em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.medal-row-meta { color: var(--gold); font-size: 0.85em; margin-top: 2px; }
.medal-row-notes { color: var(--muted); font-size: 0.82em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb-parent { color: var(--muted); }
.breadcrumb-sep { color: var(--muted); margin: 0 4px; }

.medal-list-mobile .medal-row {
    flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; min-height: auto;
}
.medal-list-mobile .medal-row img,
.medal-list-mobile .no-image.small {
    width: 100%; height: auto; aspect-ratio: 2/1; object-fit: cover;
}
.medal-list-mobile .medal-row-title { white-space: normal; }
.medal-list-mobile .medal-row-breadcrumb { white-space: normal; }

.intro-block { background: var(--panel); border-left: 4px solid var(--gold); border-radius: 6px; padding: 16px 20px; margin-bottom: 20px; }
.intro-block h2 { margin-top: 0; }
.intro-image-section { margin: 20px 0; }
.intro-image-section h2 { margin-bottom: 10px; }
.intro-image-section .intro-image-col { flex-direction: row; flex-wrap: wrap; }
.intro-flex { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.intro-image-col { display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.intro-image-col img { width: 280px; max-width: 100%; height: auto; border-radius: 6px; cursor: pointer; object-fit: cover; }
.intro-text { flex: 1; min-width: 240px; white-space: pre-wrap; line-height: 1.6; margin: 0; }

.app-footer { text-align: center; color: var(--muted); font-size: 0.8em; padding: 20px 0 30px; }

select, input[type=text], input[type=file], textarea {
    background: #3a3a4e;
    color: var(--white);
    border: 1px solid #4a4a5e;
    border-radius: 4px;
    padding: 6px 8px;
}

button, .btn-secondary, .btn-danger {
    background: var(--gold);
    color: var(--dark);
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.btn-secondary { background: #4a4a5e; color: var(--white); }
.btn-danger { background: var(--danger); color: white; }

.tag-chip {
    background: #3a3a4e;
    color: var(--gold);
    padding: 4px 11px;
    border-radius: 12px;
    font-size: 0.95em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.tag-chip.small { font-size: 0.85em; padding: 3px 9px; }

.medal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 18px;
}
.medal-card {
    background: var(--panel);
    border-radius: 8px;
    overflow: hidden;
    text-decoration: none;
    color: var(--white);
    display: block;
    transition: transform 0.15s;
}
.medal-card:hover { transform: translateY(-3px); }
.medal-card img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.no-image { width: 100%; aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; background: #3a3a4e; color: var(--muted); }
.medal-card-title { padding: 8px 10px 4px; font-weight: bold; }
.medal-card-breadcrumb { padding: 0 10px; font-size: 0.8em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.medal-card-tags { padding: 0 10px 10px; display: flex; flex-wrap: wrap; gap: 4px; }

.empty-state { color: var(--muted); grid-column: 1/-1; }

.detail-header { display: flex; justify-content: space-between; align-items: center; }
.detail-actions { display: flex; gap: 8px; }
.breadcrumb { color: var(--muted); margin-bottom: 10px; }
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.notes { background: var(--panel); padding: 12px; border-radius: 6px; white-space: pre-wrap; }

.intro-image-manage-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.intro-image-manage-item { width: 140px; }
.intro-image-manage-item img { width: 100%; height: 100px; object-fit: cover; border-radius: 6px; margin-bottom: 4px; }

.image-gallery { display: flex; gap: 20px; margin: 20px 0; flex-wrap: wrap; }
.image-slot { text-align: center; }
.image-slot img { max-width: 280px; max-height: 280px; border-radius: 6px; cursor: pointer; border: 2px solid var(--panel); }
.image-label { color: var(--muted); font-size: 0.85em; margin-bottom: 4px; }

.lightbox {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.85);
    align-items: center; justify-content: center;
    z-index: 100;
}
.lightbox img { max-width: 90vw; max-height: 90vh; }

.posts-section { margin-top: 30px; }
.posts-table { width: 100%; border-collapse: collapse; }
.posts-table th, .posts-table td { padding: 8px; border-bottom: 1px solid #3a3a4e; text-align: left; font-size: 0.9em; }

.medal-form { display: flex; flex-direction: column; gap: 10px; max-width: 520px; }
.medal-form label { color: var(--muted); font-size: 0.9em; margin-top: 6px; }
.hint { color: var(--muted); font-size: 0.8em; margin: 0; }
.tag-picker { background: var(--panel); padding: 10px; border-radius: 6px; }
.tag-picker-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.tag-picker-row select, .tag-picker-row input { flex: 1; min-width: 140px; }

.manage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.manage-card { background: var(--panel); padding: 16px; border-radius: 8px; }
.manage-card form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.plain-list { list-style: none; padding: 0; margin: 0; max-height: 220px; overflow-y: auto; }
.plain-list li { padding: 4px 0; border-bottom: 1px solid #3a3a4e; font-size: 0.9em; }
.muted { color: var(--muted); }

.compact-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; }
.compact-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-icons { display: flex; gap: 2px; flex-shrink: 0; }
.compact-icons form { display: inline; }
.inline-edit-form { display: none; gap: 6px; padding: 4px 0 8px; }
.inline-edit-form input[type="text"] { flex: 1; }

.image-swap-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 8px; }
.image-swap-slot { background: #2a2a3e; border-radius: 8px; padding: 8px; text-align: center; cursor: grab; border: 2px solid transparent; transition: border-color 0.15s; }
.image-swap-slot[draggable="true"]:hover { border-color: var(--gold); }
.image-swap-slot.dragging { opacity: 0.4; }
.image-swap-label { font-size: 0.85em; color: var(--gold); margin-bottom: 6px; }
.image-swap-slot img { width: 100%; height: 100px; object-fit: cover; border-radius: 4px; pointer-events: none; }
.image-swap-empty { height: 100px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.85em; }

.batch-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    background: var(--panel); border: 1px solid var(--gold); border-radius: 8px;
    padding: 10px 14px; margin-bottom: 14px; z-index: 5;
}
.batch-toolbar select, .batch-toolbar input[type="text"] { padding: 4px 6px; }
#batch_selected_count { font-weight: bold; color: var(--gold); }
#batch_status { font-size: 0.85em; color: var(--muted); }

.medal-row-wrapper { display: flex; align-items: center; gap: 8px; cursor: grab; }
.medal-row-wrapper.dragging { opacity: 0.4; }
.medal-row-wrapper .medal-row { flex: 1; }
.medal-select-box { flex-shrink: 0; width: 18px; height: 18px; cursor: pointer; }

.medal-card-wrapper { position: relative; cursor: grab; }
.medal-card-wrapper.dragging { opacity: 0.4; }
.card-select-box { position: absolute; top: 8px; left: 8px; z-index: 2; width: 20px; height: 20px; cursor: pointer; }

.orphan-card { border: 1px solid #c0392b; }
.orphan-badge { color: #e07856; font-size: 0.8em; margin: 2px 0; }

.block-heading { margin-top: 32px; padding-bottom: 6px; border-bottom: 2px solid var(--gold); }
.view-toggle-row { display: flex; gap: 8px; margin: 12px 0; }
.exhibit-other-venues { margin-top: -8px; margin-bottom: 12px; font-size: 0.85em; }
.exhibit-other-venues a { color: var(--gold); }

.duplicate-group { margin-bottom: 20px; border: 1px solid #444; }
.duplicate-group-items { display: flex; flex-wrap: wrap; gap: 16px; }
.duplicate-item { width: 140px; text-align: center; position: relative; }
.duplicate-item img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 6px; }
.duplicate-item .medal-select-box { position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; z-index: 2; }
.duplicate-item-title { font-size: 0.85em; margin-top: 4px; }

.vm-toggle {
    display: inline-flex; align-items: center; gap: 2px;
    background: #14141f; border-radius: 999px; padding: 4px;
}
.vm-toggle-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent; border: none; border-radius: 999px;
    padding: 8px 14px; font-size: 0.9em; font-family: inherit;
    color: var(--muted); cursor: pointer; text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.vm-toggle-btn:hover { color: var(--white); }
.vm-toggle-btn.active { background: #2a2a3e; color: var(--white); }
.vm-toggle-btn .vm-icon { color: var(--muted); flex-shrink: 0; }
.vm-toggle-btn.active .vm-icon { color: var(--gold); }
.icon-btn {
    background: transparent; border: 1px solid #4a4a5e; color: var(--white);
    padding: 2px 6px; font-size: 0.9em; border-radius: 4px; cursor: pointer; line-height: 1.4;
}
.icon-btn:hover { background: #3a3a4e; }
.icon-btn.danger:hover { background: var(--danger); border-color: var(--danger); }
.group-title-row { border-bottom: 1px solid #3a3a4e; padding-bottom: 8px; margin-bottom: 4px; }
.group-title-row .compact-name { font-weight: bold; color: var(--gold); }
.inline-edit-row {
    display: none; gap: 6px; align-items: center; background: #232335;
    padding: 6px 8px; border-radius: 4px; margin-bottom: 4px;
}
.inline-edit-row input[type=text] { flex: 1; min-width: 0; }
.tag-compact-list { list-style: none; padding: 0; margin: 0; }
.tag-compact-list li { border-bottom: 1px solid #3a3a4e; padding: 2px 0; }
.tag-compact-list li:last-child { border-bottom: none; }
.tag-compact-list li.dragging { opacity: 0.35; }
.drag-handle { cursor: grab; color: var(--muted); }
.drag-handle:active { cursor: grabbing; }
.toggle-arrow { padding: 2px 5px; margin-right: 4px; font-size: 0.75em; }
