/* ==========================================
   MangaStudio - Image Editor Component
   Apple-inspired minimalist design
   ========================================== */

/* ==========================================
   Edit Button (below image)
   ========================================== */

.btn-edit-image {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--bg-secondary, #f5f5f7);
    color: var(--text-primary, #1d1d1f);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: var(--radius-md, 12px);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    margin-top: 16px;
}

.btn-edit-image:hover {
    background: var(--bg-primary, #ffffff);
    border-color: var(--accent, #0071e3);
    color: var(--accent, #0071e3);
}

.btn-edit-image svg {
    width: 16px;
    height: 16px;
}

/* ==========================================
   Main Edit Panel Container
   ========================================== */

.image-edit-panel {
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: var(--radius-lg, 16px);
    padding: 24px;
    margin-top: 20px;
    box-shadow: var(--shadow-sm, 0 2px 8px rgba(0, 0, 0, 0.04));
    animation: panelSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes panelSlide {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.edit-panel-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ==========================================
   Panel Row (flexbox container)
   ========================================== */

.edit-panel-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

/* ==========================================
   Quick Actions Section
   ========================================== */

.edit-quick-actions {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quick-action-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary, #86868b);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}

.quick-action-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.btn-quick-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-secondary, #f5f5f7);
    color: var(--text-primary, #1d1d1f);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: var(--radius-sm, 8px);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-quick-action:hover {
    background: var(--bg-primary, #ffffff);
    border-color: var(--accent, #0071e3);
    color: var(--accent, #0071e3);
    transform: translateY(-1px);
}

.btn-quick-action svg {
    width: 14px;
    height: 14px;
}

/* Model Selector Dropdown */
.model-selector {
    padding: 8px 14px;
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: var(--radius-sm, 8px);
    font-size: 13px;
    font-weight: 500;
    background: var(--bg-primary, #ffffff);
    color: var(--text-primary, #1d1d1f);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.model-selector:hover {
    border-color: var(--accent, #0071e3);
}

.model-selector:focus {
    outline: none;
    border-color: var(--accent, #0071e3);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

/* ==========================================
   History Section
   ========================================== */

.edit-history {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary, #86868b);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}

.history-timeline {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* History Item */
.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm, 8px);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid transparent;
}

.history-item:hover {
    background: var(--bg-secondary, #f5f5f7);
    border-color: var(--border-light, #e5e5e7);
}

.history-item.active {
    background: rgba(0, 113, 227, 0.04);
    border-color: var(--accent, #0071e3);
}

.history-dot {
    width: 10px;
    height: 10px;
    background: var(--border, #d2d2d7);
    border-radius: 50%;
    flex-shrink: 0;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.history-item.active .history-dot {
    background: var(--accent, #0071e3);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15);
}

.history-info {
    flex: 1;
}

.history-version {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #1d1d1f);
}

.history-date {
    font-size: 11px;
    color: var(--text-tertiary, #a1a1a6);
    margin-top: 2px;
}

/* ==========================================
   Version History List (alternative layout)
   ========================================== */

.version-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.version-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: var(--radius-sm, 8px);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.version-item:hover {
    border-color: var(--accent, #0071e3);
    background: rgba(0, 113, 227, 0.02);
}

.version-thumbnail {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm, 8px);
    object-fit: cover;
    flex-shrink: 0;
}

.version-meta {
    flex: 1;
}

.version-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-secondary, #f5f5f7);
    color: var(--text-secondary, #86868b);
    border-radius: var(--radius-sm, 8px);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.version-badge.current {
    background: rgba(0, 113, 227, 0.1);
    color: var(--accent, #0071e3);
}

/* ==========================================
   Input Bar (Full width with inline submit)
   ========================================== */

.edit-input-bar {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

/* Input Container (full width with @ and + inside) */
.edit-input-container {
    flex: 1;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: 16px;
    padding: 10px 14px;
    transition: all 0.2s ease;
    position: relative;
}

.edit-input-container:focus-within {
    border-color: var(--accent, #0071e3);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.edit-input-field {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

/* Contenteditable Input */
.edit-input {
    flex: 1;
    min-height: 24px;
    max-height: 100px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary, #1d1d1f);
    outline: none;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.edit-input:empty:before {
    content: attr(data-placeholder);
    color: var(--text-tertiary, #86868b);
    pointer-events: none;
}

.edit-input-inline-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
    align-items: center;
}

.btn-inline-action {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-tertiary, #86868b);
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-inline-action:hover {
    background: var(--bg-secondary, #f5f5f7);
    color: var(--accent, #0071e3);
}

/* Circular Submit Button (iMessage style) */
.btn-submit-circle {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent, #0071e3);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-submit-circle:hover {
    background: #0077ed;
    transform: scale(1.05);
}

.btn-submit-circle:active {
    transform: scale(0.95);
}

.btn-submit-circle:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-submit-circle svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2.5;
}

.btn-submit-circle.processing {
    pointer-events: none;
}

.btn-submit-circle.processing svg {
    animation: spin 1s linear infinite;
}

/* ==========================================
   Character Chips Container (for @mentions)
   ========================================== */

.mentioned-characters-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.mentioned-characters-chips:empty {
    display: none;
    margin-bottom: 0;
}

.character-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(0, 113, 227, 0.1);
    color: var(--accent, #0071e3);
    border-radius: var(--radius-sm, 8px);
    font-size: 13px;
    font-weight: 500;
    margin: 0 2px;
    cursor: default;
}

.character-chip .chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 2px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.character-chip .chip-remove:hover {
    opacity: 1;
}

/* ==========================================
   Mention Dropdown
   ========================================== */

.mention-dropdown {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: var(--radius-md, 12px);
    box-shadow: var(--shadow-md, 0 4px 20px rgba(0, 0, 0, 0.08));
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
    animation: dropdownSlide 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dropdownSlide {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mention-list {
    padding: 4px;
}

.mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm, 8px);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.mention-item:hover {
    background: var(--bg-secondary, #f5f5f7);
}

.mention-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent, #0071e3);
    color: #ffffff;
    border-radius: var(--radius-sm, 8px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.mention-details {
    flex: 1;
}

.mention-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #1d1d1f);
}

.mention-role {
    font-size: 11px;
    color: var(--text-tertiary, #a1a1a6);
}

/* Custom scrollbar for mention dropdown */
.mention-dropdown::-webkit-scrollbar {
    width: 6px;
}

.mention-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.mention-dropdown::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.mention-dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* ==========================================
   Selected References (thumbnails)
   ========================================== */

.selected-references {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-light, #e5e5e7);
}

.reference-thumb {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm, 8px);
    overflow: hidden;
    border: 2px solid var(--border-light, #e5e5e7);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.reference-thumb:hover {
    border-color: var(--accent, #0071e3);
    transform: scale(1.05);
}

.reference-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.reference-thumb-remove,
.reference-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.reference-thumb:hover .reference-thumb-remove,
.reference-thumb:hover .reference-remove {
    opacity: 1;
}


/* ==========================================
   Progress Bar
   ========================================== */

.edit-progress {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-secondary, #f5f5f7);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent, #0071e3) 0%, #40a9ff 100%);
    border-radius: 3px;
    transition: width 0.4s ease;
    animation: progressPulse 1.5s ease-in-out infinite;
}

@keyframes progressPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

.progress-text {
    font-size: 13px;
    color: var(--text-secondary, #86868b);
    text-align: center;
}

/* ==========================================
   Reference Picker Modal
   ========================================== */

.reference-picker-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.reference-picker-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.reference-picker-content {
    position: relative;
    background: var(--bg-primary, #ffffff);
    border-radius: var(--radius-lg, 16px);
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg, 0 12px 40px rgba(0, 0, 0, 0.12));
    animation: modalSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Reference Picker Header */
.reference-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--border-light, #e5e5e7);
}

.reference-picker-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #1d1d1f);
    letter-spacing: -0.02em;
}

.picker-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-tertiary, #86868b);
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--radius-sm, 8px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.picker-close:hover {
    background: var(--bg-secondary, #f5f5f7);
    color: var(--text-primary, #1d1d1f);
}

/* ==========================================
   Reference Picker Body
   ========================================== */

.reference-picker-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Custom scrollbar for picker body */
.reference-picker-body::-webkit-scrollbar {
    width: 6px;
}

.reference-picker-body::-webkit-scrollbar-track {
    background: transparent;
}

.reference-picker-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.reference-picker-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* Chapter/Topic Selectors */
.chapter-selector,
.topic-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chapter-selector label,
.topic-selector label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary, #86868b);
}

.ref-select {
    padding: 10px 14px;
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: var(--radius-md, 12px);
    font-size: 14px;
    background: var(--bg-primary, #ffffff);
    color: var(--text-primary, #1d1d1f);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

.ref-select:hover {
    border-color: var(--accent, #0071e3);
}

.ref-select:focus {
    outline: none;
    border-color: var(--accent, #0071e3);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

/* ==========================================
   Reference Images Grid
   ========================================== */

.reference-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    min-height: 200px;
}

.reference-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    color: var(--text-tertiary, #a1a1a6);
}

.reference-empty svg {
    width: 32px;
    height: 32px;
}

.reference-empty span {
    font-size: 14px;
}

/* ==========================================
   Reference Thumbnail Item
   ========================================== */

.reference-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md, 12px);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.reference-item:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md, 0 4px 20px rgba(0, 0, 0, 0.08));
}

.reference-item.selected {
    border-color: var(--accent, #0071e3);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.reference-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.reference-item::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 113, 227, 0.15);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.reference-item.selected::after {
    opacity: 1;
}

.reference-check {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: var(--accent, #0071e3);
    color: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.reference-item.selected .reference-check {
    opacity: 1;
    transform: scale(1);
}

/* Reference Info Overlay */
.reference-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.reference-item:hover .reference-info {
    opacity: 1;
}

.reference-chapter {
    font-size: 11px;
    font-weight: 600;
    color: #ffffff;
}

.reference-topic {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================
   Reference Picker Footer
   ========================================== */

.reference-picker-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid var(--border-light, #e5e5e7);
    background: var(--bg-primary, #ffffff);
}

/* ==========================================
   Responsive Adjustments
   ========================================== */

@media (max-width: 768px) {
    .image-edit-panel {
        padding: 20px;
        border-radius: var(--radius-md, 12px);
    }

    .edit-panel-content {
        gap: 20px;
    }

    .edit-panel-row {
        flex-direction: column;
        gap: 20px;
    }

    .edit-input-bar {
        gap: 8px;
    }

    .btn-submit-circle {
        width: 34px;
        height: 34px;
    }

    .reference-images-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }

    .reference-picker-content {
        width: 95%;
        max-height: 90vh;
        border-radius: var(--radius-md, 12px);
    }

    .reference-picker-header,
    .reference-picker-body,
    .reference-picker-footer {
        padding: 16px;
    }

    .quick-action-controls {
        flex-wrap: wrap;
    }
}

/* ==========================================
   History Toggle Button
   ========================================== */

.edit-history-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn-history-toggle,
.btn-upload-manual {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-secondary, #f5f5f7);
    color: var(--text-primary, #1d1d1f);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-history-toggle:hover,
.btn-upload-manual:hover {
    background: var(--bg-primary, #ffffff);
    border-color: var(--accent, #0071e3);
    color: var(--accent, #0071e3);
}

.btn-history-toggle svg,
.btn-upload-manual svg {
    width: 14px;
    height: 14px;
}

.btn-upload-manual:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-regenerate-original {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    background: var(--bg-primary, #ffffff);
    color: var(--text-primary, #1d1d1f);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-regenerate-original:hover {
    background: var(--bg-secondary, #f5f5f7);
    border-color: var(--accent, #0071e3);
    color: var(--accent, #0071e3);
}

.btn-regenerate-original:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-regenerate-original svg {
    width: 14px;
    height: 14px;
}

/* ==========================================
   History Sidebar (slides from right)
   ========================================== */

.history-sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 2001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.history-sidebar-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.history-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100vh;
    background: var(--bg-primary, #ffffff);
    border-left: 1px solid var(--border-light, #e5e5e7);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
    z-index: 2002;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.history-sidebar.open {
    transform: translateX(0);
}

.history-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light, #e5e5e7);
}

.history-sidebar-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #1d1d1f);
    margin: 0;
}

.btn-sidebar-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-tertiary, #86868b);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-sidebar-close:hover {
    background: var(--bg-secondary, #f5f5f7);
    color: var(--text-primary, #1d1d1f);
}

.history-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* History Version Card with Preview */
.history-version-card {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary, #f5f5f7);
    border: 1px solid var(--border-light, #e5e5e7);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-version-card:hover {
    background: var(--bg-primary, #ffffff);
    border-color: var(--accent, #0071e3);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.history-version-card.active {
    border-color: var(--accent, #0071e3);
    background: rgba(0, 113, 227, 0.04);
}

.history-version-thumb {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--bg-tertiary, #e5e5e7);
}

.history-version-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-version-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.history-version-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1d1d1f);
}

.history-version-date {
    font-size: 11px;
    color: var(--text-tertiary, #a1a1a6);
}

.history-version-desc {
    font-size: 12px;
    color: var(--text-secondary, #86868b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-version-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.history-version-actions button {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-version-view {
    background: transparent;
    border: 1px solid var(--border-light, #e5e5e7);
    color: var(--text-secondary, #86868b);
}

.btn-version-view:hover {
    border-color: var(--accent, #0071e3);
    color: var(--accent, #0071e3);
}

.btn-version-restore {
    background: var(--accent, #0071e3);
    border: none;
    color: #ffffff;
}

.btn-version-restore:hover {
    background: #0077ed;
}

.sidebar-loading,
.sidebar-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 20px;
    color: var(--text-tertiary, #86868b);
    font-size: 13px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.sidebar-loading svg {
    animation: spin 1s linear infinite;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .history-sidebar {
        width: 100%;
    }
}
