/**
 * Epsula Modern Dark Theme Engine
 * Seamlessly integrates with Bootstrap 5.3 Color Modes and Custom Porcelain Design Tokens
 */

:root[data-bs-theme="dark"],
html[data-bs-theme="dark"],
[data-bs-theme="dark"] {
  --admin-bg: #0b0f19 !important;
  --bg-primary: #0b0f19 !important;
  --bg-secondary: #131b2e !important;
  --card-bg: #131b2e !important;
  --card-border: rgba(255, 255, 255, 0.08) !important;
  --card-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3) !important;
  --card-hover-shadow: 0 20px 35px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.4) !important;
  --text-main: #f8fafc !important;
  --text-secondary: #cbd5e1 !important;
  --text-muted: #94a3b8 !important;
  color-scheme: dark;
}

/* Page Background & Ambient Glow */
html[data-bs-theme="dark"] body.admin-light-mode,
[data-bs-theme="dark"] body.admin-light-mode,
html[data-bs-theme="dark"] body,
[data-bs-theme="dark"] body {
  background-color: #0b0f19 !important;
  color: #f8fafc !important;
}

html[data-bs-theme="dark"] body.admin-light-mode::before,
[data-bs-theme="dark"] body.admin-light-mode::before,
html[data-bs-theme="dark"] body::before,
[data-bs-theme="dark"] body::before {
  background: radial-gradient(circle, #312e81, #1e1b4b) !important;
  opacity: 0.18 !important;
}

html[data-bs-theme="dark"] body.admin-light-mode::after,
[data-bs-theme="dark"] body.admin-light-mode::after,
html[data-bs-theme="dark"] body::after,
[data-bs-theme="dark"] body::after {
  background: radial-gradient(circle, #064e3b, #0c4a6e) !important;
  opacity: 0.14 !important;
}

/* Typography & Headings */
[data-bs-theme="dark"] h1, 
[data-bs-theme="dark"] h2, 
[data-bs-theme="dark"] h3, 
[data-bs-theme="dark"] h4, 
[data-bs-theme="dark"] h5, 
[data-bs-theme="dark"] h6,
[data-bs-theme="dark"] .text-dark,
[data-bs-theme="dark"] .text-dark-custom {
  color: #f8fafc !important;
}

[data-bs-theme="dark"] .text-muted,
[data-bs-theme="dark"] .text-muted-custom {
  color: #94a3b8 !important;
}

/* Cards & Containers */
[data-bs-theme="dark"] .premium-card,
[data-bs-theme="dark"] .glass-card {
  background: #131b2e !important;
  background-color: #131b2e !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2) !important;
}

[data-bs-theme="dark"] .premium-card-header,
[data-bs-theme="dark"] .glass-card-header {
  background: #161f36 !important;
  background-color: #161f36 !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
  color: #f8fafc !important;
}

/* Navigation Bars */
[data-bs-theme="dark"] .navbar-floating-premium {
  background: rgba(19, 27, 46, 0.85) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.5), 0 5px 15px -3px rgba(0, 0, 0, 0.3) !important;
}

[data-bs-theme="dark"] .navbar-light-premium,
[data-bs-theme="dark"] .navbar-custom {
  background: rgba(19, 27, 46, 0.92) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
  box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.3) !important;
}

[data-bs-theme="dark"] .navbar-brand-premium,
[data-bs-theme="dark"] .navbar-custom .navbar-brand {
  color: #ffffff !important;
}

[data-bs-theme="dark"] .nav-link-premium {
  color: #94a3b8 !important;
}

[data-bs-theme="dark"] .nav-link-premium:hover {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.07) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
}

[data-bs-theme="dark"] .nav-link-premium.active {
  background: rgba(79, 70, 229, 0.25) !important;
  color: #a5b4fc !important;
  border-color: rgba(79, 70, 229, 0.45) !important;
  box-shadow: 0 2px 10px rgba(79, 70, 229, 0.3) !important;
}

[data-bs-theme="dark"] .navbar-toggler {
  border-color: rgba(255, 255, 255, 0.15) !important;
}

[data-bs-theme="dark"] .navbar-toggler-icon {
  filter: invert(1);
}

/* =========================================================
   TABLES: DEEP BOOTSTRAP 5 & CELL-LEVEL RESET
   ========================================================= */
[data-bs-theme="dark"] .table-premium,
[data-bs-theme="dark"] .table-custom,
[data-bs-theme="dark"] .table {
  --bs-table-bg: transparent !important;
  --bs-table-color: #f8fafc !important;
  --bs-table-hover-bg: rgba(255, 255, 255, 0.04) !important;
  --bs-table-hover-color: #ffffff !important;
  --bs-table-accent-bg: transparent !important;
  --bs-table-border-color: rgba(255, 255, 255, 0.08) !important;
  background-color: transparent !important;
  color: #f8fafc !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
}

/* Strip Bootstrap 5's inset cell shadow and force cell transparency */
[data-bs-theme="dark"] .table > :not(caption) > * > *,
[data-bs-theme="dark"] .table-premium td,
[data-bs-theme="dark"] .table-premium th,
[data-bs-theme="dark"] .table-custom td,
[data-bs-theme="dark"] .table-custom th,
[data-bs-theme="dark"] .table td,
[data-bs-theme="dark"] .table th {
  background-color: transparent !important;
  box-shadow: none !important;
  color: #f8fafc !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
}

/* Table Header */
[data-bs-theme="dark"] .table-premium thead th,
[data-bs-theme="dark"] .table-custom thead th,
[data-bs-theme="dark"] .table thead th,
[data-bs-theme="dark"] .table-light,
[data-bs-theme="dark"] thead.table-light th {
  background-color: #161f36 !important;
  color: #94a3b8 !important;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1) !important;
}

/* Table Rows & Hovers */
[data-bs-theme="dark"] .table-premium tbody tr,
[data-bs-theme="dark"] .table-custom tbody tr,
[data-bs-theme="dark"] .table tbody tr {
  background-color: transparent !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
}

[data-bs-theme="dark"] .table-premium tbody tr:hover,
[data-bs-theme="dark"] .table-custom tbody tr:hover,
[data-bs-theme="dark"] .table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.04) !important;
}

/* Neutralize inline hardcoded row backgrounds */
[data-bs-theme="dark"] tr[style*="background-color: #fafbfc"],
[data-bs-theme="dark"] tr[style*="background-color:#fafbfc"],
[data-bs-theme="dark"] tr[style*="background: #fafbfc"] {
  background-color: rgba(255, 255, 255, 0.02) !important;
}

/* Forms & Control Inputs */
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background-color: #161f36 !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  color: #f8fafc !important;
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
  background-color: #161f36 !important;
  border-color: #6366f1 !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.25) !important;
}

[data-bs-theme="dark"] .form-control::placeholder {
  color: #64748b !important;
}

[data-bs-theme="dark"] .input-group-text {
  background-color: #1e293b !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  color: #94a3b8 !important;
}

/* Badges & Pills */
[data-bs-theme="dark"] .badge-neutral {
  background: rgba(255, 255, 255, 0.08) !important;
  color: #cbd5e1 !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

[data-bs-theme="dark"] .badge-danger-light {
  background: rgba(225, 29, 72, 0.15) !important;
  color: #fb7185 !important;
  border: 1px solid rgba(225, 29, 72, 0.3) !important;
}

[data-bs-theme="dark"] .badge.bg-light {
  background: rgba(255, 255, 255, 0.08) !important;
  color: #cbd5e1 !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
}

[data-bs-theme="dark"] .bg-primary.bg-opacity-10 {
  background-color: rgba(99, 102, 241, 0.18) !important;
  color: #a5b4fc !important;
}

[data-bs-theme="dark"] .bg-danger.bg-opacity-10 {
  background-color: rgba(239, 68, 68, 0.18) !important;
  color: #fca5a5 !important;
}

[data-bs-theme="dark"] .bg-success.bg-opacity-10 {
  background-color: rgba(16, 185, 129, 0.18) !important;
  color: #6ee7b7 !important;
}

[data-bs-theme="dark"] .bg-secondary.bg-opacity-10 {
  background-color: rgba(255, 255, 255, 0.08) !important;
  color: #cbd5e1 !important;
}

/* Custom & Action Buttons */
[data-bs-theme="dark"] .btn-premium-indigo {
  background: #4f46e5 !important;
  border-color: #6366f1 !important;
  color: #ffffff !important;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4) !important;
}

[data-bs-theme="dark"] .btn-premium-indigo:hover {
  background: #4338ca !important;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5) !important;
}

[data-bs-theme="dark"] .btn-light-custom,
[data-bs-theme="dark"] .btn-white {
  background: #1e293b !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  color: #e2e8f0 !important;
}

[data-bs-theme="dark"] .btn-light-custom:hover,
[data-bs-theme="dark"] .btn-white:hover {
  background: #27354f !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-bs-theme="dark"] .btn-outline-danger-custom {
  background: rgba(225, 29, 72, 0.1) !important;
  border: 1px solid rgba(225, 29, 72, 0.35) !important;
  color: #fb7185 !important;
}

[data-bs-theme="dark"] .btn-outline-danger-custom:hover {
  background: rgba(225, 29, 72, 0.25) !important;
  color: #ffffff !important;
  border-color: rgba(225, 29, 72, 0.5) !important;
}

[data-bs-theme="dark"] .btn-dark,
[data-bs-theme="dark"] .btn-action-edit {
  background: rgba(99, 102, 241, 0.18) !important;
  border: 1px solid rgba(99, 102, 241, 0.4) !important;
  color: #a5b4fc !important;
}

[data-bs-theme="dark"] .btn-dark:hover,
[data-bs-theme="dark"] .btn-action-edit:hover {
  background: #4f46e5 !important;
  color: #ffffff !important;
  box-shadow: 0 2px 10px rgba(79, 70, 229, 0.35) !important;
}

/* Modals */
[data-bs-theme="dark"] .modal-content {
  background: #131b2e !important;
  background-color: #131b2e !important;
  color: #f8fafc !important;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7), 0 10px 20px -5px rgba(0, 0, 0, 0.5) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .modal-header,
[data-bs-theme="dark"] .edit-modal-header {
  background: #161f36 !important;
  background-color: #161f36 !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
}

[data-bs-theme="dark"] .modal-footer {
  background: #161f36 !important;
  background-color: #161f36 !important;
  border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
}

[data-bs-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* Toolbars, Inlines & Bootstrap Light Utility Overrides */
[data-bs-theme="dark"] [style*="background: #f1f5f9"],
[data-bs-theme="dark"] [style*="background:#f1f5f9"],
[data-bs-theme="dark"] [style*="background-color: #f8fafc"],
[data-bs-theme="dark"] [style*="background: #ffffff"],
[data-bs-theme="dark"] [style*="background: #fffbeb"] {
  background: #161f36 !important;
  background-color: #161f36 !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
}

[data-bs-theme="dark"] .bg-white {
  background-color: #131b2e !important;
}

[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .bg-light-subtle {
  background-color: #161f36 !important;
  color: #f8fafc !important;
}

[data-bs-theme="dark"] .border {
  border-color: rgba(255, 255, 255, 0.08) !important;
}

[data-bs-theme="dark"] .border-bottom {
  border-bottom-color: rgba(255, 255, 255, 0.08) !important;
}

[data-bs-theme="dark"] .border-top {
  border-top-color: rgba(255, 255, 255, 0.08) !important;
}

[data-bs-theme="dark"] .alert-info-custom {
  background: rgba(2, 132, 199, 0.15) !important;
  color: #7dd3fc !important;
}

/* Login Page Dark Mode */
[data-bs-theme="dark"] body.bg-base {
  background: radial-gradient(circle at 10% 20%, #0b0f19 0%, #030712 100%) !important;
  color: #f8fafc !important;
}

[data-bs-theme="dark"] .glass-auth-card {
  background: linear-gradient(135deg, rgba(19, 27, 46, 0.9) 0%, rgba(15, 23, 42, 0.8) 100%) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .logo-glass-container {
  background: rgba(19, 27, 46, 0.8) !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .brand-title {
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 60%, #94a3b8 100%) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
}

[data-bs-theme="dark"] .brand-subtitle {
  color: #94a3b8 !important;
}

[data-bs-theme="dark"] .card-heading {
  color: #f8fafc !important;
}

[data-bs-theme="dark"] .form-label-glass {
  color: #cbd5e1 !important;
}

[data-bs-theme="dark"] .glass-input-group {
  background: rgba(15, 23, 42, 0.75) !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
}

[data-bs-theme="dark"] .glass-input-group:focus-within {
  background: #161f36 !important;
  border-color: #6366f1 !important;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.25) !important;
}

[data-bs-theme="dark"] .form-control-glass {
  color: #f8fafc !important;
}

[data-bs-theme="dark"] .input-icon-glass {
  color: #94a3b8 !important;
}

/* Theme Toggle Button Styling */
.theme-toggle-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: #475569;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 0;
  text-decoration: none;
}

.theme-toggle-btn:hover {
  transform: scale(1.08) rotate(12deg);
  background: rgba(79, 70, 229, 0.1);
  color: #4f46e5;
  border-color: rgba(79, 70, 229, 0.25);
}

[data-bs-theme="dark"] .theme-toggle-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #f59e0b;
}

[data-bs-theme="dark"] .theme-toggle-btn:hover {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
}

/* =========================================================
   PREMIUM TOGGLE FILTER CARDS (LIGHT & DARK MODES)
   ========================================================= */
.premium-toggle-card {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0 !important;
  color: #0f172a;
  cursor: pointer;
  transition: all 0.25s ease !important;
}

.premium-toggle-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
}

.premium-toggle-card.active-filter-active {
  background-color: #ecfdf5 !important;
  border-color: #10b981 !important;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.22) !important;
}

.premium-toggle-card.active-filter-negative {
  background-color: #fef2f2 !important;
  border-color: #fecaca !important;
  box-shadow: 0 0 14px rgba(220, 38, 38, 0.22) !important;
}

/* Dark Mode Overrides for Toggle Cards */
[data-bs-theme="dark"] .premium-toggle-card {
  background-color: #161f36 !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  color: #f8fafc !important;
}

[data-bs-theme="dark"] .premium-toggle-card:hover {
  background-color: #1c2744 !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4) !important;
}

[data-bs-theme="dark"] .premium-toggle-card.active-filter-active {
  background-color: rgba(16, 185, 129, 0.18) !important;
  border-color: rgba(16, 185, 129, 0.5) !important;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.35) !important;
  color: #6ee7b7 !important;
}

[data-bs-theme="dark"] .premium-toggle-card.active-filter-negative {
  background-color: rgba(239, 68, 68, 0.18) !important;
  border-color: rgba(239, 68, 68, 0.5) !important;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.35) !important;
  color: #fca5a5 !important;
}

[data-bs-theme="dark"] .form-check-input {
  background-color: #1e293b;
  border-color: rgba(255, 255, 255, 0.2);
}

[data-bs-theme="dark"] .form-check-input:checked {
  background-color: #4f46e5;
  border-color: #6366f1;
}

