.folder-item .card, .pdf-item .card {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
    border-radius: 0.375rem;
}
.folder-item .card:hover, .pdf-item .card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}
.navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    border-bottom: 1px solid #dee2e6;
}
.breadcrumb {
    background-color: #f8f9fa;
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
}
.file-icon {
    width: 24px;
    height: 24px;
    margin-right: 8px;
}
.pdf-viewer {
    width: 100%;
    height: 80vh;
    border: none;
}
.loading {
    text-align: center;
    padding: 2rem;
}
.spinner-custom {
    color: #F17332 !important;
}
.btn-outline-success, .btn-outline-primary, .btn-outline-secondary {
    color: black !important;
    border-color: black !important;
}
.btn-outline-success:hover, .btn-outline-primary:hover, .btn-outline-secondary:hover {
    background-color: #FFBF46 !important;
    border-color: black !important;
    color: black !important;
}
.btn-secondary {
    background-color: black !important;
    border-color: black !important;
    color: white !important;
}
.btn-secondary:hover {
    background-color: #FFBF46 !important;
    border-color: black !important;
    color: black !important;
}
.btn:focus, .btn:active, .btn:focus-visible {
    transform: none !important;
    box-shadow: none !important;
}
.btn:active {
    transform: none !important;
}
.badge.bg-primary {
    background-color: #FFBF46 !important;
    color: black !important;
}
#logoutBtn {
    background-color: black !important;
    color: white !important;
    border: 1px solid black !important;
}
#logoutBtn:hover {
    background-color: black !important;
    color: white !important;
    border: 1px solid black !important;
}
#searchInput:focus {
    outline: none !important;
    box-shadow: none !important;
    border-color: #ced4da !important;
}
#passwordInput:focus {
    outline: none !important;
    box-shadow: none !important;
    border-color: #ced4da !important;
}
#clearSearchBtn {
    border-color: #ced4da !important;
}
#clearSearchBtn:hover {
    border-color: #ced4da !important;
}

/* Sidebar Styles */
.sidebar {
    background-color: #f8f9fa;
    border-right: 1px solid #dee2e6;
    min-height: calc(100vh - 120px);
    padding: 0;
    position: fixed;
    top: 80px;
    left: 0;
    width: 300px; /* Fixed width to ensure text visibility */
    height: calc(100vh - 80px);
    overflow-y: auto;
    z-index: 1000;
    transition: transform 0.3s ease-in-out;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    background-color: white;
}

.sidebar-content {
    padding: 1rem;
    height: calc(100vh - 200px);
    overflow-y: auto;
}

/* This rule is now defined above with additional overflow controls */

.content-header {
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 1rem;
}

/* Folder Tree Styles */
.folder-tree {
    font-size: 0.9rem;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.folder-item {
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    border-radius: 0.25rem;
    margin-bottom: 0.125rem;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.folder-item:hover {
    background-color: #e9ecef;
    transform: translateX(2px);
}

.folder-item.active {
    background-color: #FFBF46;
    color: black;
    font-weight: 500;
    transform: translateX(2px);
}

.folder-item .folder-icon {
    margin-right: 0.5rem;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.folder-item .folder-name {
    flex: 1;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.3;
}

.folder-item .folder-toggle {
    font-size: 0.8rem;
    flex-shrink: 0;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.folder-item .folder-toggle:hover {
    background-color: rgba(0,0,0,0.1);
}

.folder-children {
    margin-left: 0.5rem;
    border-left: 1px solid #dee2e6;
    padding-left: 0.5rem;
    transition: all 0.3s ease;
}

.folder-children.collapsed {
    display: none;
}

.folder-item.has-children {
    position: relative;
}

.folder-item.has-children .folder-name {
    cursor: pointer;
}

.folder-item.has-children .folder-toggle {
    color: #6c757d;
}

.folder-item.has-children .folder-toggle.expanded {
    color: #495057;
}

.folder-item.has-children .folder-toggle i {
    transition: transform 0.2s ease;
}

.folder-item.has-children .folder-toggle.collapsed i {
    transform: rotate(0deg);
}

.folder-item.has-children .folder-toggle.expanded i {
    transform: rotate(90deg);
}

/* Enhanced hierarchical styles */
.folder-item[style*="margin-left: 0rem"] {
    font-weight: 600;
    border-left: 3px solid #FFBF46;
    padding-left: 0.75rem;
}

.folder-item[style*="margin-left: 0.75rem"] {
    border-left: 2px solid #dee2e6;
    padding-left: 0.5rem;
}

.folder-item[style*="margin-left: 1.5rem"] {
    border-left: 1px solid #e9ecef;
    padding-left: 0.5rem;
    font-size: 0.85rem;
}

.folder-item[style*="margin-left: 2.25rem"] {
    border-left: 1px solid #f8f9fa;
    padding-left: 0.5rem;
    font-size: 0.8rem;
}

/* Visual hierarchy indicators */
.folder-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, transparent, #FFBF46, transparent);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.folder-item:hover::before,
.folder-item.active::before {
    opacity: 1;
}

/* Indentation lines for better visual hierarchy */
.folder-tree {
    position: relative;
}

.folder-tree::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 1px;
    background: linear-gradient(to bottom, transparent, #dee2e6, transparent);
    opacity: 0.3;
}

/* File Grid Styles */
.file-item {
    margin-bottom: 1rem;
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0; /* Allow flex items to shrink below their content size */
}

.file-item .card {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
    border-radius: 0.375rem;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    width: 100%;
    max-width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.file-item .card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

/* Ensure consistent card title height with exactly 3 lines */
.file-item .card-title {
    font-size: 0.9rem;
    line-height: 1.2;
    margin-bottom: 8px;
    height: 3.6rem; /* 3 lines * 1.2 line-height = 3.6rem */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Ensure the files container doesn't overflow horizontally */
#filesContainer,
.files-grid-container {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    gap: 1rem;
    box-sizing: border-box;
}

/* Search results container should also not overflow */
#searchResultsContainer {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    gap: 1rem;
    box-sizing: border-box;
}

/* Ensure main content area doesn't cause overflow */
.main-content {
    padding: 1rem;
    margin-left: 300px; /* Match sidebar width */
    width: calc(100% - 300px);
    max-width: calc(100% - 300px);
    overflow-x: hidden;
    box-sizing: border-box;
    margin-top: 0; /* Remove any top margin since navbar is fixed */
}

/* Prevent horizontal overflow on the entire page */
body, html {
    overflow-x: hidden;
    max-width: 100%;
    position: relative;
}

/* Ensure the main container doesn't interfere with navbar sticky positioning */
body > .container-fluid {
    position: relative;
    overflow-x: hidden;
    padding-top: 80px; /* Adequate padding to account for fixed navbar */
}

/* Ensure navbar stays fixed at top */
.navbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1030 !important;
    width: 100% !important;
    margin: 0 !important;
}

/* Ensure navbar container doesn't interfere with fixed positioning */
.navbar .container-fluid {
    overflow: visible;
    position: relative;
}

/* Override Bootstrap navbar classes */
.navbar.navbar-expand-lg {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1030 !important;
    width: 100% !important;
}

/* Ensure container-fluid doesn't cause overflow */
.container-fluid {
    max-width: 100%;
    overflow-x: hidden;
}

.thumbnail-container {
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
}

.pdf-thumbnail, .document-thumbnail {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    width: auto;
    height: auto;
}

.fallback-icon {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

/* Responsive PDF grid adjustments - only resize when necessary */
@media (min-width: 1400px) {
    .file-item {
        flex: 0 0 calc(20% - 0.8rem); /* 5 columns on extra large screens */
        width: calc(20% - 0.8rem);
        max-width: 300px; /* Prevent excessive width on very large screens */
    }
}

@media (min-width: 1200px) and (max-width: 1399px) {
    .file-item {
        flex: 0 0 calc(25% - 0.75rem); /* 4 columns on large screens */
        width: calc(25% - 0.75rem);
        max-width: 300px; /* Prevent excessive width */
    }
}

@media (min-width: 992px) and (max-width: 1199px) {
    .file-item {
        flex: 0 0 calc(33.333333% - 0.75rem); /* 3 columns on large screens */
        width: calc(33.333333% - 0.75rem);
        max-width: 300px; /* Prevent excessive width */
    }
}

@media (min-width: 768px) and (max-width: 991px) {
    .file-item {
        flex: 0 0 calc(50% - 0.5rem); /* 2 columns on medium screens */
        width: calc(50% - 0.5rem);
        max-width: 300px; /* Prevent excessive width */
    }
}

@media (max-width: 768px) {
    /* Hide search on mobile */
    .input-group {
        display: none !important;
    }
    
    /* Add vertical spacing between mobile buttons */
    .navbar-nav .me-2 {
        margin-right: 0.5rem !important;
        margin-bottom: 0.25rem !important;
    }
    
    /* Make buttons icon-only and double width on mobile */
    #mobileMenuToggle, #logoutBtn {
        padding: 0.375rem !important;
        width: 5rem !important;
        height: 2.5rem !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Hide text in logout button on mobile - target the text node */
    #logoutBtn {
        font-size: 0 !important;
    }
    
    #logoutBtn i {
        font-size: 1rem !important;
    }
    
    .sidebar {
        position: fixed;
        top: 80px;
        left: 0;
        width: 300px;
        height: calc(100vh - 80px);
        border-right: 1px solid #dee2e6;
        transform: translateX(-100%);
        z-index: 1050;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        margin-top: 0;
        padding-top: 20px; /* Add spacing from fixed navbar on mobile */
    }
    
    /* Additional spacing for content header on mobile */
    .content-header {
        padding-top: 10px;
    }
    
    .sidebar-content {
        height: calc(100vh - 200px);
    }
    
    .file-item {
        flex: 0 0 calc(50% - 0.5rem); /* 2 columns on small screens */
        width: calc(50% - 0.5rem);
        min-width: 200px; /* Prevent excessive squashing */
        max-width: 300px; /* Prevent excessive width */
    }
    
    /* Mobile overlay */
    .mobile-overlay {
        position: fixed;
        top: 80px;
        left: 0;
        width: 100%;
        height: calc(100vh - 80px);
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        display: none;
    }
    
    .mobile-overlay.show {
        display: block;
    }
}

@media (max-width: 640px) {
    .file-item {
        flex: 0 0 calc(50% - 0.5rem); /* Keep 2 columns on small tablets */
        width: calc(50% - 0.5rem);
        min-width: 180px; /* Slightly smaller minimum width */
        max-width: 300px; /* Prevent excessive width */
    }
}

@media (max-width: 480px) {
    .file-item {
        flex: 0 0 100%; /* 1 column only on very small screens */
        width: 100%;
        min-width: 0; /* Allow full width on very small screens */
        max-width: 100%; /* Allow full width on very small screens */
    }
}
