@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600&display=swap');

/* =========================================
   1. Layout หลัก & Sticky Footer
   ========================================= */
body {
    font-family: 'Kanit', sans-serif;
    background-color: #fcfcfc;
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* ดัน Footer ลงล่างสุด */
}

.page-wrapper {
    flex: 1; /* ขยายพื้นที่เนื้อหา */
    padding: 30px 20px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.layout-container {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

/* =========================================
   2. ส่วนรายการไฟล์ (ซ้าย)
   ========================================= */
.file-list-section {
    flex: 1;
    background: #fff;
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.05);
}

.file-list-section.full-width-list {
    width: 100%;
}

.file-list-section h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.4rem;
    color: #444;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 15px;
}

.file-list-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

/* --- การ์ดไฟล์ --- */
.file-card-wrapper {
    position: relative; /* สำคัญ! ใช้สำหรับอ้างอิงตำแหน่งปุ่มลบ */
    height: 100%;
}

.file-card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 15px;
    text-decoration: none;
    color: #333;
    transition: all 0.3s;
    height: 100%;
    box-sizing: border-box;
}

.file-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.08);
    border-color: #ff8c61;
}

/* ไอคอนและรูปภาพ */
.file-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 10px;
}

.file-icon.pdf { background-color: #ffebee; color: #d32f2f; }
.file-icon.img { background-color: #e3f2fd; color: #1976d2; }

.file-thumb-img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 10px;
}

.file-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.file-name {
    font-weight: 500;
    font-size: 0.95rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.file-date {
    font-size: 0.8rem;
    color: #888;
}

.action-icon {
    position: absolute;
    top: 15px;
    right: 15px;
    color: #ccc;
    font-size: 14px;
}

/* --- ปุ่มลบ (ถังขยะ) --- */
.btn-delete-file {
    position: absolute;
    top: -10px;
    right: -10px;
    background-color: #ff4d4d;
    color: white;
    border: 2px solid #fff;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
    z-index: 50;
    transition: all 0.2s;
    opacity: 0;
    transform: scale(0.8);
}

.file-card-wrapper:hover .btn-delete-file {
    opacity: 1;
    transform: scale(1);
    top: 10px;
    right: 10px;
}

.btn-delete-file:hover {
    background-color: #d63030;
    transform: scale(1.1) !important;
}

/* =========================================
   3. ส่วนอัปโหลด (ขวา)
   ========================================= */
.upload-wrapper {
    flex: 0 0 320px;
    position: sticky;
    top: 20px;
}

.upload-card {
    background: #fff;
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.05);
    text-align: center;
    border-top: 5px solid #ff8c61;
}

.upload-card h2 {
    margin: 0 0 10px 0;
    font-size: 1.3rem;
    color: #333;
}

.custom-file {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 2px dashed #ddd;
    border-radius: 12px;
    padding: 30px 20px;
    cursor: pointer;
    background: #fafafa;
    transition: all 0.3s;
    margin: 20px 0;
    min-height: 150px;
}

.custom-file:hover {
    border-color: #ff8c61;
    background: #fffdfa;
}

.upload-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #ff8c61, #ff6b6b);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-family: 'Sarabun', sans-serif;
    box-shadow: 0 4px 10px rgba(255, 107, 107, 0.3);
    transition: 0.3s;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(255, 107, 107, 0.4);
}

/* =========================================
   4. Lightbox (แก้ Z-Index ทับ Header)
   ========================================= */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000; /* ค่าสูงเพื่อให้ลอยทับ Header */
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
}

.lightbox.active {
    opacity: 1;
    visibility: visible;
}

.lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 4px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 30px;
    color: #fff;
    cursor: pointer;
}

/* =========================================
   5. Responsive
   ========================================= */
@media (max-width: 900px) {
    .layout-container {
        flex-direction: column;
    }
    .upload-wrapper {
        width: 100%;
        position: static;
        order: -1;
        margin-bottom: 20px;
    }
    .file-list-container {
        grid-template-columns: repeat(auto-fill, minmax(100%, 1fr));
    }
    /* มือถือให้ปุ่มลบโชว์ตลอด ไม่ต้อง hover */
    .btn-delete-file {
        opacity: 1;
        transform: scale(1);
        top: 10px;
        right: 10px;
    }
}