/* ============================== */
/* การตั้งค่าพื้นฐาน        */
/* ============================== */

body {
    font-family: sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #333366;
    color: #f0f0f0;
}

h1 {
    text-align: center;
    color: #F0B5B5;
    margin-bottom: 30px;
}

/* ============================== */
/* ส่วนประกอบต่างๆ         */
/* ============================== */

/* --- ช่องค้นหา --- */
.search-container {
    text-align: center;
    margin-bottom: 25px;
}

#searchInput {
    padding: 10px 15px;
    width: 80%;
    max-width: 400px;
    border: 1px solid #ccc;
    border-radius: 20px;
    font-size: 1em;
    box-sizing: border-box;
    background-color: #fff;
    color: #333;
}

#searchInput:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 8px rgba(0, 123, 255, 0.6);
}

/* --- แถบนำทางกลุ่มวิดีโอ (Navbar) --- */
.group-navbar {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #555;
    white-space: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.group-navbar .nav-item {
    display: inline-block;
    padding: 8px 15px;
    margin: 0 5px 5px 5px;
    border: 1px solid #aaa;
    background-color: #eee;
    color: #333;
    cursor: pointer;
    border-radius: 20px;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    font-size: 0.9em;
}

.group-navbar .nav-item:hover:not(.active) {
    background-color: #ddd;
    border-color: #999;
}

.group-navbar .nav-item.active {
    background-color: #007bff;
    color: #fff;
    border-color: #007bff;
    cursor: default;
}

/* --- Grid แสดงวิดีโอ --- */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

/* --- รายการวิดีโอแต่ละอัน --- */
.video-item {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.video-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

/* ลิงก์หลัก (รูปภาพและชื่อ) */
.video-item a:not(.fallback-link) {
    text-decoration: none;
    color: inherit;
    display: block;
    flex-grow: 1;
}

/* ลิงก์สำรอง */
.fallback-link {
    display: block;
    padding: 10px;
    background-color: #4a4a7d;
    color: #f0f0f0;
    text-align: center;
    text-decoration: none;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.fallback-link:hover {
    background-color: #61619c;
    color: #fff;
}

/* --- Container รูป Thumbnail (รักษาอัตราส่วน 16:9) --- */
.thumbnail-container {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    background-color: #555;
    overflow: hidden;
}

.thumbnail-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-bottom: 1px solid #ddd;
}

/* --- ชื่อวิดีโอ --- */
.video-item p {
    margin: 0;
    padding: 12px 15px;
    text-align: center;
    font-size: 1.1em;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 2.4em;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- ส่วน Pagination --- */
.pagination {
    text-align: center;
    margin-top: 30px;
    margin-bottom: 20px;
    padding: 10px 0;
}

.pagination button,
.pagination .page-number-btn {
    padding: 8px 16px;
    margin: 0 4px;
    border: 1px solid #aaa;
    background-color: #eee;
    color: #333;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    vertical-align: middle;
    font-size: 0.95em;
}

.pagination button:hover:not(:disabled),
.pagination .page-number-btn:hover:not(.active) {
    background-color: #ddd;
    border-color: #999;
}

.pagination button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
    background-color: #f5f5f5;
}

.pagination .page-number-btn.active {
    background-color: #007bff;
    color: #fff;
    border-color: #007bff;
    cursor: default;
}

.pagination span#pageNumbers {
    margin: 0 5px;
    vertical-align: middle;
}

/* ============================== */
/* การแสดงผลบนจอขนาดเล็ก      */
/* ============================== */

@media (max-width: 768px) {
    .video-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 15px;
    }

    h1 {
        font-size: 1.8em;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 1.5em;
        margin-bottom: 20px;
    }

    #searchInput {
        width: 95%;
        font-size: 0.9em;
    }

    .group-navbar {
        margin-bottom: 20px;
        padding-bottom: 10px;
    }

    .group-navbar .nav-item {
        padding: 6px 12px;
        font-size: 0.85em;
        margin: 0 3px 5px 3px;
    }

    .video-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 25px;
    }

    .video-item p {
        font-size: 1em;
        padding: 8px 10px;
        min-height: 2.2em;
    }

    .pagination {
        margin-top: 20px;
    }

    .pagination button,
    .pagination .page-number-btn {
        padding: 6px 10px;
        margin: 0 2px;
        font-size: 0.9em;
    }
}
