/* ========== 1. ตั้งค่าพื้นฐาน (Reset & Fonts) ========== */
@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #f7f9fc;
    font-family: "Kanit", sans-serif;
    color: #4a4a4a;
    line-height: 1.6;
}

/* ========== 2. Layout ========== */
.page-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

/* ========== 3. Section Header ========== */
.section-header {
    text-align: center;
    margin-bottom: 25px;
}

.section-header h2 {
    font-size: 24px;
    color: #333;
    margin-bottom: 10px;
}

.title-line {
    width: 60px;
    height: 4px;
    background: linear-gradient(to right, #ffaf7b, #ff8c61);
    margin: 0 auto;
    border-radius: 2px;
}

/* ========== 4. ส่วนตารางรายการ (Table Section) ========== */
.gallery-container {
    width: 100%;
    max-height: 550px; 
    overflow-y: auto;
    background: #fff;
    border-radius: 15px; /* ลดลงมาหน่อยให้ดูทันสมัย */
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    display: block; /* เปลี่ยนจาก grid เป็น block เพื่อรองรับ table */
}

/* แต่ง Scrollbar */
.gallery-container::-webkit-scrollbar { width: 6px; }
.gallery-container::-webkit-scrollbar-track { background: #f0f0f0; border-radius: 4px; }
.gallery-container::-webkit-scrollbar-thumb { background: #ff9f6f; border-radius: 4px; }

.activity-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.activity-table thead th {
    position: sticky;
    top: 0;
    background: #fdfdfd;
    padding: 15px;
    text-align: left;
    color: #666;
    border-bottom: 2px solid #f0f0f0;
    z-index: 10;
}

.activity-table tbody td {
    padding: 12px 15px;
    border-bottom: 1px solid #f9f9f9;
    vertical-align: middle;
}

/* Thumbnail */
.mini-thumb {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s;
    background: #eee;
}

.mini-thumb:hover {
    transform: scale(1.1);
}

.activity-name {
    max-width: 400px; 
    white-space: normal;
    word-wrap: break-word;
    line-height: 1.4;
}

.activity-actions {
    display: flex;
    gap: 8px;
}

/* ========== 5. Upload Box ========== */
.upload-wrapper {
    width: 100%;
    max-width: 500px;
    margin: 40px auto 0; /* จัดกลางหน้า */
}

.upload-box {
    background: white;
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.08);
    text-align: center;
    border-top: 6px solid #ff8c61;
}

.custom-file {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 15px;
    border: 2px dashed #ddd;
    border-radius: 16px;
    background: #fafafa;
    cursor: pointer;
    transition: all 0.3s;
}

.custom-file:hover {
    border-color: #ff9f6f;
    background: #fffaf7;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* เพิ่มเป็น 4 จะได้ไม่ยาวเกิน */
    gap: 8px;
    margin-top: 15px;
}

.preview-item {
    position: relative;
    aspect-ratio: 1/1;
    border-radius: 8px;
    overflow: hidden;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ========== 6. Buttons ========== */
.upload-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, #ffaf7b 0%, #ff8c61 100%);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 20px;
    box-shadow: 0 5px 15px rgba(255, 140, 97, 0.4);
}

.btn-view, .btn-delete-small {
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: 0.2s;
}

.btn-view { background: #e3f2fd; color: #1976d2; }
.btn-delete-small { background: #ffebee; color: #c62828; }

.btn-view:hover { background: #1976d2; color: white; }
.btn-delete-small:hover { background: #c62828; color: white; }

/* ========== 7. Lightbox ========== */
.lightbox {
    position: fixed; 
    top: 0; left: 0; 
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.9); 
    z-index: 10000;
    display: none; 
    justify-content: center; 
    align-items: center;
}

.lightbox.active { display: flex !important; }

.lightbox img { 
    max-width: 90%; 
    max-height: 85vh; 
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 45px;
    height: 45px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.3s;
}

.lightbox-close:hover {
    background: rgba(255,255,255,0.3);
    transform: rotate(90deg);
}

/* ========== 8. Mobile Responsive ========== */
@media (max-width: 768px) {
    .activity-actions {
        flex-direction: column; /* มือถือให้ปุ่มเรียงแนวตั้งจะได้ไม่เบียด */
    }
    .upload-wrapper {
        padding: 0 10px;
    }
    .preview-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
@media (max-width: 600px) {
    .gallery-container {
        overflow-x: auto; /* ยอมให้ตารางเลื่อนแนวนอนได้บนมือถือจอแคบ */
    }
    .btn-view, .btn-delete-small {
        padding: 8px; /* ลดขนาดปุ่มลงเล็กน้อย */
        font-size: 12px;
    }
}