/* Simple Product Showcase 3.1 - 前端样式 */

/* ========================================
   网格布局系统
   ======================================== */
.sps-products-grid {
    display: grid;
    /* gap由内联样式动态设置，不在此硬编码 */
    margin: 30px 0;
}

/* 桌面设备列数 (≥992px) */
@media (min-width: 992px) {
    .sps-desktop-1 { grid-template-columns: repeat(1, 1fr); }
    .sps-desktop-2 { grid-template-columns: repeat(2, 1fr); }
    .sps-desktop-3 { grid-template-columns: repeat(3, 1fr); }
    .sps-desktop-4 { grid-template-columns: repeat(4, 1fr); }
    .sps-desktop-5 { grid-template-columns: repeat(5, 1fr); }
    .sps-desktop-6 { grid-template-columns: repeat(6, 1fr); }
}

/* 平板设备列数 (768px-991px) */
@media (min-width: 768px) and (max-width: 991px) {
    .sps-tablet-1 { grid-template-columns: repeat(1, 1fr); }
    .sps-tablet-2 { grid-template-columns: repeat(2, 1fr); }
    .sps-tablet-3 { grid-template-columns: repeat(3, 1fr); }
    .sps-tablet-4 { grid-template-columns: repeat(4, 1fr); }
}

/* 手机设备列数 (<768px) */
@media (max-width: 767px) {
    .sps-mobile-1 { grid-template-columns: repeat(1, 1fr); }
    .sps-mobile-2 { grid-template-columns: repeat(2, 1fr); }
}

/* ========================================
   产品卡片基础样式
   ======================================== */
.sps-product-card {
    background: #fff;
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

/* 卡片链接样式 */
.sps-has-card-link {
    cursor: pointer;
}

.sps-card-link-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    display: block;
}

/* 确保按钮在链接覆盖层之上 */
.sps-has-card-link .sps-product-buttons {
    position: relative;
    z-index: 2;
}

.sps-has-card-link .sps-product-buttons a {
    position: relative;
    z-index: 3;
}

/* 内容对齐 */
.sps-align-left .sps-product-content {
    text-align: left;
}

.sps-align-center .sps-product-content {
    text-align: center;
}

.sps-align-right .sps-product-content {
    text-align: right;
}

.sps-align-left .sps-product-buttons {
    justify-content: flex-start;
}

.sps-align-center .sps-product-buttons {
    justify-content: center;
}

.sps-align-right .sps-product-buttons {
    justify-content: flex-end;
}

/* ========================================
   图片样式 - 多种比例支持
   ======================================== */
.sps-product-image {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: #f5f5f5;
}

/* 固定比例容器 */
.sps-product-image:not(.sps-ratio-original) {
    height: 0;
}

/* 1:1 正方形 */
.sps-ratio-1-1 {
    padding-bottom: 100%;
}

/* 4:3 标准 */
.sps-ratio-4-3 {
    padding-bottom: 75%;
}

/* 16:9 宽屏 */
.sps-ratio-16-9 {
    padding-bottom: 56.25%;
}

/* 自定义比例 - 由内联样式控制 */
.sps-ratio-custom {
    /* padding-bottom 由内联样式设置 */
}

/* 原图比例 */
.sps-ratio-original {
    height: auto;
    padding-bottom: 0;
}

.sps-ratio-original img.sps-original-ratio {
    position: static;
    width: 100%;
    height: auto;
    border-radius: inherit;
}

/* 固定比例图片样式 */
.sps-product-image:not(.sps-ratio-original) img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.3s ease, filter 0.3s ease, opacity 0.3s ease;
    border-radius: inherit;
}

/* 图片悬停效果 */
.sps-hover-none .sps-product-image img:hover {
    /* 无效果 */
}

.sps-hover-zoom:hover .sps-product-image img {
    transform: scale(1.1);
}

.sps-hover-fade:hover .sps-product-image img {
    opacity: 0.7;
}

.sps-hover-blur:hover .sps-product-image img {
    filter: blur(3px);
}

/* ========================================
   阴影选项
   ======================================== */
.sps-shadow-none {
    box-shadow: none;
}

.sps-shadow-default {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.sps-shadow-hover {
    box-shadow: none;
    transition: box-shadow 0.3s ease;
}

.sps-shadow-hover:hover {
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
}

.sps-shadow-deep {
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.sps-shadow-deep:hover {
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

/* ========================================
   边框选项
   ======================================== */
.sps-border-none {
    border: none;
}

.sps-border-thin {
    border: 1px solid #e0e0e0;
}

.sps-border-thick {
    border: 2px solid #d0d0d0;
}

/* ========================================
   内容区域
   ======================================== */
.sps-product-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

/* 产品标题 */
.sps-product-title {
    margin: 0 0 15px 0;
    color: #333;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* 产品描述 */
.sps-product-description {
    color: #666;
    line-height: 1.6;
    margin-bottom: 20px;
    font-size: 14px;
    flex-grow: 1;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.sps-product-description p {
    margin: 0 0 10px 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.sps-product-description p:last-child {
    margin-bottom: 0;
}

/* ========================================
   按钮样式 - Flatsome专用
   ======================================== */
.sps-product-buttons {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    position: relative;
}

/* Flatsome按钮样式优化 */
.sps-product-buttons .button {
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
    z-index: 10;
    /* 强制覆盖Flatsome的默认大写，保持用户输入格式 */
    text-transform: none !important;
    /* 确保垂直居中 */
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: normal !important;
}

/* ========================================
   小工具样式
   ======================================== */
.sps-widget-products {
    padding: 0;
}

.sps-widget-product {
    display: flex;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.sps-widget-product:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.sps-widget-thumbnail {
    width: 80px;
    height: 60px;
    margin-right: 15px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    background: #f5f5f5;
}

.sps-widget-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.sps-widget-content {
    flex: 1;
    min-width: 0;
}

.sps-widget-title {
    font-size: 16px;
    margin: 0 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.sps-widget-description {
    font-size: 13px;
    color: #666;
    margin-bottom: 10px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.sps-widget-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.sps-widget-button {
    display: inline-block;
    padding: 5px 10px;
    background: #2271b1;
    color: #fff;
    border-radius: 3px;
    text-decoration: none;
    font-size: 12px;
    transition: background 0.3s ease;
}

.sps-widget-button:hover {
    background: #135e96;
    color: #fff;
}

/* ========================================
   Flatsome主题特定兼容
   ======================================== */

/* UX Builder 兼容 */
.ux-builder-wrapper .sps-products-grid {
    margin: 0;
}

.flatsome .sps-product-content {
    padding: 20px !important;
}

/* ========================================
   移动端优化
   ======================================== */

/* 平板优化 */
@media (max-width: 991px) {
    .sps-product-content {
        padding: 18px;
    }
    
    .sps-product-title {
        font-size: 16px;
    }
    
    .sps-product-description {
        font-size: 13px;
    }
}

/* 手机优化 */
@media (max-width: 767px) {
    .sps-products-grid {
        /* gap由内联样式控制，在移动端自动缩小一些 */
        margin: 20px 0;
    }
    
    .sps-product-content {
        padding: 15px;
    }
    
    .sps-product-title {
        font-size: 15px;
        margin-bottom: 10px;
    }
    
    .sps-product-description {
        font-size: 13px;
        margin-bottom: 15px;
    }
    
    .sps-product-buttons {
        flex-direction: column;
        align-items: stretch;
    }
    
    .sps-button,
    .flatsome .sps-product-buttons .button {
        width: 100%;
        text-align: center;
    }
    
    /* 小工具移动端优化 */
    .sps-widget-product {
        flex-direction: column;
    }
    
    .sps-widget-thumbnail {
        width: 100%;
        height: 0;
        padding-bottom: 75%;
        margin-right: 0;
        margin-bottom: 10px;
        position: relative;
    }
    
    .sps-widget-thumbnail img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

/* 超小屏幕优化 */
@media (max-width: 480px) {
    .sps-mobile-2 {
        grid-template-columns: repeat(1, 1fr);
    }
    
    /* gap由内联样式控制 */
    
    .sps-product-content {
        padding: 12px;
    }
}

/* ========================================
   打印样式
   ======================================== */
@media print {
    .sps-product-buttons {
        display: none;
    }
    
    .sps-card-link-overlay {
        display: none;
    }
    
    .sps-products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px;
    }
    
    .sps-product-card {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }
    
    .sps-product-image {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ========================================
   辅助功能
   ======================================== */
/* 只在卡片链接获得焦点时显示卡片outline，避免与按钮outline重叠 */
.sps-card-link-overlay:focus {
    outline: 2px solid #2271b1;
    outline-offset: -2px;
}

/* 按钮focus样式保持不变 */
.sps-button:focus,
.flatsome .sps-product-buttons .button:focus {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

/* 无产品提示 */
.sps-no-products {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-size: 16px;
}

/* ========================================
   加载动画
   ======================================== */
@keyframes sps-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sps-product-card {
    animation: sps-fade-in 0.4s ease-out;
}

/* 错开动画时间 */
.sps-product-card:nth-child(2) { animation-delay: 0.1s; }
.sps-product-card:nth-child(3) { animation-delay: 0.2s; }
.sps-product-card:nth-child(4) { animation-delay: 0.3s; }
.sps-product-card:nth-child(5) { animation-delay: 0.4s; }
.sps-product-card:nth-child(6) { animation-delay: 0.5s; }

/* ========================================
   兼容性修复
   ======================================== */

/* 确保长文本不破坏布局 */
.sps-product-card * {
    max-width: 100%;
    word-break: break-word;
}

/* 修复IE11网格布局 */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
    .sps-products-grid {
        display: flex;
        flex-wrap: wrap;
    }
    
    .sps-product-card {
        flex: 0 0 calc(25% - 30px);
        margin: 15px;
    }
}

/* 修复Safari图片比例 */
@supports (-webkit-appearance: none) {
    .sps-product-image img {
        -webkit-transform: translateZ(0);
    }
}

/* ========================================
   自定义Class钩子
   ======================================== */

/* 为自定义功能预留的类 */
.sps-product-card.lightbox-trigger {
    /* 用户可自定义 */
}

.sps-button.popup-trigger {
    /* 用户可自定义 */
}

.sps-button.track-click {
    /* 用户可自定义 */
}

/* ========================================
   分页导航样式（使用Flatsome原生）
   ======================================== */
.sps-pagination {
    margin: 30px 0;
}

/* 分页对齐方式 */
.sps-pagination-align-left .page-numbers {
    justify-content: flex-start !important;
}

.sps-pagination-align-center .page-numbers {
    justify-content: center !important;
}

.sps-pagination-align-right .page-numbers {
    justify-content: flex-end !important;
}

/* 确保Flatsome分页样式正常工作 */
.sps-pagination .page-numbers {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 8px;
}

/* 强制移除li的所有margin和padding - 使用更强的选择器 */
.sps-pagination .page-numbers > li {
    list-style: none;
    margin: 0 !important;
    padding: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* 强制移除按钮元素的margin - 使用更强的选择器 */
.sps-pagination .page-numbers > li > a,
.sps-pagination .page-numbers > li > span {
    margin: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* 如果Flatsome使用了更具体的类，也要覆盖 */
.sps-pagination .nav-pagination.links > li {
    margin: 0 !important;
    padding: 0 !important;
    margin-left: 0 !important;
}

/* 响应式设计 */
@media (max-width: 767px) {
    .sps-pagination {
        margin: 20px 0;
    }
    
    .sps-pagination .page-numbers {
        gap: 5px;
    }
}

/* 打印样式 */
@media print {
    .sps-pagination {
        display: none;
    }
}
