/* ═══════════════════════════════════════════════
   Theme System — Dark/Light Mode
   ═══════════════════════════════════════════════ */

:root {
    /* Light Theme (default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-card: #ffffff;
    --bg-navbar: #212529;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --table-hover: #f1f3f5;
    --table-striped: #f8f9fa;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --card-border: 1px solid var(--border-color);
}

[data-theme="dark"] {
    --bg-primary: #1a1d23;
    --bg-secondary: #22262e;
    --bg-card: #2a2e37;
    --bg-navbar: #111418;
    --text-primary: #e9ecef;
    --text-secondary: #adb5bd;
    --text-muted: #6c757d;
    --border-color: #3a3f4b;
    --table-hover: #2a2e37;
    --table-striped: #22262e;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --card-border: 1px solid var(--border-color);
}

/* ═══ Global Scrollbar Theme (ทุกจุด scroll ในเว็บ) ═══
   ★ แก้ปัญหา: ธีมมืด scrollbar ขาวจ้า (browser default ไม่รู้จักธีม)
   ★ Pattern เดียวกับ sidebar scrollbar ด้านล่าง: webkit + @supports Firefox
   ★ ห้ามใช้ scrollbar-color บน * — จะ override ::-webkit-scrollbar 3px ของ sidebar ใน Chrome 121+ */
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
*::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}
*::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
    border: 2px solid var(--bg-secondary);   /* ★ padding ให้ thumb เล็กลงเข้ากับ track */
}
*::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
*::-webkit-scrollbar-corner {
    background: var(--bg-secondary);
}

/* ★ Sidebar 3px ต้องชนะ global 10px — ระบุใหม่หลัง global (cascade) */
.job-sidebar-pc .card::-webkit-scrollbar,
.pm-sidebar-pc .card::-webkit-scrollbar,
.job-mini-flyout::-webkit-scrollbar,
.pm-mini-flyout::-webkit-scrollbar {
    width: 3px;
    border: none;
}

/* Firefox — global */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-secondary);
}

/* ★★ Exception — สถานะ sidebar ตามเจตนาเดิม (ต้องชนะ global ข้างบน):
   1) mini rail = ซ่อน scrollbar เลย (drag-to-scroll แทน)
   2) PC sidebar + flyout = thin เท่านั้น (ไม่มี track สี — โปร่งเหมือนเดิม)
   ★ จำเป็นทั้งใน Firefox และ Chrome 121+ (ที่ scrollbar-width ชนะ ::-webkit-scrollbar) */
.job-sidebar-mini,
.pm-sidebar-mini {
    scrollbar-width: none;
}
.job-sidebar-pc .card,
.pm-sidebar-pc .card,
.job-mini-flyout,
.pm-mini-flyout {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

/* Apply theme */
body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s, color 0.3s;
    padding-top: 56px;  /* ★★ กันเนื้อหาทับ navbar (fixed-top) */
}

/* ★★ Navbar fixed-top — ลอยติดบนสุดเสมอ */
.navbar.fixed-top {
    z-index: 1030;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* ★★ Hamburger สำหรับ Sidebar — อยู่ใน navbar (Mobile <768px) */
.navbar-sidebar-toggle {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    cursor: pointer;
    margin-right: 8px;
    transition: background 0.2s;
}
.navbar-sidebar-toggle:hover {
    background: rgba(255,255,255,0.3);
}

/* ★★ ซ่อน hamburger เดิมของ sidebar — ย้ายไป navbar แล้ว */
.job-hamburger,
.pm-hamburger {
    display: none !important;
}

/* ★ Sidebar Scrollbar — บาง 3px (PC sidebar + flyout)
   ★★ Chrome 121+/Edge: `scrollbar-width:thin` จะ override ::-webkit-scrollbar (หนา ~8px)
   → ต้องใช้ @supports ให้ Firefox เท่านั้นที่ใช้ standard / Chrome+Edge ใช้ webkit 3px */
.job-sidebar-pc .card::-webkit-scrollbar,
.pm-sidebar-pc .card::-webkit-scrollbar,
.job-mini-flyout::-webkit-scrollbar,
.pm-mini-flyout::-webkit-scrollbar {
    width: 3px;
}
.job-sidebar-pc .card::-webkit-scrollbar-track,
.pm-sidebar-pc .card::-webkit-scrollbar-track,
.job-mini-flyout::-webkit-scrollbar-track,
.pm-mini-flyout::-webkit-scrollbar-track {
    background: transparent;
}
.job-sidebar-pc .card::-webkit-scrollbar-thumb,
.pm-sidebar-pc .card::-webkit-scrollbar-thumb,
.job-mini-flyout::-webkit-scrollbar-thumb,
.pm-mini-flyout::-webkit-scrollbar-thumb {
    background: var(--border-color, #ccc);
    border-radius: 3px;
}
.job-sidebar-pc .card::-webkit-scrollbar-thumb:hover,
.pm-sidebar-pc .card::-webkit-scrollbar-thumb:hover,
.job-mini-flyout::-webkit-scrollbar-thumb:hover,
.pm-mini-flyout::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted, #999);
}

/* ★★ Mini rail (64px) — ซ่อน scrollbar ทั้งหมด (แย่งพื้นที่ไอคอน)
   ยังเลื่อนได้ด้วย mouse wheel / touch / drag-to-scroll (เหมือน Quick Actions) */
.job-sidebar-mini::-webkit-scrollbar,
.pm-sidebar-mini::-webkit-scrollbar {
    display: none;
}
.job-sidebar-mini,
.pm-sidebar-mini {
    scrollbar-width: none;    /* Firefox */
    -ms-overflow-style: none; /* IE/Edge legacy */
}

/* ★★ Mini rail — Drag-to-scroll (เมาส์คลิกค้างแล้วลากเลื่อน — เหมือน Quick Actions) */
.job-sidebar-mini.draggable,
.pm-sidebar-mini.draggable { cursor: grab; }
.job-sidebar-mini.dragging,
.pm-sidebar-mini.dragging   { cursor: grabbing; }
/* ตอน drag → ปุ่มไม่รับ click (กัน navigate หลังปล่อยเมาส์บนปุ่ม) */
.job-sidebar-mini.dragging .job-mini-item,
.pm-sidebar-mini.dragging .pm-mini-item { pointer-events: none; }

/* ★ Firefox เท่านั้น — Chrome/Edge ไม่เข้า block นี้ (ใช้ webkit 3px ด้านบน) */
@supports not selector(::-webkit-scrollbar) {
    .job-sidebar-pc .card,
    .pm-sidebar-pc .card,
    .job-mini-flyout,
    .pm-mini-flyout {
        scrollbar-width: thin;
        scrollbar-color: var(--border-color, #ccc) transparent;
    }
}

.navbar-dark {
    background-color: var(--bg-navbar) !important;
}

.card {
    background-color: var(--bg-card);
    border: var(--card-border);
    color: var(--text-primary);
    box-shadow: var(--shadow);
    transition: background-color 0.3s, border-color 0.3s;
}

.card-header {
    border-bottom: 1px solid var(--border-color);
}

/* ★ Fix Bootstrap 5 table CSS variables for dark theme */
.table {
    --bs-table-color: var(--text-primary);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--border-color);
    color: var(--text-primary);
}

[data-theme="dark"] .table {
    --bs-table-color: var(--text-primary);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--border-color);
}

.table > :not(caption) > * > * {
    color: var(--text-primary);
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
    --bs-table-color-type: var(--text-primary);
    --bs-table-bg-type: var(--table-striped);
}

[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
    --bs-table-color-type: var(--text-primary);
    --bs-table-bg-type: rgba(255,255,255,0.04);
}

.table-hover > tbody > tr:hover > * {
    --bs-table-color-type: var(--text-primary);
    --bs-table-bg-type: var(--table-hover);
}

[data-theme="dark"] .table-hover > tbody > tr:hover > * {
    --bs-table-color-type: var(--text-primary);
    --bs-table-bg-type: rgba(255,255,255,0.08);
}

.table-dark {
    --bs-table-bg: var(--bg-navbar);
    --bs-table-color: #fff;
    --bs-table-striped-bg: rgba(255,255,255,0.05);
    --bs-table-hover-bg: rgba(255,255,255,0.1);
    --bs-table-striped-color: #fff;
    --bs-table-hover-color: #fff;
}

/* ★ Theme-aware table header — ใช้แทน table-dark */
.table-theme-header {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

.table-theme-header th {
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
    /* ★★ background ที่ th โดยตรง — จำเป็นสำหรับ sticky header (th position:sticky)
          เดิมใส่สีที่ thead อย่างเดียว → th โปร่งใส (Bootstrap ให้ --bs-table-bg=transparent ที่ cell)
          → scroll แล้วข้อมูลลอดผ่านใต้หัวตาราง
          !important จำเป็น — กันโดน [data-theme=dark] .table > :not(caption) > * > * override เป็น transparent */
    background-color: var(--bg-secondary) !important;
}

/* ★ Sticky table header — ป้องกันโปร่งใสเวลาเลื่อน */
thead.sticky-top,
thead.sticky-top th {
    background-color: var(--bg-secondary) !important;
    z-index: 10;
}

[data-theme="dark"] thead.sticky-top,
[data-theme="dark"] thead.sticky-top th {
    background-color: var(--bg-card) !important;
}

.text-muted {
    color: var(--text-secondary) !important;
}

.border-top {
    border-top: 1px solid var(--border-color) !important;
}

.form-control, .form-select {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-primary) !important;
    border-color: #0d6efd !important;
    color: var(--text-primary) !important;
}

/* ★ Dark theme: form-select background-image (arrow) — ใช้สีขาว */
[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23e9ecef' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") !important;
}

/* ★ Dark theme: <option> elements — ป้องกัน panel ขาว */
[data-theme="dark"] option,
[data-theme="dark"] optgroup {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] option:checked,
[data-theme="dark"] option:hover {
    background-color: #0d6efd !important;
    color: #fff !important;
}

/* ★ Disabled form controls — แยก readonly ออกจาก disabled
   readonly = ข้อมูลอ้างอิง (อ่านชัด, สื่อด้วยพื้นหลังต่างเล็กน้อย + cursor)
   disabled = ปิดใช้งาน (จาง สื่อว่าใช้ไม่ได้) */

/* ★ readonly — ตัวอักษรชัดเจนเท่า input ปกติ, พื้นหลังต่างเล็กน้อย */
.form-control:read-only,
.form-control[readonly],
textarea:read-only {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    opacity: 1;
    border-color: var(--border-color) !important;
    cursor: default;
    -webkit-text-fill-color: var(--text-primary);
}

/* ★ disabled — จางกว่า (สื่อว่าใช้งานไม่ได้) */
.form-control:disabled,
.form-select:disabled,
select:disabled {
    background-color: var(--bg-secondary) !important;
    color: var(--text-muted) !important;
    opacity: 0.55;
    border-color: var(--border-color) !important;
    cursor: not-allowed;
}

[data-theme="dark"] .form-control:read-only,
[data-theme="dark"] .form-control[readonly],
[data-theme="dark"] textarea:read-only {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    opacity: 1;
    border-color: var(--border-color) !important;
    -webkit-text-fill-color: var(--text-primary);
}

[data-theme="dark"] .form-control:disabled,
[data-theme="dark"] .form-select:disabled,
[data-theme="dark"] select:disabled {
    background-color: var(--bg-secondary) !important;
    color: var(--text-muted) !important;
    opacity: 0.55;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .form-check-input:disabled {
    opacity: 0.4;
}

[data-theme="dark"] .form-check-input:disabled + .form-check-label {
    opacity: 0.5;
}

/* ★★ PMCombo disabled state — แทน Select2 disabled (trigger จางตามสถานะ select เดิม) */
.pmc-trigger.pmc-disabled {
    background-color: var(--bg-secondary) !important;
    color: var(--text-muted) !important;
    opacity: 0.65;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .pmc-trigger.pmc-disabled {
    background-color: var(--bg-secondary) !important;
    color: var(--text-muted) !important;
    opacity: 0.65;
}

.input-group-text {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Theme toggle button */
.theme-toggle {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1.2rem;
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.1);
}

/* Dashboard cards */
.dash-card {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: none;
    overflow: hidden;
    position: relative;
}

.dash-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.dash-card .card-body {
    padding: 1.5rem;
}

.dash-card .dash-icon {
    font-size: 2.5rem;
    opacity: 0.3;
    position: absolute;
    right: 1rem;
    top: 1rem;
}

.dash-card .dash-number {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
}

.dash-card .dash-label {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Action buttons */
.btn-action {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    margin: 0 2px;
    transition: all 0.2s;
}

.btn-action:hover {
    transform: scale(1.1);
}

/* Mobile card view */
.mc-card {
    background-color: var(--bg-card);
    border: var(--card-border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
}

.mc-card .mc-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.mc-card .mc-title {
    font-weight: 600;
    font-size: 1rem;
}

.mc-card .mc-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.mc-card .mc-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* ═══════════════════════════════════════════════
   ★ Mode Toggle — Modern Pill Switch (จัดการ ↔ แจ้งซ่อม)
   ═══════════════════════════════════════════════ */
.mode-toggle {
    display: inline-flex;
    position: relative;
    border-radius: 30px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    padding: 3px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.08);
}

.mode-toggle a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.3s ease, transform 0.2s ease;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 30px;
    position: relative;
    z-index: 1;
    white-space: nowrap;
}

.mode-toggle a i {
    font-size: 1rem;
    transition: transform 0.3s ease;
}

.mode-toggle a:hover {
    color: var(--text-primary);
}

.mode-toggle a:hover i {
    transform: scale(1.15);
}

/* ★ Active state — gradient background + white text */
.mode-toggle a.active {
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.mode-toggle a.active i {
    animation: modeToggleIconPop 0.4s ease;
}

/* ★ Manage mode = blue gradient */
.mode-toggle a.active[href*="manage"],
.mode-toggle a.active[data-mode="manage"] {
    background: linear-gradient(135deg, #0d6efd, #0a58ca);
}

/* ★ Request mode = orange gradient */
.mode-toggle a.active[href*="request"],
.mode-toggle a.active[data-mode="request"] {
    background: linear-gradient(135deg, #fd7e14, #f59f00);
}

/* ★ Icon pop animation on switch */
@keyframes modeToggleIconPop {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* ★ Mobile responsive */
@media (max-width: 575.98px) {
    .mode-toggle {
        width: 100%;
        justify-content: center;
    }
    .mode-toggle a {
        flex: 1;
        justify-content: center;
        padding: 8px 12px;
        font-size: 0.8rem;
    }
}

/* Job status badges */
.badge-status-wrapv { background-color: #ffc107; color: #000; }
.badge-status-inprg { background-color: #0dcaf0; color: #000; }
.badge-status-close { background-color: #198754; color: #fff; }
.badge-status-wrfapv { background-color: #fd7e14; color: #fff; }

/* Pagination Responsive */
.pag-nav .pagination {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.pag-nav .pagination::-webkit-scrollbar {
    display: none;
}

.pag-nav .page-link {
    min-width: 38px;
    text-align: center;
    border-radius: 8px !important;
    margin: 0 2px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-card);
    color: var(--text-primary);
    font-weight: 500;
}

.pag-nav .page-item.active .page-link {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.pag-nav .page-item.disabled .page-link {
    opacity: 0.4;
    background-color: var(--bg-secondary);
}

[data-theme="dark"] .pag-nav .page-link {
    background-color: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .pag-nav .page-item.disabled .page-link {
    background-color: var(--bg-secondary);
    color: var(--text-muted);
}

/* Mobile: hide first/last, show only current ± 1 */
@media (max-width: 575.98px) {
    .pag-nav .pag-first,
    .pag-nav .pag-last,
    .pag-nav .pag-ellipsis {
        display: none;
    }
}

/* Login page theme */
[data-theme="dark"] .login-card {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════
   ★★ PMCombo (Overlay Combobox) — แทน Select2 ทั้งระบบ
   หน้าตา/ธีมจัดการที่ pm-combobox.css ทั้งหมด (Docs/ComboBoxOverlay.md)
   ═══════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════
   Bootstrap Modal — Dark Theme Support
   ═══════════════════════════════════════════════ */

/* ★ Modal content — พื้นหลัง + ตัวอักษร */
.modal-content {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}

/* ★ Modal header — ถ้าไม่มี bg-* class ให้ใช้ theme */
.modal-header:not(.bg-success):not(.bg-primary):not(.bg-danger):not(.bg-warning):not(.bg-info):not(.bg-secondary):not(.bg-dark) {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border-color) !important;
}

/* ★ Modal body */
.modal-body {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
}

/* ★ Modal footer */
.modal-footer {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-top: 1px solid var(--border-color) !important;
}

/* ★ Modal backdrop — ปรับความเข้ม */
[data-theme="dark"] .modal-backdrop.show {
    opacity: 0.7;
}

/* ★ Modal title */
.modal-title {
    color: inherit !important;
}

/* ★ btn-close — ปรับสีในธีมมืด */
[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* ★ Modal header ที่มี bg-success/bg-primary — ปล่อยให้ใช้สีเดิม */
.modal-header.bg-success .modal-title,
.modal-header.bg-primary .modal-title {
    color: #fff !important;
}

/* ★ Alert ในธีมมืด */
[data-theme="dark"] .alert-info {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .alert-warning {
    background-color: rgba(255, 193, 7, 0.15) !important;
    color: #ffc107 !important;
    border-color: rgba(255, 193, 7, 0.3) !important;
}

[data-theme="dark"] .alert-success {
    background-color: rgba(25, 135, 84, 0.15) !important;
    color: #198754 !important;
    border-color: rgba(25, 135, 84, 0.3) !important;
}

[data-theme="dark"] .alert-danger {
    background-color: rgba(220, 53, 69, 0.15) !important;
    color: #dc3545 !important;
    border-color: rgba(220, 53, 69, 0.3) !important;
}

/* ★ alert-light — ใช้ใน modal header info (GenPlan ฯลฯ) → ธีมมืดใช้ bg-secondary */
[data-theme="dark"] .alert-light {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* ═══════════════════════════════════════════════
   Bootstrap bg-light + table-light — Dark Theme Override
   ═══════════════════════════════════════════════ */

/* ★ bg-light — ใช้ใน card-header, ปุ่ม, etc. */
[data-theme="dark"] .bg-light,
[data-theme="dark"] .card-header.bg-light {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* ★ table-light — ใช้ใน thead */
[data-theme="dark"] .table-light,
[data-theme="dark"] thead.table-light,
[data-theme="dark"] thead.table-light th {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* ★ thead ที่มี style="background: #91EA91" (สีเขียวอ่อน) — ปรับในธีมมืด */
[data-theme="dark"] thead[style*="91EA91"],
[data-theme="dark"] thead[style*="#91EA91"] {
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] thead[style*="91EA91"] th,
[data-theme="dark"] thead[style*="#91EA91"] th {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}
/* ★ table-secondary (tfoot แถบรวม) — Dark Theme Override
   Bootstrap คงพื้นเทาอ่อนสว่างจ้า #e2e3e5 ในธีมมืด → แทนด้วยพื้นเข้มตาม theme */
[data-theme="dark"] .table-secondary,
[data-theme="dark"] tfoot.table-secondary,
[data-theme="dark"] tfoot.table-secondary > tr,
[data-theme="dark"] tfoot.table-secondary > tr > td {
    --bs-table-bg: var(--bg-secondary) !important;
    --bs-table-color: var(--text-primary) !important;
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}


/* ═══════════════════════════════════════════════
   List Group (Sidebar Menu) — Dark Theme
   ═══════════════════════════════════════════════ */

[data-theme="dark"] .list-group-item,
[data-theme="dark"] .list-group-item-action {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .list-group-item-action:hover,
[data-theme="dark"] .list-group-item-action:focus {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .list-group-item.active {
    background-color: #198754 !important;
    color: #fff !important;
    border-color: #198754 !important;
}

[data-theme="dark"] .list-group-item.active .bi {
    color: #fff !important;
}

/* ═══════════════════════════════════════════════
   ★ Modern Dashboard Cards — Gradient + Hover
   ═══════════════════════════════════════════════ */

.dash-card-modern {
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    border-radius: 16px;
    overflow: hidden;
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.dash-card-modern:hover {
    transform: translateY(-6px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.dash-card-modern .card-body {
    padding: 1.5rem;
    position: relative;
}

.dash-icon-modern {
    font-size: 2.5rem;
    opacity: 0.3;
    position: absolute;
    right: 1rem;
    top: 1rem;
}

.dash-number-modern {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.dash-label-modern {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.dash-sub-modern {
    opacity: 0.7;
    font-size: 0.75rem;
}

/* ★ Gradient colors — เหมือนหน้า Home */
.card-grad-blue   { background: linear-gradient(135deg, #0061a8, #00a8e8); }
.card-grad-green  { background: linear-gradient(135deg, #198754, #2ea043); }
.card-grad-orange { background: linear-gradient(135deg, #fd7e14, #f59f00); }
.card-grad-red    { background: linear-gradient(135deg, #dc3545, #e74c3c); }
.card-grad-cyan   { background: linear-gradient(135deg, #0dcaf0, #00a8e8); }
.card-grad-purple { background: linear-gradient(135deg, #6f42c1, #9b59b6); }

/* ═══════════════════════════════════════════════
   ★ Animated Dashboard Icons
   ═══════════════════════════════════════════════ */

/* ★ Float animation — ไอคอนลอยขึ้นลง */
@keyframes dashIconFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.dash-icon-animate {
    animation: dashIconFloat 2.5s ease-in-out infinite;
}

/* ★ Pulse animation — ไอคอนเต้นเหมือนหัวใจ (สำหรับการ์ดรอดำเนินการ) */
@keyframes dashIconPulse {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.2); opacity: 0.5; }
}

.dash-icon-pulse {
    animation: dashIconPulse 1.5s ease-in-out infinite;
}

/* ★ Hover: เพิ่ม animation เร็วขึ้น */
.dash-card-modern:hover .dash-icon-animate {
    animation-duration: 1s;
}

.dash-card-modern:hover .dash-icon-pulse {
    animation-duration: 0.6s;
}

/* ★ Reduce motion — ผู้ใช้ที่ตั้งค่าลดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
    .dash-icon-animate,
    .dash-icon-pulse {
        animation: none;
    }
}

/* ═══════════════════════════════════════════════
   ★★ Bootstrap Contextual Table Rows — Dark Theme Fix
   แก้ปัญหา: table-warning/table-danger พื้นเหลือง/แดงอ่อน
   + ตัวอักษรสีขาวจากธีมมืด = มองไม่เห็น
   (ใช้ใน PM/Index + PM/PlanTimeMonitor — แถวเตือน/วิกฤต)
   ═══════════════════════════════════════════════ */

/* ★ ธีมมืด: แถวเตือน (warning) — พื้นเหลืองโปร่งแสง + ตัวอักษรเหลือง */
[data-theme="dark"] .table-warning {
    --bs-table-bg: rgba(255, 193, 7, 0.12) !important;
    --bs-table-color: #ffc107 !important;
    --bs-table-color-type: #ffc107 !important;
    --bs-table-bg-type: rgba(255, 193, 7, 0.12) !important;
    --bs-table-border-color: rgba(255, 193, 7, 0.3) !important;
    color: #ffc107 !important;
}
[data-theme="dark"] .table-warning > :not(caption) > * > * {
    color: #ffc107 !important;
    background-color: transparent !important;
}

/* ★ ธีมมืด: แถววิกฤต (danger) — พื้นแดงโปร่งแสง + ตัวอักษรแดงอ่อน */
[data-theme="dark"] .table-danger {
    --bs-table-bg: rgba(220, 53, 69, 0.15) !important;
    --bs-table-color: #ff8a94 !important;
    --bs-table-color-type: #ff8a94 !important;
    --bs-table-bg-type: rgba(220, 53, 69, 0.15) !important;
    --bs-table-border-color: rgba(220, 53, 69, 0.35) !important;
    color: #ff8a94 !important;
}
[data-theme="dark"] .table-danger > :not(caption) > * > * {
    color: #ff8a94 !important;
    background-color: transparent !important;
}

/* ★ ธีมมืด: แถวปกติ (success) — พื้นเขียวโปร่งแสง + ตัวอักษรเขียวอ่อน */
[data-theme="dark"] .table-success {
    --bs-table-bg: rgba(25, 135, 84, 0.12) !important;
    --bs-table-color: #75dfb0 !important;
    --bs-table-color-type: #75dfb0 !important;
    --bs-table-bg-type: rgba(25, 135, 84, 0.12) !important;
    --bs-table-border-color: rgba(25, 135, 84, 0.3) !important;
    color: #75dfb0 !important;
}
[data-theme="dark"] .table-success > :not(caption) > * > * {
    color: #75dfb0 !important;
    background-color: transparent !important;
}

/* ★ ธีมมืด: แถวข้อมูล (info) — พื้นฟ้าโปร่งแสง + ตัวอักษรฟ้าอ่อน */
[data-theme="dark"] .table-info {
    --bs-table-bg: rgba(13, 202, 240, 0.12) !important;
    --bs-table-color: #7ee0f0 !important;
    --bs-table-color-type: #7ee0f0 !important;
    --bs-table-bg-type: rgba(13, 202, 240, 0.12) !important;
    --bs-table-border-color: rgba(13, 202, 240, 0.3) !important;
    color: #7ee0f0 !important;
}
[data-theme="dark"] .table-info > :not(caption) > * > * {
    color: #7ee0f0 !important;
    background-color: transparent !important;
}

/* ★★ ธีมมืด: thead ที่มี inline style background สีอ่อน (#d1ecf1 ฯลฯ)
   — ปัญหาเดิม: พื้นฟ้าอ่อน + ตัวอักษรขาวจากธีม = มองไม่เห็น */
[data-theme="dark"] thead.sticky-top[style*="background"],
[data-theme="dark"] thead.sticky-top[style*="#d1ecf1"] {
    background: var(--bg-secondary) !important;
}
[data-theme="dark"] thead.sticky-top[style*="background"] th,
[data-theme="dark"] thead.sticky-top[style*="#d1ecf1"] th {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* ★ ธีมมืด: แถวเตือนที่ถูก hover — คงสีเหลือง (ไม่กลืน hover ปกติ) */
[data-theme="dark"] .table-hover > tbody > tr.table-warning:hover > * {
    --bs-table-color-type: #ffc107 !important;
    --bs-table-bg-type: rgba(255, 193, 7, 0.2) !important;
    color: #ffc107 !important;
}
[data-theme="dark"] .table-hover > tbody > tr.table-danger:hover > * {
    --bs-table-color-type: #ff8a94 !important;
    --bs-table-bg-type: rgba(220, 53, 69, 0.25) !important;
    color: #ff8a94 !important;
}
[data-theme="dark"] .table-hover > tbody > tr.table-success:hover > * {
    --bs-table-color-type: #75dfb0 !important;
    --bs-table-bg-type: rgba(25, 135, 84, 0.2) !important;
    color: #75dfb0 !important;
}
[data-theme="dark"] .table-hover > tbody > tr.table-info:hover > * {
    --bs-table-color-type: #7ee0f0 !important;
    --bs-table-bg-type: rgba(13, 202, 240, 0.2) !important;
    color: #7ee0f0 !important;
}