/**
 * 智能短碼前端樣式
 * 
 * @package Uni_Shopee_Affiliate_TW
 */

/* 主容器樣式 */
.shopee-smart-products {
    margin: 30px 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.shopee-smart-products.has-title {
    margin-top: 40px;
}

/* 標題樣式 */
.shopee-products-title {
    font-size: 24px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0 0 25px 0;
    text-align: center;
    position: relative;
}

.shopee-products-title::after {
    content: '';
    display: block;
    width: 60px;
    height: 3px;
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    margin: 10px auto 0;
    border-radius: 2px;
}

/* 關鍵字標籤 */
.shopee-keywords-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 25px;
}

.shopee-keyword-tag {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: 12px;
    font-weight: 500;
    border-radius: 20px;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.shopee-keyword-tag:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    color: white;
    text-decoration: none;
}

.shopee-keyword-tag::before {
    content: '#';
    margin-right: 4px;
    opacity: 0.8;
}

/* 商品網格佈局 */
.shopee-products-grid {
    display: grid;
    gap: 20px;
    margin-bottom: 20px;
}

/* 網格模式 (4個商品以下) - 修正樣式一致性 */
.shopee-smart-products.grid-mode .shopee-products-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    justify-content: center;
    max-width: 1200px;
    margin: 0 auto;
}

/* 確保商品卡片在網格模式下的一致性 */
.shopee-smart-products.grid-mode .shopee-product-card {
    width: 100%;
    max-width: 280px;
    min-width: 280px;
    justify-self: center;
}

/* 輪播模式 (所有商品數量) - 修正：避免商品不足時的溢位問題 */
.shopee-products-slider {
    position: relative;
    overflow: hidden;
}

.shopee-products-slider .shopee-products-wrapper {
    overflow: hidden;
    width: 100%;
    position: relative;
}

.shopee-products-slider .shopee-products-grid {
    display: flex;
    gap: 20px;
    transition: transform 0.3s ease;
    width: max-content;
    will-change: transform;
    justify-content: flex-start;
    /* 確保在任何情況下都從左邊開始對齊 */
    align-items: flex-start;
}

/* 移除商品數量不足時的居中對齊，改為始終左對齊 */
.shopee-products-slider .shopee-products-grid {
    /* 強制左對齊，避免置中問題 */
    margin-left: 0;
    padding-left: 0;
}

.shopee-products-slider .shopee-product-card {
    flex: 0 0 280px;
    width: 280px;
    min-width: 280px;
    max-width: 280px;
}

/* 輪播控制按鈕 */
.shopee-slider-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

.shopee-slider-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 45px;
    height: 45px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 50% !important;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 18px;
    color: #666;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.shopee-slider-btn:hover {
    border-color: #ff6b35;
    color: #ff6b35;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 107, 53, 0.3);
}

.shopee-slider-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.shopee-slider-btn::before {
    font-family: dashicons;
    font-size: 20px;
    line-height: 1;
}

.shopee-slider-btn.prev::before {
    content: '‹';
    font-family: Arial, sans-serif;
    font-size: 24px;
    font-weight: bold;
}

.shopee-slider-btn.next::before {
    content: '›';
    font-family: Arial, sans-serif;
    font-size: 24px;
    font-weight: bold;
}

/* 輪播指示器 */
.shopee-slider-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
}

.shopee-slider-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ddd;
    cursor: pointer;
    transition: all 0.3s ease;
}

.shopee-slider-dot.active {
    background: #ff6b35;
    transform: scale(1.2);
}

/* 商品卡片樣式 */
.shopee-product-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    overflow: hidden;
    transition: all 0.3s ease;
    height: auto;
    min-height: 420px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.shopee-product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.shopee-product-link {
    text-decoration: none;
    color: inherit;
    display: block;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.shopee-product-link:hover {
    text-decoration: none;
    color: inherit;
}

/* 商品圖片 */
.shopee-product-image {
    position: relative;
    width: 100%;
    height: 220px;
    overflow: hidden;
    background: #f8f9fa;
    flex-shrink: 0;
}

.shopee-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}

.shopee-product-image img.loaded {
    opacity: 1;
}

.shopee-product-image img.error {
    opacity: 0.5;
    background: #f5f5f5;
}

.shopee-product-card:hover .shopee-product-image img {
    transform: scale(1.05);
}

/* 分潤率標籤 */
.shopee-commission-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    color: white;
    padding: 6px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
    z-index: 2;
}

.shopee-commission-badge::before {
    content: '分潤 ';
    opacity: 0.9;
}

/* 商品內容 */
.shopee-product-content {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 180px;
}

.shopee-product-name {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.3;
    margin: 0 0 8px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 40px;
}

.shopee-product-shop {
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    height: 18px;
}

.shopee-product-shop::before {
    content: '🏪';
    margin-right: 4px;
}

.shopee-product-price {
    font-size: 18px;
    font-weight: 700;
    color: #ff6b35;
    margin-bottom: 10px;
    height: 24px;
}

/* 商品元資訊 */
.shopee-product-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}

.shopee-product-rating {
    display: flex;
    align-items: center;
    gap: 6px;
}

.shopee-stars {
    display: flex;
    gap: 2px;
}

.shopee-star {
    width: 14px;
    height: 14px;
    color: #ffc107;
}

.shopee-star.filled::before {
    content: '★';
}

.shopee-star.empty::before {
    content: '☆';
}

.rating-text {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.shopee-product-sales {
    font-size: 12px;
    color: #666;
    background: #f8f9fa;
    padding: 4px 8px;
    border-radius: 12px;
}

/* 管理員可見分潤率資訊（內嵌在價格下方） */
.shopee-admin-commission-inline {
    font-size: 11px;
    color: #666;
    margin-top: 4px;
    padding: 2px 0;
    border-top: 1px solid #e0e0e0;
    font-weight: 500;
}

/* 無商品狀態 */
.shopee-no-products,
.shopee-no-keywords {
    text-align: center;
    padding: 40px 20px;
    background: #f8f9fa;
    border-radius: 12px;
    color: #666;
    font-size: 16px;
}

.shopee-no-products::before,
.shopee-no-keywords::before {
    content: '🔍';
    display: block;
    font-size: 48px;
    margin-bottom: 15px;
}

/* 載入狀態 */
.shopee-loading {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.shopee-loading::before {
    content: '';
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #ff6b35;
    border-radius: 50%;
    animation: shopee-spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes shopee-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 響應式設計 */
@media (max-width: 768px) {
    /* 網格模式 - 平板尺寸 */
    .shopee-smart-products.grid-mode .shopee-products-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 15px;
        max-width: 800px;
    }
    
    .shopee-smart-products.grid-mode .shopee-product-card {
        max-width: 250px;
        min-width: 250px;
    }
    
    /* 輪播模式 - 平板尺寸 */
    .shopee-products-slider .shopee-product-card {
        flex: 0 0 250px;
        max-width: 250px;
    }
    
    .shopee-product-content {
        padding: 15px;
    }
    
    .shopee-products-title {
        font-size: 20px;
    }
    
    .shopee-keywords-tags {
        margin-bottom: 20px;
    }
    
    .shopee-keyword-tag {
        font-size: 11px;
        padding: 5px 10px;
    }
}

@media (max-width: 480px) {
    /* 網格模式 - 手機尺寸 */
    .shopee-smart-products.grid-mode .shopee-products-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        max-width: 100%;
    }
    
    .shopee-smart-products.grid-mode .shopee-product-card {
        max-width: 100%;
        min-width: auto;
        width: 100%;
    }
    
    /* 手機版輪播模式修正 */
    .shopee-products-slider {
        /* 確保容器不會產生額外的置中效果 */
        text-align: left;
    }
    
    .shopee-products-slider .shopee-products-wrapper {
        /* 移除可能的置中樣式 */
        margin: 0;
        padding: 0;
    }
    
    .shopee-products-slider .shopee-products-grid {
        /* 手機版商品卡片尺寸調整 */
        gap: 15px;
        /* 強制左對齊，移除任何置中效果 */
        justify-content: flex-start !important;
        align-items: flex-start;
        margin: 0;
        padding: 0;
        /* 確保第一個商品從容器最左邊開始 */
        transform: translateX(0);
    }
    
    .shopee-products-slider .shopee-product-card {
        flex: 0 0 280px;
        width: 280px;
        min-width: 280px;
        max-width: 280px;
        /* 確保卡片不會被壓縮 */
    }
    
    /* 當螢幕更窄時，調整商品卡片尺寸但保持左對齊 */
    @media (max-width: 320px) {
        .shopee-products-slider .shopee-product-card {
            flex: 0 0 260px;
            width: 260px;
            min-width: 260px;
            max-width: 260px;
        }
    }
    
    .shopee-product-image {
        height: 180px;
    }
    
    .shopee-slider-controls {
        gap: 10px;
    }
    
    .shopee-slider-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}

/* 深色模式支援 */
@media (prefers-color-scheme: dark) {
    .shopee-product-card {
        background: #2a2a2a;
        color: #e0e0e0;
    }
    
    .shopee-product-name {
        color: #e0e0e0;
    }
    
    .shopee-product-shop {
        color: #b0b0b0;
    }
    
    .shopee-product-meta {
        border-top-color: #404040;
    }
    
    .shopee-product-sales {
        background: #404040;
        color: #b0b0b0;
    }
    
    .shopee-no-products,
    .shopee-no-keywords {
        background: #2a2a2a;
        color: #b0b0b0;
    }
    
    .shopee-admin-commission-inline {
        color: #4ade80;
        border-top-color: #404040;
    }
    
    .shopee-admin-controls {
        background: #2a2a2a;
        border-color: #404040;
    }
    
    .shopee-refresh-cache-btn {
        background: linear-gradient(135deg, #374151, #4b5563);
        color: #e5e7eb;
        border-color: #6b7280;
    }
    
    .shopee-refresh-cache-btn:hover {
        background: linear-gradient(135deg, #4b5563, #6b7280);
        border-color: #9ca3af;
    }
    
    .shopee-notification {
        background: #2a2a2a;
        color: #e5e7eb;
        border-color: #404040;
    }
    
    .shopee-notification-success {
        background: #065f46;
        border-color: #10b981;
    }
    
    .shopee-notification-error {
        background: #7f1d1d;
        border-color: #ef4444;
    }
}

/* 管理員快取刷新控制區域 */
.shopee-admin-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 15px;
    padding: 12px 15px;
    background: linear-gradient(135deg, #f8fafc, #e2e8f0);
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.shopee-refresh-cache-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
    border: 1px solid #2563eb;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.shopee-refresh-cache-btn:hover {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    border-color: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
    color: white;
    text-decoration: none;
}

.shopee-refresh-cache-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.shopee-refresh-cache-btn.refreshing {
    background: linear-gradient(135deg, #6b7280, #9ca3af);
    border-color: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.shopee-refresh-cache-btn .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
}

.shopee-refresh-cache-btn .dashicons.spin {
    animation: spin 1s linear infinite;
}

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

.shopee-refresh-cache-btn .btn-text {
    font-weight: 500;
    letter-spacing: 0.025em;
    color:#fff;
}

/* 通知訊息樣式 */
.shopee-notification {
    position: fixed;
    top: 32px;
    right: 20px;
    z-index: 999999;
    max-width: 400px;
    padding: 16px 20px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.shopee-notification.show {
    opacity: 1;
    transform: translateX(0);
}

.shopee-notification-success {
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    border-color: #10b981;
    color: #065f46;
}

.shopee-notification-error {
    background: linear-gradient(135deg, #fef2f2, #fecaca);
    border-color: #ef4444;
    color: #7f1d1d;
}

.shopee-notification-info {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border-color: #3b82f6;
    color: #1e40af;
}

/* 黑名單切換圖示按鈕 */
.blacklist-toggle-icon {
    background: #dc3545;
    border: none;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1000;
    margin-right: 6px;
}

.blacklist-toggle-icon.blacklisted {
    background: #28a745;
}

.blacklist-toggle-icon.blacklisted:hover {
    background: #218838;
}

.blacklist-toggle-icon:hover {
    background: #c82333;
    transform: scale(1.1);
}

.blacklist-x-icon {
    color: white;
    font-size: 12px;
    font-weight: bold;
    line-height: 1;
}

.shop-info {
    display: flex;
    align-items: center;
}

.shop-name {
    font-size: 11px;
    color: #666;
    text-align: left;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .shopee-admin-controls {
        padding: 10px 12px;
        margin-bottom: 12px;
    }
    
    .shopee-refresh-cache-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .shopee-refresh-cache-btn .dashicons {
        font-size: 14px;
        width: 14px;
        height: 14px;
    }
    
    .shopee-notification {
        top: 46px;
        right: 10px;
        left: 10px;
        max-width: none;
        font-size: 13px;
    }
}
