/* ==========================================================================
   BATTU-TABLE.CSS — HỆ THỐNG HIỂN THỊ BẢNG BÁT TỰ MANH PHÁI CHUẨN
   Đồng bộ Đại Vận • Lưu Niên • Lưu Nguyệt
   ========================================================================== */

/* 1. KHUNG CHỨA BẢNG VẬN HẠN */
.la-so-table-wrap {
    border: none !important;
    border-radius: 0 !important;
    background: #FFFFFF !important;
    box-shadow: none !important;
}

.la-so-table-wrap::-webkit-scrollbar {
    height: 6px;
}
.la-so-table-wrap::-webkit-scrollbar-track {
    background: #F1F5F9;
    border-radius: 4px;
}
.la-so-table-wrap::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 4px;
}
.la-so-table-wrap::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

.la-so-table-wrap table, 
.cosmic-table-container table, 
table.cosmic-battu-table {
    border-collapse: collapse !important;
    border-spacing: 0 !important;
    width: 100% !important;
    background: #FFFFFF !important;
    border: none !important;
}

/* Triệt tiêu viền cạnh ngoài để đường bao quanh bảng luôn thanh mảnh 1px đồng nhất */
.la-so-table-wrap table tr th:last-child,
.la-so-table-wrap table tr td:last-child {
    border-right: none !important;
}
.la-so-table-wrap table tr:last-child td {
    border-bottom: none !important;
}

/* ==========================================================================
   TYPOGRAPHY CHUẨN CHO DESKTOP / PC (MÀN HÌNH >= 641px)
   ========================================================================== */

/* 1. Dòng Tiêu Đề Cột Năm / Tháng */
.battu-col-header {
    background-color: #F1F5F9 !important;
    border-bottom: 1px solid #E2E8F0 !important;
    border-right: 1px solid #E2E8F0 !important;
    text-align: center !important;
    vertical-align: middle !important;
    padding: 7px 2px !important;
    cursor: pointer;
    box-sizing: border-box;
}
.battu-cell-header-main {
    font-size: 12px !important;
    font-weight: 700 !important;
    color: #1E293B !important;
    line-height: 1.25 !important;
    white-space: nowrap !important;
}
.battu-cell-header-sub {
    font-size: 10px !important;
    font-weight: 600 !important;
    color: #64748B !important;
    line-height: 1.2 !important;
    margin-top: 2px !important;
    white-space: nowrap !important;
}

/* 2. Dòng Thập Thần Can (Hàng Trên) */
.battu-cell-god-can {
    font-size: 11px !important;
    font-weight: 700 !important;
    text-align: center !important;
    vertical-align: middle !important;
    padding: 5px 2px 7px 2px !important;
    border-right: 1px solid #E2E8F0 !important;
    border-bottom: 1px solid #E2E8F0 !important;
    white-space: nowrap !important;
    cursor: pointer;
    line-height: 1.25 !important;
    box-sizing: border-box;
}

/* 3. Dòng Can Chi Trọng Tâm (Kích Thước Chuẩn PC) */
.battu-cell-canchi {
    text-align: center !important;
    vertical-align: middle !important;
    padding: 6px 2px 7px 2px !important;
    border-right: 1px solid #E2E8F0 !important;
    border-bottom: 1px solid #E2E8F0 !important;
    cursor: pointer;
    box-sizing: border-box;
}
.battu-can-val {
    font-size: 15px !important;
    font-weight: 900 !important;
    line-height: 1.15 !important;
}
.battu-chi-val {
    font-size: 15px !important;
    font-weight: 900 !important;
    line-height: 1.15 !important;
    margin-top: 1.5px !important;
}

/* 4. Dòng Thập Thần Chi (Hàng Dưới) */
.battu-cell-god-chi {
    font-size: 10px !important;
    font-weight: 600 !important;
    color: #64748B !important;
    text-align: center !important;
    vertical-align: middle !important;
    padding: 5px 2px 7px 2px !important;
    border-right: 1px solid #E2E8F0 !important;
    border-bottom: 1px solid #E2E8F0 !important;
    white-space: nowrap !important;
    cursor: pointer;
    line-height: 1.25 !important;
    box-sizing: border-box;
}

/* Hiệu ứng Cột Đang Chọn (col-active) trên PC */
th.battu-col-header.col-active,
td.battu-cell-god-can.col-active,
td.battu-cell-canchi.col-active,
td.battu-cell-god-chi.col-active {
    background-color: #FEF3C7 !important; /* Amber-100 */
}
th.battu-col-header.col-active .battu-cell-header-main,
th.battu-col-header.col-active .battu-cell-header-sub {
    color: #92400E !important;
}
td.battu-cell-god-chi.col-active {
    color: #92400E !important;
    font-weight: 700 !important;
}

/* ==========================================================================
   TỐI ƯU HÓA ĐẶC TRỊ RIÊNG CHO MÀN HÌNH MOBILE (<= 640px)
   Chỉ có tác dụng trên điện thoại, tuyệt đối không ảnh hưởng đến PC
   ========================================================================== */

/* ==========================================================================
   5. TỐI ƯU HÓA KHỐI THỜI VẬN & 10 CHỦ ĐỀ TRÊN DESKTOP PC (>= 641px)
   ========================================================================== */
@media (min-width: 641px) {
    #topics-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
        align-items: stretch !important;
    }
    .topic-item {
        padding: 9px 12px !important;
        border-radius: 0 !important;
        gap: 10px !important;
        min-height: 60px !important;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
    .topic-item:hover {
        border-color: #F59E0B !important;
        background-color: #FFFDF9 !important;
        box-shadow: 0 2px 8px -1px rgba(245, 158, 11, 0.15) !important;
        transform: translateY(-1px);
    }
    .topic-item.active {
        border: 2px solid #B51224 !important;
        background-color: rgba(255, 241, 242, 0.85) !important;
        box-shadow: 0 3px 10px -1px rgba(181, 18, 36, 0.18) !important;
    }
    .topic-item input[type="checkbox"] {
        width: 15px !important;
        height: 15px !important;
        margin-top: 2px !important;
        flex-shrink: 0 !important;
    }
    .topic-item .topic-title {
        font-size: 13px !important;
        font-weight: 700 !important;
        line-height: 1.3 !important;
        color: #1E293B !important;
    }
    .topic-item.active .topic-title {
        color: #881337 !important;
    }
    .topic-item svg,
    .topic-item [data-lucide] {
        width: 15px !important;
        height: 15px !important;
        flex-shrink: 0 !important;
    }
    .topic-item .text-slate-500 {
        font-size: 11px !important;
        line-height: 1.4 !important;
        color: #64748B !important;
        margin-top: 3px !important;
        display: block !important;
        -webkit-line-clamp: unset !important;
        line-clamp: unset !important;
        overflow: visible !important;
        white-space: normal !important;
    }
    .topic-item.active .text-slate-500 {
        color: #475569 !important;
    }
}

@media (max-width: 640px) {
    /* 1. Các bảng Đại Vận, Lưu Niên 5 cột trên Mobile */
    .battu-col-header {
        padding: 4px 1px !important;
    }
    .battu-cell-header-main {
        font-size: 10px !important;
    }
    .battu-cell-header-sub {
        font-size: 8.5px !important;
        margin-top: 1px !important;
    }
    .battu-cell-god-can {
        font-size: 9px !important;
        padding: 4px 1px !important;
    }
    .battu-cell-canchi {
        padding: 5px 1px !important;
    }
    .battu-can-val,
    .battu-chi-val {
        font-size: 12px !important;
        font-weight: 800 !important;
    }
    .battu-chi-val {
        margin-top: 2px !important;
    }
    .battu-cell-god-chi {
        font-size: 8.5px !important;
        padding: 4px 1px !important;
    }

    /* 2. Riêng bảng Lưu Nguyệt 6 cột trên Mobile */
    #table-luunguyet-mb-1 .battu-col-header,
    #table-luunguyet-mb-2 .battu-col-header {
        padding: 4px 0.5px !important;
    }
    #table-luunguyet-mb-1 .battu-cell-god-can,
    #table-luunguyet-mb-2 .battu-cell-god-can {
        font-size: 8px !important;
        padding: 3px 0.5px !important;
    }
    #table-luunguyet-mb-1 .battu-can-val,
    #table-luunguyet-mb-1 .battu-chi-val,
    #table-luunguyet-mb-2 .battu-can-val,
    #table-luunguyet-mb-2 .battu-chi-val {
        font-size: 11px !important;
    }
    #table-luunguyet-mb-1 .battu-cell-god-chi,
    #table-luunguyet-mb-2 .battu-cell-god-chi {
        font-size: 7.8px !important;
        padding: 2px 0.5px !important;
    }

    /* 3. Tách rời 2 hàng bảng trên Mobile cách nhau đúng 5px, đường viền thanh mảnh tinh tế */
    .block.sm\:hidden.la-so-table-box,
    div[class*="sm:hidden"].la-so-table-box,
    .la-so-table-box {
        background: transparent !important;
        border: none !important;
    }
    .block.sm\:hidden.la-so-table-box > .la-so-table-wrap,
    div[class*="sm:hidden"].la-so-table-box > .la-so-table-wrap,
    .la-so-table-box > .la-so-table-wrap {
        border: 1px solid #E2E8F0 !important;
        background: #FFFFFF !important;
        box-sizing: border-box !important;
    }
    .block.sm\:hidden.la-so-table-box > .la-so-table-wrap + .la-so-table-wrap,
    div[class*="sm:hidden"].la-so-table-box > .la-so-table-wrap + .la-so-table-wrap,
    .la-so-table-box > .la-so-table-wrap + .la-so-table-wrap,
    .la-so-table-box > div.border-t,
    .la-so-table-box > .la-so-table-wrap.border-t {
        margin-top: 5px !important;
        border-top: 1px solid #E2E8F0 !important;
    }

    /* 4. Tinh chỉnh Khối Thời Vận & Tiêu đề trên Mobile */
    #sec-chu-de .la-so-card-title {
        font-size: 11px !important;
        white-space: nowrap !important;
    }
    #badge-nam-luan-giai {
        font-size: 9px !important;
        padding: 2px 7px !important;
        white-space: nowrap !important;
    }
    #select-tieuvan-year,
    #select-daivan-step,
    #select-luunien-in-daivan {
        height: 32px !important;
        font-size: 10.5px !important;
    }

    /* 5. 10 Chủ Đề: 1 Cột trên Mobile chống vỡ chữ và rớt dòng */
    #topics-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 8px !important;
        align-items: stretch !important;
    }
    .topic-item {
        min-height: 56px !important;
        height: 100% !important;
        padding: 7px 8px !important;
        border-radius: 0 !important;
        gap: 6px !important;
    }
    .topic-item input[type="checkbox"] {
        width: 15px !important;
        height: 15px !important;
        margin-top: 1.5px !important;
        flex-shrink: 0 !important;
    }
    .topic-item .topic-title {
        font-size: 11.5px !important;
        font-weight: 700 !important;
        line-height: 1.25 !important;
    }
    .topic-item svg,
    .topic-item [data-lucide] {
        width: 13px !important;
        height: 13px !important;
        flex-shrink: 0 !important;
    }
    .topic-item .text-slate-500 {
        font-size: 9.5px !important;
        line-height: 1.35 !important;
        color: #64748B !important;
        margin-top: 2.5px !important;
        display: block !important;
        -webkit-line-clamp: unset !important;
        line-clamp: unset !important;
        overflow: visible !important;
        white-space: normal !important;
    }
}
/* ==========================================================================
   THẦN SÁT NGUYÊN CỤC & VẬN HẠN (TEXT-ONLY COLOR, KHÔNG BORDER, KHÔNG NỀN)
   ========================================================================== */
.laso-than-sat-chip-pc {
    display: block;
    width: 100%;
    padding: 2.5px 2px;
    margin: 1px 0;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s ease;
}
.laso-than-sat-chip-pc.cat-tinh {
    color: #059669 !important; /* Xanh ngọc lục bảo cát tường */
}
.laso-than-sat-chip-pc.hung-tinh {
    color: #DC2626 !important; /* Đỏ tươi hung sát */
}

/* Tinh chỉnh Bảng 6 Cột Thần Sát trên Mobile (< 640px) */
@media (max-width: 640px) {
    .laso-than-sat-desktop {
        border-radius: 0 !important;
    }
    .laso-than-sat-desktop table {
        width: 100% !important;
        min-width: 0 !important;
        table-layout: fixed !important;
    }
    .laso-than-sat-desktop th {
        padding: 4px 1px !important;
    }
    .laso-than-sat-desktop th > div:first-child {
        font-size: 9px !important;
        font-weight: 700 !important;
        line-height: 1.15 !important;
    }
    .laso-than-sat-desktop th > div:last-child {
        font-size: 7.5px !important;
        line-height: 1.15 !important;
    }
    .laso-than-sat-desktop td {
        padding: 3px 1px !important;
        vertical-align: top !important;
    }
    .laso-than-sat-chip-pc {
        font-size: 8.5px !important;
        line-height: 1.2 !important;
        padding: 1.5px 0.5px !important;
        margin: 1.5px 0 !important;
        white-space: normal !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        text-overflow: clip !important;
        overflow: visible !important;
        letter-spacing: -0.015em !important;
    }
}

/* ==========================================================================
   TINH BÀN NHẬT CHỦ (#table-bat-tu-full) - HÀNG CAN CHI (BÁT TỰ)
   Font-size: 20px chuẩn mực đồng bộ trên cả PC & Mobile (Giữ vững bố cục 100%)
   ========================================================================== */
#table-bat-tu-full .canchi-main-val,
.table-bat-tu-full-wrap .canchi-main-val {
    font-size: 20px !important;
    font-weight: 800 !important;
    line-height: 1.25 !important;
    letter-spacing: 0 !important;
    white-space: nowrap !important;
    text-align: center !important;
    display: block !important;
}

#table-bat-tu-full .canchi-main-chi,
.table-bat-tu-full-wrap .canchi-main-chi {
    margin-top: 1.5px !important;
}

@media (min-width: 641px) {
    #table-bat-tu-full .canchi-main-chi,
    .table-bat-tu-full-wrap .canchi-main-chi {
        margin-top: 1.5px !important;
    }
}

/* Can Tàng (Tàng Can): Căn chỉnh tỷ lệ chữ nhỏ gọn, thanh thoát chuẩn Bát Tự */
#table-bat-tu-full .battu-tang-can-cell,
.table-bat-tu-full-wrap .battu-tang-can-cell {
    vertical-align: middle !important;
    text-align: center !important;
    padding: 6px 3px !important;
}
#table-bat-tu-full .battu-tang-can-list,
.table-bat-tu-full-wrap .battu-tang-can-list {
    display: inline-block !important;
    text-align: left !important;
    margin: 0 auto !important;
}
#table-bat-tu-full .battu-tang-can-item,
.table-bat-tu-full-wrap .battu-tang-can-item {
    font-size: 9.5px !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;
    letter-spacing: -0.01em !important;
    white-space: nowrap !important;
    padding: 0.5px 0 !important;
}

@media (max-width: 640px) {
    /* Tối ưu phân bổ độ rộng 5 cột bảng Tinh Bàn Nhật Chủ trên Mobile */
    #table-bat-tu-full thead th:nth-child(3),
    .table-bat-tu-full-wrap table thead th:nth-child(3) {
        width: 14.8% !important;
        padding: 5px 1px !important;
        font-size: 9.5px !important;
    }
    #table-bat-tu-full thead th:nth-child(4),
    #table-bat-tu-full thead th:nth-child(5),
    #table-bat-tu-full thead th:nth-child(6),
    #table-bat-tu-full thead th:nth-child(7),
    .table-bat-tu-full-wrap table thead th:nth-child(4),
    .table-bat-tu-full-wrap table thead th:nth-child(5),
    .table-bat-tu-full-wrap table thead th:nth-child(6),
    .table-bat-tu-full-wrap table thead th:nth-child(7) {
        width: 21.3% !important;
        padding: 5px 1px !important;
        font-size: 10px !important;
    }
    /* Các dòng đơn (Chủ Tinh, Nhật, Nguyệt Kiến, Trụ, Nạp Âm) gọn gàng 1 dòng trên Mobile */
    #table-bat-tu-full tbody tr:not(.battu-tang-can-row) td,
    .table-bat-tu-full-wrap table tbody tr:not(.battu-tang-can-row) td {
        font-size: 9.5px !important;
        padding-left: 1px !important;
        padding-right: 1px !important;
    }
    #table-bat-tu-full tbody td:nth-child(3),
    .table-bat-tu-full-wrap table tbody td:nth-child(3) {
        font-size: 9px !important;
        letter-spacing: -0.02em !important;
        padding-left: 1px !important;
        padding-right: 1px !important;
    }

    /* Hàng Tàng Can trên Mobile: Lược bỏ % để thoáng chữ, tăng khoảng cách trên dưới & giữa các dòng */
    #table-bat-tu-full .battu-tang-can-cell,
    .table-bat-tu-full-wrap .battu-tang-can-cell {
        padding: 6px 2px !important;
        vertical-align: middle !important;
        text-align: center !important;
        overflow: hidden !important;
    }
    #table-bat-tu-full .battu-tang-can-list,
    .table-bat-tu-full-wrap .battu-tang-can-list {
        display: inline-block !important;
        text-align: left !important;
        transform: none !important;
        margin: 0 auto !important;
    }
    #table-bat-tu-full .battu-tang-can-item,
    .table-bat-tu-full-wrap .battu-tang-can-item,
    #table-bat-tu-full .battu-tang-can-item span,
    .table-bat-tu-full-wrap .battu-tang-can-item span {
        font-size: 8.5px !important;
        font-weight: 500 !important;
        line-height: 1.5 !important;
        letter-spacing: -0.015em !important;
        white-space: nowrap !important;
        padding: 1px 0 !important;
    }
}

/* Can Tàng legacy flex fallback */
#table-bat-tu-full td div.flex,
.table-bat-tu-full-wrap td div.flex {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}
#table-bat-tu-full td div.flex span:last-child,
.table-bat-tu-full-wrap td div.flex span:last-child {
    margin-left: 4px !important;
    display: inline-block !important;
}