@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600&display=swap');

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-sub: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --sidebar-w: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Kanit', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    /* ❌ ลบ display: flex ออกจาก body เพราะเราจะไปใช้ใน #appContent แทน */
    min-height: 100vh;
}

/* ✅ เพิ่มส่วนนี้: จัด Layout หลักให้เต็มจอ */
#appContent {
    display: flex; /* ให้ Sidebar กับ Content เรียงแนวนอน */
    width: 100%;
    min-height: 100vh;
}

/* บังคับฟอนต์ */
input, select, button, textarea {
    font-family: 'Kanit', sans-serif;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    
    /* ⚠️ แก้ไข: เลิกใช้ fixed เพื่อไม่ให้มันลอยหลุดจาก Layout */
    /* position: fixed; <--- ลบทิ้ง */
    flex-shrink: 0; /* ห้ามหดตัว */
    min-height: 100vh; /* สูงเต็มจอ */
    
    padding: 20px;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.logo {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 40px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}
.logo span { color: var(--primary); }

.menu { display: flex; flex-direction: column; gap: 15px; }

.menu-item {
    text-decoration: none;
    color: var(--text-sub);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 16px;
    transition: 0.3s;
    display: flex;
    align-items: center;
}

.menu-itemlog {
    text-decoration: none;
    color: var(--text-sub);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 16px;
    transition: 0.3s;
    display: flex;
    align-items: center;
}


.menu-item { background-color: #eff6ff; color: rgb(60, 73, 109); font-weight: 500; box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2); }
.menu-item:hover {transform: translateY(5px); background-color: #ffffff; color: #0c0303; }


.menu-itemlog { background-color: #fc9090; color: rgb(254, 254, 255); font-weight: 500; box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2); }
.menu-itemlog:hover {transform: translateY(5px); background-color: #ffffff; color: #ff2b2b; }



.menu-item.active {
    background: linear-gradient(135deg, #7d8aff, #244bfa);
    border-bottom: #0000004f 2px solid;
    /* ฟ้าเข้ม gradient */
    color: white;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);

}
.menu-item.active:hover { background-color: #d9e3f0; color: #171e52; }

/* Content */
.main-content {
    /* ⚠️ แก้ไข: ลบ margin-left ออก เพราะ Sidebar ไม่ได้ fixed แล้ว */
    /* margin-left: var(--sidebar-w); <--- ลบทิ้ง */
    
    /* ✅ สั่งให้ขยายเต็มพื้นที่ที่เหลือ */
    flex-grow: 1;
    width: calc(100% - var(--sidebar-w)); /* กันเหนียว */
    
    padding: 30px;
    overflow-x: hidden; /* กันเนื้อหาทะลุ */
}

.header-title { font-size: 24px; font-weight: 600; margin-bottom: 24px; }

.card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

/* Inputs & Buttons */
input, select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    background-color: #fff;
    transition: 0.2s;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }

button {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}
button:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
button.btn-danger { background-color: #fee2e2; color: var(--danger); }
button.btn-danger:hover { background-color: #fecaca; transform: translateY(0); }

/* 🔥 Custom Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s;
}
.modal-overlay.show { display: flex; opacity: 1; }

.modal-box {
    background: white;
    padding: 30px;
    border-radius: 24px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.2s;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}
.modal-overlay.show .modal-box { transform: scale(1); }

.modal-title { font-size: 20px; font-weight: 600; margin-bottom: 10px; }
.modal-text { color: var(--text-sub); margin-bottom: 24px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.btn-secondary { background-color: #e2e8f0; color: var(--text-main); }
.btn-secondary:hover { background-color: #cbd5e1; }

/* Mobile */
@media (max-width: 768px) {
    /* ⚠️ เปลี่ยนเป้าหมายจาก body เป็น #appContent */
    #appContent { flex-direction: column; }
    
    .sidebar {
        width: 100%; 
        height: auto; 
        min-height: auto;
        position: relative;
        border-right: none; 
        border-bottom: 1px solid var(--border);
        flex-direction: row; 
        justify-content: space-between; 
        padding: 15px 20px;
    }
    .logo { margin-bottom: 0; font-size: 18px; }
    .menu { flex-direction: row; gap: 5px; }
    .menu-item { padding: 8px 12px; font-size: 14px; white-space: nowrap; }
    
    .main-content { 
        width: 100%; 
        margin-left: 0; 
        padding: 20px; 
    }
}