/*
 * Trang bộ sưu tập (/bo-suu-tap): bố cục và trạng thái cây mà Tailwind utility không biểu diễn gọn được.
 * Dùng cùng với search-tailwind.css (kết quả, bộ lọc, skeleton). Màu theo token trong common/theme.css.
 */

/* ===== Bố cục: cây ở trên, bộ lọc ở dưới (cột trái); kết quả chiếm cột phải ===== */
.collection-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

/* Container kết quả bị JS thay nội dung mỗi lần tìm; display:contents để aside/kết quả nằm thẳng trong lưới này,
   còn cây (ngoài container) giữ nguyên trạng thái mở/đóng giữa các lần tìm. */
.collection-layout > .search-page__main-container {
    display: contents;
}

/* Màn hình nhỏ: cây nằm trên cùng, thu gọn được */
#collection-tree-body.is-collapsed {
    display: none;
}

@media (min-width: 1024px) {
    .collection-layout {
        grid-template-columns: repeat(12, minmax(0, 1fr));
        /* Kết quả trải hai hàng: hàng 2 (bộ lọc) hấp thụ phần chiều cao dư, bộ lọc nằm sát cây */
        grid-template-rows: auto 1fr;
    }

    .collection-layout > .collection-tree {
        grid-column: 1 / span 3;
        grid-row: 1;
    }

    .collection-layout .main-container__search-filter {
        grid-column: 1 / span 3;
        grid-row: 2;
    }

    .collection-layout #search-page-result-block {
        grid-column: 4 / span 9;
        grid-row: 1 / span 2;
    }

    /* Cây luôn mở trên màn hình lớn */
    #collection-tree-body.is-collapsed {
        display: block;
    }
}

/* ===== Cây bộ sưu tập ===== */
.collection-tree__row {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 2rem;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    padding-right: 0.5rem;
    border-radius: 0.5rem;
    color: rgb(var(--n600-rgb));
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.collection-tree__row[data-level="0"] {
    font-size: 0.875rem;
    font-weight: 600;
}

.collection-tree__row:hover {
    background: rgb(var(--n50-rgb));
    color: rgb(var(--brand-red-rgb));
}

.collection-tree__row:focus-visible {
    box-shadow: 0 0 0 2px rgb(var(--brand-red-rgb) / 0.45);
}

/* Nút nằm trên đường tới nút đang chọn */
.collection-tree__row.is-path {
    color: rgb(var(--brand-red-rgb));
    font-weight: 600;
}

/* Nút đang chọn */
.collection-tree__row.is-selected {
    background: rgb(var(--brand-red-rgb));
    color: #fff;
    font-weight: 700;
}

.collection-tree__row.is-selected:hover {
    background: rgb(var(--brand-red-dark-rgb));
    color: #fff;
}

.collection-tree__toggle {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    padding: 0;
    border: 0;
    border-radius: 0.25rem;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.collection-tree__toggle--leaf {
    cursor: default;
}

.collection-tree__row[aria-expanded="true"] > .collection-tree__toggle svg {
    transform: rotate(90deg);
}

.collection-tree__link {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    color: inherit;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tên dài: cho xuống dòng thay vì cắt để đọc được hết trên cột hẹp */
.collection-tree__link {
    white-space: normal;
    line-height: 1.25;
}

.collection-tree__count {
    flex: none;
    padding: 0.0625rem 0.5rem;
    border-radius: 9999px;
    background: rgb(var(--n50-rgb));
    color: rgb(var(--n600-rgb));
    font-size: 0.6875rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.collection-tree__row.is-selected .collection-tree__count {
    background: rgb(255 255 255 / 0.22);
    color: #fff;
}

@media (prefers-reduced-motion: reduce) {
    .collection-tree__row {
        transition: none;
    }
}
