/* wp-content/themes/bricks-child/assets/css/table-styles.css  (V2.9 - Mobile transpose for merged flip) */
.custom-engine-table-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 1.5rem 0;
}

.custom-engine-table {
    width: 100%;
    border-collapse: collapse !important;
}

.custom-engine-table thead th {
    background-color: #dcedf4 !important;
    color: #000000 !important;
    font-weight: 700;
    border: 1px solid #e2e2e2 !important;
    padding: 12px 10px !important;
    text-align: center;
    vertical-align: middle;
}

.custom-engine-table tbody td {
    border: 1px solid #e2e2e2 !important;
    padding: 10px !important;
    text-align: center !important;
    vertical-align: middle !important;
}

/* 行条纹（纯 CSS，含合并单元格时也生效） */
.custom-engine-table tbody tr:nth-child(odd) td {
    background-color: #ffffff !important;
}
.custom-engine-table tbody tr:nth-child(even) td {
    background-color: #f5f5f5 !important;
}

.custom-engine-table sup {
    font-size: 0.7em;
    vertical-align: super;
    line-height: 0;
}

/* 转置表默认隐藏（仅在手机端 flip+合并 时由 JS 生成并显示） */
.custom-engine-transposed {
    display: none !important;
}

/* 普通表格：整表横向滚动容器 */
.ce-table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- DataTables 控件外观 --- */
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_length {
    margin-bottom: 12px;
}
.dataTables_wrapper .dataTables_length label {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin: 0;
    text-transform: capitalize;
}
.dataTables_wrapper .dataTables_length select {
    width: auto;
    min-width: 90px;
}
.dataTables_wrapper .dataTables_filter {
    text-align: left;
}
.dataTables_wrapper .dataTables_filter label {
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-start;
    gap: 4px;
    margin: 0;
}
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 6px 10px;
    margin: 0;
}
.dataTables_wrapper .dataTables_paginate {
    margin-top: 12px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 4px 10px;
    margin: 0 2px;
    border-radius: 4px;
    color: var(--white) !important;
    cursor: pointer;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--primary) !important;
    border: 1px solid var(--primary) !important;
    color: var(--white) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.previous,
.dataTables_wrapper .dataTables_paginate .paginate_button.next {
    font-size: 1.15em;
}

.custom-engine-static thead th {
    cursor: default;
}

/* =========================================================
   Desktop ONLY: Horizontal Scroll & Sticky 1st Column
   ========================================================= */
@media screen and (min-width: 769px) {
    .custom-engine-table:not(.custom-engine-transposed) {
        display: block !important;
        width: 100% !important;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
    }
    .ce-table-scroll {
        overflow: visible !important;
    }
    .custom-engine-table .ce-sticky-col {
        position: sticky !important;
        left: 0 !important;
        z-index: 2 !important;
        box-shadow: inset -1px 0 0 #e2e2e2, inset 0 -1px 0 #e2e2e2 !important;
        border-right: 1px solid #e2e2e2 !important;
    }
    .custom-engine-table thead th.ce-sticky-col {
        background-color: #dcedf4 !important;
        z-index: 3 !important;
    }
    .custom-engine-table tbody tr:nth-child(odd) .ce-sticky-col {
        background-color: #ffffff !important;
    }
    .custom-engine-table tbody tr:nth-child(even) .ce-sticky-col {
        background-color: #f5f5f5 !important;
    }
    .custom-engine-table::-webkit-scrollbar {
        height: 10px;
    }
    .custom-engine-table::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 6px;
    }
    .custom-engine-table::-webkit-scrollbar-thumb {
        background: #bdbdbd;
        border-radius: 6px;
    }
    .custom-engine-table::-webkit-scrollbar-thumb:hover {
        background: #9e9e9e;
    }
}

/* =========================================================
   手机端
   ========================================================= */
@media screen and (max-width: 768px) {

    .dataTables_wrapper {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 15px;
    }
    .dataTables_wrapper table,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        grid-column: 1 / -1;
    }
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        width: 100%;
        float: none;
        margin: 0 0 15px 0;
        padding: 0;
    }
    .dataTables_wrapper .dataTables_length label {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }
    .dataTables_wrapper .dataTables_filter label {
        display: flex;
        flex-direction: column-reverse;
        align-items: flex-start;
    }
    .dataTables_wrapper .dataTables_length select,
    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
        margin: 0 0 5px 0 !important;
        box-sizing: border-box;
    }

    /* --- 普通表格（非 flip）：横向滚动 + 第一列固定，不超出屏幕 --- */
    .custom-engine-table-wrapper:not(.custom-engine-flip) {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .custom-engine-table-wrapper:not(.custom-engine-flip) .custom-engine-table {
        min-width: 640px;
    }
    .custom-engine-table-wrapper:not(.custom-engine-flip) .custom-engine-table th,
    .custom-engine-table-wrapper:not(.custom-engine-flip) .custom-engine-table td {
        white-space: nowrap;
    }
    .custom-engine-table-wrapper:not(.custom-engine-flip) .custom-engine-table .ce-sticky-col {
        position: sticky !important;
        left: 0 !important;
        z-index: 2 !important;
        box-shadow: 3px 0 6px rgba(0, 0, 0, 0.08);
    }
    .custom-engine-table-wrapper:not(.custom-engine-flip) .custom-engine-table thead th.ce-sticky-col {
        background-color: #dcedf4 !important;
        z-index: 3 !important;
    }
    .custom-engine-table-wrapper:not(.custom-engine-flip) .custom-engine-table tbody tr:nth-child(odd) .ce-sticky-col {
        background-color: #ffffff !important;
    }
    .custom-engine-table-wrapper:not(.custom-engine-flip) .custom-engine-table tbody tr:nth-child(even) .ce-sticky-col {
        background-color: #f5f5f5 !important;
    }

    /* =========================================================
       FLIP（无合并单元格）：表头固定为左列，仅 tbody 横向滚动
       ========================================================= */
    .custom-engine-flip:not([data-static="true"]) {
        max-width: 100%;
        overflow: hidden;
    }
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table {
        display: flex !important;
        width: 100% !important;
        max-width: 100%;
        border: none !important;
        margin: 0;
    }
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table thead {
        display: block;
        flex: 0 0 auto;
        z-index: 2;
        background-color: #dcedf4;
        box-shadow: 2px 0 5px rgba(0, 0, 0, 0.12);
    }
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table thead tr {
        display: flex;
        flex-direction: column;
    }
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table tbody {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        flex: 1 1 auto;
        min-width: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table tbody tr {
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
    }
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table th,
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table td {
        display: flex !important;
        align-items: center;
        justify-content: center;
        text-align: center !important;
        height: 52px;
        flex: 0 0 52px;
        padding: 0 10px !important;
        box-sizing: border-box;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        border: 1px solid #e2e2e2 !important;
        border-top: none !important;
    }
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table thead th {
        min-width: 150px;
        position: relative;
    }
    .custom-engine-flip:not([data-static="true"]) .custom-engine-table tbody td {
        min-width: 110px;
    }

    /* =========================================================
       FLIP + 含合并单元格：显示 JS 生成的「转置表」
       （原表头变成最左固定列，合并单元格保留），隐藏原始表。
       ========================================================= */
    .custom-engine-has-transpose {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .custom-engine-has-transpose > .custom-engine-table:not(.custom-engine-transposed) {
        display: none !important;
    }
    .custom-engine-transposed {
        display: table !important;
        width: auto !important;
        min-width: 100%;
        border-collapse: separate !important;
        border-spacing: 0 !important;
    }
    .custom-engine-transposed th,
    .custom-engine-transposed td {
        display: table-cell !important;
        border: 1px solid #e2e2e2 !important;
        padding: 10px !important;
        white-space: nowrap;
        min-width: 110px;
        text-align: center;
        vertical-align: middle;
        line-height:1.2;
    }
    /* 最左侧固定表头列 */
    .custom-engine-transposed .ce-thead-col {
        position: sticky !important;
        left: 0 !important;
        z-index: 2 !important;
        background-color: #dcedf4 !important;
        color: #000 !important;
        font-weight: 700;
        min-width: 150px;
        border-right: 1px solid #e2e2e2 !important;   /* add */
        box-shadow: 2px 0 5px rgba(0, 0, 0, 0.12);
    }
}

@media screen and (max-width: 640px) {
    .dataTables_wrapper .dataTables_filter {
        margin-top: 0em !important;
    }
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    color: white !important;
    border: 1px solid var(--primary) !important;
    background: var(--primary) !important;
}

.dataTables_filter {
    display: none !important;
}

.dataTables_length {
    display: none !important;
}

table.dataTable.no-footer {
    border-bottom: 0px solid rgba(0, 0, 0, 0.3);
}