/* ========================================================
   Custom CSS for KPI Management System
   Font: Sarabun / TH Sarabun New (สารบัญ / สารบรรณ)
   รองรับทั้งแบบ Offline (Local TTF) และ Online (Google Fonts)
   ======================================================== */

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

/* Local Offline Fallback - Sarabun & TH Sarabun New */
@font-face {
    font-family: 'Sarabun';
    src: url('../fonts/Sarabun-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Sarabun';
    src: url('../fonts/Sarabun-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Sarabun';
    src: url('../fonts/Sarabun-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Sarabun';
    src: url('../fonts/Sarabun-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* Alias 'TH Sarabun New' และ 'สารบัญ' ให้ชี้ไปที่ฟอนต์ Sarabun */
@font-face {
    font-family: 'TH Sarabun New';
    src: url('../fonts/Sarabun-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'TH Sarabun New';
    src: url('../fonts/Sarabun-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* กำหนดฟอนต์สารบัญครอบคลุมทั่วทั้งระบบ */
:root {
    --app-font-family: 'Sarabun', 'TH Sarabun New', 'THSarabunNew', Tahoma, sans-serif;
}

body, html {
    font-family: var(--app-font-family) !important;
    font-size: 15.5px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    color: #2c3e50;
    background-color: #f4f6f9;
}

/* องค์ประกอบฟอร์ม, ตาราง, และ UI ทั้งหมด */
input, select, textarea, button, optgroup,
.btn, .form-control, .input-group-text, .custom-select,
.select2, .select2-container,
table, .table, th, td,
.card, .card-title, .card-header, .card-body, .card-footer,
.modal, .dropdown-menu, .alert, .badge, .popover, .tooltip,
.main-header, .main-sidebar, .brand-text, .user-panel,
.nav-link, .nav-header, .content-wrapper, .breadcrumb,
.login-box, .login-card-body, .register-card-body {
    font-family: var(--app-font-family) !important;
}

/* หัวเรื่องและการ์ด */
h1, h2, h3, h4, h5, h6, .card-title, .brand-text, .nav-header {
    font-family: var(--app-font-family) !important;
    font-weight: 600;
}

/* ========================================================
   FontAwesome 5 Icons Protection (ป้องกันฟอนต์ไอคอนหาย)
   ห้ามให้ font-family ของ Sarabun ไปทับไอคอนเด็ดขาด
   ======================================================== */
.fa, .fas, .far, .fal, .fad,
.fa::before, .fas::before, .far::before, .fal::before, .fad::before,
.fa::after, .fas::after, .far::after, .fal::after, .fad::after,
[class*="fa-"]::before, [class*="fa-"]::after {
    font-family: "Font Awesome 5 Free" !important;
}

.fa, .fas,
.fa::before, .fas::before,
.fa::after, .fas::after {
    font-weight: 900 !important;
}

.far,
.far::before,
.far::after {
    font-weight: 400 !important;
}

.fab,
.fab::before,
.fab::after {
    font-family: "Font Awesome 5 Brands" !important;
    font-weight: 400 !important;
}

/* KPI Status Colors */
.kpi-status-pass {
    background-color: #d4edda !important;
    color: #155724 !important;
    font-weight: 600;
}

.kpi-status-pass-c {
    background-color: #fff3cd !important;
    color: #856404 !important;
    font-weight: 600;
}

.kpi-status-fail {
    background-color: #f8d7da !important;
    color: #721c24 !important;
    font-weight: 600;
}

.kpi-status-na {
    background-color: #f8f9fa !important;
    color: #6c757d !important;
}

/* Spreadsheet Grid Form Styling */
.table-kpi-grid th, .table-kpi-grid td {
    vertical-align: middle;
    padding: 0.35rem 0.45rem;
    font-size: 14.5px;
}

.table-kpi-grid input.kpi-cell-input {
    width: 100%;
    min-width: 65px;
    text-align: right;
    padding: 2px 4px;
    font-size: 14px;
    border: 1px solid #ced4da;
    border-radius: 3px;
    font-family: var(--app-font-family) !important;
}

.table-kpi-grid input.kpi-cell-input:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.15rem rgba(0,123,255,.25);
    outline: none;
    background-color: #fffde7;
}

.table-kpi-grid input.kpi-cell-input[readonly],
.table-kpi-grid input.kpi-cell-input:disabled {
    background-color: #e9ecef;
    cursor: not-allowed;
    color: #495057;
}

/* Monthly Status Badges */
.badge-status-draft { background-color: #6c757d; color: #fff; }
.badge-status-submitted { background-color: #ffc107; color: #212529; }
.badge-status-approved { background-color: #28a745; color: #fff; }
.badge-status-rejected { background-color: #dc3545; color: #fff; }

/* Executive Dashboard Styling */
.card-hover {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.12) !important;
}
.dashboard-section-header {
    border-left: 4px solid #007bff;
    padding-left: 10px;
    margin-bottom: 0.85rem;
    font-weight: 700;
}
.dashboard-metric-number {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1.1;
}
.chart-container-card {
    position: relative;
    min-height: 320px;
}

/* ========================================================
   Sidebar Layout: Full Height & Pinned Bottom Logout
   ======================================================== */
.main-sidebar {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
}

.main-sidebar .sidebar {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
}

.sidebar-bottom-logout {
    flex-shrink: 0 !important;
    margin-top: auto !important;
    border-top: 1px solid rgba(255, 255, 255, 0.12) !important;
    background-color: #1a1e22 !important;
    padding: 8px 10px !important;
}

.sidebar-bottom-logout a {
    color: #ff5252 !important;
    transition: all 0.2s ease-in-out;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14.5px;
}

.sidebar-bottom-logout a:hover {
    background-color: rgba(220, 53, 69, 0.2) !important;
    color: #ff8080 !important;
}

/* Sidebar Mini Collapsed Mode Support */
.sidebar-mini.sidebar-collapse .sidebar-bottom-logout {
    padding: 8px 2px !important;
    text-align: center !important;
}

.sidebar-mini.sidebar-collapse .sidebar-bottom-logout .logout-text {
    display: none !important;
}

.sidebar-mini.sidebar-collapse .sidebar-bottom-logout a {
    justify-content: center !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.sidebar-mini.sidebar-collapse .sidebar-bottom-logout a i {
    margin-right: 0 !important;
}

/* ========================================================
   Sidebar Nav Item Spacing & Comfortable Margins
   ======================================================== */
.main-sidebar .sidebar {
    padding-top: 14px !important;
    padding-bottom: 14px !important;
}

.sidebar .nav-sidebar .nav-item {
    margin-bottom: 5px !important;
}

.sidebar .nav-sidebar .nav-item:last-child {
    margin-bottom: 0 !important;
}

.sidebar .nav-sidebar .nav-link {
    padding: 0.55rem 0.85rem !important;
    border-radius: 6px !important;
    font-size: 14.8px !important;
    line-height: 1.45 !important;
}

.sidebar .nav-sidebar .nav-link .nav-icon {
    font-size: 1.15rem !important;
    margin-right: 0.75rem !important;
    width: 1.4rem !important;
    text-align: center !important;
}

/* Category Section Headers (เช่น การจัดการระบบ) */
.sidebar .nav-sidebar .nav-header {
    padding: 1.1rem 0.85rem 0.45rem 0.85rem !important;
    font-size: 0.85rem !important;
    letter-spacing: 0.4px;
    color: #8c9ba5 !important;
}

/* Sub-treeview Spacing (เมนูย่อยรายงาน) */
.sidebar .nav-sidebar .nav-treeview {
    padding-top: 4px !important;
    padding-bottom: 4px !important;
}

.sidebar .nav-sidebar .nav-treeview .nav-item {
    margin-bottom: 3px !important;
}

.sidebar .nav-sidebar .nav-treeview .nav-link {
    padding: 0.42rem 0.85rem 0.42rem 1.75rem !important;
    font-size: 14px !important;
}

/* ========================================================
   Standard Select2 Styling (Form-Control & Multi-Select)
   ทำให้กรอบเลือกหลายรายการ (เช่น แผนกที่มอบหมาย) ได้มาตรฐาน
   ======================================================== */
.select2-container {
    width: 100% !important;
    display: block !important;
}

/* Single Select Box */
.select2-container .select2-selection--single {
    height: 38px !important;
    border: 1px solid #ced4da !important;
    border-radius: 4px !important;
    background-color: #fff !important;
    padding: 4px 8px !important;
    display: flex !important;
    align-items: center !important;
}

.select2-container .select2-selection--single .select2-selection__rendered {
    color: #495057 !important;
    font-size: 14.8px !important;
    padding-left: 4px !important;
    line-height: normal !important;
}

.select2-container .select2-selection--single .select2-selection__arrow {
    height: 36px !important;
    right: 8px !important;
}

/* Multiple Select Box (กรอบเลือกหลายแผนก) */
.select2-container .select2-selection--multiple {
    min-height: 42px !important;
    border: 1px solid #ced4da !important;
    border-radius: 4px !important;
    background-color: #fff !important;
    padding: 3px 6px !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
}

.select2-container--focus .select2-selection--multiple,
.select2-container--focus .select2-selection--single,
.select2-container--open .select2-selection--multiple,
.select2-container--open .select2-selection--single {
    border-color: #80bdff !important;
    outline: 0 !important;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25) !important;
}

/* Selected Badges / Chips */
.select2-container .select2-selection--multiple .select2-selection__choice {
    background-color: #e8f4fd !important;
    border: 1px solid #b8daff !important;
    color: #0056b3 !important;
    border-radius: 4px !important;
    padding: 4px 10px !important;
    margin: 3px 5px 3px 0 !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    display: inline-flex !important;
    align-items: center !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
}

.select2-container .select2-selection--multiple .select2-selection__choice__remove {
    color: #dc3545 !important;
    margin-right: 6px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    border-right: 1px solid #b8daff !important;
    padding-right: 6px !important;
}

.select2-container .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: #a71d2a !important;
}

.select2-container .select2-search--inline .select2-search__field {
    margin: 4px 2px !important;
    padding: 2px 6px !important;
    font-family: var(--app-font-family) !important;
    font-size: 14.5px !important;
    color: #495057 !important;
    height: 28px !important;
}

/* Dropdown Menu */
.select2-dropdown {
    border: 1px solid #ced4da !important;
    border-radius: 4px !important;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
    font-size: 14.5px !important;
    z-index: 9999 !important;
}

.select2-results__option {
    padding: 8px 12px !important;
}

.select2-results__option--highlighted {
    background-color: #007bff !important;
    color: #fff !important;
}

/* ========================================================
   Action Buttons Spacing & Separation (เว้นวรรคปุ่มทุกการจัดการ)
   ======================================================== */

/* 1. ปุ่มในตารางข้อมูล (Table Action Buttons) ให้แยกจากกันอย่างสวยงาม */
.table td .btn-group,
.table td .action-btns,
table td .btn-group,
td .btn-group {
    display: inline-flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
}

.table td .btn-group > .btn,
.table td .action-btns > .btn,
table td .btn-group > .btn,
td .btn-group > .btn,
.table td .btn,
.table td a.btn,
table td a.btn {
    margin-left: 0 !important;
    margin-right: 0 !important;
    border-radius: 4px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.82rem !important;
    padding: 0.28rem 0.55rem !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: transform 0.15s ease, box-shadow 0.15s ease !important;
}

.table td .btn-group > .btn:hover,
.table td a.btn:hover,
table td .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12) !important;
}

/* ลบล้างการติดกันของ .btn-group เดิมในตาราง */
.table td .btn-group > .btn:not(:last-child):not(.dropdown-toggle),
.table td .btn-group > .btn-group:not(:last-child) > .btn,
table td .btn-group > .btn:not(:last-child):not(.dropdown-toggle) {
    border-top-right-radius: 4px !important;
    border-bottom-right-radius: 4px !important;
}

.table td .btn-group > .btn:not(:first-child),
.table td .btn-group > .btn-group:not(:first-child) > .btn,
table td .btn-group > .btn:not(:first-child) {
    border-top-left-radius: 4px !important;
    border-bottom-left-radius: 4px !important;
}

/* 2. ปุ่มที่อยู่ติดกันในตาราง (เมื่อไม่ได้ใช้ btn-group) */
table td .btn + .btn,
table td .btn + a.btn,
table td a.btn + .btn,
table td a.btn + a.btn {
    margin-left: 6px !important;
}

/* 3. ปุ่มที่อยู่ติดกันทั่วไป (ใน Card Header, Card Footer, Modal, Form, Toolbar) */
.card-tools .btn + .btn,
.card-tools .btn + a.btn,
.card-tools a.btn + .btn,
.card-tools a.btn + a.btn,
.card-footer .btn + .btn,
.card-footer .btn + a.btn,
.card-footer a.btn + .btn,
.card-footer a.btn + a.btn,
.modal-footer .btn + .btn,
.modal-footer .btn + a.btn,
.modal-footer a.btn + .btn,
.modal-footer a.btn + a.btn,
.btn-toolbar .btn + .btn,
.form-inline .btn + .btn,
.form-inline a.btn + .btn,
.form-inline .btn + a.btn,
.form-inline a.btn + a.btn {
    margin-left: 8px !important;
}

/* 4. ระยะห่างระหว่างไอคอนและข้อความในปุ่ม */
.btn i:not(:only-child),
.btn .fas:not(:only-child),
.btn .far:not(:only-child) {
    margin-right: 5px !important;
}

/* ยกเว้น: ปุ่มใน Pagination ของ DataTables ไม่ต้องใส่ margin */
.pagination .page-item .page-link,
.dataTables_paginate .paginate_button {
    margin-left: 0 !important;
}

/* ========================================================
   Global Print Stylesheet (พิมพ์รายงานและแบบฟอร์มทั่วทั้งระบบ)
   ======================================================== */
@media print {
    /* ซ่อน UI แถบเมนูและปุ่มควบคุมทั้งหมด */
    .main-header,
    .main-sidebar,
    .main-footer,
    .content-header,
    .d-print-none,
    nav,
    aside,
    footer,
    .btn,
    .btn-group {
        display: none !important;
    }

    body, html {
        background: #fff !important;
        color: #000 !important;
        font-family: 'Sarabun', 'TH Sarabun New', Tahoma, sans-serif !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .wrapper,
    .content-wrapper,
    .content,
    .container-fluid {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        min-height: auto !important;
        width: 100% !important;
    }

    /* บังคับพิมพ์สีพื้นหลังของตารางและสถานะ */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
}

/* ========================================================
   Year Selector Badge in Navbar (ตัวเลือกปี พ.ศ. บน Navbar)
   แก้ปัญหาคลิกแล้วพื้นขาวมองไม่เห็นข้อความ (White text on white background)
   ======================================================== */
.year-badge-selector {
    background: linear-gradient(135deg, #0056b3 0%, #007bff 100%) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    border-radius: 20px !important;
    padding: 4px 12px 4px 10px !important;
    box-shadow: 0 2px 5px rgba(0, 123, 255, 0.25) !important;
    transition: all 0.2s ease-in-out;
}

.year-badge-selector:hover {
    background: linear-gradient(135deg, #004494 0%, #0069d9 100%) !important;
    box-shadow: 0 3px 8px rgba(0, 86, 179, 0.35) !important;
}

.year-badge-selector .calendar-icon {
    color: #ffd700 !important; /* สีเหลืองทองให้เด่นชัด */
    font-size: 0.95rem;
}

.year-badge-selector .year-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: #ffffff !important;
    letter-spacing: 0.2px;
}

#globalYearSelector {
    background-color: transparent !important;
    color: #ffffff !important;
    font-weight: 700 !important;
    font-size: 0.875rem !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

#globalYearSelector:focus {
    background-color: rgba(255, 255, 255, 0.15) !important;
    color: #ffffff !important;
    outline: none !important;
    box-shadow: none !important;
}

/* คมชัด 100%: รายการปีใน Dropdown (Option elements) กำหนดสีพื้นหลังขาวและตัวหนังสือสีดำเข้มชัดเจน */
#globalYearSelector option {
    background-color: #ffffff !important;
    color: #212529 !important; /* ตัวหนังสือสีดำเข้มคมชัด ไม่กลืนกับพื้นขาว */
    font-size: 0.9rem !important;
    font-weight: 600 !important;
    padding: 8px 12px !important;
}

#globalYearSelector option:checked,
#globalYearSelector option:hover {
    background-color: #e8f0fe !important;
    color: #0056b3 !important;
    font-weight: 700 !important;
}





