/*
 * CSF Group Buy Display Stylesheet
 * Version: 2.1.0
 * Author: CSF001
 * Last Updated: 2025-11-04
 *
 * --- CHANGELOG ---
 * v2.1.0 (2025-11-04):
 * - 替换硬编码颜色为主题 CSS 变量，支持暗色模式
 * - 优化边框、背景、文本颜色的主题适配
 *
 * --- STRUCTURE ---
 * 1. Global Styles (Tabs, Buttons, Base Layout)
 * 2. General Group Display Block
 * 3. User's Current Group Display Block
 * 4. Empty/Notice States
 * 5. Responsive Adjustments (Mobile)
 */

/* ============================================= */
/* 1. Global Styles (Tabs, Buttons, Base Layout) */
/* ============================================= */

/* --- Tabs --- */
.csf-group-tabs {
    display: flex;
    gap: 20px;
    border-bottom: 2px solid var(--main-border-color);
    margin-bottom: 16px;
}

.csf-group-tab {
    font-size: 16px;
    font-weight: 500;
    color: var(--muted-color);
    padding: 8px 4px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

.csf-group-tab:hover {
    color: var(--key-color);
}

.csf-group-tab.active {
    font-weight: 600;
    color: #ff4d4f;
    border-bottom-color: #ff4d4f;
}

.csf-group-tab-content {
    padding-top: 0;
}

/* --- Buttons (Base Styles) --- */
.csf-group-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-height: 40px;
    padding: 0 24px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    white-space: nowrap;
    line-height: 1;
}

/* Primary / Default Button Style */
.csf-group-btn,
.csf-group-start-btn,
.csf-group-join-current-btn,
.csf-group-primary-btn {
    background-color: #ff4d4f;
    color: #fff;
}

.csf-group-btn:hover,
.csf-group-start-btn:hover,
.csf-group-join-current-btn:hover,
.csf-group-primary-btn:hover {
    background-color: #d9363e;
    color: #fff;
}

/* Secondary Button Style */
.csf-group-secondary-btn {
    background-color: #6c757d;
    color: #fff;
}
.csf-group-secondary-btn:hover {
    background-color: #5a6268;
}

/* Exit Button Style */
.csf-exit-btn {
    background-color: #fff;
    color: #ff4d4f;
    border-color: #ff4d4f;
}

.csf-exit-btn:hover {
    background-color: #ff4d4f;
    color: #fff;
}

/* Subtext inside buttons */
.csf-btn-subtext,
.csf-pay-btn small {
    font-size: 12px;
    margin-left: 6px;
    display: inline-block;
    line-height: 1;
}

/* ======================================= */
/* 2. General Group Display Block          */
/* ======================================= */

.csf-group-display {
    padding: 20px;
    background: var(--body-bg-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px var(--main-shadow);
    display: block;
}

.csf-group-display h3 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 18px;
    color: var(--key-color);
}

/* --- Price Section --- */
.csf-group-price {
    display: flex;
    gap: 8px;
    align-items: baseline;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.csf-group-discount-price {
    font-size: 24px;
    font-weight: 700;
    color: #ff4d4f;
}

.csf-group-original-price {
    font-size: 14px;
    color: var(--muted-2-color);
    text-decoration: line-through;
}

.csf-group-price-save {
    background: #fff0f0;
    color: #ff4d4f;
    font-size: 12px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 4px;
}

/* --- Progress & Time Section --- */
.csf-group-progress-container,
.csf-group-payment-progress-container {
    margin-top: 10px;
}

.csf-group-progress-text-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--main-color);
}

.csf-group-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--main-border-color);
    border-radius: 4px;
    overflow: hidden;
}

.csf-group-progress-fill {
    height: 100%;
    background: #ff7875;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.csf-group-payment-fill {
    background: #52c41a;
}

/* --- Time & Status Section --- */
.csf-group-time-container {
    font-size: 14px;
    color: var(--muted-color);
    margin-top: 12px;
}
.csf-group-status-display {
    font-size: 14px;
    font-weight: 600;
}
.csf-group-status-running { color: #fa8c16; }
.csf-group-status-pending-payment { color: #1890ff; }
.csf-group-status-success { color: #52c41a; }
.csf-group-status-failed { color: #f5222d; }

/* --- Users Avatars Section --- */
.csf-group-users-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
}

.csf-group-users-text {
    font-size: 14px;
    color: var(--key-color);
}

.csf-group-avatars {
    display: flex;
}

.csf-group-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #fff;
    margin-left: -8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.csf-group-avatar:first-child {
    margin-left: 0;
}
.csf-group-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- Actions Area --- */
.csf-group-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.csf-group-more {
    margin-top: 16px;
    text-align: center;
}
.csf-group-more-link {
    font-size: 14px;
    color: #1890ff;
    text-decoration: none;
}
.csf-group-more-link:hover {
    text-decoration: underline;
}

/* ======================================= */
/* 3. User's Current Group Display Block   */
/* ======================================= */

.csf-group-user-display {
    border: 1px solid var(--main-border-color);
    background: var(--main-bg-color);
}

.csf-group-user-display .csf-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--main-border-color);
    margin-bottom: 16px;
}

.csf-group-user-display .csf-group-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    color: var(--key-color);
}

.csf-group-user-display .csf-group-status {
    font-size: 13px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 15px;
}
.csf-group-status-running { background-color: #fff7e6; color: #fa8c16; }
.csf-group-status-pending-payment { background-color: #e6f7ff; color: #1890ff; }
.csf-group-status-success { background-color: #f6ffed; color: #52c41a; }
.csf-group-status-failed { background-color: #fff1f0; color: #f5222d; }

/* 暗色模式下的状态标签 */
.dark-theme .csf-group-status-running { background-color: rgba(255, 247, 230, 0.1); color: #ffc53d; }
.dark-theme .csf-group-status-pending-payment { background-color: rgba(230, 247, 255, 0.1); color: #69c0ff; }
.dark-theme .csf-group-status-success { background-color: rgba(246, 255, 237, 0.1); color: #95de64; }
.dark-theme .csf-group-status-failed { background-color: rgba(255, 241, 240, 0.1); color: #ff7875; }

/* Members List in User's Group */
.csf-group-members-container {
    margin-top: 20px;
}
.csf-group-members-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.csf-group-members-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--key-color);
}
.csf-group-members-count {
    font-size: 13px;
    color: var(--muted-2-color);
}

.csf-group-members-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.csf-group-member {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--body-bg-color);
    border: 1px solid var(--main-border-color);
    border-radius: 6px;
}
.csf-group-member-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    overflow: hidden;
}
.csf-group-member-name {
    flex: 1;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--main-color);
}
.csf-group-member-status {
    font-size: 12px;
    color: var(--muted-2-color);
}
.csf-group-member-paid .csf-group-member-status { color: #52c41a; }
.csf-group-member-unpaid .csf-group-member-status { color: #f5222d; }
.csf-group-member-current {
    border-color: #ff7875;
}

/* 暗色模式下的成员卡片 */
.dark-theme .csf-group-member {
    background: var(--main-bg-color);
}

.csf-group-user-actions {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.csf-exit-wrapper {
    margin-left: auto;
}
.csf-exit-hint {
    font-size: 12px;
    color: var(--muted-2-color);
    text-align: center;
    margin-top: 6px;
    display: none; /* Usually hidden on desktop */
}

/* ======================================= */
/* 4. Empty/Notice States                  */
/* ======================================= */

.csf-group-empty-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    background-color: var(--body-bg-color);
    border: 1px dashed var(--main-border-color);
    border-radius: 8px;
}

.csf-group-empty-icon {
    margin-bottom: 15px;
    color: #ff7875;
}

.csf-group-empty-notice h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--key-color);
}

.csf-group-empty-notice p {
    margin: 0;
    font-size: 14px;
    color: var(--muted-2-color);
}

.csf-group-notice {
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 16px;
}
.csf-group-warning {
    background-color: #fffbe6;
    border: 1px solid #ffe58f;
    color: #d46b08;
}

/* Special case for empty state to center the button */
.csf-group-empty-wrapper + .csf-group-actions {
    justify-content: center;
}

/* ======================================= */
/* 5. Responsive Adjustments (Mobile)      */
/* ======================================= */

@media (max-width: 768px) {
    .csf-group-display, .csf-group-user-display {
        padding: 16px;
    }

    /* 缩小标题与提示框的间距 */
    .csf-group-display h3 {
        margin-bottom: 6px !important;
    }

    .csf-group-notice {
        margin-bottom: 10px !important;
        padding: 8px 12px !important;
        font-size: 13px !important;
    }

    /* 移除内容区域的上边距 */
    .csf-group-tab-content {
        padding-top: 0 !important;
    }

    .csf-group-tabs {
        gap: 16px;
    }
    .csf-group-tab {
        font-size: 15px;
    }

    .csf-group-btn {
        width: 100%;
        padding: 12px 0;
    }

    .csf-group-actions, .csf-group-user-actions {
        flex-direction: column;
        width: 100%;
    }

    .csf-exit-wrapper {
        margin-left: 0;
        width: 100%;
    }
    .csf-exit-hint {
        display: block;
    }

    /* Responsive button text for exit button */
    .csf-desktop-text {
        display: none;
    }
    .csf-mobile-text {
        display: inline;
    }

    .csf-group-members-list {
        grid-template-columns: 1fr;
    }
}

/* --- Layout isolation: Do NOT use flow-root as it breaks theme's float layout --- */
.csf-group-standalone-wrapper,
.csf-group-fallback-wrapper{
    /* 完全不干扰主题布局，让它自然流动 */
}

/* ======================================= */
/* 6. Card Product Form (发卡商品表单)     */
/* ======================================= */

/* 基础样式 - 清除浮动 */
.csf-card-form-bar::after {
    content: "";
    display: table;
    clear: both;
}

/* 移动端响应式优化 (768px以下) */
@media (max-width: 768px) {
    /* 表单容器 - 全宽对齐 */
    .csf-card-form-bar {
        padding: 12px 15px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
        text-align: center !important;
    }

    /* 第一行容器包装器（用于水平居中） */
    .csf-card-form-bar::before {
        content: "";
        display: block;
        clear: both;
    }

    /* === 第一行：团购价 + 库存 + 数量（紧凑排列，水平+垂直居中） === */
    .csf-card-price-section,
    .csf-card-stock-section,
    .csf-card-quantity-section {
        float: none !important;
        display: inline-flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        width: auto !important;
        margin-right: 12px !important;
        padding-right: 12px !important;
        border-right: 1px solid var(--main-border-color) !important;
        margin-bottom: 15px !important;
        box-sizing: border-box;
        vertical-align: middle !important;
    }

    .csf-card-quantity-section {
        border-right: none !important;
        margin-right: 0 !important;
        padding-right: 0 !important;
    }

    /* 标签样式 - 居中对齐 */
    .csf-card-price-section .csf-card-label,
    .csf-card-stock-section .csf-card-label,
    .csf-card-quantity-section .csf-card-label {
        font-size: 11px !important;
        margin-bottom: 4px !important;
        white-space: nowrap;
        color: var(--muted-color);
        text-align: center !important;
    }

    /* 价格和库存数值 - 居中对齐 */
    .csf-card-price-value,
    .csf-card-stock-value {
        font-size: 18px !important;
        font-weight: 600 !important;
        white-space: nowrap;
        line-height: 1.2;
        text-align: center !important;
    }

    .csf-card-price-value span,
    .csf-card-stock-value span {
        font-size: 11px !important;
        font-weight: normal !important;
    }

    /* 省钱提示 - 居中对齐 */
    .csf-card-save-amount {
        font-size: 10px !important;
        margin-top: 2px !important;
        line-height: 1;
        text-align: center !important;
    }

    /* 数量控制器 */
    .csf-card-quantity-controls {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* 缩小触摸区域以适应一行 */
    .csf-card-qty-minus,
    .csf-card-qty-plus {
        width: 34px !important;
        height: 34px !important;
        font-size: 16px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .csf-card-qty-input {
        width: 55px !important;
        height: 34px !important;
        font-size: 15px !important;
        margin: 0 5px !important;
        text-align: center !important;
    }

    /* === 第二行：合计金额（独占一行，居中） === */
    .csf-card-total-section {
        float: none !important;
        width: 100% !important;
        margin-right: 0 !important;
        padding-right: 0 !important;
        border-right: none !important;
        text-align: center !important;
        margin-bottom: 12px !important;
        padding-bottom: 12px !important;
        border-bottom: 1px solid var(--main-border-color) !important;
        clear: both !important;
    }

    .csf-card-total-section .csf-card-label {
        font-size: 11px !important;
        margin-bottom: 4px !important;
        color: var(--muted-color);
    }

    .csf-card-total-value {
        font-size: 22px !important;
        font-weight: 600 !important;
    }

    /* === 第三行：操作按钮（全宽堆叠） === */
    .csf-card-actions-section {
        float: none !important;
        width: 100% !important;
        margin-right: 0 !important;
        clear: both !important;
    }

    .csf-card-actions-section .csf-group-btn,
    .csf-card-actions-section .csf-group-start-btn,
    .csf-card-actions-section .csf-direct-buy-btn {
        width: 100% !important;
        height: 44px !important;
        line-height: 44px !important;
        padding: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 8px !important;
        display: block !important;
        box-sizing: border-box !important;
        font-size: 15px !important;
    }

    .csf-card-actions-section .csf-group-start-btn {
        margin-bottom: 8px !important;
    }

    .csf-card-actions-section .csf-direct-buy-btn {
        margin-bottom: 0 !important;
    }
}

/* 小屏幕手机优化 (480px以下) */
@media (max-width: 480px) {
    /* 进一步减少内边距 */
    .csf-card-form-bar {
        padding: 10px 12px !important;
    }

    /* 缩小价格和库存字号 */
    .csf-card-price-value,
    .csf-card-stock-value {
        font-size: 16px !important;
    }

    /* 缩小合计字号 */
    .csf-card-total-value {
        font-size: 22px !important;
    }

    /* 缩小按钮 */
    .csf-card-actions-section .csf-group-btn,
    .csf-card-actions-section .csf-group-start-btn,
    .csf-card-actions-section .csf-direct-buy-btn {
        font-size: 14px !important;
        height: 44px !important;
        line-height: 44px !important;
    }

    /* 优化数量选择器 */
    .csf-card-qty-minus,
    .csf-card-qty-plus {
        width: 40px !important;
        height: 40px !important;
    }

    .csf-card-qty-input {
        width: 65px !important;
        height: 40px !important;
        margin: 0 6px !important;
    }
}
