/* File: assets/css/lelib-sidebar.css */

/* Sidebar Container */
.tv-sidebar {
    position: relative; background: #ffffff; border-radius: 16px;
    padding: 20px; 
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.08); 
    border: 1px solid rgba(0, 0, 0, 0.04);
    min-width: 280px; overflow: hidden; 
    opacity: 1; transform: translateX(0); visibility: visible;
    transition: opacity 0.3s ease, transform 0.5s cubic-bezier(0.4, 0, 0.2, 1), padding 0.5s ease, visibility 0.5s step-end;
}
.tv-layout.is-collapsed .tv-sidebar {
    opacity: 0; transform: translateX(-30px); padding: 0; border: none; margin: 0; visibility: hidden;
}
@media (max-width: 768px) {
    .tv-sidebar { width: 100%; order: -1; margin-bottom: 20px; min-width: 0; }
}

/* Header */
.tv-sidebar-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; min-height: 36px; padding-bottom: 10px;
    border-bottom: 1px solid #f3f4f6; white-space: nowrap; 
}

/* Reset Btn */
.tv-btn-reset {
    font-size: 0.75rem; font-weight: 700; 
    color: #fff; background: var(--tv-count-fg);
    border: 1px solid var(--tv-count-fg); 
    border-radius: 20px; padding: 4px 10px;
    cursor: pointer; display: none; align-items: center; gap: 6px; transition: all 0.2s;
}
.tv-btn-reset:hover { opacity: 0.9; transform: translateY(-1px); }

/* Toggle Btn */
.tv-toggle-close {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 0; 
    border-radius: 50%; background: #f3f4f6; color: #6b7280;
    cursor: pointer; border: 1px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: auto; box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.tv-toggle-close svg { width: 20px; height: 20px; stroke-width: 2.5; transition: transform 0.3s ease; }
.tv-toggle-close:hover {
    background: var(--tv-accent-bg); color: var(--tv-accent-hover);
    border-color: #d1d5db; transform: scale(1.05);
}
.tv-toggle-close:hover svg { transform: translateX(-2px); }

/* Toolbar */
.tv-side-toolbar { margin-bottom: 20px; }
.tv-side-toolbar label {
    font-size: 0.7rem; font-weight: 800; text-transform: uppercase;
    color: #9ca3af; letter-spacing: 0.05em; display: block; margin-bottom: 6px;
}

/* Lists */
.tv-side-block { margin-bottom: 28px; }
.tv-side-block:last-child { margin-bottom: 0; }
.tv-side-title {
    font-size: 0.8rem; font-weight: 800; text-transform: uppercase;
    color: #111827; margin-bottom: 10px; letter-spacing: 0.025em; white-space: nowrap;
}
.tv-side-list {
    list-style: none; margin: 0; display: flex; flex-direction: column;
    padding: 0 !important; gap: 1px; 
}
#tv-facet-authors ul {
    max-height: 350px; overflow-y: auto; overflow-x: hidden;
    padding-right: 2px; scrollbar-width: thin; scrollbar-color: #d1d5db transparent;
}
#tv-facet-authors ul::-webkit-scrollbar { width: 4px; }
#tv-facet-authors ul::-webkit-scrollbar-track { background: transparent; }
#tv-facet-authors ul::-webkit-scrollbar-thumb { background-color: #d1d5db; border-radius: 4px; }

/* --- ITEM LAYOUT --- */
.tv-side-list label.tv-facet-label {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%;
    
    /* [CẬP NHẬT] Padding thoáng hơn một chút */
    padding: 4px 5px; 
    
    border-radius: 6px; cursor: pointer; transition: all 0.15s ease;
    color: #4b5563; font-size: 0.9rem; font-weight: 500;
    border: 1px solid transparent; 
}
.tv-side-list label.tv-facet-label:hover { 
    background-color: #f9fafb; color: var(--tv-accent-hover); 
}

/* Facet Left: Checkbox + Tên */
.tv-facet-left {
    display: flex; align-items: center; flex: 1; min-width: 0; 
    padding-right: 8px; gap: 8px; 
}

/* Name */
.tv-side-name { 
    flex: 1; 
    line-height: 1.4; 
    padding-top: 1px; 
    white-space: normal !important; /* Cho phép xuống dòng */
    overflow: visible !important;
    text-overflow: clip !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.tv-facet-input {
    appearance: none; -webkit-appearance: none;
    background-color: #fff; width: 16px; height: 16px;
    border: 2px solid #d1d5db; border-radius: 4px;
    display: grid; place-content: center;
    transition: all 0.2s; cursor: pointer; flex-shrink: 0; margin: 0;
    align-self: flex-start; margin-top: 2px; 
}
.tv-facet-input::before {
    content: ""; width: 8px; height: 8px;
    transform: scale(0); transition: 0.2s transform ease-in-out;
    box-shadow: inset 1em 1em white; transform-origin: center;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.tv-facet-input:checked {
    background-color: var(--tv-accent); border-color: var(--tv-accent);
}
.tv-facet-input:checked::before { transform: scale(1); }

/* Facet Right: Count + Info */
.tv-facet-right {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 6px; flex-shrink: 0; position: relative; min-width: 30px;
    align-self: flex-start; 
}

/* Count Badge */
.tv-count--menu {
    font-size: 0.7rem; background: var(--tv-count-bg); color: var(--tv-count-fg);      
    padding: 1px 6px; border-radius: 10px; font-weight: 700;
    transition: all 0.2s; border: none; white-space: nowrap;
    opacity: 1; visibility: visible; display: inline-block;
}

/* Active Row State */
.tv-facet-item:has(.tv-facet-input:checked) label.tv-facet-label {
    background-color: var(--tv-accent-bg); color: var(--tv-accent-hover); font-weight: 600;
}
.tv-facet-item:has(.tv-facet-input:checked) .tv-count--menu {
    background: var(--tv-count-fg); color: #ffffff; 
}

/* Info Button */
.tv-facet-info {
    display: inline-flex; align-items: center; justify-content: center;
    color: #9ca3af; cursor: pointer; transition: all 0.2s;
    padding: 2px;
    opacity: 0; visibility: hidden; position: absolute; right: 0; transform: translateX(-5px);
}
.tv-facet-info:hover {
    color: var(--tv-accent, #2563eb); transform: scale(1.1);
}

/* --- LOGIC HIỂN THỊ THÔNG MINH --- */

@media (hover: hover) {
    /* 1. Với dòng Tác Giả (có class .tv-has-info): Ẩn số, Hiện nút i */
    .tv-facet-item.tv-has-info:hover .tv-count { 
        display: none !important; 
    }
    .tv-facet-item.tv-has-info:hover .tv-facet-info {
        opacity: 1; visibility: visible; 
        transform: translateX(0); position: static; 
    }
    .tv-facet-item.tv-has-info:hover .tv-facet-right { 
        justify-content: flex-end; 
    }

    /* 2. Với dòng KHÔNG PHẢI Tác Giả: Counter luôn hiện */
    .tv-facet-item:not(.tv-has-info):hover .tv-count {
        display: inline-block !important;
        opacity: 1 !important; 
        visibility: visible !important;
    }
}

@media (hover: none) {
    .tv-facet-right { gap: 8px; }
    
    .tv-facet-info {
        position: static; opacity: 1 !important; visibility: visible !important;
        transform: none !important; padding: 6px; margin: -6px;
    }
    
    .tv-count { opacity: 1 !important; visibility: visible !important; display: inline-block !important; }
}

/* Visual Feedback during AJAX (Updating) */
.tv-sidebar.is-updating .tv-side-list {
    opacity: 0.5;
    transition: opacity 0.2s ease;
    pointer-events: auto;
}