@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;600;700&display=swap');

/* =========================================
   1. Variables & Reset (ธีมหลัก)
   ========================================= */
:root {
    --primary-green: #133d55;    /* สีหลัก (Sidebar, Headings) */
    --soft-green: #a3b1a4;       /* สีรอง/Border Focus */
    --bg-cream: #f4f5f0;         /* พื้นหลัง */
    --text-dark: #4a4a4a;        /* สีตัวอักษร */
    --white: #ffffff;
    --shadow: 0 10px 30px rgba(0,0,0,0.08);
    --input-bg: #fafafa;
    --danger: #e74c3c;
    --sidebar-width: 260px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Sarabun', sans-serif;
}

body {
    background-color: var(--bg-cream);
    color: var(--text-dark);
    font-size: 16px;
    min-height: 100vh;
    overflow-x: hidden;
}

/* =========================================
   2. Layout Utilities
   ========================================= */
.flex-center-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100%;
}

/* =========================================
   3. Sidebar Layout (New & Improved)
   ========================================= */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--primary-green);
    color: var(--white);
    position: fixed;
    top: 0; left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column; /* จัดเรียงแนวตั้ง เพื่อดัน footer ลงล่าง */
    box-shadow: 4px 0 20px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.sidebar-header {
    padding: 25px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 10px;
}

.sidebar-header h4 {
    font-weight: 700;
    font-size: 1.4rem;
    margin: 0;
    letter-spacing: 1px;
}

.sidebar-header p {
    font-size: 0.8rem;
    color: var(--soft-green);
    margin-top: 5px;
    opacity: 0.8;
}

/* ส่วนเมนู Scroll ได้ถ้าหน้าจอยาวไม่พอ */
.nav-links {
    flex: 1;
    padding: 10px 15px;
    overflow-y: auto;
}

.sidebar a {
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    display: flex;
    align-items: center;
    padding: 12px 20px;
    font-size: 0.95rem;
    margin-bottom: 5px;
    border-radius: 10px; /* ขอบมนสวยงาม */
    transition: all 0.3s ease;
}

.sidebar a:hover {
    background-color: rgba(255,255,255,0.1);
    color: var(--white);
    transform: translateX(5px);
}

.sidebar a.active {
    background-color: var(--white);
    color: var(--primary-green);
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.sidebar a i { 
    width: 25px; 
    margin-right: 12px; 
    text-align: center; 
    font-size: 1.1rem;
}

/* ส่วน Footer ของ Sidebar (ปุ่ม Logout) */
.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px;
    background-color: rgba(231, 76, 60, 0.15);
    color: #ff6b6b;
    border-radius: 8px;
    text-decoration: none;
    transition: 0.3s;
    font-weight: 600;
}

.btn-logout:hover {
    background-color: #e74c3c;
    color: white;
}

/* =========================================
   3.5 Top Navbar & Main Content Wrapper
   ========================================= */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-navbar {
    height: 70px;
    background-color: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.04);
    position: sticky;
    top: 0;
    z-index: 900;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-info {
    text-align: right;
    line-height: 1.2;
}

.user-info span {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary-green);
}

.user-info small {
    font-size: 0.8rem;
    color: #888;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background-color: var(--primary-green);
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 0.9rem;
}

/* พื้นที่เนื้อหาจริง (เว้นระยะจาก Navbar) */
.content-wrapper {
    padding: 30px 40px;
    flex: 1;
}

/* =========================================
   4. Cards (Login & Dashboard)
   ========================================= */
/* Login Card */
.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
    animation: fadeIn 0.8s ease-out;
}

.login-card {
    background: var(--white);
    padding: 40px 30px;
    border-radius: 24px;
    box-shadow: var(--shadow);
    text-align: center;
}

/* Dashboard Card */
.card-custom {
    background: var(--white);
    border-radius: 20px;
    box-shadow: var(--shadow);
    border: none;
    margin-bottom: 25px;
    overflow: hidden;
    height: 100%; /* ให้ยืดเต็ม Column */
}

.card-header-custom {
    background-color: var(--primary-green);
    color: var(--white);
    padding: 15px 20px;
    font-weight: 600;
    font-size: 16px;
    border-bottom: none;
}

.card-body-custom {
    padding: 25px;
}

/* =========================================
   5. Forms & Inputs
   ========================================= */
.form-label, .input-group label {
    display: block;
    font-size: 14px;
    margin-bottom: 6px;
    color: var(--primary-green);
    font-weight: 600;
}

.form-control, .form-select, .input-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #eee;
    border-radius: 10px;
    outline: none;
    transition: all 0.2s ease;
    background-color: var(--input-bg);
    font-size: 15px;
    color: var(--text-dark);
}

.form-control:focus, .form-select:focus, .input-group input:focus {
    border-color: var(--soft-green);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(163, 177, 164, 0.2);
}

.input-group { margin-bottom: 20px; text-align: left; }

/* =========================================
   6. Buttons
   ========================================= */
.btn-theme, .btn-login {
    padding: 10px 24px;
    background-color: var(--primary-green);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(19, 61, 85, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn-theme:hover, .btn-login:hover {
    background-color: #0f3246;
    transform: translateY(-2px);
    color: white;
    box-shadow: 0 6px 15px rgba(19, 61, 85, 0.3);
}

/* =========================================
   7. Loading Overlay & Animations
   ========================================= */
.overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.85);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.spinner {
    width: 45px; height: 45px;
    border: 4px solid #e0e0e0;
    border-top: 4px solid var(--primary-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   8. Specific Components (Profile/HN)
   ========================================= */
.profile-pic-box {
    border: 2px dashed #ccc;
    background-color: #fafafa;
    border-radius: 12px;
    height: 100%;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #888;
    cursor: pointer;
    transition: all 0.3s;
}

.profile-pic-box:hover {
    background-color: #fff;
    border-color: var(--primary-green);
    color: var(--primary-green);
}

.hn-box {
    background-color: #e9ecef;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    border: 1px solid #dee2e6;
}

.hn-number {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-dark);
    letter-spacing: 1px;
}

/* =========================================
   9. Responsive
   ========================================= */
@media (max-width: 992px) {
    :root { --sidebar-width: 80px; }

    .sidebar-header h4, .sidebar-header p, .user-info, 
    .sidebar a span, .sidebar-footer span { 
        display: none; 
    }
    
    .sidebar-header { padding: 15px 0; }
    .sidebar a { justify-content: center; padding: 15px 0; }
    .sidebar a i { margin: 0; font-size: 1.4rem; }
    
    .btn-logout { padding: 12px 0; }
    .btn-logout i { margin: 0 !important; font-size: 1.2rem; }
    
    .top-navbar { padding: 0 20px; }
    .content-wrapper { padding: 20px; }
}

@media (max-width: 576px) {
    :root { --sidebar-width: 0px; } /* ซ่อน Sidebar บนมือถือ */
    
    .sidebar { transform: translateX(-100%); width: 240px; }
    .sidebar.show { transform: translateX(0); }
    
    .sidebar-header h4, .sidebar a span, .sidebar-footer span { 
        display: inline-block; 
    }
    .sidebar a { justify-content: flex-start; padding: 12px 20px; }
    .sidebar a i { margin-right: 12px; }
    
    .top-navbar h5 { font-size: 1rem; }
    .content-wrapper { padding: 15px; }
}

/* ปรับปรุงหน้า Login สำหรับ Tablet และ Mobile */
@media (max-width: 768px) {
    .login-container {
        max-width: 90%; /* ขยายความกว้างให้เกือบเต็มหน้าจอ */
        padding: 10px;
    }

    .login-card {
        padding: 30px 20px; /* ลด Padding ภายในลงเล็กน้อย */
        border-radius: 20px;
        /* ขยับขึ้นด้านบนเล็กน้อยเพื่อให้ดูเด่น */
        margin-top: -10vh; 
    }

    .login-header h2 {
        font-size: 1.5rem;
    }

    .btn-login {
        width: 100%; /* ปุ่มเต็มความกว้าง */
        padding: 14px; /* เพิ่มความสูงปุ่มให้กดง่ายขึ้นบนจอสัมผัส */
    }
}

/* สำหรับมือถือขนาดเล็กมาก */
@media (max-width: 480px) {
    .login-card {
        margin-top: 0; /* กลับมาอยู่กึ่งกลางปกติถ้าจอสั้นมาก */
        padding: 25px 15px;
    }
}