/* =================================================== */
/* 1. รีเซ็ตค่าพื้นฐาน และโครงสร้างหลัก (Global Styles) */
/* =================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Sarabun', sans-serif;
}

body {
    background-color: #f4f6f9;
    color: #333;
    line-height: 1.6;
}

/* แถบเมนูนำทาง (Navbar) */
header {
    background-color: #8B0000; /* สีแดงเข้ม จปร. */
    color: #fff;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 4px solid #FFD700;
    position: relative;
    z-index: 1000;
}

.logo-area {
    display: flex !important;
    align-items: center !important; /* จัดให้รูปโลโก้และตัวหนังสืออยู่กึ่งกลางแนวตั้งพอดีกัน */
    gap: 12px !important;           /* เว้นระยะห่างระหว่างรูปและตัวอักษรให้พอดี */
}

.logo-area img {
    width: 60px !important;         /* ปรับขนาดความกว้างโลโก้ */
    height: 60px !important;        /* ปรับขนาดความสูงโลโก้ */
    object-fit: contain !important; /* ป้องกันไม่ให้รูปภาพบิดเบี้ยวหรือเบนสัดส่วน */
    display: block !important;
}

.logo-area h2 {
    margin: 0 !important;           /* ลบระยะขอบที่ดันด้านบนและด้านล่าง */
    font-size: 1.35rem !important;  /* ปรับขนาดตัวอักษรให้พอดีกับความสูงโลโก้ */
    white-space: nowrap !important; /* บังคับไม่ให้ชื่อหน่วยงานตัดขึ้นบรรทัดใหม่เมื่อจอมือถือแคบ */
    line-height: 1 !important;
}

/* เมนูสำหรับ Desktop */
nav ul {
    display: flex;
    list-style: none;
    gap: 20px;
}

nav ul li a {
    color: #fff;
    text-decoration: none;
    font-weight: bold;
    transition: color 0.3s;
}

nav ul li a:hover, nav ul li a.active {
    color: #FFD700;
}

/* ปุ่มสามจุดสำหรับเปิด Dropdown (ซ่อนไว้ก่อนบนจอคอม) */
.menu-toggle {
    display: none;
    font-size: 24px;
    cursor: pointer;
    background: none;
    border: none;
    color: white;
    padding: 5px 10px;
}

/* ส่วนเนื้อหาหลัก (Responsive Container) */
.container {
    width: 90%;
    max-width: 1200px;
    margin: 2rem auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    padding: 2rem;
}

h1, h2, h3 {
    color: #8B0000;
    margin-bottom: 1rem;
}

/* ฟุตเตอร์ท้ายหน้า */
footer {
    background-color: #222;
    color: #fff;
    text-align: center;
    padding: 1.5rem;
    margin-top: 3rem;
    font-size: 0.9rem;
    border-top: 3px solid #8B0000;
}

/* =================================================== */
/* 2. สไตล์หน้าอื่นๆ (หน้าคำถวายอาลัย / ข่าวสาร / ผู้บังคับบัญชา) */
/* =================================================== */

/* 🖤 หน้าคำถวายอาลัย (โทนดำ-ขาว ตัวหนังสือขาวตามสั่ง) */
.mourning-body {
    background-color: #000000;
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.mourning-container {
    text-align: center;
    max-width: 600px;
    width: 100%;
    padding: 2.5rem 1.5rem;
    border: 1px solid #444444;
    background: #111111;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.05);
}

.mourning-container h2 {
    color: #ffffff; /* ตัวหนังสือขาว */
    font-weight: 700;
    margin-top: 1.5rem;
}

.mourning-container p {
    color: #cccccc; /* ขาวหม่นเพื่อความสบายตา */
}

.mourning-king-img {
    max-width: 100%;
    height: auto;
    max-height: 350px;
    border: 1px solid #333;
    filter: grayscale(100%); /* ทำภาพให้เป็นขาวดำ */
}

.btn-enter {
    display: inline-block;
    margin-top: 2rem;
    padding: 12px 30px;
    background-color: #222222;
    color: #ffffff;
    text-decoration: none;
    border: 1px solid #555555;
    font-weight: bold;
    transition: 0.3s;
    border-radius: 4px;
}

.btn-enter:hover {
    background-color: #ffffff;
    color: #000000;
    border-color: #ffffff;
}

/* ระบบ Grid สำหรับข่าวสาร (Responsive) */
.grid-news {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 1.5rem;
}

.news-card {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 5px;
    overflow: hidden;
    transition: transform 0.3s;
}

.news-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.news-content {
    padding: 15px;
}

/* หน้าผู้บังคับบัญชา (Responsive) */
.commander-flex {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-top: 1.5rem;
}

.commander-card {
    background: #fff;
    border: 1px solid #ddd;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    width: 100%;
    max-width: 260px;
}

.commander-card img {
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 10px;
}

.history-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.history-img {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    border-radius: 5px;
}

/* =================================================== */
/* 🌟 3. สไตล์ส่วนกล่อง Pop-up (Modal) ที่แก้ไขให้ Responsive */
/* =================================================== */
.image-modal {
    display: none; /* ซ่อนไว้เริ่มต้น */
    position: fixed;
    z-index: 2000; /* ให้อยู่เหนือทุกส่วนรวมถึงเมนู */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9); /* เพิ่มความเข้มพื้นหลังดำโปร่งแสง */
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 15px; 
    box-sizing: border-box;
}

/* เมื่อสั่งเปิดคลาส active ให้แสดงผลแบบ Flex */
.image-modal.active {
    display: flex;
    opacity: 1;
}

/* คอนเทนเนอร์ภายในกล่อง */
.modal-content {
    position: relative;
    width: 100%;       
    max-width: 90%;    /* คุมกล่องไม่ให้ใหญ่เกิน 90% ของความกว้างหน้าจอ */
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* 🎯 ตัวรูปภาพใน Pop-up (ควบคุมผ่าน ID เพื่อความแม่นยำ) */
#modalTargetImg {
    width: 100% !important;
    max-width: 550px !important; /* จำกัดขนาดความกว้างที่เหมาะสมในการอ่านผังบนมือถือ */
    height: auto !important;     /* บังคับให้ย่อ-ขยายตามสัดส่วนจริง (Aspect Ratio) */
    max-height: 65vh !important; /* จำกัดความสูงไม่ให้ล้นทะลุหน้าจอมือถือแนวตั้ง */
    object-fit: contain !important; /* ป้องกันภาพบิดเบี้ยว */
    border-radius: 6px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
    border: 3px solid #ffffff; 
    box-sizing: border-box;
}

/* ข้อความใต้ภาพชื่อแผนก */
.modal-caption {
    color: #ffffff;
    margin-top: 12px;
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
    width: 100%;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}

/* ปุ่มกากบาทปิด (X) ย้ายตำแหน่งให้สัมพันธ์กับรูป ไม่หลุดขอบบนหน้าจอ */
.modal-close {
    position: absolute;
    top: -45px;
    right: 0;
    color: #ffffff;
    font-size: 38px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    user-select: none;  
    z-index: 2010;
}

.modal-close:hover {
    color: #FFD700; /* เปลี่ยนเป็นสีทองประจำหน่วยเมื่อ Hover */
    transform: scale(1.1);
}

/* =================================================== */
/* 📱 4. RESPONSIVE STYLES (สำหรับมือถือและแท็บเล็ต) */
/* =================================================== */
@media (max-width: 768px) {
    header {
        padding: 1rem;
    }

    /* แสดงปุ่มสามจุด */
    .menu-toggle {
        display: block;
    }

    /* แปลงเมนูธรรมดาให้เป็น Dropdown List ยุบลงมา */
    nav {
        display: none; 
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background-color: #8B0000;
        border-bottom: 4px solid #FFD700;
    }

    /* เมื่อปุ่มสามจุดถูกกด จะเพิ่มคลาส .show ผ่าน JS */
    nav.show {
        display: block;
    }

    nav ul {
        flex-direction: column;
        gap: 0;
    }

    nav ul li {
        width: 100%;
    }

    nav ul li a {
        display: block;
        padding: 15px 20px;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    
    nav ul li a:hover {
        background-color: rgba(0,0,0,0.2);
    }

    .container {
        padding: 1.5rem 1rem;
        margin: 1rem auto;
    }
}

/* 📱 ปรับแต่งขนาด Pop-up เพิ่มเติมสำหรับหน้าจอมือถือขนาดเล็กมาก (ต่ำกว่า 576px) */
@media (max-width: 576px) {
    .modal-content {
        max-width: 95%; /* ขยายพื้นที่แสดงผลให้เต็มตาขึ้นบนหน้าจอแคบ */
    }
    
    #modalTargetImg {
        max-height: 58vh !important; /* ลดความสูงลงเล็กน้อยเพื่อหลบแถบ URL ของเบราว์เซอร์มือถือ */
    }
    
    .modal-close {
        top: -42px;       
        right: 0;
        font-size: 32px;  
    }
    
    .modal-caption {
        font-size: 1rem;  
        margin-top: 8px;
    }
}