* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #ecddbb;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* BỎ height: 85vh + overflow:hidden để khỏi cắt nội dung */
.container {
    background: white;
    border-radius: 16px;
    padding: 40px;
    max-width: 1400px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    /* KHÔNG dùng overflow:hidden ở đây nữa */
    /* KHÔNG fix height cứng nữa để tránh bị cắt */
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
    font-size: 32px;
    flex-shrink: 0;
}

.auth-section {
    display: flex;
    gap: 12px;
    flex-direction: column;
    align-items: center;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    max-width: 400px;
    padding: 14px 18px;
    border: 2px solid #e1e4e8;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: #667eea;
}

button {
    padding: 14px 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Phần này chiếm hết chiều cao còn lại trong container nếu có */
.files-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* HEADER CỐ ĐỊNH TRÊN, KHÔNG SCROLL KHI CUỘN LIST */
.files-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 15px;
    flex-shrink: 0;
}

.files-header h2 {
    color: #333;
    font-size: 24px;
}

.header-info {
    display: flex;
    gap: 15px;
    align-items: center;
}

#usernameDisplay {
    color: #667eea;
    font-weight: 600;
    font-size: 14px;
}

.logout-btn {
    padding: 10px 20px;
    font-size: 14px;
    background: #dc3545;
}

.logout-btn:hover {
    box-shadow: 0 8px 20px rgba(220, 53, 69, 0.4);
}

/* CONTROLS CỐ ĐỊNH, KHÔNG SCROLL */
.controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e1e4e8;
    flex-shrink: 0;
    background: white;
}

.search-box {
    width: 100%;
}

.search-box input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e1e4e8;
    border-radius: 8px;
    font-size: 15px;
}

.search-box input:focus {
    outline: none;
    border-color: #667eea;
}

.control-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.sort-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.sort-buttons button {
    padding: 10px 16px;
    font-size: 14px;
    background: #f6f8fa;
    color: #333;
    border: 2px solid #e1e4e8;
    white-space: nowrap;
}

.sort-buttons button.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.sort-buttons button:hover {
    border-color: #667eea;
}

.reload-btn {
    background: #28a745 !important;
    color: white !important;
    border-color: #28a745 !important;
}

.reload-btn:hover {
    box-shadow: 0 8px 20px rgba(40, 167, 69, 0.4) !important;
}

.pagination-top {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-btn {
    padding: 10px 20px;
    font-size: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: 600;
    white-space: nowrap;
}

.page-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.page-btn:active:not(:disabled) {
    transform: translateY(0);
}

.page-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.5;
}

.page-info {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    padding: 8px 16px;
    background: #f6f8fa;
    border-radius: 8px;
    border: 2px solid #e1e4e8;
    white-space: nowrap;
}

/* ===== PHẦN QUAN TRỌNG NHẤT: CHỈ FILE LIST SCROLL ===== */

/* đặt max-height theo viewport để chắc chắn luôn có chiều cao để scroll */
#filesList {
    /* phần còn lại trong .files-section */
    flex: 1;
    min-height: 0;

    /* hạn chế chiều cao theo viewport để chắc chắn xuất hiện scrollbar */
    max-height: 60vh;

    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 10px;

    /* Debug: nếu muốn nhìn vùng scroll ở đâu thì bật border này
       border: 1px solid red;
    */
}

/* SCROLLBAR HIỆN RÕ */
#filesList::-webkit-scrollbar {
    width: 14px;
}

#filesList::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 7px;
    margin: 5px;
}

#filesList::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 7px;
    border: 3px solid #f1f1f1;
}

#filesList::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* Firefox */
#filesList {
    scrollbar-width: auto;
    scrollbar-color: #667eea #f1f1f1;
}

.file-item {
    padding: 16px;
    border: 2px solid #e1e4e8;
    border-radius: 8px;
    margin-bottom: 12px;
    transition: all 0.3s;
    background: white;
}

.file-item:hover {
    border-color: #667eea;
    background: #f6f8fa;
    transform: translateX(4px);
}

.file-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.file-name {
    font-weight: 600;
    color: #333;
    word-break: break-word;
    flex: 1;
    min-width: 300px;
}

.file-meta {
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 13px;
    color: #666;
    flex-shrink: 0;
}

.file-size {
    background: #e1e4e8;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
}

.file-date {
    color: #666;
    font-size: 12px;
    white-space: nowrap;
}

.file-link {
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: transform 0.2s;
    display: inline-block;
    white-space: nowrap;
}

.file-link:hover {
    transform: translateY(-2px);
}

.loading {
    text-align: center;
    padding: 40px;
    color: #666;
    font-size: 16px;
}

.error-message {
    background: #fee;
    color: #c33;
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 15px;
    text-align: center;
    width: 100%;
    max-width: 400px;
}

.no-files {
    text-align: center;
    padding: 40px;
    color: #999;
    font-size: 16px;
}

@media (max-width: 1024px) {
    .control-buttons {
        flex-direction: column;
        align-items: stretch;
    }
    
    .sort-buttons,
    .pagination-top {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .container {
        max-width: 100%;
        padding: 20px;
    }
    
    h1 {
        font-size: 24px;
        margin-bottom: 15px;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .sort-buttons {
        justify-content: center;
    }
    
    .pagination-top {
        justify-content: center;
    }
    
    .file-info {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .file-meta {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }
    
    .file-name {
        min-width: auto;
    }
    
    #filesList::-webkit-scrollbar {
        width: 10px;
    }
}
