/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #007AFF;
    --primary-hover: #0056CC;
    --success-color: #34C759;
    --success-hover: #2BA84A;
    --secondary-color: #6C757D;
    --secondary-hover: #545B62;
    --danger-color: #FF3B30;
    --background: #F5F5F7;
    --surface: #FFFFFF;
    --border: #D1D1D6;
    --text-primary: #1C1C1E;
    --text-secondary: #8E8E93;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* 工具栏样式 */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    gap: 16px;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 按钮样式 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background-color: var(--success-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--secondary-hover);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* 选择框组 */
.select-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.select-group label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 14px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

select:focus {
    border-color: var(--primary-color);
}

select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 主内容区 */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    width: 320px;
    min-width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.sort-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sort-controls select {
    flex: 1;
}

/* 图片列表 */
.image-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.image-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--background);
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.image-item:hover {
    background: #E8E8ED;
}

.image-item.active {
    border-color: var(--primary-color);
    background: rgba(0, 122, 255, 0.05);
}

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

.image-item.drag-over {
    border-color: var(--primary-color);
    border-style: dashed;
}

.reorder-btns {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reorder-btn {
    width: 24px;
    height: 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 12px;
}

.reorder-btn:hover:not(:disabled) {
    background: var(--border);
    color: var(--text-primary);
}

.reorder-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.image-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}

.image-info {
    flex: 1;
    min-width: 0;
}

.image-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.image-name.renamed {
    color: var(--primary-color);
}

.image-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.delete-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--danger-color);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.2s;
}

.delete-btn:hover {
    background: rgba(255, 59, 48, 0.1);
}

/* 预览区 */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 16px;
    overflow: hidden;
}

.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.preview-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.hint {
    font-size: 12px;
    color: var(--text-secondary);
}

.preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 16px;
    position: relative;
}

.preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: zoom-in;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 空状态 */
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
    height: 100%;
    width: 100%;
}

/* 加载遮罩 */
.loading-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-mask.active {
    display: flex;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-content p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 16px;
    width: 90vw;
    height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 24px;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.close-btn:hover {
    background: var(--background);
    color: var(--text-primary);
}

.zoom-container {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: grab;
    background: #2C2C2E;
}

.zoom-container:active {
    cursor: grabbing;
}

.zoom-container img {
    max-width: none;
    max-height: none;
    transition: transform 0.1s ease-out;
    transform-origin: center center;
}

.zoom-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.zoom-level {
    font-size: 14px;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* 响应式设计 */
@media (max-width: 900px) {
    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: auto;
        max-height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 600px) {
    .toolbar {
        flex-direction: column;
        gap: 12px;
    }

    .toolbar-left,
    .toolbar-right {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
}
