/* ==========================================
   2. PHÂN LOẠI LỜI NÓI (PHẬT / VUA / CHÚNG)
   ========================================== */

:root {
    --color-phat: #0044ff;
    --color-vua: #d97706;
    --color-chung: #800080;
}

[data-theme="dark"] {
    --color-phat: #60a5fa;
    --color-vua: #fbbf24;
    --color-chung: #c084fc;
}

.quote-phat { color: var(--color-phat) !important; }
.quote-vua  { color: var(--color-vua) !important; }
.quote-chung{ color: var(--color-chung) !important; }
/* ==========================================================================
   1. KHUNG CHÍNH & THẺ NỀN (CARDS & CONTAINERS)
   ========================================================================== */
.chapter-header-box {
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-border-color);
    border-left: 5px solid var(--pico-primary);
    padding: 1rem 1.5rem;
    border-radius: var(--pico-border-radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    margin-bottom: 1.5rem;
}

.panel-card {
    background: var(--pico-card-background-color);
    padding: 1.5rem;
    border-radius: var(--pico-border-radius);
    border: 1px solid var(--pico-border-color);
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--pico-border-color);
    margin-bottom: 1.2rem;
    color: var(--pico-primary);
}

/* Thẻ collapsible (xổ xuống) đồng bộ chuẩn Pico CSS */
details.chapter-collapsible,
.chapter-collapsible {
    background-color: var(--pico-card-background-color) !important;
    color: var(--pico-color) !important;
    border: 1px solid var(--pico-card-border-color, var(--pico-border-color)) !important;
    border-radius: var(--pico-border-radius, 8px);
    margin-bottom: 1.25rem;
    padding: 0.75rem 1.25rem;
    box-shadow: none;
}

details.chapter-collapsible[open] {
    background-color: var(--pico-card-background-color) !important;
}

details.chapter-collapsible summary,
.chapter-collapsible summary {
    font-weight: 700;
    color: var(--pico-color) !important;
    cursor: pointer;
    padding: 0.2rem 0;
}

details.chapter-collapsible summary:hover,
.chapter-collapsible summary:hover {
    color: var(--pico-primary) !important;
}

/* ==========================================================================
   2. FORM, INPUT & DANH SÁCH KÉO THẢ
   ========================================================================== */
.radio-fieldset {
    border: 1px solid var(--pico-border-color) !important;
    border-radius: var(--pico-border-radius, 6px);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    background-color: var(--pico-background-color) !important;
}

.radio-fieldset legend {
    padding: 0 6px;
    font-weight: 700;
    color: var(--pico-color);
}

.radio-fieldset input[type="radio"] {
    accent-color: var(--pico-primary);
    cursor: pointer;
}

.radio-item-highlight {
    font-weight: 600;
    color: var(--pico-primary);
}

/* Danh sách kéo thả */
.drag-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin-bottom: 6px;
    background: var(--pico-background-color);
    border: 1px solid var(--pico-border-color);
    border-radius: 6px;
    cursor: grab;
    transition: background 0.2s;
}
.drag-item:active { cursor: grabbing; }
.drag-item.sortable-ghost { opacity: 0.4; background: #e0e0e0; }

.btn-delete-item {
    background: transparent;
    border: none;
    color: #d9534f;
    cursor: pointer;
    padding: 2px 8px;
    font-size: 0.95rem;
    margin-bottom: 0;
    width: auto;
}
.btn-delete-item:hover { color: #a94442; }

/* ==========================================================================
   3. CÂY MỤC LỤC (TREEVIEW DESKTOP & MOBILE)
   ========================================================================== */
.manage-book-container { 
    display: flex; 
    flex-direction: column; 
    gap: 1.5rem; 
}

@media (min-width: 768px) and (orientation: landscape), (min-width: 992px) {
    .manage-book-container { flex-direction: row; align-items: flex-start; }
    .manage-tree-sidebar {  
        width: 330px;  
        flex-shrink: 0;  
        border-right: 1px solid var(--pico-border-color);  
        padding-right: 1rem;  
        max-height: 82vh;
        display: flex;             /* Thêm flex để chia bố cục header cố định và body cuộn */
        flex-direction: column;    /* Xếp dọc header và phần tree */
    }
    .manage-mobile-select { display: none !important; }
    .manage-form-content { flex: 1; }
}



@media (max-width: 767px), (orientation: portrait) {
    .manage-tree-sidebar { display: none !important; }
    .manage-mobile-select { display: block !important; }
}

.tree-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--pico-border-color);
}

.tree-header-btn {
    padding: 0 !important;
    width: 32px !important;
    height: 32px !important;
    font-size: 0.85rem !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin: 0 !important;
    line-height: 1 !important;
    box-sizing: border-box !important;
    vertical-align: middle !important;
}

/* Khung cuộn & định dạng dòng của TreeView */
#tree-container-desktop {
    font-size: 0.88rem !important;
    line-height: 1.25 !important;
    overflow-x: auto !important;
    overflow-y: auto !important;   /* <-- SỬA THÀNH AUTO ĐỂ BẬT THANH CUỘN DỌC */
    flex: 1;                       /* Cho phép co giãn chiếm hết chiều cao còn lại của sidebar */
    max-height: calc(82vh - 60px); /* Giới hạn chiều cao trừ đi phần header phía trên */
    white-space: nowrap !important;
    max-width: 100%;
    padding-bottom: 8px;
}

/* Đã gỡ bỏ padding-left !important để JS tự điều chỉnh thụt lề cấp con */
#tree-container-desktop ul,
.tree-container ul {
    list-style: none !important;
    margin: 0 !important;
    min-width: max-content;
}

#tree-container-desktop li,
.tree-container li {
    margin: 0 !important;
    padding: 0 !important;
    list-style-type: none !important;
    white-space: nowrap !important;
}

#tree-container-desktop details,
#tree-container-desktop summary,
.tree-container details,
.tree-container summary {
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

#tree-container-desktop summary::-webkit-details-marker {
    display: none;
}

.tree-node-row,
#tree-container-desktop summary {
    display: flex !important;
    align-items: center !important;
    white-space: nowrap !important;
    width: max-content !important;
    padding: 1px 0 !important;
    min-height: 22px;
}
/* Căn chỉnh nhánh cây nằm chính giữa tâm Icon Folder bên trên */
.tree-branch-symbol {
    color: #888;
    font-family: monospace;
    font-weight: bold;
    user-select: none;
    line-height: 1;
    display: inline-block;
    margin-right: 2px;
}

/* Icon folder và file cố định độ rộng để căn lề chuẩn xác */
.tree-node-icon {
    width: 16px !important;
    text-align: center;
    margin-right: 6px;
    flex-shrink: 0;
}

#tree-container-desktop a {
    white-space: nowrap !important;
    display: inline-block;
}

.tree-node-active {
    background-color: var(--pico-primary-background) !important;
    color: var(--pico-primary) !important;
    font-weight: 700 !important;
    border-radius: 4px;
    padding: 2px 8px;
    display: inline-block;
    border: 1px solid var(--pico-primary-border) !important;
}



.tree-toggle-icon {
    cursor: pointer;
    display: inline-block;
    width: 18px;
    text-align: center;
    margin-right: 4px;
    color: var(--pico-primary);
}

.tree-scroll-container {
    max-height: 78vh;
    overflow-x: auto;
    overflow-y: auto;
    white-space: nowrap;
    padding-right: 10px;
}

/* ==========================================================================
   4. PHÂN LOẠI KHÁC (BADGES, BREADCRUMB, PREVIEW)
   ========================================================================== */
.badge-book-title {
    background-color: var(--pico-primary);
    color: #ffffff !important;
    padding: 0.35rem 0.85rem;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.stat-badge-box {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    background: rgba(0,0,0,0.03);
    padding: 10px 15px;
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 0.85rem;
}

.stat-badge-item { 
    display: inline-flex; 
    align-items: center; 
    gap: 5px; 
}

.content-summary-preview {
    background: var(--pico-card-background-color, #f9f9f9);
    border: 1px solid var(--pico-border-color);
    border-radius: 6px;
    padding: 1rem;
    max-height: 250px;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--pico-color);
}

.custom-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    margin-bottom: 12px;
    color: var(--pico-muted-color);
    padding: 6px 12px;
    background: var(--pico-card-background-color, rgba(255, 255, 255, 0.03));
    border-radius: 6px;
    border: 1px solid var(--pico-border-color);
}

.custom-breadcrumb a {
    color: var(--pico-color);
    text-decoration: none;
}

.custom-breadcrumb a:hover {
    text-decoration: underline;
}


/* Import Font Rasa từ Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Rasa:ital,wght@0,400;0,600;1,400;1,600&display=swap');

/* ==========================================
   1. ĐỊNH DẠNG BÀI THƠ (poem-table)
   ========================================== */
.poem-table {
    border-collapse: collapse;
    border: none !important;
    margin-top: 1rem;
    margin-bottom: 1rem;
    width: auto;
}

.poem-table td {
    padding: 3px 0 !important;
    border: none !important;
    line-height: 1.6;
    background-color:transparent !important;
}

/* Thụt lề responsive */
@media (max-width: 767px) {
    .poem-table { margin-left: 2.5rem !important; }
}
@media (min-width: 768px) and (max-width: 1023px) {
    .poem-table { margin-left: 6rem !important; }
}
@media (min-width: 1024px) {
    .poem-table { margin-left: 10rem !important; }
}

/* Ép tất cả các thẻ bên trong bảng mang class quote (phạt, vua, chung) đổi màu triệt để */
table.poem-table.quote-phat, table.poem-table.quote-phat * { color: var(--color-phat) !important; }
table.poem-table.quote-vua, table.poem-table.quote-vua *   { color: var(--color-vua) !important; }
table.poem-table.quote-chung, table.poem-table.quote-chung * { color: var(--color-chung) !important; }

/* Bàn, Khối văn bản và P có border-left */
blockquote.quote-phat, div.quote-phat {
    border-left: 4px solid var(--color-phat) !important;
    padding-left: 12px !important;
}
blockquote.quote-vua, div.quote-vua {
    border-left: 4px solid var(--color-vua) !important;
    padding-left: 12px !important;
}
blockquote.quote-chung, div.quote-chung {
    border-left: 4px solid var(--color-chung) !important;
    padding-left: 12px !important;
}

/* Bỏ border-left cho UL và OL */
ul.quote-phat, ol.quote-phat,
ul.quote-vua, ol.quote-vua,
ul.quote-chung, ol.quote-chung {
    border-left: none !important;
    padding-left: 20px !important;
}

/* ==========================================
   3. BADGE BO TRÒN (2 ĐẦU 1/2 HÌNH TRÒN)
   ========================================== */

.badge{text-indent: 0 !important;}
/* ==========================================
   PICO CSS TOOLTIP - KÉO MŨI TÊN LÒI RA KHỎI BONG BÓNG
   ========================================== */
[data-tooltip] {
    border-bottom: 1.5px dotted #5f55e8;
    color: #5f55e8;
    cursor: help;
    position: relative;
    display: inline;
    text-indent: 0 !important;
}

/* 1. Đẩy cả 2 về lề trái, xóa bỏ căn giữa mặc định */
[data-tooltip]:hover::before,
[data-tooltip]:hover::after {
    left: 0 !important;
    transform: none !important;
    text-indent: 0 !important;
}

/* 2. BONG BÓNG (::before): Nâng chiều cao lên một chút để chừa chỗ cho mũi tên bên dưới */
[data-tooltip]:hover::before {
    bottom: 100% !important;
    margin-bottom: 6px !important; /* Tạo khoảng trống 6px phía dưới cho mũi tên */
    white-space: normal !important;
    max-width: 260px !important;
    width: max-content !important;
    z-index: 9999 !important;
    text-indent: 0 !important;
}

/* 3. MŨI TÊN (::after): Đặt chèn ngay mép dưới bong bóng, thụt vào 12px */
[data-tooltip]:hover::after {
    bottom: 100% !important;
    margin-bottom: 0px !important; /* Đặt nằm sát chân bong bóng */
    margin-left: 12px !important;  /* Neo theo góc trái */
    text-indent: 0 !important;
    z-index: 10000 !important;     /* Đẩy z-index cao hơn bong bóng để không bị che */
}
/* ==========================================
   5. BLOCKQUOTE & CHỮ NGHIÊNG (FONT RASA)
   ========================================== */
blockquote {
    font-family: 'Rasa', serif !important;
    font-style: italic !important;
    font-size: 1.1rem;
    line-height: 1.6;
}

i, em {
    font-family: 'Rasa', serif;
    font-style: italic;
}

/* ==========================================
   1. TABS PICO (ĐÓNG KHUNG & HIỆN VIỀN RÕ RÀNG)
   ========================================== */
.htmb-tabs {
    display: flex;
    flex-direction: column;
    margin: 1.5rem 0;
}

.htmb-tabs input[type="radio"] {
    display: none;
}

.htmb-tab-header {
    display: flex;
    gap: 4px;
    margin-bottom: -1px;
    z-index: 2;
}

/* Nút Tab mặc định */
.htmb-tab-header label {
    padding: 8px 18px;
    margin: 0;
    cursor: pointer;
    border: 1px solid var(--pico-border-color, rgba(127, 127, 127, 0.3)) !important;
    border-bottom: none !important;
    border-radius: 6px 6px 0 0;
    font-weight: 500;
    color: var(--pico-color);
    opacity: 0.65;
    background: rgba(127, 127, 127, 0.08);
    transition: all 0.2s ease;
}

/* Tab được chọn: Ăn liền viền với khung dưới (Tự động nhận diện theo vị trí, không phụ thuộc tên ID) */
.htmb-tabs input[type="radio"]:nth-of-type(1):checked ~ .htmb-tab-header label:nth-child(1),
.htmb-tabs input[type="radio"]:nth-of-type(2):checked ~ .htmb-tab-header label:nth-child(2),
.htmb-tabs input[type="radio"]:nth-of-type(3):checked ~ .htmb-tab-header label:nth-child(3),
.htmb-tabs input[type="radio"]:nth-of-type(4):checked ~ .htmb-tab-header label:nth-child(4),
.htmb-tabs input[type="radio"]:nth-of-type(5):checked ~ .htmb-tab-header label:nth-child(5),
.htmb-tabs input[type="radio"]:nth-of-type(6):checked ~ .htmb-tab-header label:nth-child(6),
.htmb-tabs input[type="radio"]:nth-of-type(7):checked ~ .htmb-tab-header label:nth-child(7),
.htmb-tabs input[type="radio"]:nth-of-type(8):checked ~ .htmb-tab-header label:nth-child(8),
.htmb-tabs input[type="radio"]:nth-of-type(9):checked ~ .htmb-tab-header label:nth-child(9),
.htmb-tabs input[type="radio"]:nth-of-type(10):checked ~ .htmb-tab-header label:nth-child(10),
.htmb-tabs input[type="radio"]:nth-of-type(11):checked ~ .htmb-tab-header label:nth-child(11),
.htmb-tabs input[type="radio"]:nth-of-type(12):checked ~ .htmb-tab-header label:nth-child(12),
.htmb-tabs input[type="radio"]:nth-of-type(13):checked ~ .htmb-tab-header label:nth-child(13),
.htmb-tabs input[type="radio"]:nth-of-type(14):checked ~ .htmb-tab-header label:nth-child(14),
.htmb-tabs input[type="radio"]:nth-of-type(15):checked ~ .htmb-tab-header label:nth-child(15) {
    opacity: 1;
    background: var(--pico-card-background-color, var(--pico-background-color));
    color: var(--pico-color);
    border-color: var(--pico-border-color, rgba(127, 127, 127, 0.3)) !important;
    border-bottom: 1px solid var(--pico-card-background-color, var(--pico-background-color)) !important;
}

/* Khung bọc Nội dung Tab */
.htmb-tab-content {
    border: 1px solid var(--pico-border-color, rgba(127, 127, 127, 0.3)) !important;
    border-radius: 0 6px 6px 6px;
    padding: 16px;
    background: var(--pico-card-background-color, var(--pico-background-color));
    color: var(--pico-color);
    position: relative;
    z-index: 1;
}

.htmb-tab-content > div {
    display: none;
}

/* Hiển thị nội dung tương ứng theo vị trí */
.htmb-tabs input[type="radio"]:nth-of-type(1):checked ~ .htmb-tab-content > div:nth-child(1),
.htmb-tabs input[type="radio"]:nth-of-type(2):checked ~ .htmb-tab-content > div:nth-child(2),
.htmb-tabs input[type="radio"]:nth-of-type(3):checked ~ .htmb-tab-content > div:nth-child(3),
.htmb-tabs input[type="radio"]:nth-of-type(4):checked ~ .htmb-tab-content > div:nth-child(4),
.htmb-tabs input[type="radio"]:nth-of-type(5):checked ~ .htmb-tab-content > div:nth-child(5),
.htmb-tabs input[type="radio"]:nth-of-type(6):checked ~ .htmb-tab-content > div:nth-child(6),
.htmb-tabs input[type="radio"]:nth-of-type(7):checked ~ .htmb-tab-content > div:nth-child(7),
.htmb-tabs input[type="radio"]:nth-of-type(8):checked ~ .htmb-tab-content > div:nth-child(8),
.htmb-tabs input[type="radio"]:nth-of-type(9):checked ~ .htmb-tab-content > div:nth-child(9),
.htmb-tabs input[type="radio"]:nth-of-type(10):checked ~ .htmb-tab-content > div:nth-child(10),
.htmb-tabs input[type="radio"]:nth-of-type(11):checked ~ .htmb-tab-content > div:nth-child(11),
.htmb-tabs input[type="radio"]:nth-of-type(12):checked ~ .htmb-tab-content > div:nth-child(12),
.htmb-tabs input[type="radio"]:nth-of-type(13):checked ~ .htmb-tab-content > div:nth-child(13),
.htmb-tabs input[type="radio"]:nth-of-type(14):checked ~ .htmb-tab-content > div:nth-child(14),
.htmb-tabs input[type="radio"]:nth-of-type(15):checked ~ .htmb-tab-content > div:nth-child(15) {
    display: block;
}
/* ==========================================
   2. ACCORDION (ĐỒNG BỘ TIÊU ĐỀ & KHUNG NỀN)
   ========================================== */
/* ==========================================
   2. ACCORDION (BỎ OUTLINE/VIỀN MÀU PHÁT SÁNG KHỦNG KHI CLICK)
   ========================================== */
.htmb-accordion {
    border: 1px solid var(--pico-border-color, rgba(127, 127, 127, 0.3)) !important;
    border-radius: 6px;
    overflow: hidden;
    margin: 1.5rem 0;
    background: var(--pico-card-background-color, var(--pico-background-color));
}

.htmb-accordion details {
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    border-bottom: 1px solid var(--pico-border-color, rgba(127, 127, 127, 0.2)) !important;
}

.htmb-accordion details:last-child {
    border-bottom: none !important;
}

/* Tiêu đề Accordion */
.htmb-accordion summary {
    padding: 12px 16px !important;
    margin: 0 !important;
    font-weight: 600;
    color: var(--pico-color);
    background: rgba(127, 127, 127, 0.08) !important;
    cursor: pointer;
    transition: background 0.2s ease;
    
    /* XÓA VIỀN MÀU FOCUS KHI CLICK CHUỘT */
    outline: none !important;
    box-shadow: none !important;
}

.htmb-accordion summary:focus,
.htmb-accordion summary:focus-visible,
.htmb-accordion details[open] > summary:focus {
    outline: none !important;
    box-shadow: none !important;
}

.htmb-accordion summary:hover {
    background: rgba(127, 127, 127, 0.15) !important;
}

/* Nội dung bên trong mục Accordion */
.htmb-accordion details > p,
.htmb-accordion details > div {
    padding: 16px;
    margin: 0;
    color: var(--pico-color);
    background: var(--pico-card-background-color, var(--pico-background-color));
    border-top: 1px solid var(--pico-border-color, rgba(127, 127, 127, 0.2)) !important;
}

main p {
    text-indent: 4rem;
}