/* File: assets/css/backend_style.css */
/* --- Global Styles & Variables --- */
@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600&display=swap');

/* --- ⬇️ CSS สำหรับปุ่ม ☰ (Sidebar Toggle) ⬇️ --- */
.sidebar-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    z-index: 1001; /* อยู่เหนือ Sidebar */
    /* (Desktop) ซ่อนปุ่มนี้ไว้ก่อน */
    display: none; 
}
.sidebar-toggle-btn span {
    display: block;
    width: 25px;
    height: 3px;
    background-color: var(--primary-color);
    margin: 5px 0;
    transition: all 0.3s;
}

/* (เพิ่ม) พื้นหลังมืดๆ สำหรับปิดเมนู (บนมือถือ) */
#sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 999; /* อยู่ใต้ Sidebar แต่เหนือ Content */
}

/* --- ⬇️ (เพิ่ม) ตรรกะการเปิด Sidebar ⬇️ --- */
body.sidebar-open .sidebar {
    transform: translateX(0); /* 1. แสดง Sidebar */
}
body.sidebar-open .admin-wrapper > .main-content {
    margin-left: 250px; /* 2. ดัน Content ไปทางขวา */
}
/* --- ⬆️ (จบตรรกะ) ⬆️ --- */

:root {
    --primary-color: #C00000; /* Red */
    --secondary-color: #1a253c; /* Dark Blue */
    --accent-color: #D4AF37;   /* Gold */
    --bg-color: #f4f7fa;
    --sidebar-bg: #1a253c;
    --header-bg: #ffffff;
    --text-color: #333;
    --light-text-color: #f1f1f1;
    --border-color: #e1e1e1;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
    --font-family: 'Kanit', sans-serif;
}

body {
    font-family: var(--font-family);
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* --- Login Page Styles --- */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: var(--bg-color);
}

.login-box {
    background: var(--header-bg);
    padding: 2rem 3rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    text-align: center;
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    color: var(--secondary-color);
    margin-top: 0;
}

.login-box p {
    color: #777;
    margin-bottom: 2rem;
}

.login-box .form-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

.login-box .form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.login-box .form-group input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-sizing: border-box;
}

.login-btn {
    width: 100%;
    padding: 0.9rem;
    border: none;
    background-color: var(--primary-color);
    color: white;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.login-btn:hover {
    background-color: #a00000;
}

/* --- Main Admin Layout --- */
.admin-wrapper {
    /* display: flex; */
}

.admin-wrapper > .main-content {
    /* flex-grow: 1; <-- ลบทิ้ง */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin-left: 0;
    /* (ลบ width: 100%; และ box-sizing: border-box; ทิ้งไป) */
    transition: margin-left 0.3s ease-in-out; /* <-- 3. แก้ไขบรรทัดนี้ */
}

/* --- Sidebar Styles --- */
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--light-text-color);
    flex-shrink: 0;
    /* --- ⬇️ (แก้ไข) เปลี่ยนเป็น Fixed และซ่อน ⬇️ --- */
    position: fixed; /* 1. เปลี่ยนเป็น fixed */
    height: 100vh;  /* 2. สูงเต็มจอ */
    z-index: 1000;
    transform: translateX(-100%); /* 3. ซ่อนไว้ด้านซ้าย (ค่าเริ่มต้น) */
    transition: transform 0.3s ease-in-out;
    /* --- ⬆️ (จบส่วนแก้ไข) ⬆️ --- */
}

.sidebar-header {
    padding: 1.5rem;
    text-align: center;
    background-color: rgba(0,0,0,0.2);
}

.sidebar-header h2 {
    margin: 0;
    color: var(--accent-color);
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

.sidebar-nav a {
    display: block;
    color: var(--light-text-color);
    text-decoration: none;
    padding: 1rem 1.5rem;
    transition: background-color 0.3s, color 0.3s;
    position: relative; /* 1. เพิ่ม position */
    border-left: none; /* 2. ลบ border-left (ถ้ามี) */
}

/* 3. เพิ่ม ::after สำหรับขีดเส้นใต้ */
.sidebar-nav a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 1.5rem;
    transform: none;
    /* transform: translateX(-50%); ให้อยู่กึ่งกลาง */
    width: 0;
    height: 3px;
    background-color: var(--accent-color); /* สีทอง */
    transition: width 0.3s ease-in-out;
}

.sidebar-nav a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--accent-color); /* เปลี่ยนสีตัวอักษรเมื่อ hover */
}

/* 4. เมื่อ Active หรือ Hover ให้ขีดเส้นใต้ */
.sidebar-nav a:hover::after,
.sidebar-nav a.active::after {
    width: calc(100% - 3rem); /* ⬅️ 3. (100% ลบ padding ซ้าย-ขวา) */
}

.sidebar-nav a.active {
    background-color: rgba(0,0,0,0.3);
    font-weight: 500;
    color: var(--accent-color);
}

/* --- Header Styles (Premium UI) --- */
.admin-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px); /* เอฟเฟกต์กระจกเบลอๆ เวลาเลื่อนผ่านเนื้อหา */
    padding: 1.2rem 2.5rem; /* 💡 ปรับขอบซ้าย-ขวาให้ตรงกับเนื้อหาด้านล่างเป๊ะๆ */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03); /* เงาอ่อนๆ ดูผู้ดี */
    border-bottom: 1px solid #edf2f7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky; /* 💡 ทำให้ Header ติดหนึบอยู่ด้านบนสุดเวลา Scroll */
    top: 0;
    z-index: 99;
}

.admin-header h1 {
    margin: 0;
    font-size: 1.25rem;
    color: #0f172a;
    font-weight: 600;
    border-left: 4px solid #fbbf24; /* ขีดเส้นสีทองด้านหน้าข้อความ */
    padding-left: 12px;
}

.user-info {
    font-size: 0.95rem;
    color: #64748b;
    display: flex;
    align-items: center;
}

/* 💡 แต่งปุ่มออกจากระบบให้เป็นปุ่มสีแดงเด่นๆ */
.user-info a {
    color: #ef4444;
    text-decoration: none;
    font-weight: 600;
    margin-left: 10px;
    padding: 6px 14px;
    border-radius: 50px;
    background: #fef2f2;
    transition: all 0.2s;
}

.user-info a:hover {
    background: #fee2e2;
    color: #dc2626;
    transform: translateY(-1px);
}

/* --- Page Content Styles --- */
.page-content {
    padding: 2rem;
    flex-grow: 1;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.page-header h2 {
    margin: 0;
}

/* --- Buttons --- */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: opacity 0.3s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background-color: var(--primary-color); color: white; }
.btn-secondary { background-color: #6c757d; color: white; }
.btn-danger { background-color: #dc3545; color: white; }

/* --- Tables --- */
.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

thead {
    background-color: #f8f9fa;
}

th {
    font-weight: 600;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background-color: #f1f1f1;
}

.action-links a {
    margin-right: 0.5rem;
}

/* --- Status Badges --- */
.status {
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: capitalize;
}
.status.published { background-color: #d4edda; color: #155724; }
.status.draft { background-color: #fff3cd; color: #856404; }

/* --- Forms --- */
.form-container {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.form-group {
    margin-bottom: 1.5rem;
}
.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-sizing: border-box;
    font-family: var(--font-family);
}
.form-group textarea {
    resize: vertical;
    min-height: 150px;
}
/* --- FIX: Form Actions (Buttons) Layout --- */
.form-actions {
    border-top: 1px solid #eee;
    padding-top: 20px;
    margin-top: 20px;
    display: flex;
    /* Aligns buttons to the right */
    justify-content: flex-end;
    /* Increases space between buttons */
    gap: 15px; 
}

/* --- Alerts --- */
.alert {
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 4px;
    border: 1px solid transparent;
}
.alert-success {
    color: #155724;
    background-color: #d4edda;
    border-color: #c3e6cb;
}
.alert-danger {
    color: #721c24;
    background-color: #f8d7da;
    border-color: #f5c6cb;
}

/* --- Footer --- */
.admin-footer {
    text-align: center;
    padding: 1rem;
    margin-top: auto;
    font-size: 0.9rem;
    color: #777;
}

/* Image Management Styles */
.image-management-grid {
    display: grid;
    /* Changed minmax from 150px to 120px */
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    background-color: #f9f9f9;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

.image-thumb {
    border: 1px solid #ccc;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}

.image-thumb img {
    width: 100%;
    /* ค่าเดิม height 90px */
    height: 150px;
    object-fit: cover;
    display: block;
}

.image-actions {
    padding: 8px;
    background-color: rgba(255, 255, 255, 0.95);
    font-size: 0.8rem;
}
.image-actions label {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
}
.btn-delete-img {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    width: 100%;
    font-size: 0.8rem;
}
.btn-delete-img:hover {
    background-color: #c0392b;
}

/* ⬇️ เพิ่ม CSS สำหรับลิงก์เปิดแท็บใหม่ และเส้นคั่น ⬇️ */
.sidebar-nav a[target="_blank"] {
    color: #f1c40f; /*
 ทำให้เป็นสีเหลืองทอง */
}
.sidebar-nav a[target="_blank"]:hover {
    color: #fff;
    background-color: rgba(241, 196, 15, 0.1);
}

.sidebar-separator {
    height: 1px;
    background-color: rgba(255, 255, 255, 0.1);
    margin: 10px 20px;
}

/* --- ⬇️ เพิ่ม CSS สำหรับ Dashboard ⬇️ --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.stat-card {
    background-color: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.stat-card-info h3 {
    margin: 0 0 5px 0;
    font-size: 1.1rem;
    color: #555;
}
.stat-card-info .stat-number {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--primary-color);
}
.stat-card-icon {
    font-size: 3rem;
    color: var(--primary-color);
    opacity: 0.1;
}

/* --- Dashboard Recent Activity --- */
.recent-activity-grid {
    display: grid;
    grid-template-columns: 1fr; /* ⬅️ แก้ไขเป็น 1 คอลัมน์ */
    gap: 1.5rem;
}
.recent-list-card .data-table td {
    padding: 0.75rem 1rem; /*
 ลด padding ของตาราง */
}
.recent-list-card .data-table tr:hover {
    background-color: #f9f9f9;
}
.recent-list-card .data-table a {
    font-weight: 500;
    text-decoration: none;
    color: #333;
}
.recent-list-card .data-table a:hover {
    color: var(--primary-color);
}
.recent-list-card .data-table small {
    color: #777;
    font-size: 0.85rem;
}

/* --- Responsive Design (UPGRADED) --- */
@media (max-width: 768px) {

    /* 1. (แทนที่) แสดงปุ่ม ☰ และจัด Header ใหม่ */
    .sidebar-toggle-btn {
        display: block; /* ⬅️ โชว์ปุ่ม ☰ บนมือถือ */
        margin-right: 10px; /* ⬅️ เว้นระยะห่างจาก H1 */
    }
    .admin-header h1 {
        flex-grow: 1; /* ⬅️ ให้ H1 ยืดไปดัน user-info */
        font-size: 1.25rem;
    }

    /* 2. (แทนที่) Sidebar จะเป็น Overlay (ไม่ดัน Content) */
    .sidebar {
        /* (ใช้ค่า fixed, z-index, transform จาก Desktop) */
        width: 280px; /* ⬅️ กว้างขึ้นเล็กน้อยบนมือถือ */
    }

    /* 3. (แทนที่) .main-content จะไม่ถูก "ดัน" บนมือถือ */
    body.sidebar-open .admin-wrapper > .main-content {
    margin-left: 0; 
    }

    /* 4. (เพิ่ม) แสดง Backdrop เมื่อเมนูเปิด */
    body.sidebar-open #sidebar-backdrop {
        display: block;
    }

    /* 5. (แทนที่) Sidebar Nav บนมือถือ (ให้กลับไปเป็นแนวตั้ง) */
    .sidebar-header { display: block; } /* ⬅️ (เอา Header กลับมา) */
    .sidebar-nav ul {
        display: block; /* ⬅️ กลับเป็นแนวตั้ง */
        margin: 1rem 0;
    }
    .sidebar-nav a {
        padding: 1rem 1.5rem; /* ⬅️ กลับไปเป็น padding เดิม */
    }

    /* (CSS ส่วนที่เหลือ .page-content, .card-header, ฯลฯ ยังใช้ได้) */
    .page-content { padding: 1rem; } 
    .admin-header {
        flex-direction: row; /* ⬅️ บังคับแนวนอน */
        align-items: center;
        gap: 0; /* ⬅️ ไม่ต้องมี gap */
    }
    .card-header {
        flex-direction: column;
        gap: 10px;
    }
}

/* 💡 จัดการช่องว่าง (Padding) ของเนื้อหาด้านในให้เป็นระเบียบ */
.admin-wrapper .main-content .main-content {
    padding: 2rem 2.5rem;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .admin-wrapper .main-content .main-content {
        padding: 1.5rem 1rem;
    }
}