/* =====================================================================
   Cremation UI Theme v3.1  —  ปรับเฉพาะหน้าตา (Visual layer only)
   ใช้ร่วมกับ Bootstrap 5.3 + Tailwind (prefix tw-) + Three.js
   - ทุก selector ขึ้นต้นด้วย html.cui เพื่อไม่ชนกับ CSS เดิม
   - ไม่เปลี่ยนโครงสร้าง เมนู หรือเนื้อหาใดๆ
   ===================================================================== */

/* ---------- 1. Design tokens ---------- */
html.cui {
  --cui-primary: #2563eb;
  --cui-primary-2: #1e40af;
  --cui-navy: #0f1e46;
  --cui-navy-2: #172b66;
  --cui-teal: #0d9488;
  --cui-gold: #d4a63a;
  --cui-ink: #1b2537;
  --cui-muted: #64748b;
  --cui-line: rgba(15, 30, 70, 0.08);
  --cui-surface: rgba(255, 255, 255, 0.93);
  --cui-surface-solid: #ffffff;
  --cui-radius: 1.1rem;
  --cui-radius-sm: 0.7rem;
  --cui-shadow-sm: 0 1px 2px rgba(15, 30, 70, 0.06), 0 4px 12px rgba(15, 30, 70, 0.05);
  --cui-shadow: 0 2px 4px rgba(15, 30, 70, 0.04), 0 12px 32px rgba(15, 30, 70, 0.09);
  --cui-shadow-lg: 0 6px 12px rgba(15, 30, 70, 0.06), 0 24px 60px rgba(15, 30, 70, 0.16);
  --cui-ease: cubic-bezier(0.2, 0.75, 0.2, 1);
  --cui-grad-primary: linear-gradient(120deg, #1e40af 0%, #2563eb 55%, #0ea5e9 100%);
  --cui-grad-nav: linear-gradient(115deg, #0f1e46 0%, #1e3a8a 45%, #2563eb 80%, #0d9488 120%);
  --cui-grad-side: linear-gradient(170deg, #0f1e46 0%, #15296a 55%, #12355f 100%);
  --cui-grad-gold: linear-gradient(120deg, #b7862a, #e7c46a 50%, #b7862a);

  --bs-body-font-family: 'Sarabun', 'Kanit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bs-border-radius: 0.7rem;
  --bs-border-radius-lg: 1rem;
  --bs-link-color-rgb: 37, 99, 235;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 2. Page background + typography ---------- */
html.cui body {
  font-family: var(--bs-body-font-family);
  color: var(--cui-ink);
  background:
    radial-gradient(1100px 600px at -10% -10%, rgba(37, 99, 235, 0.10), transparent 60%),
    radial-gradient(900px 600px at 110% 10%, rgba(13, 148, 136, 0.09), transparent 60%),
    radial-gradient(800px 500px at 50% 120%, rgba(212, 166, 58, 0.08), transparent 60%),
    linear-gradient(180deg, #f7f9fe 0%, #eef2f9 100%) !important;
  background-attachment: fixed !important;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  animation: cuiPageIn 0.55s ease both;
}

html.cui h1, html.cui h2, html.cui h3, html.cui h4, html.cui h5, html.cui h6,
html.cui .h1, html.cui .h2, html.cui .h3, html.cui .h4, html.cui .h5, html.cui .h6,
html.cui .navbar-brand, html.cui .modal-title, html.cui .offcanvas-title,
html.cui .card-title, html.cui .sidebar-section-title {
  font-family: 'Kanit', 'Sarabun', sans-serif;
  letter-spacing: 0.005em;
}

html.cui ::selection { background: rgba(37, 99, 235, 0.18); color: inherit; }

html.cui a { transition: color 0.2s ease; }

/* Three.js canvas (ใส่โดย JS) */
#cui-bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s ease;
}
#cui-bg.cui-ready { opacity: 1; }

/* Scrollbar */
html.cui ::-webkit-scrollbar { width: 10px; height: 10px; }
html.cui ::-webkit-scrollbar-track { background: transparent; }
html.cui ::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.45), rgba(13, 148, 136, 0.45));
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
html.cui ::-webkit-scrollbar-thumb:hover { background-color: rgba(37, 99, 235, 0.7); }
html.cui { scrollbar-width: thin; scrollbar-color: rgba(37, 99, 235, 0.45) transparent; }

/* ---------- 3. Top progress bar + back-to-top ---------- */
.cui-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  z-index: 2000;
  background: linear-gradient(90deg, #0ea5e9, #2563eb, #d4a63a);
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.6);
  border-radius: 0 3px 3px 0;
  transition: width 0.5s var(--cui-ease), opacity 0.4s ease 0.2s;
  pointer-events: none;
}
.cui-progress.is-loading { width: 70%; transition: width 6s cubic-bezier(0.1, 0.6, 0.2, 1); }
.cui-progress.is-done { width: 100%; opacity: 0; }

.cui-totop {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  width: 46px; height: 46px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: var(--cui-grad-primary);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.35);
  z-index: 1030;
  display: grid; place-items: center;
  font-size: 1.2rem;
  opacity: 0;
  transform: translateY(16px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.35s var(--cui-ease), box-shadow 0.25s ease;
}
.cui-totop.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.cui-totop:hover { box-shadow: 0 14px 30px rgba(37, 99, 235, 0.45); transform: translateY(-3px); }

/* ---------- 4. Navbar (top menu) ---------- */
html.cui .navbar {
  transition: box-shadow 0.3s ease, background 0.3s ease, backdrop-filter 0.3s ease;
}
html.cui .navbar.bg-primary,
html.cui .navbar.bg-dark,
html.cui .navbar.navbar-dark:not([class*="bg-"]) {
  background: var(--cui-grad-nav) !important;
  background-size: 200% 100% !important;
  animation: cuiGradientShift 18s ease-in-out infinite;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: 0 8px 28px rgba(15, 30, 70, 0.22);
}
html.cui .navbar.bg-light,
html.cui .navbar.bg-white,
html.cui .navbar.navbar-light {
  background: rgba(255, 255, 255, 0.92) !important;
  border-bottom: 1px solid var(--cui-line);
  box-shadow: 0 6px 22px rgba(15, 30, 70, 0.06);
}
html.cui body.cui-scrolled .navbar { box-shadow: 0 12px 34px rgba(15, 30, 70, 0.28); }

html.cui .navbar-brand {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  transition: transform 0.3s var(--cui-ease), text-shadow 0.3s ease;
}
html.cui .navbar-dark .navbar-brand { text-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); }
html.cui .navbar-brand img {
  border-radius: 12px;
  transition: transform 0.5s var(--cui-ease);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.2));
}
html.cui .navbar-brand:hover img { transform: rotate(-6deg) scale(1.06); }

html.cui .navbar .nav-link {
  position: relative;
  border-radius: 0.6rem;
  padding-inline: 0.8rem !important;
  font-weight: 500;
  transition: background-color 0.25s ease, color 0.25s ease;
}
html.cui .navbar-dark .nav-link:hover,
html.cui .navbar-dark .nav-link:focus { background-color: rgba(255, 255, 255, 0.12); }
html.cui .navbar-light .nav-link:hover { background-color: rgba(37, 99, 235, 0.08); }
html.cui .navbar .nav-link:not(.dropdown-toggle)::before {
  content: "";
  position: absolute;
  left: 0.8rem; right: 0.8rem; bottom: 0.25rem;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, #7dd3fc, #e7c46a);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s var(--cui-ease);
}
html.cui .navbar .nav-link:hover::before,
html.cui .navbar .nav-link.active::before,
html.cui .navbar .nav-link.cui-active::before { transform: scaleX(1); }

html.cui .navbar .btn { border-radius: 999px; }
html.cui .navbar-toggler {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 0.75rem;
  padding: 0.4rem 0.6rem;
  transition: background-color 0.2s ease, transform 0.2s ease;
}
html.cui .navbar-toggler:focus { box-shadow: 0 0 0 0.2rem rgba(125, 211, 252, 0.35); }
html.cui .navbar-toggler:active { transform: scale(0.94); }

/* เมนูที่ยุบบนมือถือ */
@media (max-width: 991.98px) {
  html.cui .navbar-dark .navbar-collapse.show,
  html.cui .navbar-dark .navbar-collapse.collapsing {
    margin-top: 0.6rem;
    padding: 0.5rem;
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  html.cui .navbar .nav-link:not(.dropdown-toggle)::before { display: none; }
}

/* ---------- 5. Sidebar menus ---------- */
html.cui .sidebar-container,
html.cui .sidebar:not(.bg-orange):not([class*="bg-"]),
html.cui nav.sidebar:not(.bg-orange) {
  background:
    radial-gradient(400px 220px at 0% 0%, rgba(125, 211, 252, 0.16), transparent 70%),
    radial-gradient(300px 260px at 100% 100%, rgba(212, 166, 58, 0.14), transparent 70%),
    var(--cui-grad-side) !important;
  box-shadow: 6px 0 30px rgba(15, 30, 70, 0.18);
}
html.cui .sidebar.bg-orange,
html.cui .bg-orange {
  background:
    radial-gradient(360px 220px at 0% 0%, rgba(255, 255, 255, 0.18), transparent 70%),
    linear-gradient(165deg, #f59e0b 0%, #ea7a12 45%, #c2410c 100%) !important;
}

html.cui .sidebar-container h5,
html.cui .sidebar .sidebar-title {
  font-weight: 600;
  letter-spacing: 0.02em;
}

html.cui .sidebar-username,
html.cui .sidebar .sidebar-user {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0.9rem;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 8px 20px rgba(0, 0, 0, 0.12);
  font-weight: 500;
}

html.cui .sidebar-section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: rgba(226, 232, 255, 0.72) !important;
  font-size: 0.82rem !important;
  font-weight: 500 !important;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
html.cui .sidebar-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.25), transparent);
}

html.cui .sidebar-link,
html.cui .sidebar a:not(.btn),
html.cui .sidebar .nav-link,
html.cui .sidebar-container a:not(.btn) {
  position: relative;
  color: rgba(241, 245, 255, 0.9) !important;
  border-radius: 0.75rem;
  transition: background-color 0.25s ease, color 0.25s ease, padding-left 0.3s var(--cui-ease), transform 0.25s var(--cui-ease);
  overflow: hidden;
}
html.cui .sidebar-link::before,
html.cui .sidebar a:not(.btn)::before,
html.cui .sidebar-container a:not(.btn)::before {
  content: "";
  position: absolute;
  left: 0; top: 18%; bottom: 18%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, #7dd3fc, #e7c46a);
  transform: scaleY(0);
  transition: transform 0.3s var(--cui-ease);
}
html.cui .sidebar-link:hover,
html.cui .sidebar a:not(.btn):hover,
html.cui .sidebar .nav-link:hover,
html.cui .sidebar-container a:not(.btn):hover {
  color: #fff !important;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04)) !important;
  padding-left: 1.25rem;
}
html.cui .sidebar-link:hover::before,
html.cui .sidebar a:not(.btn):hover::before,
html.cui .sidebar-container a:not(.btn):hover::before,
html.cui .sidebar-link.cui-active::before,
html.cui .sidebar a.cui-active::before,
html.cui .sidebar-container a.cui-active::before { transform: scaleY(1); }
html.cui .sidebar-link.cui-active,
html.cui .sidebar a.cui-active,
html.cui .sidebar .nav-link.active,
html.cui .sidebar-container a.cui-active {
  color: #fff !important;
  background: linear-gradient(90deg, rgba(125, 211, 252, 0.22), rgba(255, 255, 255, 0.05)) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10);
  font-weight: 600;
}
html.cui .sidebar-link:active,
html.cui .sidebar a:not(.btn):active { transform: scale(0.98); }

/* Offcanvas (เมนูบนมือถือ/แท็บเล็ต) */
html.cui .offcanvas {
  border: 0 !important;
  box-shadow: 0 0 60px rgba(15, 30, 70, 0.35);
}
html.cui .offcanvas.offcanvas-start { border-radius: 0 1.4rem 1.4rem 0; }
html.cui .offcanvas.offcanvas-end { border-radius: 1.4rem 0 0 1.4rem; }
html.cui .offcanvas.offcanvas-start,
html.cui .offcanvas.offcanvas-end { width: min(300px, 86vw); }
html.cui .offcanvas-header { padding: 1.1rem 1.25rem; }
html.cui .offcanvas-body { scrollbar-width: thin; }
html.cui .offcanvas-backdrop.show {
  opacity: 0.45;
}
html.cui .offcanvas-backdrop {
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
html.cui .offcanvas.showing .offcanvas-body > *,
html.cui .offcanvas.show:not(.hiding) .offcanvas-body > * {
  animation: cuiSlideIn 0.45s var(--cui-ease) both;
}
html.cui .offcanvas.show .offcanvas-body > *:nth-child(2) { animation-delay: 0.04s; }
html.cui .offcanvas.show .offcanvas-body > *:nth-child(3) { animation-delay: 0.08s; }
html.cui .offcanvas.show .offcanvas-body > *:nth-child(4) { animation-delay: 0.12s; }
html.cui .offcanvas.show .offcanvas-body > *:nth-child(5) { animation-delay: 0.16s; }
html.cui .offcanvas.show .offcanvas-body > *:nth-child(n+6) { animation-delay: 0.2s; }

/* ---------- 6. Cards & dashboard tiles ---------- */
html.cui .card {
  border-color: var(--cui-line);
  border-radius: var(--cui-radius);
  background-color: var(--cui-surface);
  box-shadow: var(--cui-shadow);
  transition: transform 0.35s var(--cui-ease), box-shadow 0.35s var(--cui-ease), border-color 0.3s ease;
}
html.cui .card.bg-light { background-color: rgba(248, 250, 255, 0.92) !important; }
html.cui .card.shadow-lg { box-shadow: var(--cui-shadow-lg) !important; }
html.cui .card.shadow-sm { box-shadow: var(--cui-shadow-sm) !important; }
html.cui .card:hover { box-shadow: var(--cui-shadow-lg); }
html.cui .card.cui-lift:hover { transform: translateY(-5px); border-color: rgba(37, 99, 235, 0.18); }

html.cui .card-header {
  border-bottom: 1px solid var(--cui-line);
  background: linear-gradient(180deg, rgba(241, 245, 255, 0.9), rgba(255, 255, 255, 0.6));
  font-weight: 600;
}
html.cui .card-header:first-child { border-radius: var(--cui-radius) var(--cui-radius) 0 0; }
html.cui .card-header.bg-primary,
html.cui .card-header.bg-success,
html.cui .card-header.bg-info,
html.cui .card-header.bg-danger,
html.cui .card-header.bg-warning,
html.cui .card-header.bg-dark,
html.cui .card-header.bg-secondary { border-bottom: 0; }
html.cui .card-footer {
  background: rgba(248, 250, 255, 0.7);
  border-top: 1px solid var(--cui-line);
}
html.cui .card-footer:last-child { border-radius: 0 0 var(--cui-radius) var(--cui-radius); }

/* สีพื้นหลังแบบไล่เฉด (ใช้ class เดิมของ Bootstrap) */
html.cui .bg-primary:not(.navbar):not(.badge):not(.progress-bar):not(.sidebar) { background-image: linear-gradient(135deg, #1e40af 0%, #2563eb 55%, #38bdf8 130%) !important; }
html.cui .bg-success:not(.badge):not(.progress-bar) { background-image: linear-gradient(135deg, #047857 0%, #10b981 60%, #6ee7b7 140%) !important; }
html.cui .bg-info:not(.badge):not(.progress-bar)    { background-image: linear-gradient(135deg, #0369a1 0%, #0ea5e9 60%, #67e8f9 140%) !important; }
html.cui .bg-danger:not(.badge):not(.progress-bar)  { background-image: linear-gradient(135deg, #9f1239 0%, #e11d48 60%, #fb7185 140%) !important; }
html.cui .bg-warning:not(.badge):not(.progress-bar) { background-image: linear-gradient(135deg, #b45309 0%, #f59e0b 60%, #fcd34d 140%) !important; }
html.cui .bg-secondary:not(.badge):not(.progress-bar) { background-image: linear-gradient(135deg, #334155 0%, #64748b 100%) !important; }
html.cui .bg-dark:not(.badge):not(.navbar) { background-image: linear-gradient(135deg, #0b1220 0%, #1e293b 100%) !important; }

html.cui .dashboard-box,
html.cui .dashboard-circle {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 30px rgba(15, 30, 70, 0.14) !important;
  transition: transform 0.4s var(--cui-ease), box-shadow 0.4s var(--cui-ease) !important;
  will-change: transform;
}
html.cui .dashboard-box { border-radius: 1.1rem !important; }
html.cui .dashboard-box::before,
html.cui .dashboard-circle::before {
  content: "";
  position: absolute;
  width: 160px; height: 160px;
  right: -50px; top: -60px; left: auto; bottom: auto;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 70%);
  z-index: -1;
  transition: transform 0.8s var(--cui-ease);
}
html.cui .dashboard-box::after,
html.cui .dashboard-circle::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; right: auto;
  left: -60%;
  width: 40%; height: auto;
  border: 0; border-radius: 0;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.28), transparent);
  transform: skewX(-20deg);
  animation: cuiShine 6s ease-in-out infinite;
  z-index: -1;
  pointer-events: none;
}
html.cui .dashboard-box:hover,
html.cui .dashboard-circle:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 44px rgba(15, 30, 70, 0.22) !important;
}
html.cui .dashboard-box:hover::before { transform: scale(1.35) translate(-10px, 10px); }
html.cui .dashboard-box.cui-tilting {
  transform: perspective(900px) rotateX(var(--cui-rx, 0deg)) rotateY(var(--cui-ry, 0deg)) translateY(-6px);
  transition: transform 0.12s linear, box-shadow 0.4s var(--cui-ease) !important;
}
html.cui .dashboard-box h2,
html.cui .circle-value {
  font-family: 'Kanit', sans-serif;
  font-weight: 600;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  font-variant-numeric: tabular-nums;
}
html.cui .dashboard-box h6 { opacity: 0.95; font-weight: 500; letter-spacing: 0.01em; }
html.cui .dashboard-box .bi,
html.cui .dashboard-box i { display: inline-block; animation: cuiFloat 4s ease-in-out infinite; }

html.cui .shortcut-card,
html.cui .hover-card {
  border-radius: 1.1rem !important;
  transition: transform 0.35s var(--cui-ease), box-shadow 0.35s var(--cui-ease), background-color 0.3s ease !important;
}
html.cui .shortcut-card:hover,
html.cui .hover-card:hover {
  transform: translateY(-7px);
  box-shadow: 0 22px 44px rgba(37, 99, 235, 0.16) !important;
}
html.cui .shortcut-card .display-4,
html.cui .hover-card .display-4 {
  display: inline-block;
  transition: transform 0.45s var(--cui-ease);
}
html.cui .shortcut-card:hover .display-4,
html.cui .hover-card:hover .display-4 { transform: scale(1.14) rotate(-6deg); }

/* ---------- 7. Buttons ---------- */
html.cui .btn {
  --bs-btn-border-radius: 0.7rem;
  --bs-btn-font-weight: 500;
  --bs-btn-focus-box-shadow: 0 0 0 0.22rem rgba(37, 99, 235, 0.25);
  position: relative;
  transition: transform 0.2s var(--cui-ease), box-shadow 0.25s ease, background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, filter 0.2s ease;
}
html.cui .btn-sm { --bs-btn-border-radius: 0.55rem; }
html.cui .btn-lg { --bs-btn-border-radius: 0.9rem; }
html.cui .btn:not(:disabled):not(.disabled):hover { transform: translateY(-2px); }
html.cui .btn:not(:disabled):not(.disabled):active { transform: translateY(0) scale(0.97); }
html.cui .btn-group > .btn:hover,
html.cui .input-group > .btn:hover { transform: none; }

html.cui .btn-primary { background-image: linear-gradient(120deg, #1e40af, #2563eb 60%, #3b82f6); border-color: #2563eb; box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28); }
html.cui .btn-success { background-image: linear-gradient(120deg, #047857, #10b981); border-color: #059669; box-shadow: 0 6px 16px rgba(16, 185, 129, 0.26); }
html.cui .btn-danger  { background-image: linear-gradient(120deg, #be123c, #f43f5e); border-color: #e11d48; box-shadow: 0 6px 16px rgba(225, 29, 72, 0.24); }
html.cui .btn-warning { background-image: linear-gradient(120deg, #f59e0b, #fbbf24); border-color: #f59e0b; box-shadow: 0 6px 16px rgba(245, 158, 11, 0.26); }
html.cui .btn-info    { background-image: linear-gradient(120deg, #0284c7, #22d3ee); border-color: #0ea5e9; box-shadow: 0 6px 16px rgba(14, 165, 233, 0.26); --bs-btn-color: #fff; --bs-btn-hover-color: #fff; --bs-btn-active-color: #fff; }
html.cui .btn-secondary { background-image: linear-gradient(120deg, #475569, #64748b); border-color: #64748b; box-shadow: 0 6px 16px rgba(71, 85, 105, 0.22); }
html.cui .btn-dark    { background-image: linear-gradient(120deg, #0f172a, #334155); border-color: #1e293b; box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25); }
html.cui .btn-primary:hover, html.cui .btn-success:hover, html.cui .btn-danger:hover,
html.cui .btn-warning:hover, html.cui .btn-info:hover, html.cui .btn-secondary:hover,
html.cui .btn-dark:hover { filter: brightness(1.07) saturate(1.05); }
html.cui .btn-light { --bs-btn-bg: rgba(255, 255, 255, 0.92); --bs-btn-hover-bg: #fff; --bs-btn-border-color: rgba(15, 30, 70, 0.10); --bs-btn-hover-border-color: rgba(37, 99, 235, 0.25); box-shadow: var(--cui-shadow-sm); }
html.cui [class*="btn-outline-"] { border-width: 1.5px; --bs-btn-bg: rgba(255, 255, 255, 0.55); }
html.cui .navbar [class*="btn-outline-"],
html.cui .bg-primary [class*="btn-outline-"],
html.cui .bg-dark [class*="btn-outline-"],
html.cui .sidebar-container [class*="btn-outline-"],
html.cui .btn-outline-light { --bs-btn-bg: rgba(255, 255, 255, 0.06); }
html.cui [class*="btn-outline-"]:hover { box-shadow: 0 8px 18px rgba(15, 30, 70, 0.14); }
html.cui .btn-link { box-shadow: none !important; }

/* Ripple (สร้างโดย JS) */
.cui-ripple-host { overflow: hidden !important; }
.cui-ripple {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: currentColor;
  opacity: 0.25;
  transform: scale(0);
  animation: cuiRipple 0.6s ease-out forwards;
}

/* ---------- 8. Forms ---------- */
html.cui .form-control,
html.cui .form-select {
  border-color: #d6deeb;
  border-radius: var(--cui-radius-sm);
  background-color: rgba(255, 255, 255, 0.92);
  transition: border-color 0.2s ease, box-shadow 0.25s ease, background-color 0.2s ease;
}
html.cui .form-control:hover:not(:disabled):not([readonly]),
html.cui .form-select:hover:not(:disabled) { border-color: #a9bbdc; }
html.cui .form-control:focus,
html.cui .form-select:focus {
  border-color: #60a5fa;
  background-color: #fff;
  box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.14), 0 6px 16px rgba(37, 99, 235, 0.08);
}
html.cui .form-control:disabled,
html.cui .form-control[readonly] { background-color: #f1f4fa; }
html.cui .form-label { font-weight: 500; color: #334155; }
html.cui .form-check-input { border-color: #a9bbdc; transition: all 0.2s ease; }
html.cui .form-check-input:checked { background-color: var(--cui-primary); border-color: var(--cui-primary); box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3); }
html.cui .form-check-input:focus { box-shadow: 0 0 0 0.22rem rgba(37, 99, 235, 0.18); }
html.cui .input-group-text {
  border-color: #d6deeb;
  background: linear-gradient(180deg, #f6f8fd, #eef2fa);
  color: var(--cui-primary-2);
}
html.cui .input-group > :first-child:not(.dropdown-menu) { border-top-left-radius: var(--cui-radius-sm); border-bottom-left-radius: var(--cui-radius-sm); }
html.cui .input-group > :last-child:not(.dropdown-menu) { border-top-right-radius: var(--cui-radius-sm); border-bottom-right-radius: var(--cui-radius-sm); }
html.cui .input-group:focus-within .input-group-text { border-color: #60a5fa; color: var(--cui-primary); }
html.cui .was-validated .form-control:invalid,
html.cui .form-control.is-invalid { animation: cuiShake 0.4s ease; }

/* jQuery UI datepicker */
html.cui .ui-datepicker {
  border: 0 !important;
  border-radius: 1rem !important;
  padding: 0.5rem !important;
  box-shadow: var(--cui-shadow-lg) !important;
  font-family: var(--bs-body-font-family) !important;
}
html.cui .ui-datepicker .ui-datepicker-header { border: 0; border-radius: 0.7rem; background: var(--cui-grad-primary); color: #fff; }
html.cui .ui-datepicker .ui-state-default { border-radius: 0.5rem; border-color: transparent; text-align: center; }
html.cui .ui-datepicker .ui-state-active,
html.cui .ui-datepicker .ui-state-hover { background: var(--cui-primary); color: #fff; border-color: var(--cui-primary); }

/* ---------- 9. Tables ---------- */
html.cui .table {
  --bs-table-hover-bg: rgba(37, 99, 235, 0.06);
  --bs-table-striped-bg: rgba(37, 99, 235, 0.025);
  border-color: rgba(15, 30, 70, 0.08);
  vertical-align: middle;
}
html.cui .table > thead > tr > th,
html.cui .table > thead > tr > td {
  font-family: 'Kanit', 'Sarabun', sans-serif;
  font-weight: 500;
  letter-spacing: 0.01em;
}
html.cui .table > thead:not([class*="table-"]) > tr > *,
html.cui .table:not([class*="table-dark"]) > thead.table-light > tr > * {
  --bs-table-bg: #edf2fc;
  --bs-table-color: #1e3a8a;
  border-bottom-color: rgba(37, 99, 235, 0.25);
}
html.cui .table > thead.table-dark > tr,
html.cui .table > thead.table-primary > tr,
html.cui .table.table-dark > thead > tr {
  background-color: #1e3a8a;
  background-image: linear-gradient(120deg, #0f1e46, #1e3a8a 55%, #1d4ed8);
}
html.cui .table > thead.table-dark > tr > *,
html.cui .table > thead.table-primary > tr > *,
html.cui .table.table-dark > thead > tr > * {
  --bs-table-bg: transparent;
  --bs-table-bg-type: transparent;
  --bs-table-accent-bg: transparent;
  background-color: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.08);
}
html.cui .table > tbody > tr { transition: background-color 0.2s ease; }
html.cui .table-hover > tbody > tr:hover > * { --bs-table-bg-state: rgba(37, 99, 235, 0.07); }
html.cui .table-responsive {
  border-radius: 0.9rem;
  scrollbar-width: thin;
}
html.cui .card > .table-responsive:last-child,
html.cui .card-body > .table-responsive { box-shadow: inset 0 0 0 1px var(--cui-line); }

/* DataTables (ถ้ามี) */
html.cui .dataTables_wrapper .dataTables_filter input,
html.cui .dataTables_wrapper .dataTables_length select,
html.cui div.dt-container .dt-input { border-radius: 0.6rem; border: 1px solid #d6deeb; padding: 0.3rem 0.6rem; }

/* ---------- 10. Pagination / badges / list ---------- */
html.cui .pagination { gap: 0.3rem; flex-wrap: wrap; }
html.cui .pagination .page-link {
  border-radius: 0.65rem !important;
  border-color: var(--cui-line);
  color: var(--cui-primary-2);
  background: rgba(255, 255, 255, 0.85);
  min-width: 2.4rem;
  text-align: center;
  transition: all 0.25s var(--cui-ease);
  box-shadow: var(--cui-shadow-sm);
}
html.cui .pagination .page-link:hover { transform: translateY(-2px); background: #fff; color: var(--cui-primary); border-color: rgba(37, 99, 235, 0.3); }
html.cui .pagination .page-item.active .page-link {
  background: var(--cui-grad-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.3);
}
html.cui .pagination .page-item.disabled .page-link { opacity: 0.55; box-shadow: none; }

html.cui .badge { border-radius: 999px; font-weight: 500; padding: 0.4em 0.75em; letter-spacing: 0.01em; }

html.cui .list-group { border-radius: var(--cui-radius); }
html.cui .list-group-item { border-color: var(--cui-line); transition: background-color 0.2s ease, padding-left 0.25s var(--cui-ease); }
html.cui .list-group-item-action:hover { background: rgba(37, 99, 235, 0.06); padding-left: 1.3rem; }
html.cui .list-group-item.active { background: var(--cui-grad-primary); border-color: transparent; }

html.cui .nav-tabs { border-bottom-color: var(--cui-line); gap: 0.25rem; }
html.cui .nav-tabs .nav-link { border-radius: 0.7rem 0.7rem 0 0; transition: all 0.2s ease; }
html.cui .nav-tabs .nav-link.active { color: var(--cui-primary); font-weight: 600; box-shadow: inset 0 -2px 0 var(--cui-primary); }
html.cui .nav-pills .nav-link { border-radius: 999px; transition: all 0.2s ease; }
html.cui .nav-pills .nav-link.active { background: var(--cui-grad-primary); box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28); }

html.cui .progress { border-radius: 999px; background: rgba(37, 99, 235, 0.08); }
html.cui .progress-bar { background-image: linear-gradient(90deg, #2563eb, #0ea5e9); }

/* ---------- 11. Alerts ---------- */
html.cui .alert {
  border: 0;
  border-left: 4px solid currentColor;
  border-radius: 0.9rem;
  box-shadow: 0 8px 22px rgba(15, 30, 70, 0.07);
  animation: cuiAlertIn 0.55s var(--cui-ease) both;
}
html.cui .alert-success { background: linear-gradient(120deg, rgba(209, 250, 229, 0.95), rgba(236, 253, 245, 0.92)); color: #065f46; }
html.cui .alert-danger  { background: linear-gradient(120deg, rgba(255, 228, 230, 0.95), rgba(255, 241, 242, 0.92)); color: #9f1239; }
html.cui .alert-warning { background: linear-gradient(120deg, rgba(254, 243, 199, 0.95), rgba(255, 251, 235, 0.92)); color: #92400e; }
html.cui .alert-info    { background: linear-gradient(120deg, rgba(224, 242, 254, 0.95), rgba(240, 249, 255, 0.92)); color: #075985; }
html.cui .alert-primary { background: linear-gradient(120deg, rgba(219, 234, 254, 0.95), rgba(239, 246, 255, 0.92)); color: #1e3a8a; }

/* ---------- 12. Dropdowns ---------- */
html.cui .dropdown-menu {
  border: 1px solid var(--cui-line);
  border-radius: 0.95rem;
  padding: 0.4rem;
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: var(--cui-shadow-lg);
}
html.cui .dropdown-menu.show { animation: cuiDropIn 0.22s var(--cui-ease) both; }
html.cui .dropdown-item {
  border-radius: 0.6rem;
  padding: 0.5rem 0.8rem;
  transition: background-color 0.2s ease, padding-left 0.25s var(--cui-ease), color 0.2s ease;
}
html.cui .dropdown-item:hover,
html.cui .dropdown-item:focus { background: rgba(37, 99, 235, 0.08); color: var(--cui-primary-2); padding-left: 1.05rem; }
html.cui .dropdown-item.active,
html.cui .dropdown-item:active { background: var(--cui-grad-primary); color: #fff; }

/* ---------- 13. Modals / Popups ---------- */
html.cui .modal-backdrop.show { opacity: 0.62; }
html.cui .modal-backdrop {
  background: radial-gradient(circle at 50% 30%, #1e3a8a, #050b1f 75%);
}
html.cui .modal.fade .modal-dialog {
  transform: translateY(24px) scale(0.94);
  opacity: 0;
  transition: transform 0.42s var(--cui-ease), opacity 0.3s ease;
}
html.cui .modal.show .modal-dialog { transform: none; opacity: 1; }
html.cui .modal.modal-static .modal-dialog { transform: scale(1.02); }
html.cui .modal-content {
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 1.3rem;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 30px 80px rgba(5, 11, 31, 0.35);
}
html.cui .modal-header { position: relative; border-bottom-color: var(--cui-line); }
html.cui .modal-header::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 4px;
  background: linear-gradient(90deg, #2563eb, #0ea5e9, #d4a63a, #2563eb);
  background-size: 300% 100%;
  animation: cuiGradientShift 6s linear infinite;
}
html.cui .modal-footer { border-top-color: var(--cui-line); background: rgba(248, 250, 255, 0.7); }
html.cui .btn-close { border-radius: 0.6rem; transition: transform 0.3s var(--cui-ease), opacity 0.2s ease, background-color 0.2s ease; }
html.cui .btn-close:hover { transform: rotate(90deg); }

/* ---------- 14. Login popup (index.php → #loginModal) ---------- */
html.cui #loginModal .modal-dialog { max-width: 440px; }
html.cui #loginModal .modal-content {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 1.6rem !important;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 40px 100px rgba(5, 11, 31, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.4) inset;
}
html.cui #loginModal .modal-header {
  position: relative;
  overflow: hidden;
  color: #fff;
  padding: 1.6rem 1.6rem 1.4rem !important;
  background: linear-gradient(125deg, #0f1e46 0%, #1e3a8a 45%, #2563eb 80%, #0d9488 130%);
  background-size: 180% 180%;
  animation: cuiGradientShift 10s ease-in-out infinite;
}
html.cui #loginModal .modal-header::after {
  content: "";
  position: absolute;
  width: 220px; height: 220px;
  right: -70px; top: -110px;
  border-radius: 50%;
  border: 38px solid rgba(255, 255, 255, 0.07);
  pointer-events: none;
}
html.cui #loginModal .modal-title { font-weight: 600; letter-spacing: 0.01em; }
html.cui #loginModal .modal-title .bi {
  display: inline-grid;
  place-items: center;
  width: 2.3rem; height: 2.3rem;
  margin-right: 0.6rem !important;
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 0 0 rgba(125, 211, 252, 0.6);
  animation: cuiPulseRing 2.4s ease-out infinite;
  vertical-align: middle;
}
html.cui #loginModal .modal-header .btn-close { filter: invert(1) grayscale(1) brightness(2); opacity: 0.8; position: relative; z-index: 1; }
html.cui #loginModal .modal-body { padding: 1.6rem !important; }
html.cui #loginModal .input-group { border-radius: 0.9rem; transition: box-shadow 0.25s ease, transform 0.25s var(--cui-ease); }
html.cui #loginModal .input-group:focus-within { box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.14); transform: translateY(-1px); }
html.cui #loginModal .input-group .form-control:focus { box-shadow: none; }
html.cui #loginModal .input-group-text { background: #f3f6fd !important; }
html.cui #loginModal .modal-body .mb-3,
html.cui #loginModal .modal-body .mb-4,
html.cui #loginModal .modal-body .d-grid { animation: cuiFadeUp 0.5s var(--cui-ease) both; }
html.cui #loginModal.show .modal-body .mb-3 { animation-delay: 0.08s; }
html.cui #loginModal.show .modal-body .mb-4 { animation-delay: 0.16s; }
html.cui #loginModal.show .modal-body .d-grid { animation-delay: 0.24s; }
html.cui #loginModal .btn-primary,
html.cui .btn-login,
html.cui body.cui-auth form .btn-primary,
html.cui body.cui-auth form button[type="submit"].btn {
  position: relative;
  overflow: hidden;
  background-image: linear-gradient(115deg, #0f1e46, #2563eb 60%, #0d9488) !important;
  background-size: 160% 100% !important;
  border: 0;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.32);
  transition: background-position 0.6s var(--cui-ease), transform 0.2s var(--cui-ease), box-shadow 0.25s ease;
}
html.cui #loginModal .btn-primary:hover,
html.cui .btn-login:hover,
html.cui body.cui-auth form .btn-primary:hover { background-position: 100% 0 !important; box-shadow: 0 16px 32px rgba(37, 99, 235, 0.4); }
html.cui #loginModal .btn-primary::after,
html.cui .btn-login::after,
html.cui body.cui-auth form .btn-primary::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: -40%;
  width: 30%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  transform: skewX(-20deg);
  animation: cuiShine 3.8s ease-in-out infinite;
}

/* ---------- 15. Login / auth pages (body.cui-auth ใส่โดย JS) ---------- */
html.cui body.cui-auth {
  background:
    radial-gradient(900px 600px at 10% 10%, rgba(56, 189, 248, 0.25), transparent 60%),
    radial-gradient(800px 600px at 90% 90%, rgba(13, 148, 136, 0.25), transparent 60%),
    linear-gradient(140deg, #050b1f 0%, #0f1e46 40%, #1e3a8a 75%, #0f4c5c 100%) !important;
  background-attachment: fixed !important;
}
html.cui body.cui-auth .card,
html.cui body.cui-auth .login-card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  animation: cuiAuthIn 0.9s var(--cui-ease) both;
}
html.cui body.cui-auth .login-icon {
  animation: cuiFloat 4.5s ease-in-out infinite, cuiPulseRing 2.6s ease-out infinite;
}
html.cui body.cui-auth .card-header {
  background: linear-gradient(125deg, #0f1e46, #2563eb 70%, #0d9488);
  color: #fff;
  border-bottom: 0;
}

/* ข้อความที่อยู่นอกการ์ดบนพื้นหลังเข้ม ให้อ่านง่าย */
html.cui body.cui-auth :is(h1, h2, h3, h4, h5, h6, p, small, span, .lead, .text-muted, .text-secondary, .text-dark, .text-success, .text-primary, .text-info):not(.card *):not(.login-card *):not(.modal *):not(form *):not(.btn *):not(.btn):not(.badge) {
  color: #eef3ff !important;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
}
html.cui body.cui-auth footer,
html.cui body.cui-auth footer * { color: rgba(226, 232, 255, 0.75) !important; background: transparent !important; border-color: rgba(255, 255, 255, 0.12) !important; }

/* ---------- 16. Footer ---------- */
html.cui footer.bg-light,
html.cui footer.bg-white {
  background: rgba(255, 255, 255, 0.7) !important;
  border-top: 1px solid var(--cui-line) !important;
}
html.cui footer a { text-decoration: none; font-weight: 500; }
html.cui footer a:hover { text-decoration: underline; }

/* ---------- 17. Reveal on scroll (ใส่ class โดย JS) ---------- */
html.cui .cui-reveal {
  opacity: 0;
  transform: translateY(22px);
}
html.cui .cui-reveal.cui-in {
  opacity: 1;
  transform: none;
  transition: opacity 0.7s ease var(--cui-delay, 0s), transform 0.8s var(--cui-ease) var(--cui-delay, 0s), box-shadow 0.35s var(--cui-ease), border-color 0.3s ease;
}

/* ---------- 18. Charts / images / misc ---------- */
html.cui canvas:not(#cui-bg) { max-width: 100%; }
html.cui .img-thumbnail { border-radius: 0.9rem; box-shadow: var(--cui-shadow-sm); transition: transform 0.35s var(--cui-ease), box-shadow 0.35s ease; }
html.cui .img-thumbnail:hover { transform: scale(1.03); box-shadow: var(--cui-shadow); }
html.cui .card-img-top { transition: transform 0.6s var(--cui-ease); }
html.cui .card:hover > .card-img-top { transform: scale(1.04); }
html.cui .card:has(> .card-img-top) { overflow: hidden; }
html.cui hr { opacity: 0.12; }
html.cui .text-primary { color: #1d4ed8 !important; }
html.cui .tooltip-inner { border-radius: 0.6rem; padding: 0.4rem 0.7rem; }
html.cui .toast { border-radius: 1rem; border: 0; box-shadow: var(--cui-shadow-lg); }

/* SweetAlert2 (ถ้ามี) */
html.cui .swal2-popup { border-radius: 1.4rem !important; font-family: var(--bs-body-font-family) !important; box-shadow: 0 30px 80px rgba(5, 11, 31, 0.35) !important; }
html.cui .swal2-styled { border-radius: 0.75rem !important; }
html.cui .swal2-styled.swal2-confirm { background-image: var(--cui-grad-primary) !important; }

/* ---------- 18b. Full-screen layout (เต็มกรอบ เต็มจอ ทุกอุปกรณ์) ----------
   ขยายพื้นที่เนื้อหาให้เต็มความกว้างหน้าจอ โดยไม่แตะเมนู/เนื้อหา
   ไม่ใช้กับหน้า Login (การ์ด Login ยังอยู่กลางจอขนาดเดิม) และป๊อปอัป */
html.cui body { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }

/* คอนเทนเนอร์หลักทุกแบบ → เต็มความกว้าง */
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) :is(.container, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl, .container-box, .report-card):not(.navbar *):not(.modal *):not(.offcanvas *):not(.dropdown-menu *),
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) main > div:not(.row):not([class*="col"]):not(.modal):not(.offcanvas):not(.toast-container):not(.position-fixed):not(.position-absolute),
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) main:is(.container, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl) {
  width: 100% !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) body > :is(.container, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl),
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) main:is(.container, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl),
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) main > :is(.container, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl) {
  padding-left: clamp(0.75rem, 2.2vw, 2rem);
  padding-right: clamp(0.75rem, 2.2vw, 2rem);
}

/* การ์ด/ฟอร์มที่ถูกจำกัดความกว้าง → เต็มกรอบ */
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) .card:not(.modal *):not(.offcanvas *):not(.dropdown-menu *):not(.login-card) {
  max-width: 100% !important;
}
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) :is(.card, .container, form, main > div)[style*="max-width"]:not(.modal *):not(.offcanvas *) {
  max-width: 100% !important;
  width: 100% !important;
}
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) main > .card,
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) main > div > .card:only-child { width: 100%; }

/* คอลัมน์เดียวที่จัดกึ่งกลาง → ขยายเต็มแถว */
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) .row.justify-content-center > [class*="col"]:only-child:not(.modal *) {
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
}

/* Layout มีเมนูข้าง: เมื่อเมนูข้างถูกซ่อน (Tablet/Mobile) ให้เนื้อหาเต็มจอ */
@media (max-width: 991.98px) {
  html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) .row > :is(.d-none.d-lg-block, .d-none.d-lg-flex) ~ :is(main, [class*="col-md-"], [class*="col-sm-"]) {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
  }
}
@media (max-width: 767.98px) {
  html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) .row > :is(.d-none.d-md-block, .d-none.d-md-flex) ~ :is(main, [class*="col-"]) {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
  }
}
/* Desktop: เนื้อหาหลักกินพื้นที่ที่เหลือข้างเมนูทั้งหมด */
@media (min-width: 992px) {
  html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) .row > :is(nav, aside, div):is(.sidebar, .sidebar-container, [class*="col-md-2"], [class*="col-lg-2"]):is(.d-lg-block, .sidebar, .sidebar-container) + main {
    flex: 1 1 0% !important;
    width: auto !important;
    max-width: none !important;
  }
}

/* ตารางกว้าง: เลื่อนแนวนอนได้ในกรอบ ไม่ล้นจอ (มือถือ/แท็บเล็ต) */
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) .table-responsive { width: 100%; -webkit-overflow-scrolling: touch; }
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) main { min-width: 0; }
html.cui body:not(.cui-auth):not(:has(.login-card)):not(:has(input[type="password"]):not(:has(.navbar, .sidebar, .sidebar-container, #sidebar))) .d-flex.flex-column.min-vh-100 { min-height: 100dvh !important; }

/* ---------- 19. Responsive: Tablet & Mobile ---------- */
@media (max-width: 991.98px) {
  html.cui .card { --cui-radius: 1rem; }
  html.cui .table > :not(caption) > * > * { padding: 0.6rem 0.65rem; }
}
@media (max-width: 767.98px) {
  html.cui body { background-attachment: scroll !important; }
  html.cui .navbar-brand { font-size: 1rem; white-space: normal; line-height: 1.3; }
  html.cui .sidebar-link,
  html.cui .sidebar a:not(.btn),
  html.cui .sidebar-container a:not(.btn) { padding-top: 0.6rem; padding-bottom: 0.6rem; }
  html.cui .dashboard-box h2 { font-size: 1.55rem; }
  html.cui .table { font-size: 0.9rem; }
  html.cui .modal-dialog { margin: 0.75rem; }
  html.cui .modal-content { border-radius: 1.1rem; }
  html.cui .btn:not(:disabled):not(.disabled):hover { transform: none; }
  html.cui .card.cui-lift:hover,
  html.cui .shortcut-card:hover,
  html.cui .hover-card:hover { transform: none; }
  html.cui .cui-totop { width: 42px; height: 42px; right: 0.8rem; bottom: 0.8rem; }
}
@media (max-width: 575.98px) {
  html.cui #loginModal .modal-dialog { margin: 0.9rem; }
  html.cui #loginModal .modal-header { padding: 1.3rem 1.2rem 1.1rem !important; }
  html.cui #loginModal .modal-body { padding: 1.2rem !important; }
  html.cui .pagination .page-link { min-width: 2.1rem; padding: 0.35rem 0.55rem; }
  html.cui .table { font-size: 0.84rem; }
}
@media (hover: none) {
  html.cui .dashboard-box:hover,
  html.cui .dashboard-circle:hover { transform: none; }
}

/* ---------- 20. Keyframes ---------- */
@keyframes cuiPageIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cuiFadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes cuiSlideIn { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }
@keyframes cuiDropIn { from { opacity: 0; transform: translateY(-6px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes cuiAlertIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes cuiAuthIn { from { opacity: 0; transform: translateY(30px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes cuiGradientShift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes cuiShine { 0% { left: -60%; } 55%, 100% { left: 130%; } }
@keyframes cuiFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes cuiRipple { to { transform: scale(2.6); opacity: 0; } }
@keyframes cuiShake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes cuiPulseRing {
  0% { box-shadow: 0 0 0 0 rgba(125, 211, 252, 0.55); }
  70% { box-shadow: 0 0 0 14px rgba(125, 211, 252, 0); }
  100% { box-shadow: 0 0 0 0 rgba(125, 211, 252, 0); }
}

/* ---------- 21. Accessibility & Print ---------- */
@media (prefers-reduced-motion: reduce) {
  html.cui *, html.cui *::before, html.cui *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  html.cui .cui-reveal { opacity: 1; transform: none; }
}

@media print {
  #cui-bg, .cui-progress, .cui-totop { display: none !important; }
  html.cui body { background: #fff !important; animation: none !important; }
  html.cui *, html.cui *::before, html.cui *::after { animation: none !important; transition: none !important; }
  html.cui .cui-reveal { opacity: 1 !important; transform: none !important; }
  html.cui .card { -webkit-backdrop-filter: none; backdrop-filter: none; box-shadow: none !important; background: #fff !important; }
  html.cui .dashboard-box::before, html.cui .dashboard-box::after,
  html.cui .dashboard-circle::before, html.cui .dashboard-circle::after { display: none !important; }
  html.cui .table > thead > tr > * { color: #000 !important; background: #eee !important; }
}

/* =====================================================================
   22. Full-width layout — แสดงเต็มกรอบ เต็มจอ ทุกหน้า (ยกเว้นหน้า Login)
   ปรับเฉพาะความกว้าง/ระยะขอบ ไม่เปลี่ยนเมนูหรือเนื้อหา
   ===================================================================== */
html.cui-full {
  --cui-gutter: clamp(0.75rem, 2.2vw, 2rem);
}

/* 22.1 Bootstrap containers → เต็มความกว้าง */
html.cui-full body .container,
html.cui-full body .container-sm,
html.cui-full body .container-md,
html.cui-full body .container-lg,
html.cui-full body .container-xl,
html.cui-full body .container-xxl {
  max-width: 100% !important;
  width: 100%;
  box-sizing: border-box;
  padding-left: var(--cui-gutter);
  padding-right: var(--cui-gutter);
}
html.cui-full body .navbar > .container,
html.cui-full body .navbar > .container-fluid { padding-left: var(--cui-gutter); padding-right: var(--cui-gutter); }

/* 22.2 กล่องเนื้อหาที่ถูกจำกัดความกว้างไว้ในหน้าเดิม */
html.cui-full body main,
html.cui-full body main > .container,
html.cui-full body main > div,
html.cui-full body main > section,
html.cui-full body main > form,
html.cui-full body .container-box,
html.cui-full body .form-box,
html.cui-full body .report-card,
html.cui-full body .main-content,
html.cui-full body .content-wrapper,
html.cui-full body .card:not(.login-card):not(.modal .card):not(.dropdown-menu .card),
html.cui-full body .container[style*="max-width"],
html.cui-full body .card[style*="max-width"],
html.cui-full body .cui-fill {
  max-width: none !important;
}
html.cui-full body .form-box,
html.cui-full body .report-card,
html.cui-full body .container-box,
html.cui-full body .cui-fill { width: auto !important; align-self: stretch; box-sizing: border-box; }
html.cui-full body .card[style*="max-width"]:not([class*="col-"]) { width: 100%; }

/* 22.2b หน้าที่จำกัดด้วย width: min(100%, ...px) เช่น index.php, cremation.php */
html.cui-full body > main:not([class*="col-"]),
html.cui-full body > nav:not(.navbar),
html.cui-full body > .flex-fill:not([class*="col-"]),
html.cui-full body .flex-column > main:not([class*="col-"]) {
  width: 100% !important;
  min-width: 0;
  max-width: none !important;
  box-sizing: border-box;
  margin-left: 0;
  margin-right: 0;
}
html.cui-full body.container-fluid {
  padding-left: var(--cui-gutter) !important;
  padding-right: var(--cui-gutter) !important;
}

/* 22.3 คอลัมน์เดี่ยวที่ถูกจัดกึ่งกลาง (ฟอร์ม/การ์ด) → เต็มแถว */
html.cui-full body .row.justify-content-center > [class*="col-"]:only-child,
html.cui-full body .row.justify-content-md-center > [class*="col-"]:only-child,
html.cui-full body .row.justify-content-lg-center > [class*="col-"]:only-child,
html.cui-full body .row > [class*="col-"].mx-auto:only-child,
html.cui-full body .row > [class*="offset-"]:only-child {
  flex: 0 0 100% !important;
  max-width: 100% !important;
  width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* 22.4 แถบเมนูด้านข้างถูกซ่อน (Tablet/Mobile) → พื้นที่เนื้อหาเต็มจอ */
@media (max-width: 991.98px) {
  html.cui-full body .row:has(> .d-none.d-lg-block) > :not(.d-none):is(main, [class*="col-"]),
  html.cui-full body .row:has(> .d-none.d-lg-flex) > :not(.d-none):is(main, [class*="col-"]) {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
  }
}
@media (max-width: 1199.98px) {
  html.cui-full body .row:has(> .d-none.d-xl-block) > :not(.d-none):is(main, [class*="col-"]) {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
  }
}
@media (max-width: 767.98px) {
  html.cui-full body .row:has(> .d-none.d-md-block) > :not(.d-none):is(main, [class*="col-"]) {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
  }
}

/* 22.5 ตาราง/กราฟ ใช้พื้นที่เต็มกรอบ */
html.cui-full body .table-responsive,
html.cui-full body .card > .table,
html.cui-full body .card-body > .table { width: 100%; }

html.cui body table.cui-tscroll {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* 22.6 Tablet */
@media (max-width: 991.98px) {
  html.cui-full body main[class*="p-4"],
  html.cui-full body main[class*="p-5"] { padding: var(--cui-gutter) !important; }
}

/* 22.7 Mobile — ลดระยะขอบให้เนื้อหาเต็มจอ */
@media (max-width: 575.98px) {
  html.cui-full { --cui-gutter: 0.6rem; }
  html.cui-full body main { padding-left: var(--cui-gutter) !important; padding-right: var(--cui-gutter) !important; }
  html.cui-full body .card:not(.login-card):not(.shortcut-card):not(.hover-card) { padding: 1rem; }
  html.cui-full body .card.p-4,
  html.cui-full body .card.p-5 { padding: 1rem !important; }
  html.cui-full body .card > .card-body { padding: 0.9rem; }
  html.cui-full body .row { --bs-gutter-x: 0.9rem; }
  html.cui-full body .container-fluid:has(> .row) { padding-left: 0.45rem !important; padding-right: 0.45rem !important; }
  html.cui-full body .py-5 { padding-top: 1.25rem !important; padding-bottom: 1.25rem !important; }
}

@media print {
  html.cui-full body .container,
  html.cui-full body main { padding-left: 0 !important; padding-right: 0 !important; }
}

/* =====================================================================
   23. Hero: โลโก้ 3D เคลื่อนไหว + การ์ดต้อนรับ (index.php)
   JS ใส่ class: .cui-hero-card (การ์ด), .cui-hero (กล่องโลโก้), .cui-logo3d (รูปโลโก้)
   ===================================================================== */
html.cui .cui-hero-card {
  background:
    radial-gradient(620px 260px at 50% -40px, rgba(231, 196, 106, 0.20), transparent 70%),
    radial-gradient(520px 300px at 12% 0%, rgba(37, 99, 235, 0.10), transparent 70%),
    radial-gradient(520px 300px at 88% 0%, rgba(13, 148, 136, 0.10), transparent 70%),
    linear-gradient(180deg, #ffffff 0%, rgba(250, 252, 255, 0.97) 40%, rgba(255, 255, 255, 0.96) 100%) !important;
  border: 1px solid rgba(212, 166, 58, 0.18) !important;
  box-shadow: 0 2px 6px rgba(15, 30, 70, 0.04), 0 30px 70px rgba(15, 30, 70, 0.12), inset 0 1px 0 #fff !important;
}

html.cui .cui-hero {
  position: relative;
  isolation: isolate;
  padding-top: 0.5rem;
  perspective: 1000px;
}
html.cui .cui-hero > :not(.cui-logo-halo) { position: relative; z-index: 2; }

/* วงแสงด้านหลังโลโก้ (ตำแหน่งตั้งโดย JS) */
html.cui .cui-hero::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: var(--cui-logo-cx, 50%);
  top: var(--cui-logo-cy, 110px);
  width: var(--cui-logo-glow, 320px);
  height: var(--cui-logo-glow, 320px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 240, 200, 0.55) 0%, rgba(231, 196, 106, 0.18) 32%, rgba(37, 99, 235, 0.06) 55%, transparent 70%);
  filter: blur(8px);
  animation: cuiHaloPulse 5.5s ease-in-out infinite;
  pointer-events: none;
}
/* เงาบนพื้นใต้โลโก้ */
html.cui .cui-hero::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: var(--cui-logo-cx, 50%);
  top: var(--cui-logo-bottom, 200px);
  width: calc(var(--cui-logo-w, 220px) * 0.62);
  height: 18px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(15, 30, 70, 0.30), rgba(15, 30, 70, 0) 70%);
  animation: cuiShadowPulse 7s ease-in-out infinite;
  pointer-events: none;
}

/* Three.js halo canvas */
html.cui .cui-logo-halo {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  left: var(--cui-logo-cx, 50%);
  top: var(--cui-logo-cy, 110px);
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 1s ease;
}
html.cui .cui-logo-halo.cui-ready { opacity: 1; }
html.cui .cui-hero > canvas.cui-logo-halo-front { z-index: 4; }

/* โลโก้ 3D */
html.cui .cui-hero > img.cui-logo3d {
  position: relative;
  z-index: 3 !important;
  display: inline-block;
  transform-origin: 50% 55%;
  transform-style: preserve-3d;
  backface-visibility: visible;
  will-change: transform, filter;
  cursor: grab;
  filter:
    drop-shadow(0 1px 0 rgba(150, 105, 30, 0.55))
    drop-shadow(0 2px 0 rgba(110, 75, 20, 0.35))
    drop-shadow(0 14px 16px rgba(16, 42, 103, 0.20));
  animation: cuiLogo3D 9s ease-in-out infinite, cuiLogoLight 9s ease-in-out infinite;
  transition: transform 0.25s ease-out;
}
html.cui .cui-hero > img.cui-logo3d.cui-logo-hover {
  animation: none;
  transform: perspective(900px) rotateX(var(--cui-lx, 0deg)) rotateY(var(--cui-ly, 0deg)) translateY(-8px) scale(1.04);
}
html.cui .cui-hero > img.cui-logo3d.cui-logo-spin {
  animation: cuiLogoSpin 1.3s cubic-bezier(0.3, 0.7, 0.2, 1) both !important;
}

/* หัวข้อ "ยินดีต้อนรับสู่ระบบ" ไล่สีเคลื่อนไหว */
html.cui .cui-hero h1 {
  display: table;
  margin-left: auto;
  margin-right: auto;
  background: linear-gradient(90deg, #102a67 0%, #2563eb 25%, #0d9488 45%, #b7862a 60%, #2563eb 80%, #102a67 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: cuiTextFlow 8s linear infinite, cuiFadeUp 0.8s var(--cui-ease) 0.2s both;
  letter-spacing: 0.01em;
}
html.cui .cui-hero p {
  animation: cuiFadeUp 0.8s var(--cui-ease) 0.35s both;
}

/* หัวข้อสรุปข้อมูล — เส้นประดับสองข้าง */
html.cui .cui-hero-card > h4 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
}
html.cui .cui-hero-card > h4::before,
html.cui .cui-hero-card > h4::after {
  content: "";
  flex: 0 1 120px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(212, 166, 58, 0.8));
}
html.cui .cui-hero-card > h4::after { background: linear-gradient(90deg, rgba(212, 166, 58, 0.8), transparent); }

/* กล่องสรุปตัวเลขในการ์ดต้อนรับ */
html.cui .cui-hero-card .dashboard-box {
  min-height: 150px;
  border: 1px solid rgba(255, 255, 255, 0.28) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 14px 34px rgba(15, 30, 70, 0.18) !important;
  background-size: 160% 160% !important;
  animation: cuiTileFlow 12s ease-in-out infinite;
}
html.cui .cui-hero-card .dashboard-box h6 { display: flex; align-items: center; justify-content: center; gap: 0.15rem; }
html.cui .cui-hero-card .dashboard-box h6 .bi {
  display: inline-grid;
  place-items: center;
  width: 2.25em;
  height: 2.25em;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35), 0 6px 14px rgba(0, 0, 0, 0.12);
  font-size: 1.05em;
}
html.cui .cui-hero-card .dashboard-box:hover h6 .bi { animation: cuiIconPop 0.6s var(--cui-ease); }
html.cui .cui-hero-card .dashboard-box h2 { letter-spacing: -0.01em; }
html.cui .cui-hero-card .row > [class*="col-"]:nth-child(2) .dashboard-box { animation-delay: -3s; }
html.cui .cui-hero-card .row > [class*="col-"]:nth-child(3) .dashboard-box { animation-delay: -6s; }
html.cui .cui-hero-card .row > [class*="col-"]:nth-child(4) .dashboard-box { animation-delay: -9s; }

@keyframes cuiLogo3D {
  0%   { transform: perspective(900px) rotateY(-16deg) rotateX(5deg) translateY(0); }
  25%  { transform: perspective(900px) rotateY(0deg) rotateX(-2deg) translateY(-10px); }
  50%  { transform: perspective(900px) rotateY(16deg) rotateX(4deg) translateY(-2px); }
  75%  { transform: perspective(900px) rotateY(0deg) rotateX(-3deg) translateY(-12px); }
  100% { transform: perspective(900px) rotateY(-16deg) rotateX(5deg) translateY(0); }
}
@keyframes cuiLogoLight {
  0%, 50%, 100% { filter: brightness(1) drop-shadow(0 1px 0 rgba(150, 105, 30, 0.55)) drop-shadow(0 2px 0 rgba(110, 75, 20, 0.35)) drop-shadow(0 14px 16px rgba(16, 42, 103, 0.20)) drop-shadow(0 0 10px rgba(231, 196, 106, 0.18)); }
  25%, 75% { filter: brightness(1.08) saturate(1.06) drop-shadow(0 1px 0 rgba(150, 105, 30, 0.55)) drop-shadow(0 2px 0 rgba(110, 75, 20, 0.35)) drop-shadow(0 14px 16px rgba(16, 42, 103, 0.20)) drop-shadow(0 0 22px rgba(231, 196, 106, 0.40)); }
}
@keyframes cuiLogoSpin {
  from { transform: perspective(900px) rotateY(0deg) scale(1); }
  50%  { transform: perspective(900px) rotateY(180deg) scale(1.08) translateY(-10px); }
  to   { transform: perspective(900px) rotateY(360deg) scale(1); }
}
@keyframes cuiHaloPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(0.92); opacity: 0.75; }
  50% { transform: translate(-50%, -50%) scale(1.06); opacity: 1; }
}
@keyframes cuiShadowPulse {
  0%, 50%, 100% { transform: translate(-50%, -50%) scaleX(1); opacity: 0.9; }
  25%, 75% { transform: translate(-50%, -50%) scaleX(0.78); opacity: 0.55; }
}
@keyframes cuiTextFlow { from { background-position: 0% 50%; } to { background-position: 250% 50%; } }
@keyframes cuiTileFlow { 0%, 100% { background-position: 0% 0%; } 50% { background-position: 100% 100%; } }
@keyframes cuiIconPop { 0% { transform: scale(1); } 40% { transform: scale(1.25) rotate(-8deg); } 100% { transform: scale(1); } }

@media (max-width: 575.98px) {
  html.cui .cui-hero-card > h4::before,
  html.cui .cui-hero-card > h4::after { flex-basis: 28px; }
  html.cui .cui-hero-card .dashboard-box { min-height: 120px; }
}
@media (prefers-reduced-motion: reduce) {
  html.cui .cui-hero > img.cui-logo3d { animation: none !important; transform: none; }
}
@media print {
  html.cui .cui-logo-halo, html.cui .cui-hero::before, html.cui .cui-hero::after { display: none !important; }
  html.cui .cui-hero > img.cui-logo3d { animation: none !important; transform: none !important; filter: none !important; }
  html.cui .cui-hero h1 { -webkit-text-fill-color: currentColor; background: none; }
}
