/**
 * Affiliate System Frontend Styles
 * 分销系统前端样式
 */

/* 强制样式重置和优先级保证 */
.affiliate-system,
.affiliate-system *,
.affiliate-stats-widget,
.affiliate-stats-widget * {
    box-sizing: border-box !important;
}

/* 确保分销系统样式优先级最高 */
.affiliate-stats-widget {
    position: relative !important;
    z-index: 999 !important;
}

/* 统计卡片样式 */
.affiliate-stats-widget {
    background: #fff !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 8px !important;
    padding: 20px !important;
    margin-bottom: 20px !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
}

.affiliate-stats-widget h4 {
    margin: 0 0 20px 0 !important;
    color: #333 !important;
    font-size: 18px !important;
    text-align: center !important;
    border-bottom: 2px solid #f0f0f0 !important;
    padding-bottom: 10px !important;
}

/* 三排统计布局样式 */
.affiliate-stats-widget .stats-section {
    margin-bottom: 25px !important;
}

.affiliate-stats-widget .stats-section:last-child {
    margin-bottom: 0 !important;
}

.affiliate-stats-widget .section-title {
    margin: 0 0 15px 0 !important;
    color: #444 !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    padding: 8px 12px !important;
    background: #f8f9fa !important;
    border-left: 4px solid #007cba !important;
    border-radius: 0 4px 4px 0 !important;
}

.affiliate-stats-widget .stats-grid {
    display: grid !important;
    gap: 12px !important;
}

/* 第一排：直接推广数据 - 7列 */
.affiliate-stats-widget .stats-row-1 {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
}

/* 第二排：邀请数据 - 分为两行，每行5列 */
.affiliate-stats-widget .stats-row-2-first,
.affiliate-stats-widget .stats-row-2-second {
    grid-template-columns: repeat(5, 1fr) !important;
    margin-bottom: 12px !important;
}

.affiliate-stats-widget .stats-row-2-second {
    margin-bottom: 0 !important;
}

/* 第三排：佣金数据 - 6列 */
.affiliate-stats-widget .stats-row-3 {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) !important;
}

.affiliate-stats-widget .stat-item {
    text-align: center !important;
    padding: 15px 10px !important;
    background: #f8f9fa !important;
    border-radius: 6px !important;
    border: 1px solid #e9ecef !important;
    transition: transform 0.3s ease, box-shadow 0.3s ease !important;
    min-height: 80px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
}

.affiliate-stats-widget .stat-item:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15) !important;
}

.affiliate-stats-widget .stat-value {
    display: block !important;
    font-size: 20px !important;
    font-weight: bold !important;
    color: #333 !important;
    margin-bottom: 5px !important;
    line-height: 1.2 !important;
}

.affiliate-stats-widget .stat-label {
    font-size: 11px !important;
    color: #666 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.3px !important;
    line-height: 1.3 !important;
}

/* 第一排颜色主题 - 直接推广 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(1) .stat-value { color: #3498db !important; } /* 访客量 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(2) .stat-value { color: #2ecc71 !important; } /* 支付订单 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(3) .stat-value { color: #f39c12 !important; } /* 营业额 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(4) .stat-value { color: #27ae60 !important; } /* 直接佣金 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(5) .stat-value { color: #e74c3c !important; } /* 退款单数 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(6) .stat-value { color: #e67e22 !important; } /* 退款金额 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(7) .stat-value { color: #c0392b !important; } /* 退款扣除佣金 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(8) .stat-value { color: #28a745 !important; } /* 转化率 */
.affiliate-stats-widget .stats-row-1 .stat-item:nth-child(9) .stat-value { color: #dc3545 !important; } /* 退款率 */

/* 第二排颜色主题 - 邀请数据第一行 */
.affiliate-stats-widget .stats-row-2-first .stat-item:nth-child(1) .stat-value { color: #1abc9c !important; } /* 邀请分销员 */
.affiliate-stats-widget .stats-row-2-first .stat-item:nth-child(2) .stat-value { color: #3498db !important; } /* 邀请人访客 */
.affiliate-stats-widget .stats-row-2-first .stat-item:nth-child(3) .stat-value { color: #2ecc71 !important; } /* 邀请人订单 */
.affiliate-stats-widget .stats-row-2-first .stat-item:nth-child(4) .stat-value { color: #f39c12 !important; } /* 邀请人营业额 */
.affiliate-stats-widget .stats-row-2-first .stat-item:nth-child(5) .stat-value { color: #27ae60 !important; } /* 邀请人佣金 */

/* 第二排颜色主题 - 邀请数据第二行 */
.affiliate-stats-widget .stats-row-2-second .stat-item:nth-child(1) .stat-value { color: #e74c3c !important; } /* 邀请人退款 */
.affiliate-stats-widget .stats-row-2-second .stat-item:nth-child(2) .stat-value { color: #c0392b !important; } /* 邀请人退款金额 */
.affiliate-stats-widget .stats-row-2-second .stat-item:nth-child(3) .stat-value { color: #8e44ad !important; } /* 邀请人退款扣除佣金 */
.affiliate-stats-widget .stats-row-2-second .stat-item:nth-child(4) .stat-value { color: #9b59b6 !important; } /* 邀请人转化率 */
.affiliate-stats-widget .stats-row-2-second .stat-item:nth-child(5) .stat-value { color: #e67e22 !important; } /* 邀请人退款率 */

/* 第三排颜色主题 - 佣金数据 */
.affiliate-stats-widget .stats-row-3 .stat-item:nth-child(1) .stat-value { color: #27ae60 !important; } /* 自主流量分佣 */
.affiliate-stats-widget .stats-row-3 .stat-item:nth-child(2) .stat-value { color: #2ecc71 !important; } /* 自主订单分佣 */
.affiliate-stats-widget .stats-row-3 .stat-item:nth-child(3) .stat-value { color: #e67e22 !important; } /* 二级流量分佣 */
.affiliate-stats-widget .stats-row-3 .stat-item:nth-child(4) .stat-value { color: #16a085 !important; } /* 下级流量分佣 */
.affiliate-stats-widget .stats-row-3 .stat-item:nth-child(5) .stat-value { color: #1abc9c !important; } /* 下级订单分佣 */

/* 响应式设计 */
@media (max-width: 1200px) {
    .affiliate-stats-widget .stats-row-1 {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
    }
    .affiliate-stats-widget .stats-row-2-first,
    .affiliate-stats-widget .stats-row-2-second,
    .affiliate-stats-widget .stats-row-3 {
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) !important;
    }
}

@media (max-width: 768px) {
    .affiliate-stats-widget .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .affiliate-stats-widget .stat-value {
        font-size: 18px !important;
    }
    .affiliate-stats-widget .stat-label {
        font-size: 10px !important;
    }
}

@media (max-width: 480px) {
    .affiliate-stats-widget .stats-grid {
        grid-template-columns: 1fr !important;
    }
    .affiliate-stats-widget .stat-item {
        padding: 12px 8px !important;
        min-height: 70px !important;
    }
}

/* 兼容旧版样式 */
.stat-card {
    text-align: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

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

.stat-card.visitors .stat-value {
    color: #3498db;
}

.stat-card.referrals .stat-value {
    color: #2ecc71;
}

.stat-card.earnings .stat-value {
    color: #f39c12;
}

.stat-card.conversion .stat-value {
    color: #e74c3c;
}

/* 推荐链接生成器样式 */
.referral-link-generator {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.referral-link-generator h4 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 16px;
}

.link-generator-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 5px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.form-group input,
.form-group select {
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #007cba;
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.1);
}

.generate-btn {
    background: #007cba;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.generate-btn:hover {
    background: #005a87;
}

.generate-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.generated-link {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    display: none;
}

.generated-link.show {
    display: block;
}

.link-display {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.link-url {
    flex: 1;
    padding: 8px 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    color: #333;
    word-break: break-all;
}

.copy-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    transition: background-color 0.3s ease;
}

.copy-btn:hover {
    background: #218838;
}

.copy-btn.copied {
    background: #6c757d;
}

.social-share {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.social-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    text-decoration: none;
    color: white;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: opacity 0.3s ease;
}

.social-btn:hover {
    opacity: 0.8;
}

.social-btn.facebook {
    background: #3b5998;
}

.social-btn.twitter {
    background: #1da1f2;
}

.social-btn.linkedin {
    background: #0077b5;
}

.social-btn.whatsapp {
    background: #25d366;
}

.social-btn.email {
    background: #6c757d;
}

/* 产品搜索样式 */
.product-search {
    position: relative;
}

.product-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.product-search-results.show {
    display: block;
}

.product-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.3s ease;
}

.product-item:hover {
    background: #f8f9fa;
}

.product-item:last-child {
    border-bottom: none;
}

.product-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
}

.product-price {
    font-size: 12px;
    color: #666;
}

/* 分销员侧边栏小部件 */
.affiliate-sidebar-widget {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    margin: 20px 0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.affiliate-sidebar-widget h3 {
    margin: 0 0 10px 0;
    font-size: 18px;
    font-weight: bold;
}

.affiliate-sidebar-widget p {
    margin: 0 0 15px 0;
    font-size: 14px;
    opacity: 0.9;
    line-height: 1.5;
}

.affiliate-cta-btn {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid rgba(255,255,255,0.3);
    padding: 10px 20px;
    border-radius: 25px;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
    display: inline-block;
}

.affiliate-cta-btn:hover {
    background: rgba(255,255,255,0.3);
    border-color: rgba(255,255,255,0.5);
    transform: translateY(-2px);
    color: white;
}

/* WooCommerce 我的账户集成 */
.woocommerce-MyAccount-navigation ul li.woocommerce-MyAccount-navigation-link--affiliate-dashboard a {
    position: relative;
}

.woocommerce-MyAccount-navigation ul li.woocommerce-MyAccount-navigation-link--affiliate-dashboard a:before {
    content: "\f307";
    font-family: "dashicons";
    margin-right: 8px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .link-display {
        flex-direction: column;
        align-items: stretch;
    }
    
    .social-share {
        justify-content: center;
    }
    
    .affiliate-sidebar-widget {
        margin: 10px 0;
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .affiliate-sidebar-widget h3 {
        font-size: 16px;
    }
    
    .affiliate-sidebar-widget p {
        font-size: 13px;
    }
}

/* 加载动画 */
.loading {
    position: relative;
    pointer-events: none;
}

.loading:after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* 成功/错误消息 */
.affiliate-message {
    padding: 12px 16px;
    border-radius: 4px;
    margin: 10px 0;
    font-size: 14px;
}

.affiliate-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.affiliate-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.affiliate-message.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* 工具提示 */
.affiliate-tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
}

.affiliate-tooltip .tooltip-text {
    visibility: hidden;
    width: 200px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 4px;
    padding: 8px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -100px;
    font-size: 12px;
    line-height: 1.4;
}

.affiliate-tooltip .tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.affiliate-tooltip:hover .tooltip-text {
    visibility: visible;
}

/* 进度条 */
.affiliate-progress {
    width: 100%;
    height: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
    margin: 10px 0;
}

.affiliate-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #007cba, #0056b3);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* 徽章样式 */
.affiliate-badge {
    display: inline-block;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    border-radius: 12px;
    letter-spacing: 0.5px;
}

.affiliate-badge.new {
    background: #28a745;
    color: white;
}

.affiliate-badge.hot {
    background: #dc3545;
    color: white;
}

.affiliate-badge.trending {
    background: #ffc107;
    color: #333;
}

/* 卡片悬停效果 */
.affiliate-card {
    transition: all 0.3s ease;
    cursor: pointer;
}

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

/* 自定义滚动条 */
.affiliate-scroll::-webkit-scrollbar {
    width: 6px;
}

.affiliate-scroll::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.affiliate-scroll::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.affiliate-scroll::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 打印样式 */
@media print {
    .affiliate-sidebar-widget,
    .social-share,
    .copy-btn,
    .generate-btn {
        display: none !important;
    }
    
    .affiliate-stats-widget,
    .referral-link-generator {
        border: 1px solid #000;
        box-shadow: none;
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    .stat-card {
        border: 2px solid #000;
    }
    
    .affiliate-sidebar-widget {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
}

/* 减少动画模式支持 */
@media (prefers-reduced-motion: reduce) {
    .stat-card,
    .affiliate-card,
    .social-btn,
    .copy-btn,
    .generate-btn,
    .affiliate-cta-btn {
        transition: none;
    }
    
    .loading:after {
        animation: none;
    }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
    .affiliate-stats-widget,
    .referral-link-generator {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .affiliate-stats-widget h3,
    .referral-link-generator h4 {
        color: #e2e8f0;
        border-color: #4a5568;
    }
    
    .stat-card {
        background: #4a5568;
        border-color: #718096;
        color: #e2e8f0;
    }
    
    .form-group input,
    .form-group select,
    .link-url {
        background: #4a5568;
        border-color: #718096;
        color: #e2e8f0;
    }
    
    .generated-link {
        background: #4a5568;
        border-color: #718096;
    }
}

/* Traffic Sources Styles */
.traffic-sources-section {
    margin-top: 25px !important;
    padding-top: 20px !important;
    border-top: 1px solid #e9ecef !important;
}

.sources-title {
    margin: 0 0 15px 0 !important;
    color: #495057 !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    text-align: center !important;
}

.sources-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
    gap: 15px !important;
    margin-top: 15px !important;
}

.source-item {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    padding: 15px 10px !important;
    background: #f8f9fa !important;
    border: 1px solid #e9ecef !important;
    border-radius: 8px !important;
    transition: all 0.3s ease !important;
    text-align: center !important;
}

.source-item:hover {
    background: #e9ecef !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1) !important;
}

.source-icon {
    font-size: 24px !important;
    margin-bottom: 8px !important;
    line-height: 1 !important;
}

.source-content {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
}

.source-value {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: #495057 !important;
    margin-bottom: 4px !important;
    line-height: 1.2 !important;
}

.source-label {
    font-size: 12px !important;
    color: #6c757d !important;
    font-weight: 500 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    line-height: 1 !important;
}

/* Responsive adjustments for traffic sources */
@media (max-width: 768px) {
    .sources-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    .source-item {
        padding: 12px 8px !important;
    }
    
    .source-icon {
        font-size: 20px !important;
    }
    
    .source-value {
        font-size: 16px !important;
    }
    
    .source-label {
        font-size: 11px !important;
    }
}

@media (max-width: 480px) {
    .sources-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .source-item {
        padding: 10px 6px !important;
    }
    
    .source-icon {
        font-size: 18px !important;
        margin-bottom: 6px !important;
    }
    
    .source-value {
        font-size: 14px !important;
    }
    
    .source-label {
        font-size: 10px !important;
    }
}

/* 帮助图标样式 */
.help-icon {
    display: inline-block !important;
    margin-left: 8px !important;
    font-size: 14px !important;
    color: #666 !important;
    cursor: help !important;
    border-radius: 50% !important;
    width: 18px !important;
    height: 18px !important;
    text-align: center !important;
    line-height: 18px !important;
    background: #f0f0f0 !important;
    transition: all 0.3s ease !important;
}

.help-icon:hover {
    background: #007cba !important;
    color: white !important;
    transform: scale(1.1) !important;
}

/* Tooltip样式 */
.help-icon[data-tooltip]:hover::after {
    content: attr(data-tooltip) !important;
    position: absolute !important;
    background: #333 !important;
    color: white !important;
    padding: 6px 10px !important;
    border-radius: 4px !important;
    font-size: 9px !important;
    white-space: normal !important;
    z-index: 1000 !important;
    margin-top: 25px !important;
    margin-left: -120px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2) !important;
    max-width: 280px !important;
    width: 280px !important;
    line-height: 1.3 !important;
}

.help-icon[data-tooltip]:hover::before {
    content: '' !important;
    position: absolute !important;
    border: 6px solid transparent !important;
    border-bottom-color: #333 !important;
    margin-top: 19px !important;
    margin-left: -6px !important;
    z-index: 1001 !important;
}

/* 为第三排右侧的卡片调整tooltip位置 */
.stats-row-3 .stat-item:nth-child(n+4) .help-icon[data-tooltip]:hover::after {
    margin-left: -200px !important;
}

.stats-row-3 .stat-item:nth-child(n+4) .help-icon[data-tooltip]:hover::before {
    margin-left: -86px !important;
}

/* 禁用浏览器默认tooltip */
.help-icon {
    pointer-events: auto !important;
}

.help-icon[data-tooltip] {
    position: relative !important;
}