.theme-edit-page .page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.theme-edit-page .page-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.back-link {
    text-decoration: none;
    color: var(--primary);
    margin-right: 0.5rem;
}

.back-link:hover {
    color: var(--primary-dark, #1d4ed8);
}

/* Edit layout */
.edit-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
    align-items: start;
}

.edit-main {
    min-width: 0;
}

.edit-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-body {
    padding: 1.25rem;
}

.card-header-static {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

/* Dynamic form fields */
.field-group {
    margin-bottom: 1rem;
}

.field-group:last-child {
    margin-bottom: 0;
}

/* Sidebar 基礎欄位容器：有內容時才保留底部間距 */
[id^="sidebar-field-"]:not(:empty) {
    margin-bottom: 1rem;
}

.field-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
}

.field-group .field-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.field-group textarea {
    min-height: 120px;
    resize: vertical;
}

.field-group .checkbox-group,
.field-group .radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.field-group .checkbox-group label,
.field-group .radio-group label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-weight: 400;
    cursor: pointer;
}

.field-group .checkbox-group input,
.field-group .radio-group input {
    width: auto;
}

/* Level / cascading selects */
.level-selects {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.level-selects select {
    flex: 1;
    min-width: 150px;
}

/* Meta info */
.meta-info {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.meta-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
    padding: 0.25rem 0;
}

.meta-label {
    color: var(--text-secondary);
}

/* File code section */
.file-code-section {
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.file-code-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.file-code-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.file-code-list {
    margin-bottom: 0.5rem;
}

.file-upload-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    cursor: pointer;
}

.file-upload-text {
    font-size: 0.8125rem;
    flex-shrink: 0;
}

.file-upload-label input[type="file"] {
    font-size: 0.8125rem;
}

.file-code-progress {
    margin-top: 0.375rem;
}

/* File item with thumbnail/icon */
.file-item {
    display: grid;
    grid-template-columns: 80px 1fr;
    grid-template-rows: auto auto;
    grid-template-areas: "thumb top" "thumb bottom";
    gap: 0.25rem 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.file-item:last-child {
    border-bottom: none;
}

.file-item-thumb {
    grid-area: thumb;
    width: 80px;
    height: 80px;
    background: #f3f4f6;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
}

.file-item-thumb a {
    display: block;
    width: 100%;
    height: 100%;
}

.file-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.file-item-thumb svg {
    width: 80px;
    height: 80px;
}

/* 右上列：大小 + 更換 + × */
.file-item-top {
    grid-area: top;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;
    align-self: end;
}

.file-item-size {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* 右下列：顯示名稱 + 改名按鈕 */
.file-item-bottom {
    grid-area: bottom;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    min-width: 0;
    align-self: start;
}

.file-item-title-text {
    font-size: 0.875rem;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

input[type="text"].file-item-title-input {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    padding: 0.2rem 0.375rem;
    border: 1px solid var(--border);
    border-radius: var(--radius, 4px);
    width: auto;
}

.file-item-edit-btn,
.file-item-confirm-btn,
.file-item-cancel-btn,
.file-item-replace-btn,
.file-item-delete {
    background: none;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0.125rem 0.375rem;
    white-space: nowrap;
}

.file-item-edit-btn:hover    { border-color: var(--primary); color: var(--primary); }
.file-item-confirm-btn       { border-color: #16a34a; color: #16a34a; }
.file-item-confirm-btn:hover { background: #dcfce7; }
.file-item-cancel-btn        { border-color: #6b7280; color: #6b7280; }
.file-item-cancel-btn:hover  { background: #f3f4f6; }
.file-item-replace-btn:hover { border-color: #d97706; color: #d97706; }
.file-item-delete:hover      { border-color: #dc2626; color: #dc2626; }

/* placeholder style for unused rule block */
.file-code-title-row-removed {
    display: none;
    box-sizing: border-box;
}

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s;
}

/* Examine status */
.examine-status {
    font-size: 0.875rem;
}

.examine-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.examine-actions .btn {
    flex: 1;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* Required indicator */
.required-star {
    color: #ef4444;
}

/* History card */
.history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-link-sm {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.8125rem;
    padding: 0;
    text-decoration: underline;
}

.btn-link-sm:hover {
    color: var(--primary-dark, #1d4ed8);
}

.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.history-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8125rem;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.history-action-badge {
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-weight: 500;
}

.history-action-INSERT  { background: #dcfce7; color: #15803d; }
.history-action-UPDATE  { background: #dbeafe; color: #1d4ed8; }
.history-action-DELETE  { background: #fee2e2; color: #dc2626; }
.history-action-RESTORE { background: #fef9c3; color: #92400e; }

.history-item-user {
    color: var(--text-secondary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item-time {
    color: var(--text-secondary);
    white-space: nowrap;
}

.btn-history-restore {
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    margin-top: 0.25rem;
}

@media (max-width: 768px) {
    .edit-layout {
        grid-template-columns: 1fr;
    }
    .theme-edit-page .page-header-row {
        flex-direction: column;
    }
}
