/* ==========================================================================
   1. CORE VARIABLES & BASE (ค่ากำหนดหลัก)
   ========================================================================== */
:root {
    /* Color Palette */
    --primary-green: #10b981;    /* Emerald 500 */
    --hover-green: #059669;      /* Emerald 600 */
    --light-green: #ecfdf5;      /* Emerald 50 */
    --primary-orange: #f97316;   /* Orange 500 */
    --hover-orange: #ea580c;     /* Orange 600 */
    --text-header: #1e293b;      /* Slate 800 */
    --text-label: #334155;       /* Slate 700 */
    --bg-main: #f8fafc;          /* Slate 50 */
    
    /* Layout Sizes */
    --sidebar-width: 280px;
    --sidebar-mini-width: 80px;
    
    /* Transitions */
    --transition-speed: 0.3s;
    --transition-curve: cubic-bezier(0.4, 0, 0.2, 1);
}

body { 
    font-family: 'Kanit', sans-serif; 
    background-color: var(--bg-main);
    color: var(--text-header);
    margin: 0;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ==========================================================================
   2. LAYOUT & SIDEBAR (โครงสร้างหลักและการนำทาง)
   ========================================================================== */
#sidebar-container {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    transition: all var(--transition-speed) var(--transition-curve);
    background: white;
    z-index: 1001;
    position: relative;
    border-right: 1px solid #f1f5f9;
}

/* Sidebar Collapsed State (เมื่อกดปุ่ม Toggle) */
#sidebar-container.sidebar-collapsed { 
    width: var(--sidebar-mini-width) !important; 
    min-width: var(--sidebar-mini-width) !important;
}

#sidebar-container.sidebar-collapsed .sidebar-text,
#sidebar-container.sidebar-collapsed p,
#sidebar-container.sidebar-collapsed .fa-chevron-right { 
    display: none !important; 
}

/* Navigation Links */
.nav-link-modern {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #64748b;
    font-weight: 500;
    border-radius: 1.25rem; /* ความมนระดับ 20px */
    transition: all 0.2s ease;
    text-decoration: none;
    margin: 4px 12px;
    position: relative;
}

.nav-link-modern:hover, .nav-link-modern.active {
    background-color: var(--light-green) !important;
    color: var(--primary-green) !important;
}

.nav-link-modern.active::after {
    content: "";
    position: absolute;
    right: -12px; top: 20%;
    width: 4px; height: 60%;
    background-color: var(--primary-green);
    border-radius: 4px 0 0 4px;
}

.nav-icon { width: 24px; text-align: center; font-size: 1.1rem; }

/* ==========================================================================
   3. COMPONENTS & CARDS (องค์ประกอบหน้าเว็บ)
   ========================================================================== */

/* Glassmorphism Card (ใช้ใน Dashboard และหน้าฟอร์ม) */
.glass-card { 
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 2.5rem; /* ความมนระดับ 40px */
    border: 1px solid #f1f5f9; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.02); 
    transition: all 0.3s var(--transition-curve);
}

.glass-card:hover { 
    transform: translateY(-5px); 
    box-shadow: 0 15px 35px rgba(16, 185, 129, 0.08); 
}

/* Modern Inputs (สำหรับหน้า Profile และ New Ticket) */
.form-input-profile, .profile-input-field {
    width: 100%;
    background-color: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 1.25rem; /* ความมนระดับ 20px */
    padding: 0.875rem 1.25rem;
    font-size: 1rem;
    transition: all 0.3s ease;
    color: var(--text-header);
}

.form-input-profile:focus {
    border-color: var(--primary-orange);
    outline: none;
    box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.1);
}

/* Status Badges */
.status-badge {
    padding: 6px 16px;
    border-radius: 999px; /* ทรงแคปซูล */
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ==========================================================================
   4. BUTTONS (ปุ่มกดแบบมน)
   ========================================================================== */

/* ปุ่มบันทึก/ส่งข้อมูลหลัก */
.btn-save-full {
    background-color: var(--primary-orange);
    color: white;
    width: 100%;
    padding: 1.15rem;
    border-radius: 1.5rem !important; /* ความมนระดับ 24px */
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    border: none;
    transition: all 0.3s var(--transition-curve);
    box-shadow: 0 10px 15px -3px rgba(249, 115, 22, 0.2);
    cursor: pointer;
}

.btn-save-full:hover {
    background-color: var(--hover-orange);
    transform: translateY(-2px);
    box-shadow: 0 15px 25px rgba(249, 115, 22, 0.3);
}

/* ปุ่ม Logout */
.logout-btn-modern {
    width: calc(100% - 24px);
    margin: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    border-radius: 1.25rem !important;
    font-weight: 700;
    color: #ef4444;
    background: #fff1f2;
    transition: all 0.2s;
    border: 1px solid #fee2e2;
}

/* ==========================================================================
   5. UTILITIES (แอนิเมชัน และ Scrollbar)
   ========================================================================== */

/* Scrollbar เขียวอ่อนพรีเมียม */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f8fafc; }
::-webkit-scrollbar-thumb { 
    background: #a7f3d0; /* เขียวอ่อน Emerald 200 */
    border-radius: 10px; 
}
::-webkit-scrollbar-thumb:hover { background: #6ee7b7; }

/* Animation */
.fade-in {
    animation: fadeIn 0.5s ease-out;
}

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

/* Table Design (สำหรับหน้า My Tickets) */
.modern-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
}

.modern-table tr {
    background: white;
    border-radius: 1.25rem;
    transition: transform 0.2s ease;
}

.modern-table td {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid #f1f5f9;
    border-bottom: 1px solid #f1f5f9;

   
}

.modern-table td:first-child { border-left: 1px solid #f1f5f9; border-radius: 1.25rem 0 0 1.25rem; }
.modern-table td:last-child { border-right: 1px solid #f1f5f9; border-radius: 0 1.25rem 1.25rem 0; }

/* ==========================================================================
   8. MODAL & OVERLAYS (ส่วนควบคุมหน้าต่างป๊อปอัพ)
   ========================================================================== */

/* คลาสสำหรับปิด Scroll ของ Body เมื่อเปิด Modal */
.modal-open { 
    overflow: hidden !important; 
    padding-right: 6px; /* ป้องกันหน้าจอกระตุกจาก Scrollbar ที่หายไป */
}

/* ป้องกันหัวตาราง (Sticky Header) บังความมนของ Glass Card */
.sticky-header th:first-child { 
    border-top-left-radius: 2.5rem; 
}

.sticky-header th:last-child { 
    border-top-right-radius: 2.5rem; 
}

/* ส่วนเสริมสำหรับ Modal Content (ถ้าต้องการให้ทุกหน้าเหมือนกัน) */
.modal-content-modern {
    background: white;
    border-radius: 2.5rem;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* พื้นหลังมืด (Backdrop) */
.modal-backdrop-blur {
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
/* ==========================================================================
   9. MOBILE RESPONSIVE (แก้ไขเพิ่มเติมเพื่อรองรับมือถือ โดยไม่กระทบ Desktop)
   ========================================================================== */

@media (max-width: 1024px) {
    /* 1. จัดการ Sidebar: ในจอเล็กให้ซ่อนไว้ก่อน (รอ JS มาเปิด) */
    #sidebar-container {
        position: fixed;
        left: -100%; /* ซ่อนไปทางซ้าย */
        height: 100vh;
        z-index: 9999;
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }

    /* คลาสที่จะถูกเติมโดย layout.js เมื่อกดปุ่ม Hamburger */
    #sidebar-container.mobile-open {
        left: 0 !important;
    }

    /* 2. จัดการ Main Content: ไม่ให้โดน Sidebar ทับและลด Padding */
    #main-content {
        margin-left: 0 !important;
        padding: 15px !important;
        width: 100% !important;
        min-width: 100% !important;
    }

    /* 3. จัดการ Card: ลดความมนลงเล็กน้อยเพื่อให้เหลือพื้นที่เนื้อหามากขึ้น */
    .glass-card {
        border-radius: 1.5rem !important; /* ลดจาก 2.5rem */
        padding: 1.25rem !important;
    }

    /* 4. จัดการ Table: บังคับให้ปัดซ้าย-ขวาได้ (สำคัญมาก) */
    .table-container-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modern-table {
        min-width: 600px; /* ป้องกันตารางบีบตัวจนอ่านไม่ออก */
    }

    /* 5. จัดการ Input และ Button: ปรับขนาดให้เหมาะกับนิ้วกด */
    .form-input-profile, .btn-save-full {
        font-size: 16px !important; /* ป้องกัน iOS ซูมหน้าจออัตโนมัติเมื่อคลิก Input */
    }
}

/* แถม: ส่วนแสดงผลเมื่อเปิดผ่านมือถือให้มีปุ่ม Hamburger */
#mobile-header-bar {
    display: none;
}

@media (max-width: 1024px) {
    #mobile-header-bar {
        display: flex;
        align-items: center;
        padding: 10px 20px;
        background: white;
        border-bottom: 1px solid #f1f5f9;
        position: sticky;
        top: 0;
        z-index: 1000;
    }
}
/* ==========================================================================
   10. SWEETALERT & NOTIFICATION FIX (แก้ไขแจ้งเตือนไม่กลางจอ)
   ========================================================================== */
.swal2-container {
    z-index: 10000 !important; /* ให้อยู่เหนือทุกอย่างรวมถึง Sidebar */
}

/* บังคับให้แจ้งเตือนอยู่กลางหน้าจอเสมอในมือถือ */
@media (max-width: 1024px) {
    .swal2-popup {
        margin: auto !important;
        width: 90% !important; /* ให้เหลือขอบข้างเล็กน้อย */
        border-radius: 1.5rem !important; /* ความมนให้เข้ากับ Glass Card */
    }
    
    /* กรณีใช้ Toast (แจ้งเตือนมุมจอ) ให้ขยับมาตรงกลางบนสุด */
    .swal2-container.swal2-top-end,
    .swal2-container.swal2-top {
        justify-content: center !important;
        align-items: flex-start !important;
        padding-top: 20px !important;
    }
}

/* style.css */
:root {
    --bg-main: #f8fafc;
    --text-header: #1e293b;
    --card-bg: #ffffff;
    --border-color: #f1f5f9;
}

/* เมื่อมี class .dark ที่ <html> หรือ <body> */
.dark {
    --bg-main: #0f172a;    /* สีกรมท่าเข้มมาก */
    --text-header: #f1f5f9; /* สีตัวอักษรขาวเทา */
    --card-bg: #1e293b;    /* สีการ์ดเข้ม */
    --border-color: #334155;
}

body {
    background-color: var(--bg-main);
    color: var(--text-header);
    transition: background-color 0.3s ease; /* เพิ่มความสมูทตอนเปลี่ยนโหมด */
}

/* ปรับสี glass-card ในโหมดมืด */
.dark .glass-card {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    color: var(--text-header);
}

/* ปรับสี Input ในโmotherมืด */
.dark .form-input-profile {
    background-color: #334155;
    border-color: #334155;
    color: white;
}

/* สไตล์ Tab แบบ Modern Glassmorphism */
.tabs-container {
    display: flex;
    gap: 12px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.tab-btn {
    position: relative;
    padding: 10px 24px;
    border-radius: 16px;
    font-weight: 600;
    font-size: 0.875rem;
    color: #94a3b8; /* slate-400 */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--primary-green);
    background: rgba(255, 255, 255, 0.8);
}

.tab-btn.active {
    color: white;
    background: var(--primary-green);
    box-shadow: 0 8px 15px rgba(16, 185, 129, 0.25);
    transform: translateY(-2px);
}

/* จุดสถานะสีขาวในแท็บที่เลือก */
.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: white;
    border-radius: 50%;
}

/* Badge ตัวเลข (ถ้าต้องการใช้) */
.tab-count {
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.05);
    font-size: 0.7rem;
}

.tab-btn.active .tab-count {
    background: rgba(255, 255, 255, 0.2);
}
/* การเลือกสถานะแบบการ์ดที่ล้อตามสไตล์ Tab */
.status-card-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 5px;
    background: #f8fafc;
    border: 2px solid #f1f5f9;
    border-radius: 1.25rem; /* 20px ตามโครงสร้างเดิม */
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.2s var(--transition-curve);
}

.status-card-selector:hover {
    background: white;
    border-color: #cbd5e1;
    color: var(--text-label);
}

/* สถานะ Active ของแต่ละสี */
.status-card-selector.active-success {
    background: var(--light-green);
    border-color: var(--primary-green);
    color: var(--primary-green);
    box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.1);
}

.status-card-selector.active-progress {
    background: #fff7ed;
    border-color: var(--primary-orange);
    color: var(--primary-orange);
    box-shadow: 0 10px 15px -3px rgba(249, 115, 22, 0.1);
}

.status-card-selector.active-reject {
    background: #fff1f2;
    border-color: #ef4444;
    color: #ef4444;
    box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.1);
}
