/* ========================================
   3个按钮对齐修复 - 专门解决第三个按钮与第一个按钮左右对齐问题
   版本: 2.0.4
   ======================================== */

/* 
 * 问题：4个按钮时正常，3个按钮时第三个和第一个不对齐
 * 原因：flex布局在奇数按钮时无法完美对称分布
 * 解决方案：为3个按钮创建特殊的网格布局，确保对称对齐
 */

/* ========================================
   3个按钮特殊布局 - 完美对称对齐
   ======================================== */

/* 当只有3个按钮时，使用特殊布局确保对称对齐 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child),
.zib-netdisk-download-section tbody:has(td:nth-child(3):last-child),
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) {
    display: grid !important;
    grid-template-columns: 1fr 1fr 1fr !important;
    gap: 16px !important;
    justify-items: center !important;
    align-items: center !important;
    width: 100% !important;
    max-width: 600px !important;
    margin: 0 auto !important;
}

/* 3个按钮时的td样式 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child) td,
.zib-netdisk-download-section tbody:has(td:nth-child(3):last-child) td,
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) td {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* 第一个按钮：左对齐 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child) td:nth-child(1),
.zib-netdisk-download-section tbody:has(td:nth-child(3):last-child) td:nth-child(1),
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) td:nth-child(1) {
    justify-self: start !important;
    margin-right: auto !important;
    margin-left: 0 !important;
}

/* 第二个按钮：居中对齐 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child) td:nth-child(2),
.zib-netdisk-download-section tbody:has(td:nth-child(3):last-child) td:nth-child(2),
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) td:nth-child(2) {
    justify-self: center !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* 第三个按钮：右对齐 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child) td:nth-child(3),
.zib-netdisk-download-section tbody:has(td:nth-child(3):last-child) td:nth-child(3),
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) td:nth-child(3) {
    justify-self: end !important;
    margin-left: auto !important;
    margin-right: 0 !important;
}

/* 3个按钮时的按钮样式统一 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child) .zib-netdisk-btn,
.zib-netdisk-download-section tbody:has(td:nth-child(3):last-child) .zib-netdisk-btn,
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) .zib-netdisk-btn {
    width: 160px !important;
    min-width: 160px !important;
    max-width: 160px !important;
    margin: 0 !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

/* ========================================
   4个按钮布局 - 保持原有正常显示
   ======================================== */

/* 4个按钮时使用flex布局 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(4):last-child),
.zib-netdisk-download-section tbody:has(td:nth-child(4):last-child),
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(4):last-child) {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 16px !important;
    width: 100% !important;
}

/* 4个按钮时的td样式 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(4):last-child) td,
.zib-netdisk-download-section tbody:has(td:nth-child(4):last-child) td,
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(4):last-child) td {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ========================================
   2个按钮布局 - 对称分布
   ======================================== */

/* 2个按钮时使用特殊布局 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(2):last-child),
.zib-netdisk-download-section tbody:has(td:nth-child(2):last-child),
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(2):last-child) {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 16px !important;
    justify-items: center !important;
    align-items: center !important;
    width: 100% !important;
    max-width: 400px !important;
    margin: 0 auto !important;
}

/* 第一个按钮：左对齐 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(2):last-child) td:nth-child(1),
.zib-netdisk-download-section tbody:has(td:nth-child(2):last-child) td:nth-child(1),
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(2):last-child) td:nth-child(1) {
    justify-self: start !important;
    margin-right: auto !important;
    margin-left: 0 !important;
}

/* 第二个按钮：右对齐 */
.zib-netdisk-download-shortcode tbody:has(td:nth-child(2):last-child) td:nth-child(2),
.zib-netdisk-download-section tbody:has(td:nth-child(2):last-child) td:nth-child(2),
div[id^="zib-netdisk-buttons-"]:has(td:nth-child(2):last-child) td:nth-child(2) {
    justify-self: end !important;
    margin-left: auto !important;
    margin-right: 0 !important;
}

/* ========================================
   响应式适配 - 移动端单列显示
   ======================================== */

@media (max-width: 768px) {
    /* 移动端所有布局都改为单列 */
    .zib-netdisk-download-shortcode tbody,
    .zib-netdisk-download-section tbody,
    div[id^="zib-netdisk-buttons-"] tbody {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 12px !important;
        max-width: 300px !important;
    }
    
    /* 移动端td样式 */
    .zib-netdisk-download-shortcode td,
    .zib-netdisk-download-section td,
    div[id^="zib-netdisk-buttons-"] td {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        justify-content: center !important;
    }
    
    /* 移动端按钮样式 */
    .zib-netdisk-download-shortcode td .zib-netdisk-btn,
    .zib-netdisk-download-section td .zib-netdisk-btn,
    div[id^="zib-netdisk-buttons-"] td .zib-netdisk-btn {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        margin: 0 !important;
    }
}

/* ========================================
   调试样式 - 用于测试对齐效果
   ======================================== */

.debug-3-buttons .zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child),
.debug-3-buttons .zib-netdisk-download-section tbody:has(td:nth-child(3):last-child),
.debug-3-buttons div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) {
    outline: 3px solid red !important;
    background-color: rgba(255, 0, 0, 0.1) !important;
}

.debug-3-buttons .zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child) td,
.debug-3-buttons .zib-netdisk-download-section tbody:has(td:nth-child(3):last-child) td,
.debug-3-buttons div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) td {
    outline: 2px solid blue !important;
    background-color: rgba(0, 0, 255, 0.1) !important;
}

.debug-3-buttons .zib-netdisk-download-shortcode tbody:has(td:nth-child(3):last-child) .zib-netdisk-btn,
.debug-3-buttons .zib-netdisk-download-section tbody:has(td:nth-child(3):last-child) .zib-netdisk-btn,
.debug-3-buttons div[id^="zib-netdisk-buttons-"]:has(td:nth-child(3):last-child) .zib-netdisk-btn {
    outline: 2px solid green !important;
    background-color: rgba(0, 255, 0, 0.1) !important;
}