/**
 * 高级布局样式
 * 支持Quilted、Grid、Masonry三种布局模式
 * 支持Compact、Standard、Comfortable三种密度
 */

/* ==================== 布局切换工具栏 ==================== */
.layout-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding: 15px 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.layout-controls-left,
.layout-controls-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.layout-control-label {
    color: #666;
    font-size: 14px;
    margin-right: 5px;
}

.layout-mode-btn,
.density-btn {
    padding: 8px 16px;
    border: 1px solid #d9d9d9;
    background: #fff;
    color: #666;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.layout-mode-btn:hover,
.density-btn:hover {
    color: #1890ff;
    border-color: #1890ff;
    transform: translateY(-1px);
}

.layout-mode-btn.active,
.density-btn.active {
    background: #1890ff;
    color: #fff;
    border-color: #1890ff;
    font-weight: 500;
}

.layout-mode-btn svg,
.density-btn svg {
    width: 16px;
    height: 16px;
}

/* ==================== 基础容器样式 ==================== */
.waterfall {
    width: 100%;
    margin: 0 auto;
}

.waterfall-item {
    position: relative;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.waterfall-item:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(-4px);
}

.waterfall-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s;
}

/* 图片悬停放大效果 */
.waterfall-item:hover img {
    transform: scale(1.05);
}

.waterfall-item-info {
    padding: 12px 16px;
    background: #fff;
}

.waterfall-item-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.waterfall-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #999;
    font-size: 12px;
}

.waterfall-item-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* ==================== Quilted拼图布局 ==================== */
.layout-quilted.waterfall {
    display: grid;
    /* 动态设置: grid-template-columns, gap, grid-auto-rows */
}

/* Quilted布局的图片容器高度100% */
.layout-quilted .waterfall-item {
    height: 100%;
}

.layout-quilted .waterfall-item img {
    height: 100%;
    object-fit: cover;
}

/* 大图片的标题更大 */
.layout-quilted .waterfall-item[style*="span 2"] .waterfall-item-title {
    font-size: 16px;
    font-weight: 600;
}

/* ==================== Grid网格布局 ==================== */
.layout-grid.waterfall {
    display: grid;
    /* 动态设置: grid-template-columns, gap */
}

/* Grid布局保持宽高比1:1 */
.layout-grid .waterfall-item {
    aspect-ratio: 1;
}

.layout-grid .waterfall-item img {
    height: 100%;
    object-fit: cover;
}

/* ==================== Masonry瀑布流布局 ==================== */
.layout-masonry.waterfall {
    column-count: 4; /* 动态设置 */
    column-gap: 15px; /* 动态设置 */
}

.layout-masonry .waterfall-item {
    break-inside: avoid;
    margin-bottom: 15px; /* 动态设置 */
}

.layout-masonry .waterfall-item img {
    width: 100%;
    height: auto;
    object-fit: contain;
}

/* ==================== 密度设置 ==================== */

/* 紧凑模式 */
.density-compact.layout-quilted {
    gap: 10px;
}

.density-compact.layout-grid {
    gap: 10px;
}

.density-compact.layout-masonry {
    column-gap: 10px;
}

.density-compact .waterfall-item {
    margin-bottom: 10px;
}

.density-compact .waterfall-item-info {
    padding: 10px 12px;
}

.density-compact .waterfall-item-title {
    font-size: 13px;
}

/* 标准模式（默认） */
.density-standard.layout-quilted {
    gap: 15px;
}

.density-standard.layout-grid {
    gap: 15px;
}

.density-standard.layout-masonry {
    column-gap: 15px;
}

.density-standard .waterfall-item {
    margin-bottom: 15px;
}

/* 舒适模式 */
.density-comfortable.layout-quilted {
    gap: 20px;
}

.density-comfortable.layout-grid {
    gap: 20px;
}

.density-comfortable.layout-masonry {
    column-gap: 20px;
}

.density-comfortable .waterfall-item {
    margin-bottom: 20px;
}

.density-comfortable .waterfall-item-info {
    padding: 16px 20px;
}

.density-comfortable .waterfall-item-title {
    font-size: 15px;
    margin-bottom: 8px;
}

/* ==================== 响应式设计 ==================== */

/* 大屏幕（>1400px） */
@media (min-width: 1400px) {
    .container {
        max-width: 1400px;
    }
}

/* 中等屏幕（768px - 1200px） */
@media (max-width: 1200px) {
    .layout-controls {
        flex-direction: column;
        gap: 15px;
    }

    .layout-controls-left,
    .layout-controls-right {
        width: 100%;
        justify-content: center;
    }
}

/* 小屏幕（<768px） */
@media (max-width: 768px) {
    .layout-controls {
        padding: 12px 15px;
    }

    .layout-mode-btn,
    .density-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    .layout-control-label {
        font-size: 12px;
    }

    .layout-mode-btn svg,
    .density-btn svg {
        width: 14px;
        height: 14px;
    }

    /* 移动端简化显示 */
    .layout-controls-right {
        display: none; /* 移动端隐藏密度控制，节省空间 */
    }
}

/* 超小屏幕（<480px） */
@media (max-width: 480px) {
    .waterfall-item-title {
        font-size: 13px;
    }

    .waterfall-item-meta {
        font-size: 11px;
    }

    .layout-mode-btn span {
        display: none; /* 隐藏文字，只显示图标 */
    }
}

/* ==================== 加载动画优化 ==================== */
.waterfall-item {
    animation: fadeInUp 0.5s ease-out;
}

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

/* 为不同索引的项目添加延迟，创建波浪效果 */
.waterfall-item:nth-child(1) { animation-delay: 0.05s; }
.waterfall-item:nth-child(2) { animation-delay: 0.10s; }
.waterfall-item:nth-child(3) { animation-delay: 0.15s; }
.waterfall-item:nth-child(4) { animation-delay: 0.20s; }
.waterfall-item:nth-child(5) { animation-delay: 0.25s; }
.waterfall-item:nth-child(6) { animation-delay: 0.30s; }
.waterfall-item:nth-child(n+7) { animation-delay: 0.35s; }

/* ==================== 骨架屏（加载占位符） ==================== */
.waterfall-item.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.waterfall-item.skeleton img {
    opacity: 0;
}

.waterfall-item.skeleton .waterfall-item-info {
    opacity: 0.3;
}

/* ==================== 暗色主题适配 ==================== */
[data-theme="dark"] .layout-controls {
    background: #1f1f1f;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .layout-mode-btn,
[data-theme="dark"] .density-btn {
    background: #2a2a2a;
    border-color: #3a3a3a;
    color: #ccc;
}

[data-theme="dark"] .layout-mode-btn:hover,
[data-theme="dark"] .density-btn:hover {
    border-color: #1890ff;
    color: #1890ff;
}

[data-theme="dark"] .layout-mode-btn.active,
[data-theme="dark"] .density-btn.active {
    background: #1890ff;
    color: #fff;
}

[data-theme="dark"] .waterfall-item {
    background: #1f1f1f;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .waterfall-item-info {
    background: #1f1f1f;
}

[data-theme="dark"] .waterfall-item-title {
    color: #e0e0e0;
}

[data-theme="dark"] .waterfall-item-meta {
    color: #999;
}

/* ==================== 打印样式 ==================== */
@media print {
    .layout-controls {
        display: none;
    }

    .waterfall-item {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* ==================== 模态窗口 ==================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: #fff;
    border-radius: 8px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-content h3 {
    margin-bottom: 20px;
    font-size: 20px;
    font-weight: 600;
    color: #333;
}

/* 暗色主题下的模态窗口 */
[data-theme="dark"] .modal-content {
    background: #1f1f1f;
    color: #fff;
}

[data-theme="dark"] .modal-content h3 {
    color: #fff;
}
