@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap');
@font-face { font-family: 'THSarabun'; src: url('../../fonts/THSarabun.ttf') format('truetype'); }

/* =========================================
   1. GLOBAL STYLES (ตั้งค่าพื้นฐาน)
========================================= */
body { font-family: 'Prompt', sans-serif; background-color: #f0f2f5; margin: 0; padding: 0; }
.flex-row { display: flex; gap: 20px; width: 100%; }
.flex-1 { flex: 1; width: 100%; }
.mb-spacing { margin-bottom: 25px !important; }
.text-danger { color: #dc3545 !important; }
.text-primary { color: #0A3D73 !important; }

/* =========================================
   2. FRONTEND STYLES (หน้าค้นหา & หน้า Preview)
========================================= */
body.frontend-body { display: flex; flex-direction: column; min-height: 100vh; }
.cmat-header { background: #0A3D73; color: white; padding: 12px 5%; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 4px 15px rgba(0,0,0,0.1); position: sticky; top: 0; z-index: 1000; }
.cmat-header-left { display: flex; align-items: center; gap: 15px; }
.cmat-header-left img { height: 50px; background: transparent; padding: 0; border-radius: 0; }
.cmat-header-left h1 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.3; }
.cmat-header-left p { margin: 0; font-size: 12px; color: rgba(255,255,255,0.7); }
.cmat-nav { display: flex; gap: 20px; }
.cmat-nav a { color: white; text-decoration: none; font-size: 14px; font-weight: 500; transition: color 0.3s; display: flex; align-items: center; gap: 6px; }
.cmat-nav a:hover, .cmat-nav a.active { color: #FBB03B; }

.content-wrapper { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 40px 20px; width: 100%; box-sizing: border-box; }
.main-container { width: 100%; display: flex; flex-direction: column; align-items: center; }
.search-container { max-width: 750px; }
.preview-container-wrapper { max-width: 900px; }

.public-card, .preview-main-card { background: #fff; padding: 40px 50px; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); width: 100%; box-sizing: border-box; margin-bottom: 20px; display: flex; flex-direction: column; align-items: center; }
.highlight-subtitle { background: #f8f9fa; border: 1px solid #eaeaea; border-top: 4px solid #0A3D73; padding: 18px 20px; border-radius: 12px; margin-bottom: 35px; text-align: center; width: 100%; max-width: 800px; }
.highlight-subtitle p { margin: 0; color: #555; font-size: 14.5px; line-height: 1.6; }
.highlight-subtitle b { color: #0A3D73; font-size: 16px; display: block; margin-bottom: 8px; }
.warning-box { background: #fff3cd; padding: 15px 20px; border-radius: 8px; border: 1px solid #ffe69c; color: #664d03; text-align: center; width: 100%; max-width: 800px; margin-bottom: 30px; }
.warning-box h4 { margin: 0 0 5px 0; font-size: 15px; font-weight: 700; }
.warning-box p { margin: 0; font-size: 14px; line-height: 1.5; }

.cmat-footer { background: #06203a; color: rgba(255,255,255,0.6); text-align: center; padding: 35px 20px; font-size: 13.5px; border-top: 4px solid #FBB03B; width: 100%; box-sizing: border-box; }
.cmat-footer b { color: white; font-size: 15px; }
.cmat-footer a { color: #FBB03B; text-decoration: none; font-weight: 500; transition: 0.3s; }
.cmat-footer a:hover { color: white; }

/* =========================================
   3. BACKEND STYLES (ระบบแอดมิน)
========================================= */
body.admin-body { background-color: #f4f7f6; margin: 0; display: flex; flex-direction: column; min-height: 100vh; }

.admin-body .cmat-header { height: 75px; position: fixed; width: 100%; top: 0; left: 0; z-index: 1001; display: flex; justify-content: space-between; align-items: center; padding: 0 25px; box-sizing: border-box; background: #0A3D73; color: white; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
.admin-body .cmat-header-left { display: flex; align-items: center; gap: 15px; }
.admin-body .cmat-header-left img { height: 45px; background: transparent; padding: 0; border-radius: 0; }
.admin-body .cmat-header-left h1 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.3; color: white; }
.admin-body .cmat-header-left p { margin: 0; font-size: 12px; color: rgba(255,255,255,0.7); }

.admin-full-footer { width: 100%; margin: 0 !important; position: relative; z-index: 105; box-sizing: border-box; }

.topbar-right { display: flex; align-items: center; position: relative; }
.user-profile { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 5px 12px; border-radius: 50px; transition: background 0.3s; border: 1px solid transparent; }
.user-profile:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); }
.user-name-badge { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 14.5px; font-weight: 700; color: white; }
.user-role-badge { background-color: #E5A822; color: #000; font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; }
.user-avatar { font-size: 30px; color: white; line-height: 1; }

.user-dropdown-menu { display: none; position: absolute; top: calc(100% + 10px); right: 0; background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,0.1); border-radius: 12px; width: 220px; padding: 8px 0; border: 1px solid #eaeaea; z-index: 1002; animation: fadeDown 0.2s ease-out; }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.user-dropdown-menu .dropdown-header { padding: 10px 15px; background: #f8f9fa; margin-bottom: 5px; border-bottom: 1px solid #eaeaea; display: none;}
.user-dropdown-menu a { display: flex; align-items: center; gap: 10px; padding: 10px 18px; color: #444; text-decoration: none; font-size: 13.5px; font-weight: 500; transition: background 0.2s;}
.user-dropdown-menu a:hover { background: #f0f2f5; color: #0A3D73; }

.admin-wrapper { flex: 1; display: flex; width: 100%; padding-top: 75px; box-sizing: border-box; }
.sidebar { width: 260px; background: linear-gradient(180deg, #0A3D73 0%, #06203a 100%); color: white; padding: 20px 12px; position: fixed; top: 75px; height: calc(100vh - 75px); overflow-y: auto; z-index: 100; box-sizing: border-box; transition: 0.3s; box-shadow: 4px 0 15px rgba(0,0,0,0.05); }

.sidebar-title { font-size: 10.5px; font-weight: 700; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 1px; margin: 10px 0 5px 12px; }
.sidebar a.nav-link, .sidebar a.out-link { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,0.7); text-decoration: none; padding: 10px 15px; border-radius: 8px; margin-bottom: 2px; font-size: 13px; font-weight: 500; transition: all 0.3s ease; }
.sidebar a.nav-link i, .sidebar a.out-link i { font-size: 16px; }
.sidebar a.nav-link:hover, .sidebar a.out-link:hover { color: #fff; background: rgba(255,255,255,0.1); transform: translateX(5px); }
.sidebar a.nav-link.active { background: #E5A822; color: #000; font-weight: 700; box-shadow: 0 4px 10px rgba(229, 168, 34, 0.3); transform: translateX(5px); }

.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); z-index: 99; opacity: 0; transition: opacity 0.3s; }
.sidebar-overlay.active { display: block; opacity: 1; }

.content { flex: 1; padding: 35px 40px 40px 40px; margin-left: 260px; box-sizing: border-box; width: calc(100% - 260px); transition: 0.3s; display: flex; flex-direction: column; }
.tab-section { display: none; animation: fadeIn 0.3s ease; }
.tab-section.active { display: block; }

.stat-card { background: #fff; padding: 20px 15px; border-radius: 16px; text-align: center; box-shadow: 0 4px 20px rgba(0,0,0,0.03); border: 1px solid #eaeaea; border-bottom: 5px solid; transition: transform 0.3s; }
.stat-card:hover { transform: translateY(-5px); }
.stat-card.primary { border-bottom-color: #0A3D73; } .stat-card.primary h1 { color: #0A3D73; }
.stat-card.success { border-bottom-color: #198754; } .stat-card.success h1 { color: #198754; }
.stat-card.danger { border-bottom-color: #dc3545; } .stat-card.danger h1 { color: #dc3545; }
.stat-card h6 { color: #6c757d; font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.stat-card h1 { margin: 0; font-size: 36px; font-weight: 700; line-height: 1; }

.card { background: #fff; border: none; border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,0.04); padding: 25px; margin-bottom: 30px;}
.card-header { border-bottom: 2px solid #f0f2f5; padding-bottom: 15px; margin-bottom: 20px; font-weight: 700; font-size: 16px !important; color: #0A3D73; margin-top: 0;}

/* =========================================
   4. FORMS, BUTTONS & MODALS
========================================= */
.form-label { font-weight: 600; color: #444; margin-bottom: 8px; display: block; font-size: 14px; }
.form-control, .form-select { width: 100%; padding: 12px 15px; border: 1px solid #dce1e6; border-radius: 8px; font-size: 14px; font-family: 'Prompt', sans-serif; box-sizing: border-box; margin-bottom: 20px; transition: all 0.3s; }
.form-control:focus, .form-select:focus { border-color: #0A3D73; outline: none; box-shadow: 0 0 0 3px rgba(10, 61, 115, 0.1); }

.name-input-group { display: flex; gap: 15px; width: 100%; }
.prefix-input { width: 130px; flex-shrink: 0; }

.btn { padding: 10px 20px; font-size: 14px; border-radius: 8px; transition: 0.3s; border: none; cursor: pointer; font-family: 'Prompt', sans-serif;}
.btn:hover { filter: brightness(0.95); transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
.btn-primary { background: #0A3D73; color: white; }
.btn-success { background: #198754; color: white; }
.btn-danger { background: #dc3545; color: white; }
.btn-warning { background: #FBB03B; color: #000; }
.btn-info { background: #0dcaf0; color: #000; }
.btn-outline { background: #fff; border: 1px solid #ccc; color: #333; }

.btn-modern { border-radius: 50px; padding: 12px 25px; font-size: 15px; font-weight: 600; transition: all 0.3s ease; display: inline-flex; justify-content: center; align-items: center; cursor: pointer; border: none; }
.btn-wrapper { text-align: center; margin-top: 10px; width: 100%; }
.search-btn { padding: 12px 40px; font-size: 16px; }
.action-bar { display: flex; flex-direction: row; justify-content: center; gap: 20px; width: 100%; max-width: 600px; }

.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); z-index: 9999; align-items: center; justify-content: center; backdrop-filter: blur(2px);}
.modal-content { background: #fff; padding: 30px; border-radius: 12px; width: 100%; max-width: 500px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); max-height: 90vh; overflow-y: auto;}

.pass-wrapper { position: relative; } 
.pass-eye { position: absolute; right: 15px; top: 50%; transform: translateY(-50%); cursor: pointer; color: #6c757d; font-size: 1.2rem; z-index: 10;}

.chk-lg { width: 18px; height: 18px; cursor: pointer; }
.badge { padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; background: #eee; color: #555; display: inline-block; white-space: nowrap; } 
.bg-success { background: #d4edda !important; color: #155724 !important; } 
.bg-warning { background: #fff3cd !important; color: #856404 !important; }
.bg-danger { background: #f8d7da !important; color: #721c24 !important; }
.bg-secondary { background: #e2e3e5 !important; color: #383d41 !important; }

/* =========================================
   5. CERTIFICATE PREVIEW
========================================= */
.preview-container, .preview-container-real { position: relative; width: 100%; max-width: 800px; aspect-ratio: 210/148.5; background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,0.1); overflow: hidden; border-radius: 6px; border: 1px solid #eaeaea; margin-bottom: 30px; container-type: inline-size; }
.preview-bg, .preview-bg-real { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: fill; z-index: 1; }
.preview-text-name, .preview-text-name-real { position: absolute; width: 100%; text-align: center; line-height: 1; margin: 0; white-space: nowrap; z-index: 10; font-family: 'THSarabun', sans-serif;}
.preview-text-cert, .preview-text-cert-real { position: absolute; line-height: 1; margin: 0; white-space: nowrap; z-index: 10; font-family: 'THSarabun', sans-serif;}

/* =========================================
   6. SETTINGS & DATATABLES
========================================= */
.dataTables_wrapper .dataTables_length { margin-bottom: 15px; float: left; }
.dataTables_wrapper .dataTables_filter { margin-bottom: 15px; float: right; }
.dataTables_wrapper::after { content: ""; clear: both; display: table; } 
.dt-buttons { display: none !important; } 
#tableTrainees, #tableReport, .dataTable, .table { font-size: 13px !important; width: 100% !important;} 
#tableTrainees td, #tableReport td { padding: 8px 10px !important; vertical-align: middle; }
.dataTables_filter input { padding: 6px 12px; border: 1px solid #ccc; border-radius: 8px; margin-left: 8px; font-size: 13.5px; } 
.dataTables_length select { padding: 5px 10px; border: 1px solid #ccc; border-radius: 8px; margin: 0 5px; font-size: 13.5px; } 
.text-truncate-course { max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: middle; } 

.settings-wrapper { display: flex; gap: 25px; align-items: flex-start; }
.settings-controls { flex: 0 0 360px; }
.settings-preview { flex: 1; width: 100%; position: sticky; top: 85px; z-index: 10; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.input-group-custom label { font-size: 12px; color: #555; font-weight: 600; margin-bottom: 4px; display: block; }
.input-group-custom .form-control { width: 100%; padding: 4px 8px; font-size: 13px; height: 32px; border-radius: 6px; margin-bottom:0; }
.input-group-custom input[type="color"] { height: 32px; padding: 1px; border-radius: 6px; }
.input-group-custom .checkbox-label { height: 32px; display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #dce1e6; border-radius: 6px; padding: 0 10px; cursor: pointer; font-weight: 600; color: #444; transition: 0.2s; font-size: 13px;}

.error-box { background: #ffebee; color: #dc3545; padding: 12px; border-radius: 8px; margin-bottom: 20px; text-align: center; font-weight: 600; font-size: 14px; border: 1px solid #ffcdd2; width: 100%; box-sizing: border-box; }
.captcha-box { display: flex; align-items: center; justify-content: space-between; background: #f8f9fa; padding: 10px 15px; border: 1px solid #dce1e6; border-radius: 8px; margin-bottom: 10px; }
.captcha-box img { border-radius: 6px; mix-blend-mode: multiply; height: 35px; }
.captcha-btn { background: none; border: none; font-size: 22px; cursor: pointer; color: #0A3D73; transition: transform 0.3s; }
.captcha-btn:hover { transform: rotate(90deg); }

/* =========================================
   7. RESPONSIVE (รองรับมือถือ)
========================================= */
/* 🔴 ตั้งค่าสีปุ่มให้เป็นสีขาว (White) อย่างเด็ดขาด */
.mobile-menu-btn { display: none; background: none; color: #ffffff !important; font-size: 28px; padding: 0; margin-right: 12px; border: none; cursor: pointer; }

@media (max-width: 1100px) {
    .settings-wrapper { flex-direction: column; }
    .settings-controls { flex: 1; width: 100%; }
    .settings-preview { position: static; top: auto; margin-bottom: 20px; } 
}

@media (max-width: 991px) {
    .admin-body .cmat-header { height: 60px; padding: 10px 15px; }
    .admin-body .cmat-header-left img { height: 35px; }
    
    /* 🔴 ซ่อนข้อความยาวๆ ข้างโลโก้บนมือถือ เพื่อไม่ให้กินพื้นที่และดันเลย์เอาท์ */
    .admin-body .cmat-header-left div { display: none !important; }

    .admin-wrapper { padding-top: 60px; }
    
    .sidebar { top: 60px; height: calc(100vh - 60px); transform: translateX(-100%); }
    .sidebar.active { transform: translateX(0); }
    
    .content { margin-left: 0; width: 100%; padding: 15px 15px 25px 15px; }
    .card { padding: 15px; margin-bottom: 20px; }
    .card-body { padding: 5px !important; }
    .stat-card { padding: 15px; }
    .stat-card h1 { font-size: 32px; }
    
    /* 🔴 แสดงปุ่ม Hamburger */
    .mobile-menu-btn { display: block; margin-right: 10px; font-size: 24px; }
    
    .user-name-badge { display: none !important; }
    .user-avatar { font-size: 26px; }
    .user-dropdown-menu .dropdown-header { display: block; }
    .admin-body .cmat-footer { margin-left: -15px; margin-right: -15px; padding: 25px 15px; }
    
    .text-truncate-course { max-width: 150px; }
    .flex-row { flex-direction: column; gap: 10px; width: 100%; }
    
    .name-input-group { flex-direction: column; gap: 0; }
    .prefix-input { width: 100%; margin-bottom: 15px; }

    .dataTables_wrapper .top { flex-direction: column !important; align-items: stretch !important; gap: 10px; margin-bottom: 15px !important;}
    .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter { float: none; text-align: left; width: 100%; margin-bottom: 5px; }
    .dataTables_wrapper .dataTables_filter label { display: flex; flex-direction: column; width: 100%; font-weight: 600;}
    .dataTables_wrapper .dataTables_filter input { width: 100%; margin-left: 0; margin-top: 5px; box-sizing: border-box; }
}

@media (max-width: 768px) {
    .frontend-body .cmat-header { flex-direction: column; gap: 15px; padding: 15px 20px; text-align: center; height: auto; }
    .frontend-body .cmat-header-left { flex-direction: column; gap: 10px; }
    .public-card, .preview-main-card { padding: 30px 20px; }
    .btn-modern.search-btn { width: 100%; }
    .action-bar { flex-direction: column-reverse; gap: 15px; }

    .admin-body .cmat-header { flex-direction: row; justify-content: space-between; align-items: center; }
    .admin-body .cmat-header-left { flex-direction: row; gap: 10px; }
}

/* =========================================
   8. PRINT STYLES
========================================= */
@media print {
    @page { size: A4 landscape; margin: 0mm !important; }
    body, html { background: white !important; padding: 0 !important; margin: 0 !important; width: 100% !important; height: 100% !important; }
    .cmat-header, .cmat-footer, .warning-box, .action-bar, .header-brand, .highlight-subtitle { display: none !important; }
    .main-container, .preview-main-card, .content-wrapper { display: block !important; max-width: none !important; width: 100% !important; margin: 0 !important; padding: 0 !important; box-shadow: none !important; border: none !important; background: transparent !important; }
    .preview-container { position: absolute !important; top: 0 !important; left: 0 !important; width: 297mm !important; height: 210mm !important; max-width: none !important; margin: 0 !important; padding: 0 !important; border: none !important; border-radius: 0 !important; box-shadow: none !important; aspect-ratio: auto !important; }
    .preview-bg { width: 297mm !important; height: 210mm !important; object-fit: fill !important; display: block !important; }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }
}
.swal2-container { z-index: 99999 !important; }

/* =========================================
   9. FIX POPUP Z-INDEX (แก้ป๊อปอัปซ้อนกัน)
========================================= */
.swal2-container { z-index: 99999 !important; font-family: 'Prompt', sans-serif !important; }

/* =========================================
   10. MODAL & PREVIEW SPECIFIC (ย้ายมาจากไฟล์ PHP เพื่อเพิ่มความเร็ว Caching)
========================================= */
/* จากไฟล์ view_modals.php */
.prefix-wrap { width: 140px; flex-shrink: 0; }
.modal-form-group { margin-bottom: 15px; }
.modal-form-group .form-control, .modal-form-group .form-select { margin-bottom: 0; }
@media (max-width: 991px) {
    .prefix-wrap { width: 100%; }
}

/* จากไฟล์ preview.php */
body.page-preview { display: flex; flex-direction: column; min-height: 100vh; padding: 0; background-color: #f0f2f5; margin: 0; font-family: 'Prompt', sans-serif;}
.page-preview .cmat-header-left img { background: #fff; padding: 3px; border-radius: 6px; }

@media print {
    .page-preview .cmat-header, .page-preview .cmat-footer, .page-preview .warning-box, .page-preview .action-bar { display: none !important; }
    .page-preview .content-wrapper { padding: 0 !important; }
}