/* =========================================
   1. General Setup & Variables
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;700&display=swap');

:root {
    --primary-blue: #1a3a5a;
    --hover-bg: #f8f9fa;
    --border-color: #e0e0e0;
    --text-color: #333;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Sarabun', sans-serif;
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden; /* Prevent horizontal scroll */
    
    /* *** Sticky Footer Setup *** */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* =========================================
   2. Header & Navbar Structure
   ========================================= */
header {
    background: #fff;
    border-bottom: 2px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar {
    max-width: 1527px;
    margin: 0 auto;
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    position: relative; 
}

/* Logo */
.logo img {
    height: 60px;
    display: block;
    object-fit: contain;
}

/* Hamburger (Hidden on PC) */
.hamburger {
    display: none;
}

/* =========================================
   3. PC Menu Styles (Default)
   ========================================= */
.menu {
    display: block;
}

.main-menu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 0;
}

/* --- Parent Menu --- */
.main-menu > li {
    position: relative;
}

.main-menu > li > a {
    text-decoration: none;
    color: var(--primary-blue);
    padding: 28px 20px;
    display: block;
    font-weight: 700;
    font-size: 1.1rem;
    transition: color 0.3s;
}

.main-menu > li > a:hover {
    color: #0056b3;
}

/* --- Standard Sub-menu (Dropdown) --- */
.sub-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: #fff;
    min-width: 280px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    border-top: 3px solid var(--primary-blue);
    padding: 10px 0;
    list-style: none;
    z-index: 9999;
}

.sub-menu li {
    display: block;
    width: 100%;
}

.sub-menu li a {
    text-decoration: none;
    color: var(--text-color);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    font-size: 1rem;
    font-weight: 500;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.2s;
}

.sub-menu li a::before {
    content: '❯';
    font-size: 0.8rem;
    margin-right: 10px;
    color: var(--primary-blue);
}

.sub-menu li a:hover {
    background-color: var(--hover-bg);
    color: var(--primary-blue);
}

/* =========================================
   4. Mega Menu Styles (PC)
   ========================================= */

/* Parent Wrapper */
.mega-dropdown {
    position: static !important; /* Static to allow full width relative to Navbar */
}

/* Content Container */
.mega-menu-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: #fff;
    box-shadow: 0 10px 20px rgba(0,0,0,0.15);
    border-top: 3px solid var(--primary-blue);
    padding: 30px;
    z-index: 9999;
    
    /* Grid Layout: Default 4 Columns */
    grid-template-columns: repeat(4, 1fr); 
    gap: 30px;
    box-sizing: border-box; 
}

/* Content Layout */
.mega-column h3 {
    font-size: 1.1rem;
    color: var(--primary-blue);
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 15px;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
}

.mega-column ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mega-column ul li {
    margin-bottom: 5px;
    display: block;
}

.mega-column ul li a {
    text-decoration: none;
    color: var(--text-color);
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    padding: 6px 0;
    transition: color 0.2s;
    white-space: normal;
}

.mega-column ul li a::before {
    content: '❯';
    font-size: 0.8rem;
    margin-right: 10px;
    color: var(--primary-blue);
    flex-shrink: 0;
}

.mega-column ul li a:hover {
    color: var(--primary-blue);
    background-color: transparent; 
}

/* --- PC Logic (Hover & Columns) --- */
@media (min-width: 1025px) {
    /* Hover Logic */
    .has-children:hover .sub-menu {
        display: block;
    }
    .mega-dropdown:hover .mega-menu-content {
        display: grid;
    }

    /* 3 Column Logic (Download Menu) */
    .mega-menu-content.cols-3 {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* =========================================
   5. Mobile Styles (max-width: 1024px)
   ========================================= */
@media (max-width: 1024px) {
    
    /* Hamburger Icon */
    .hamburger {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        width: 30px;
        height: 21px;
        cursor: pointer;
    }
    .hamburger span {
        display: block;
        width: 100%;
        height: 3px;
        background-color: var(--primary-blue);
        border-radius: 3px;
    }

    /* Mobile Menu Container */
    .menu {
        display: none;
        position: absolute;
        top: 80px;
        left: 0;
        width: 100%;
        background-color: #fff;
        box-shadow: 0 10px 10px rgba(0,0,0,0.1);
        border-top: 1px solid #eee;
        
        /* Scrollable Menu */
        max-height: calc(100vh - 80px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .menu.active {
        display: block;
    }

    .main-menu {
        flex-direction: column;
        padding-bottom: 20px;
    }

    .main-menu > li {
        width: 100%;
        border-bottom: 1px solid #eee;
        /* Reset Position for Mobile Accordion */
        position: relative !important;
    }

    .main-menu > li > a {
        padding: 15px 20px;
        font-size: 1rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
    }

    /* --- Standard Sub-menu Reset --- */
    .sub-menu {
        position: static; /* No float */
        box-shadow: none;
        border-top: none;
        background-color: #f9f9f9;
        width: 100%;
        padding: 0;
        display: none;
    }
    .sub-menu li a {
        padding-left: 30px;
    }

    /* --- Mega Menu Reset (FIXED: No jumping to bottom) --- */
    .mega-dropdown {
        position: relative !important;
    }

    .mega-menu-content,
    .mega-menu-content.cols-3 {
        position: relative !important; /* Stop absolute positioning */
        top: auto !important;
        left: auto !important;
        width: 100% !important;
        box-shadow: none;
        border-top: none;
        padding: 0;
        display: none;
        grid-template-columns: 1fr !important; /* Force 1 column */
        gap: 0;
    }

    .mega-column {
        padding: 15px 20px;
        border-bottom: 1px solid #eee;
        background: #f9f9f9;
    }

    .mega-column h3 {
        font-size: 1rem;
        margin-bottom: 10px;
        color: var(--primary-blue);
        border-bottom: none;
        padding-bottom: 0;
    }

    .mega-column ul li a {
        padding-left: 10px;
        font-size: 1rem;
    }

    /* Logic: Open via Class */
    .has-children.open .sub-menu {
        display: block;
    }
    .mega-dropdown.open .mega-menu-content {
        display: block;
    }

    /* Highlight Active Parent */
    .has-children.open > a, 
    .mega-dropdown.open > a {
        color: var(--primary-blue);
        background-color: #f0f4f8;
    }

    /* Prevent Hover effects on Mobile */
    .has-children:hover .sub-menu,
    .mega-dropdown:hover .mega-menu-content {
        display: none;
    }
    /* Only allow display block if class 'open' is present */
    .has-children.open .sub-menu,
    .mega-dropdown.open .mega-menu-content {
        display: block; /* or grid for mega menu PC but block works for mobile reset */
    }
}

/* =========================================
   6. Content Helpers (Banner Optimization)
   ========================================= */
.main-content {
    max-width: 1527px; /* หรือปรับเป็น 1920px หากต้องการให้เนื้อหากว้างเท่าแบนเนอร์ */
    margin: 20px auto;
    padding: 0 20px;
    flex: 1; 
    width: 100%;
}

.banner-container {
    width: 100%;
    max-width: 1920px; /* ปรับให้รองรับภาพความละเอียดสูง */
    margin: 0 auto;
    background: #f0f0f0;
    overflow: hidden;
}

.banner-img {
    width: 100%;
    height: auto;
    display: block;
    /* ควบคุมความสูงบนจอ PC ไม่ให้บังเนื้อหาด้านล่างมากเกินไป */
    max-height: 600px; 
    object-fit: cover; /* บังคับให้ภาพเต็มพื้นที่โดยไม่เสียสัดส่วน */
    object-position: center; /* ให้จุดกึ่งกลางภาพ (Safe Zone) อยู่ตรงกลางเสมอ */
}

/* เพิ่มส่วนนี้เพื่อให้แบนเนอร์บนมือถือดูไม่แบนเป็นเส้น */
@media (max-width: 768px) {
    .banner-img {
        min-height: 250px; /* ความสูงขั้นต่ำเพื่อให้ยังอ่านข้อความในภาพออก */
    }
}
/* =========================================
   7. Footer Styles
   ========================================= */
footer {
    background-color: var(--primary-blue);
    color: #ffffff;
    margin-top: 50px;
    padding-top: 50px;
    font-size: 0.95rem;
}

.footer-container {
    max-width: 1527px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 40px;
    margin-bottom: 40px;
}

.footer-section h3 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid rgba(255,255,255,0.3);
    padding-bottom: 10px;
    display: inline-block;
}

.footer-section h4 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 10px;
    color: #e0e0e0;
}

.footer-section p {
    line-height: 1.8;
    color: #dcdcdc;
    margin-bottom: 10px;
}

.footer-section a {
    color: #ffffff;
    text-decoration: none;
    transition: color 0.3s;
}

.footer-section a:hover {
    color: #ffd700;
    text-decoration: underline;
}

.social-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.social-links a {
    background: rgba(255,255,255,0.1);
    padding: 8px 15px;
    border-radius: 4px;
    width: fit-content;
}

.social-links a:hover {
    background: rgba(255,255,255,0.2);
    text-decoration: none;
}

.copyright {
    background-color: #122b44;
    text-align: center;
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.85rem;
    color: #aaa;
}

.copyright p {
    margin: 0;
}

@media (max-width: 768px) {
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 30px;
    }
    
    .footer-section {
        text-align: center;
    }

    .footer-section h3 {
        display: inline-block;
    }

    .social-links {
        align-items: center;
    }
}
/* =========================================
   8. Inner Page Styles (หน้าเพจภายใน - รองรับมือถือ)
   ========================================= */

.main-content {
    max-width: 100%; 
    margin: 0 auto; 
    padding: 0;      
    flex: 1;
    width: 100%;
}

.page-banner {
    background-color: var(--primary-blue);
    width: 100%;
    padding: 80px 20px;   
    text-align: center;
    margin: 0;            
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.page-banner h1 {
    color: #ffffff;
    margin: 0;
    font-size: 3.5rem;    
    font-weight: 700;
    line-height: 1.2;
}
.content-section {
    max-width: 1200px;    
    margin: 0 auto;
    padding: 50px 20px;   
    background-color: #ffffff;
}

@media (max-width: 1024px) {
    .page-banner {
        padding: 60px 20px; 
    }
    .page-banner h1 {
        font-size: 2.5rem;  
    }
}

@media (max-width: 768px) {
    .page-banner {
        padding: 40px 15px; 
    }
    .page-banner h1 {
        font-size: 1.8rem;  
    }
    .content-section {
        padding: 30px 15px; 
    }
}

/* =========================================
   9. Card & Grid System (Missing Fixed)
   ========================================= */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    margin-top: 30px;
}

.common-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

.card-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    overflow: hidden;
}

.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.common-card:hover .card-thumb img {
    transform: scale(1.05);
}

.date-badge {
    position: absolute;
    top: 15px;
    left: 15px;
    background: var(--primary-blue);
    color: #fff;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.card-info {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-info h5 {
    margin: 0 0 10px 0;
    color: var(--primary-blue);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-info .meta {
    margin: auto 0 0 0;
    font-size: 0.85rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-info .meta i {
    color: var(--primary-blue);
}

@media (max-width: 576px) {
    .card-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}