:root {
    --app-primary: #435ebe;
    --app-primary-dark: #374d9c;
    --app-primary-darker: #2e4081;
    --app-primary-soft: #eceff9;
    --app-primary-rgb: 67, 94, 190;
    --app-on-primary: #ffffff;
    --app-radius: 12px;
    --app-font: 'Sarabun', 'Sarabun', sans-serif;
    --primary-color: #435ebe;
    --bs-primary: #435ebe;
    --bs-primary-rgb: 67, 94, 190;
    --bs-link-color: #435ebe;
    --bs-link-hover-color: #374d9c;
    --bs-link-color-rgb: 67, 94, 190;
    --bs-focus-ring-color: rgba(67, 94, 190, .25);
}
html { font-size: 16px; }
html body, html body .form-control, html body .form-select, html body .btn, html body .dropdown-menu, html body .swal2-popup,
html body table.dataTable, html body .dataTables_wrapper { font-family: var(--app-font) !important; }

/* ---------- สีหลัก ---------- */
.btn-primary {
    --bs-btn-color: var(--app-on-primary); --bs-btn-bg: var(--app-primary); --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-color: var(--app-on-primary); --bs-btn-hover-bg: var(--app-primary-dark); --bs-btn-hover-border-color: var(--app-primary-dark);
    --bs-btn-active-color: var(--app-on-primary); --bs-btn-active-bg: var(--app-primary-darker); --bs-btn-active-border-color: var(--app-primary-darker);
    --bs-btn-disabled-color: var(--app-on-primary); --bs-btn-disabled-bg: var(--app-primary); --bs-btn-disabled-border-color: var(--app-primary);
    --bs-btn-focus-shadow-rgb: 67, 94, 190;
}
.btn-outline-primary {
    --bs-btn-color: var(--app-primary); --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-color: var(--app-on-primary); --bs-btn-hover-bg: var(--app-primary); --bs-btn-hover-border-color: var(--app-primary);
    --bs-btn-active-color: var(--app-on-primary); --bs-btn-active-bg: var(--app-primary-dark); --bs-btn-active-border-color: var(--app-primary-dark);
    --bs-btn-disabled-color: var(--app-primary); --bs-btn-disabled-border-color: var(--app-primary);
}
.bg-primary { background-color: var(--app-primary) !important; color: var(--app-on-primary); }
.text-primary { color: var(--app-primary) !important; }
.border-primary { border-color: var(--app-primary) !important; }
.progress-bar { background-color: var(--app-primary); }
.form-control:focus, .form-select:focus { border-color: var(--app-primary) !important; box-shadow: 0 0 0 .2rem rgba(67, 94, 190, .2) !important; }
.form-check-input:checked { background-color: var(--app-primary); border-color: var(--app-primary); }
.page-link { color: var(--app-primary); }
.active > .page-link, .page-link.active { background-color: var(--app-primary); border-color: var(--app-primary); color: var(--app-on-primary); }
.nav-pills .nav-link.active, .nav-pills .show > .nav-link { background-color: var(--app-primary); color: var(--app-on-primary) !important; }
.dropdown-item.active, .dropdown-item:active { background-color: var(--app-primary); }
.bg-gradient-primary { background: linear-gradient(135deg, var(--app-primary) 0%, var(--app-primary-dark) 100%) !important; }
.login-header { background: linear-gradient(135deg, var(--app-primary) 0%, var(--app-primary-dark) 100%) !important; color: var(--app-on-primary) !important; }
.btn-login { background-color: var(--app-primary) !important; border-color: var(--app-primary) !important; color: var(--app-on-primary) !important; }
.btn-login:hover { background-color: var(--app-primary-dark) !important; }
.bg-header-plan { background-color: var(--app-primary) !important; color: var(--app-on-primary) !important; }
.bg-header-output { background-color: var(--app-primary-soft) !important; color: var(--app-primary-darker) !important; }
html body .navbar-brand { color: var(--app-primary) !important; }
html body .main-navbar .nav-link.active, html body .main-navbar .nav-link:hover { color: var(--app-primary) !important; background-color: var(--app-primary-soft); }
.nav-tabs-custom .nav-link.active { background-color: var(--app-primary-soft) !important; color: var(--app-primary) !important; }
.nav-tabs-custom .nav-link.active::after { background-color: var(--app-primary) !important; }
.btn-target { background-color: var(--app-primary-dark) !important; }

/* ---------- มุมโค้ง ---------- */
.card, .modal-content, .settings-card, .report-card, .card-custom, .page-header, .filter-box, .login-card, .stat-card, .summary-box { border-radius: var(--app-radius) !important; }
.btn { border-radius: calc(var(--app-radius) * .6); }
.form-control, .form-select { border-radius: calc(var(--app-radius) * .6); }

/* ---------- ซ่อนปุ่มตามสิทธิ์ (UX เท่านั้น — เซิร์ฟเวอร์ตรวจสิทธิ์จริงทุกครั้ง) ---------- */
html.role-executive #btn-edit, html.role-executive #btn-save, html.role-executive .btn-target,
html.role-finance #btn-edit, html.role-finance #btn-save, html.role-finance .btn-target,
html.role-executive #form-transfer, html.role-executive #form-usage { display: none !important; }
html.role-executive .txn-only { display: none !important; }

/* ---------- โหมดมืด ---------- */
[data-bs-theme="dark"] body { background-color: #12151c !important; color: #dee2e6 !important; }
[data-bs-theme="dark"] .card, [data-bs-theme="dark"] .card-custom, [data-bs-theme="dark"] .settings-card,
[data-bs-theme="dark"] .page-header, [data-bs-theme="dark"] .filter-box, [data-bs-theme="dark"] .report-card,
[data-bs-theme="dark"] .table-responsive-main, [data-bs-theme="dark"] .login-card, [data-bs-theme="dark"] .nav-tabs-custom,
[data-bs-theme="dark"] .card-header, [data-bs-theme="dark"] .bg-white { background-color: #1c212b !important; color: #dee2e6 !important; }
[data-bs-theme="dark"] .main-navbar { background: rgba(28, 33, 43, .96) !important; }
[data-bs-theme="dark"] .bg-light, [data-bs-theme="dark"] .modal-body.bg-light, [data-bs-theme="dark"] .modal-footer.bg-light { background-color: #232a36 !important; color: #dee2e6 !important; }
[data-bs-theme="dark"] .text-dark, [data-bs-theme="dark"] .text-secondary { color: #dee2e6 !important; }
[data-bs-theme="dark"] .text-muted { color: #9aa4b2 !important; }
[data-bs-theme="dark"] .table { --bs-table-bg: transparent; --bs-table-color: #dee2e6; --bs-table-hover-bg: rgba(255,255,255,.04); --bs-table-striped-bg: rgba(255,255,255,.03); }
[data-bs-theme="dark"] .table thead th, [data-bs-theme="dark"] table.dataTable thead th { background-color: #232a36 !important; color: #adb5bd !important; border-color: #2f3744 !important; }
[data-bs-theme="dark"] .table td, [data-bs-theme="dark"] .table th { border-color: #2f3744 !important; }
[data-bs-theme="dark"] .sticky-col { background-color: #1c212b !important; }
[data-bs-theme="dark"] .sticky-corner, [data-bs-theme="dark"] .bg-header-activity { background-color: #232a36 !important; color: #dee2e6 !important; }
[data-bs-theme="dark"] .bg-header-output { background-color: #2a3447 !important; color: #cfd8ea !important; }
[data-bs-theme="dark"] .row-group td, [data-bs-theme="dark"] td.bg-light { background-color: #262e3b !important; color: #e9ecef !important; }
[data-bs-theme="dark"] .clickable-cell:hover { background-color: #2f3744; }
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select, [data-bs-theme="dark"] .input-group-text { background-color: #12151c; color: #dee2e6; border-color: #3a4352; }
[data-bs-theme="dark"] .swal2-popup { background: #1c212b; color: #dee2e6; }
[data-bs-theme="dark"] .swal2-title, [data-bs-theme="dark"] .swal2-html-container { color: #dee2e6; }
[data-bs-theme="dark"] .dropdown-menu { background-color: #1c212b; }
[data-bs-theme="dark"] .dropdown-item { color: #dee2e6; }
[data-bs-theme="dark"] .dropdown-item:hover { background-color: #2a3341; }
[data-bs-theme="dark"] .dataTables_wrapper, [data-bs-theme="dark"] .page-link { color: #dee2e6; }
[data-bs-theme="dark"] .page-link { background-color: #1c212b; border-color: #2f3744; }
[data-bs-theme="dark"] .btn-edit, [data-bs-theme="dark"] .btn-edit-row { background-color: #3a3220; }
[data-bs-theme="dark"] .btn-delete, [data-bs-theme="dark"] .btn-delete-row { background-color: #3d2326; }
[data-bs-theme="dark"] .code-badge { background-color: #2a3341; color: #cbd5e1; }
[data-bs-theme="dark"] .manual-toc a.active { background-color: #2a3447; }

/* ---------- พิมพ์ ---------- */
@media print { .main-navbar, .no-print { display: none !important; } body { background: #fff !important; } }
