/*
Theme Name: บ้านเพียรพิทักษ์ Astra Child
Theme URI: [Your Website URL]
Description: Custom styles and templates for Baan Pianpitak based on the Astra Theme.
Author: Pianpitak Web Helper
Author URI: [Your Website URL]
Template: astra
Version: 1.0.46 
License: GNU General Public License v2 or later License URI: http: //www.gnu.org/licenses/gpl-2.0.html
Text Domain: pianpitak-astra-child */
/* ---------------------------------------------------------------------------------------
    1. HOME PAGE FEATURED SECTION STYLES (ULTRA PROFESSIONAL LOOK)
--------------------------------------------------------------------------------------- */

.featured-events-section {
    max-width: 1280px;
    margin: 70px auto;
    padding: 0 25px;
    text-align: center;
    background-color: transparent;
}

/* ส่วนหัวและคำเชิญชวน */
.section-intro {
    margin-bottom: 60px;
    padding: 20px 0;
}

.intro-headline {
    font-size: 2.75rem;
    font-weight: 800;
    color: #2c3e50;
    margin-bottom: 20px;
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.intro-body {
    font-size: 1.15rem;
    color: #555;
    max-width: 850px;
    margin: 0 auto 40px;
    line-height: 1.8;
}

.cta-archive-button {
    display: inline-block;
    background-color: #2EAF5E;
    color: #ffffff;
    font-size: 1.15rem;
    font-weight: 700;
    padding: 16px 45px;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.3s ease;
    border: none;
    box-shadow: 0 8px 20px rgba(46, 175, 94, 0.2);
    letter-spacing: 0.5px;
}

.cta-archive-button:hover {
    background-color: #258C4B;
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(46, 175, 94, 0.35);
}

/* Grid แสดงกิจกรรม 3 อัน */
.featured-events-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 35px;
    padding: 40px 0;
}

/* *** FIX: แก้ไขการ์ดกิจกรรมตัวอย่าง (Featured Preview Card) */
.event-post.featured-preview-card {
    background-color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    overflow: hidden;
    text-align: left;
    border: 1px solid #f0f0f0;

    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
}

.event-post.featured-preview-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

/* FIX: Image Wrapper (กล่องที่ห่อหุ้มรูปภาพ) */
.event-post.featured-preview-card .post-gallery-wrapper {
    aspect-ratio: 1 / 1 !important;
    width: 100% !important;
    height: auto !important;
    overflow: hidden !important;
    position: relative !important;
    flex-shrink: 0 !important;
}

/* กล่องรูปภาพจริง (อาจมาจาก Astra หรือ WordPress) */
.post-gallery.single-image-preview {
    height: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
}

/* ภาพเดียวที่เป็นจัตุรัส (ลิงก์ a) - FIX: กำจัด Line Height ที่ทำให้เกิดช่องว่าง */
.event-post.featured-preview-card .post-gallery a.single-image-link {
    display: block !important;
    overflow: hidden !important;
    width: 100% !important;
    height: 100% !important;
    line-height: 0 !important;
    font-size: 0 !important;
}

/* ตัวรูปภาพเอง */
.post-gallery.single-image-preview img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* ปรับ Header ของการ์ดตัวอย่างให้กระชับมาก */
.event-post.featured-preview-card .post-header {
    padding: 20px 25px 15px;
    text-align: left;
    border-bottom: none;

    flex-grow: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
}

.event-post.featured-preview-card .post-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1.4;
    max-height: calc(1.3rem * 1.4 * 2);
    text-align: left;
}

.event-post.featured-preview-card .post-header h2 a {
    color: #2c3e50;
}

/* วันที่ */
.event-post.featured-preview-card .post-date {
    font-size: 0.95rem;
    color: #666;
    font-weight: 500;
    margin-top: 8px;
    text-align: left;
}


/* Responsive adjustment for tablets/mobile */
@media (max-width: 992px) {
    .featured-events-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 30px;
    }
}

@media (max-width: 768px) {
    .intro-headline {
        font-size: 2.2rem;
    }

    .event-post.featured-preview-card .post-header {
        padding-top: 15px;
    }

    .event-post.featured-preview-card .post-header h2,
    .event-post.featured-preview-card .post-date {
        text-align: center;
    }
}

@media (max-width: 576px) {
    .featured-events-section {
        margin: 50px auto;
        padding: 0 15px;
    }

    .featured-events-grid {
        grid-template-columns: 1fr;
        gap: 25px;
    }
}


/* ---------------------------------------------------------------------------------------
    2. PIANPITAK CUSTOM BLOG BANNER (CONTACT US PAGE STYLE) - VERSION 1.0.46
    (ใช้สไตล์นี้สำหรับ Event Archive Header ด้วย)
--------------------------------------------------------------------------------------- */

.blog-banner-section {
    background-color: transparent;
    padding: 30px 20px 20px;
    text-align: center;
    box-shadow: none;
    border-radius: 0;
    margin-bottom: 0;

    /* START: FIX 1 - Vertical Center Header Content */
    display: flex;
    align-items: center;
    /* Center items vertically */
    justify-content: center;
    min-height: 150px;
    flex-direction: column;
    /* END: FIX 1 */
}

.blog-banner-container {
    max-width: 800px;
    margin: 0 auto;
}

.blog-banner-title {
    font-size: 3rem;
    font-weight: 800;
    color: #2EAF5E;
    margin-bottom: 10px;
    line-height: 1.2;
    letter-spacing: normal;
    text-shadow: none;
}

.blog-banner-subtitle {
    font-size: 1.15rem;
    color: #555;
    line-height: 1.6;
    margin: 0 auto;
    max-width: 600px;
    font-weight: 400;
}


/* Responsive Styles for Banner */
@media (max-width: 992px) {
    .blog-banner-section {
        padding: 40px 20px 25px;
    }

    .blog-banner-title {
        font-size: 2.5rem;
    }

    .blog-banner-subtitle {
        font-size: 1.05rem;
    }
}

@media (max-width: 768px) {
    .blog-banner-section {
        padding: 30px 15px 20px;
    }

    .blog-banner-title {
        font-size: 2rem;
    }

    .blog-banner-subtitle {
        font-size: 1rem;
    }
}

/* ---------------------------------------------------------------------------------------
    3. CUSTOM CSS FOR EVENT WALL (ARCHIVE PAGE STYLES - RESTORED)
--------------------------------------------------------------------------------------- */

/* Global Styles & Container */
body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f7;
}

.feed-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
}

.site-main {
    padding: 0;
}

/* --- Individual Post Card Styling (Archive Page) --- */
.event-post {
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform 0.3s ease-in-out;
}

.event-post:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.post-header {
    /* บังคับความสูง Header สำหรับ Archive (3 บรรทัด) */
    padding: 15px 15px 10px;
    border-bottom: none;
    text-align: center;
    flex-shrink: 0;
    /* min-height: 100px;  <-- REMOVED TO FIX VERTICAL SNAPPING */

    /* START: FIX 2 - Ensure content snaps to top */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    /* Ensures content starts from the top */
    min-height: unset;
    /* Ensure the text area is only as tall as its content */
    /* END: FIX 2 */
}

.post-header h2 {
    font-size: 1.5rem;
    margin-top: 0;

    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
    font-weight: 700;
    line-height: 1.3;
    max-height: calc(1.5rem * 1.3 * 3);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.post-header h2 a {
    color: #2c3e50;
    text-decoration: none;
    transition: color 0.2s;
}

.post-header h2 a:hover {
    color: #2EAF5E;
}

.post-date {
    font-size: 0.95rem;
    color: #2EAF5E;
    font-weight: 600;
    margin-top: 5px;
    margin-bottom: 0;
}

/* ซ่อน Excerpt */
.event-post .post-content.post-excerpt {
    display: none;
    height: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

/* Archive Gallery Showcase Grid (2x2) */
.post-gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 2px;
    aspect-ratio: unset;
    width: 100%;
    height: auto;
}

/* บังคับให้แต่ละช่องของ Grid เป็นสี่เหลี่ยมจัตุรัส (1:1) */
.post-gallery a {
    display: block;
    position: relative;
    overflow: hidden;
    height: auto;
    width: 100%;
    aspect-ratio: 1 / 1;
}

.post-gallery img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.post-gallery a.view-all-card .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.4);
    color: #ffffff;
    font-size: 1.2rem;
    font-weight: 700;
    transition: background-color 0.3s;
    opacity: 1;
}

/* Gallery Footer Styling (Archive Page) */
.gallery-footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: 30px;
    border-top: 1px solid #e0e0e0;
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* ---------------------------------------------------------------------------------------
    4. SINGLE EVENT PAGE STYLES
--------------------------------------------------------------------------------------- */

/* 1. CONTAINER CENTERING & HEIGHT FIX (Maximum Priority) */
.single-event-post {
    max-width: 1000px !important;
    width: 90% !important;
    margin: 30px auto !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    height: auto !important;
    min-height: unset !important;
}

.single-event-container {
    background-color: #ffffff !important;
    padding: 30px !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05) !important;
    min-height: 500px !important;
    height: auto !important;
    display: block !important;
    overflow: hidden !important;
}

/* Header & Content Styling */
.single-post-header {
    text-align: center !important;
    margin-bottom: 30px !important;
    padding-bottom: 20px !important;
    border-bottom: 1px solid #f0f0f0 !important;
}

.single-post-header h1 {
    font-size: 2.5rem !important;
    font-weight: 800 !important;
    color: #2c3e50 !important;
    margin-bottom: 5px !important;
    line-height: 1.2 !important;
}

.single-post-date {
    font-size: 1rem !important;
    color: #2EAF5E !important;
    font-weight: 600 !important;
    display: block !important;
    margin-top: 10px !important;
}

/* Content Area Styling */
.single-post-content {
    line-height: 1.8 !important;
    font-size: 1.05rem !important;
    color: #444 !important;
}

.single-post-content p {
    margin-bottom: 1.5rem !important;
}

.single-post-content h2,
.single-post-content h3 {
    color: #2c3e50 !important;
    font-weight: 700 !important;
    margin-top: 2rem !important;
    margin-bottom: 1rem !important;
    border-bottom: 2px solid #2eaf5e33;
    /* Light green underline */
    padding-bottom: 5px;
}

/* Gallery Styling */
.post-gallery.flex-event-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    /* FIX 1: เปลี่ยน grid-auto-rows ให้ยืดหยุ่นขึ้น เพื่อแก้ปัญหารูปซ้อนและช่องว่าง */
    grid-auto-rows: 1fr !important;
    grid-auto-flow: dense !important;
    /* FIX 2: ช่วยให้ Grid จัดเรียงรูปภาพเติมช่องว่างได้ดีขึ้น */
    gap: 10px !important;
    margin-top: 30px !important;
}

/* Image Item Styling (must be set in PHP) */
.post-gallery.flex-event-grid a {
    display: block !important;
    overflow: hidden !important;
    position: relative !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05) !important;
    border-radius: 6px !important;
}

.post-gallery.flex-event-grid a img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    transition: transform 0.4s ease-in-out !important;
    display: block !important;
}

.post-gallery.flex-event-grid a:hover img {
    transform: scale(1.05) !important;
}


/* Layout Rules for the Flex Grid (Must match PHP logic) */

/* 2x2 Cover Image (FIX 3: เปลี่ยนจาก span 1 เป็น span 2 เพื่อให้เป็น 2x2 area) */
.post-gallery.flex-event-grid a.cover-item {
    grid-column: span 2 !important;
    grid-row: span 2 !important;
    /* <--- แก้ไขจาก span 1 เป็น span 2 */
    aspect-ratio: unset !important;
}

/* Fillers (Single squares) - for image 6 and 7 */
.post-gallery.flex-event-grid a.grid-fill-1 {
    grid-row: span 1 !important;
    grid-column: span 1 !important;
    aspect-ratio: 1 / 1 !important;
}

.post-gallery.flex-event-grid a.grid-fill-2 {
    grid-row: span 1 !important;
    grid-column: span 1 !important;
    aspect-ratio: 1 / 1 !important;
}


/* Back to Archive Link */
.back-link-container {
    text-align: center !important;
    margin-top: 40px !important;
    padding-top: 20px !important;
    border-top: 1px dashed #ddd !important;
}

.back-to-archive {
    display: inline-block !important;
    color: #2c3e50 !important;
    font-size: 1.1rem !important;
    font-weight: 600 !important;
    text-decoration: none !important;
    transition: color 0.2s !important;
    padding: 10px 15px !important;
    border-radius: 4px !important;
}

.back-to-archive:hover {
    color: #2EAF5E !important;
}


/* Responsive Styles for Single Event Page */

/* Wide Tablet/Desktop */
@media (max-width: 1024px) {
    .single-event-post {
        padding: 0 30px !important;
        width: auto !important;
    }
}

/* Tablet Screens: 2 Columns */
@media (max-width: 768px) {
    .single-event-post {
        padding: 0 20px !important;
        width: auto !important;
    }

    .post-gallery.flex-event-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* FIX: บังคับให้ Cover Item กลับมาเป็น 1x1 ใน Responsive เพื่อไม่ให้เลย์เอาต์พัง */
    .post-gallery.flex-event-grid a.cover-item {
        grid-column: span 1 !important;
        grid-row: span 1 !important;
        aspect-ratio: 1 / 1 !important;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08) !important;
    }

    .post-gallery.flex-event-grid a.grid-fill-1,
    .post-gallery.flex-event-grid a.grid-fill-2 {
        grid-row: unset !important;
        grid-column: unset !important;
    }
}

/* Mobile Screens: 1 Column */
@media (max-width: 576px) {
    .post-gallery.flex-event-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    .post-gallery.flex-event-grid a.cover-item {
        grid-column: 1 / -1 !important;
        aspect-ratio: 16 / 9 !important;
        grid-row: unset !important;
    }
}

/* --------------------------------------------------------------------------------------
    5. FIX: Header Text Wrap Issue (Archive/Blog Page H1) - v1.0.44
--------------------------------------------------------------------------------------- */

.gallery-header h1 {
    /* บังคับไม่ให้ข้อความขึ้นบรรทัดใหม่ แม้ความกว้างจะไม่พอ */
    white-space: nowrap;

    /* ให้ข้อความอยู่ตรงกลาง */
    text-align: center;
}

/* แก้ไขปัญหาสระลอย/ตกขอบ (ถ้ามี) */
.gallery-header {
    overflow-x: hidden;
}

/* ---------------------------------------------------------------------------------------
    6. FIX: Remove White Space Above Banner on Archive Pages - v1.0.46
--------------------------------------------------------------------------------------- */
/* Targets ALL main content wrappers on archive pages to eliminate the theme's default top padding. */
.archive #primary,
.archive #main,
.archive .content-area,
.post-type-archive-event .site-main,
.ast-container {
    margin-top: 0 !important;
}