/**
 * 小红书历史记录图片编辑共享样式
 * 被 xiaohongshu.html 和 user_settings.html 共同使用
 */

/* 多层模态框 z-index 层级管理（从低到高）
 * 1040: 列表模态框的 backdrop（Bootstrap 默认）
 * 1050: 列表模态框（Bootstrap 默认）
 * 1055: 详情模态框的 backdrop
 * 1060: 详情模态框
 * 1065: 编辑模态框的 backdrop
 * 1070: 编辑模态框
 */
#manualHistoryDetailModal,
#autoWritingHistoryDetailModal {
    z-index: 1060 !important;
}

#manualImageEditModal,
#autoWritingImageEditModal {
    z-index: 1070 !important;
}

/* 图片序列预览容器 */
.sequence-preview {
    display: flex;
    gap: var(--spacing-lg, 16px);
    overflow-x: auto;
    padding: var(--spacing-md, 12px) 0;
    scroll-snap-type: x mandatory;
}

/* 历史记录图片项 */
.history-image-item {
    width: 150px;
    flex-shrink: 0;
    cursor: grab;
    transition: transform 0.2s, opacity 0.2s;
    user-select: none;
}

.history-image-item:hover {
    transform: translateY(-2px);
}

.history-image-item.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.history-image-item:active {
    cursor: grabbing;
}

/* 确保按钮区域不触发拖拽 */
.history-image-delete,
.history-image-actions button {
    -webkit-user-drag: none;
    user-select: none;
}

.history-image-wrapper {
    position: relative;
    width: 100%;
    padding-top: 100%; /* 1:1 aspect ratio */
    background: var(--bg-secondary, #f8f9fa);
    border-radius: var(--radius-base, 8px);
    overflow: hidden;
    border: 2px solid var(--border-color, #e5e7eb);
    transition: border-color 0.2s;
}

.history-image-item:hover .history-image-wrapper {
    border-color: var(--primary-color, #3b82f6);
}

.history-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white;
    cursor: pointer;
}

/* 图片序号 */
.history-image-number {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 28px;
    height: 28px;
    background: var(--primary-color, #3b82f6);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm, 12px);
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* 图片类型标签 */
.history-image-type {
    position: absolute;
    bottom: 8px;
    left: 8px;
    font-size: 0.65rem;
    padding: 2px 6px;
    opacity: 0.9;
}

/* 删除按钮 */
.history-image-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, transform 0.1s, background 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
    font-size: 14px;
}

.history-image-item:hover .history-image-delete {
    opacity: 1;
}

.history-image-delete:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.history-image-delete:active {
    transform: scale(0.95);
}

/* 图片左右移动箭头 */
.history-image-move {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 36px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 8;
    font-size: 14px;
    padding: 0;
}

.history-image-move-left { left: 4px; }
.history-image-move-right { right: 4px; }

.history-image-item:hover .history-image-move {
    opacity: 0.7;
}

.history-image-move:hover {
    opacity: 1 !important;
    background: rgba(37, 99, 235, 0.85);
}

.history-image-move:disabled {
    display: none;
}

/* 操作按钮 */
.history-image-actions {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 8px;
}

.history-image-actions .btn {
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
}

/* 生成中状态遮罩 */
.history-image-item.generating .history-image-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 5;
}

.history-image-item.generating .history-image-wrapper::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: historyImageSpin 0.8s linear infinite;
    z-index: 6;
}

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

.history-image-item.generating .history-image-actions {
    opacity: 0.5;
    pointer-events: none;
}

/* 生成状态提示文字 */
.history-image-item.generating .generating-text {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    z-index: 7;
    white-space: nowrap;
}

/* 图片预览 Lightbox */
.image-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 1090;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.image-lightbox.show {
    display: flex;
}

.lightbox-content {
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: default;
}

.lightbox-content img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: lightboxFadeIn 0.2s ease-out;
}

@keyframes lightboxFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 2;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 2;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }

.lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 16px;
    border-radius: 20px;
}
