/* =========================================
   1. CORE VARIABLES & SETUP
   ========================================= */
:root {
    --bg-dark: #0f172a;       /* สีพื้นหลังหลัก */
    --glass-bg: rgba(255, 255, 255, 0.05); /* สีพื้นกระจก */
    --neon-blue: #0ea5e9;     /* สีนีออนฟ้า */
    --neon-pink: #d946ef;     /* สีนีออนชมพู */
    --text-main: #e2e8f0;     /* สีตัวหนังสือหลัก */
    --sidebar-width: 260px;
}

body {
    background-color: var(--bg-dark);
    /* พื้นหลัง Gradient ให้ดูมีมิติ */
    background-image: radial-gradient(circle at 10% 20%, rgba(14, 165, 233, 0.08) 0%, transparent 20%),
                      radial-gradient(circle at 90% 80%, rgba(217, 70, 239, 0.08) 0%, transparent 20%);
    font-family: 'Kanit', sans-serif;
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden; /* ป้องกันเลื่อนซ้ายขวา */
}

a { text-decoration: none; }

/* =========================================
   2. LAYOUT & SIDEBAR (แก้ไข Scroll)
   ========================================= */
.wrapper {
    display: flex;
    width: 100%;
}

/* Sidebar สไตล์กระจก + เลื่อนได้ */
#sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    height: 100vh; /* ความสูงเต็มจอ */
    background: rgba(15, 23, 42, 0.95); /* สีพื้นหลังเข้มขึ้นเพื่อให้อ่านง่าย */
    backdrop-filter: blur(15px);
    border-right: 1px solid rgba(255,255,255,0.1);
    transition: all 0.3s;
    position: fixed; /* ล็อคตำแหน่ง */
    top: 0;
    left: 0;
    z-index: 999;
    overflow-y: auto; /* *** สำคัญ: ให้เลื่อนขึ้นลงได้ *** */
}

#sidebar .sidebar-header {
    padding: 25px 20px;
    background: rgba(255,255,255,0.02);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

#sidebar ul.components {
    padding: 15px 0;
}

#sidebar ul li a {
    padding: 12px 25px;
    font-size: 1em;
    display: block;
    color: var(--text-main);
    transition: 0.3s;
    border-left: 4px solid transparent;
}

#sidebar ul li a:hover, 
#sidebar ul li a.active, 
#sidebar ul li a[aria-expanded="true"] {
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.15), transparent);
    color: var(--neon-blue);
    border-left: 4px solid var(--neon-blue);
    text-shadow: 0 0 10px rgba(14, 165, 233, 0.5);
}

#sidebar ul li a i {
    margin-right: 12px;
    width: 25px;
    text-align: center;
}

/* Dropdown Menu ใน Sidebar */
#sidebar ul ul a {
    font-size: 0.9em;
    padding-left: 55px !important;
    background: rgba(0,0,0,0.2);
}

/* เนื้อหาหลัก (ขยับหนี Sidebar) */
#content {
    width: 100%;
    margin-left: var(--sidebar-width);
    padding: 20px;
    min-height: 100vh;
    transition: all 0.3s;
}

/* Navbar บนสุด */
.top-navbar {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding: 15px 30px;
    margin-bottom: 30px;
    border-radius: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* =========================================
   3. COMPONENTS & UI ELEMENTS
   ========================================= */

/* Glassmorphism Card (การ์ดกระจก) */
.glass-box {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

/* Custom Input Fields */
.form-control, .form-select {
    background: rgba(0, 0, 0, 0.3) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: #fff !important;
    border-radius: 8px;
}

.form-control:focus, .form-select:focus {
    background: rgba(0, 0, 0, 0.5) !important;
    border-color: var(--neon-blue) !important;
    box-shadow: 0 0 10px rgba(14, 165, 233, 0.3) !important;
}

/* Placeholder สีจางๆ */
::placeholder { color: rgba(255,255,255,0.4) !important; }

/* ปุ่มกดสไตล์นีออน */
.btn-neon {
    background: linear-gradient(135deg, var(--neon-blue), #2563eb);
    border: none;
    color: white;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
}

.btn-neon:hover {
    box-shadow: 0 0 20px var(--neon-blue);
    transform: translateY(-2px);
    color: white;
}

/* ตาราง */
.table-dark {
    background-color: transparent !important;
    --bs-table-bg: transparent;
}
.table-hover tbody tr:hover {
    background-color: rgba(255,255,255,0.05) !important;
}
td, th { border-color: rgba(255,255,255,0.1) !important; }

/* Modal (หน้าต่างเด้ง) */
.modal-content {
    background: #1e293b; /* สีพื้นหลังโมดอล */
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}
.btn-close { filter: invert(1); } /* กากบาทสีขาว */

/* =========================================
   4. SCROLLBAR CUSTOMIZATION (แถบเลื่อนสวยๆ)
   ========================================= */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1); 
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2); 
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--neon-blue); 
}

/* สำหรับ Sidebar โดยเฉพาะ (ให้เล็กหน่อย) */
#sidebar::-webkit-scrollbar {
    width: 5px;
}

/* =========================================
   5. PRINTING (สำหรับการพิมพ์บิล)
   ========================================= */
@media print {
    .no-print, #sidebar, .top-navbar { display: none !important; }
    .wrapper { display: block; width: 100%; }
    #content { margin: 0; padding: 0; width: 100%; }
    body { background: white; color: black; }
    .glass-box { 
        border: 1px solid #ddd; 
        box-shadow: none; 
        background: white !important; 
        color: black !important; 
    }
    .text-white { color: black !important; }
}
/* การแสดงผลบนมือถือ/PDA */
@media (max-width: 768px) {
    #sidebar { margin-left: -260px; } /* ซ่อนเมนู */
    #sidebar.active { margin-left: 0; } /* กดแล้วค่อยโชว์ */
    #content { margin-left: 0; width: 100%; }
    .top-navbar { padding: 10px; }
    
    /* ปรับช่องสแกนให้ใหญ่กดง่าย */
    #scanInput { height: 60px; font-size: 24px; }
}
/* Custom Accordion for Dark Theme */
.accordion-button {
    background-color: rgba(255,255,255,0.05) !important;
    color: var(--text-main) !important;
    border: 1px solid rgba(255,255,255,0.1);
}

.accordion-button:not(.collapsed) {
    background-color: rgba(14, 165, 233, 0.2) !important; /* สีฟ้านีออนจางๆ ตอนเปิด */
    color: var(--neon-blue) !important;
    box-shadow: none;
}

.accordion-button::after {
    filter: invert(1); /* เปลี่ยนลูกศรเป็นสีขาว */
}

.accordion-item {
    background-color: transparent;
    border: none;
}

.accordion-body {
    background-color: rgba(0,0,0,0.2) !important;
    border: 1px solid rgba(255,255,255,0.05);
    border-top: none;
    border-radius: 0 0 10px 10px;
    line-height: 1.8;
}