/* Dark Mode CSS Variables and Styles */
:root {
    /* Light Mode Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #ddd;
    --navbar-bg: #f8f9fa;
    --card-bg: #ffffff;
    --input-bg: #ffffff;
    --shadow: rgba(0, 0, 0, 0.1);
    --link-color: #007bff;
    --link-hover: #0056b3;
}

/* Dark Mode - Target both our custom attribute and override template variables */
[data-theme="dark"],
html[data-theme="dark"],
.layout-wrapper[data-theme="dark"],
body[data-theme="dark"] {
    /* Dark Mode Colors */
    --bg-primary: #1a1a1a !important;
    --bg-secondary: #2d2d2d !important;
    --bg-tertiary: #3a3a3a !important;
    --text-primary: #e0e0e0 !important;
    --text-secondary: #b0b0b0 !important;
    --border-color: #444 !important;
    --navbar-bg: #2d2d2d !important;
    --card-bg: #2d2d2d !important;
    --input-bg: #3a3a3a !important;
    --shadow: rgba(0, 0, 0, 0.3) !important;
    --link-color: #4da3ff !important;
    --link-hover: #66b3ff !important;
    
    /* Override Sneat/Frest Template Variables */
    --bs-body-bg: #1a1a1a !important;
    --bs-body-color: #e0e0e0 !important;
    --bs-card-bg: #2d2d2d !important;
    --bs-border-color: #444 !important;
    --bs-emphasis-color: #e0e0e0 !important;
    --bs-secondary-color: #b0b0b0 !important;
    --bs-tertiary-bg: #3a3a3a !important;
}

/* Apply Dark Mode Styles - High specificity selectors */
[data-theme="dark"] body,
html[data-theme="dark"] body,
body[data-theme="dark"],
[data-theme="dark"].layout-wrapper,
.layout-wrapper[data-theme="dark"] {
    background-color: #1a1a1a !important;
    color: #e0e0e0 !important;
}

/* Force body background regardless of template */
html[data-theme="dark"],
html[data-theme="dark"] body {
    background: #1a1a1a !important;
}

[data-theme="dark"] .navbar-custom,
html[data-theme="dark"] .navbar-custom,
body[data-theme="dark"] .navbar-custom,
[data-theme="dark"] .navbar-light,
html[data-theme="dark"] .navbar-light,
body[data-theme="dark"] .navbar-light,
[data-theme="dark"] .bg-light,
html[data-theme="dark"] .bg-light,
body[data-theme="dark"] .bg-light,
[data-theme="dark"] .navbar,
html[data-theme="dark"] .navbar,
body[data-theme="dark"] .navbar {
    background-color: #2d2d2d !important;
}

[data-theme="dark"] .navbar-custom .navbar-brand,
html[data-theme="dark"] .navbar-custom .navbar-brand,
body[data-theme="dark"] .navbar-custom .navbar-brand,
[data-theme="dark"] .navbar-custom .navbar-nav .nav-link,
html[data-theme="dark"] .navbar-custom .navbar-nav .nav-link,
body[data-theme="dark"] .navbar-custom .navbar-nav .nav-link,
[data-theme="dark"] .navbar-light .navbar-brand,
html[data-theme="dark"] .navbar-light .navbar-brand,
body[data-theme="dark"] .navbar-light .navbar-brand,
[data-theme="dark"] .navbar-light .navbar-nav .nav-link,
html[data-theme="dark"] .navbar-light .navbar-nav .nav-link,
body[data-theme="dark"] .navbar-light .navbar-nav .nav-link,
[data-theme="dark"] .nav-link,
html[data-theme="dark"] .nav-link,
body[data-theme="dark"] .nav-link {
    color: #e0e0e0 !important;
}

[data-theme="dark"] .navbar-custom .nav-item:hover .nav-link,
html[data-theme="dark"] .navbar-custom .nav-item:hover .nav-link,
body[data-theme="dark"] .navbar-custom .nav-item:hover .nav-link {
    color: #66b3ff !important;
}

[data-theme="dark"] .navbar-custom .dropdown-menu,
[data-theme="dark"] .dropdown-menu {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .navbar-custom .dropdown-item,
[data-theme="dark"] .dropdown-item {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .navbar-custom .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:hover {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .card,
html[data-theme="dark"] .card,
body[data-theme="dark"] .card,
[data-theme="dark"] .menu-game-card,
[data-theme="dark"] .game-card,
[data-theme="dark"] .top-games {
    background-color: #2d2d2d !important;
    border-color: #444 !important;
    color: #e0e0e0 !important;
}

[data-theme="dark"] .card-header,
html[data-theme="dark"] .card-header,
body[data-theme="dark"] .card-header,
[data-theme="dark"] .card-body,
html[data-theme="dark"] .card-body,
body[data-theme="dark"] .card-body,
[data-theme="dark"] .card-footer,
html[data-theme="dark"] .card-footer,
body[data-theme="dark"] .card-footer {
    background-color: #2d2d2d !important;
    color: #e0e0e0 !important;
    border-color: #444 !important;
}

/* Card title */
[data-theme="dark"] .card-title,
html[data-theme="dark"] .card-title,
body[data-theme="dark"] .card-title {
    color: #ffffff !important;
}

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

[data-theme="dark"] .table {
    color: var(--text-primary) !important;
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] .table thead th {
    border-color: var(--border-color) !important;
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .table td,
[data-theme="dark"] .table th {
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--bg-tertiary) !important;
}

[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-control,
body[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
html[data-theme="dark"] .form-select,
body[data-theme="dark"] .form-select,
[data-theme="dark"] input,
html[data-theme="dark"] input,
body[data-theme="dark"] input,
[data-theme="dark"] textarea,
html[data-theme="dark"] textarea,
body[data-theme="dark"] textarea,
[data-theme="dark"] select,
html[data-theme="dark"] select,
body[data-theme="dark"] select {
    background-color: #3a3a3a !important;
    color: #e0e0e0 !important;
    border-color: #444 !important;
}

[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-control:focus,
body[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus,
html[data-theme="dark"] .form-select:focus,
body[data-theme="dark"] .form-select:focus {
    background-color: #3a3a3a !important;
    color: #e0e0e0 !important;
    border-color: #4da3ff !important;
    box-shadow: 0 0 0 0.2rem rgba(77, 163, 255, 0.25) !important;
}

[data-theme="dark"] .modal-content {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer {
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .btn-outline-primary,
[data-theme="dark"] .btn-outline-secondary,
[data-theme="dark"] .btn-outline-success,
[data-theme="dark"] .btn-outline-danger,
[data-theme="dark"] .btn-outline-warning,
[data-theme="dark"] .btn-outline-info {
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] a {
    color: var(--link-color) !important;
}

[data-theme="dark"] a:hover {
    color: var(--link-hover) !important;
}

[data-theme="dark"] .text-muted {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .border,
[data-theme="dark"] .border-top,
[data-theme="dark"] .border-bottom,
[data-theme="dark"] .border-left,
[data-theme="dark"] .border-right {
    border-color: var(--border-color) !important;
}

[data-theme="dark"] hr {
    border-color: var(--border-color) !important;
}

/* Dark Mode Toggle Button */
.dark-mode-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
    color: var(--text-primary);
}

.dark-mode-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .dark-mode-toggle {
    color: var(--text-primary);
}

[data-theme="dark"] .dark-mode-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.dark-mode-toggle i {
    font-size: 20px;
    transition: transform 0.3s ease;
    color: inherit;
}

.dark-mode-toggle:hover i {
    transform: rotate(20deg);
}

/* Prevent flash on page load - hide until theme is set */
html:not(.theme-managed) body {
    opacity: 0;
}

html.theme-managed body {
    opacity: 1;
    transition: opacity 0.1s ease-in;
}

/* Instant display for dark mode (already set by init script) */
html.theme-managed[data-theme="dark"] body {
    opacity: 1;
    transition: none;
}

/* Smooth transition for theme changes - only after initial load */
html.theme-managed body,
html.theme-managed .navbar,
html.theme-managed .card,
html.theme-managed .form-control,
html.theme-managed .table,
html.theme-managed .modal-content,
html.theme-managed .list-group-item {
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

/* Faster transition for toggling */
html.theme-managed.transitioning body,
html.theme-managed.transitioning *  {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease !important;
}

/* Admin Panel Specific Styles - MAXIMUM SPECIFICITY */
[data-theme="dark"] .layout-wrapper,
html[data-theme="dark"] .layout-wrapper,
body[data-theme="dark"] .layout-wrapper,
.layout-wrapper[data-theme="dark"] {
    background-color: #1a1a1a !important;
}

[data-theme="dark"] .menu,
html[data-theme="dark"] .menu,
body[data-theme="dark"] .menu {
    background-color: #2d2d2d !important;
}

[data-theme="dark"] .menu-inner,
html[data-theme="dark"] .menu-inner,
body[data-theme="dark"] .menu-inner {
    background-color: #2d2d2d !important;
}

[data-theme="dark"] .menu-item .menu-link,
html[data-theme="dark"] .menu-item .menu-link,
body[data-theme="dark"] .menu-item .menu-link {
    color: #e0e0e0 !important;
}

[data-theme="dark"] .menu-item.active > .menu-link,
html[data-theme="dark"] .menu-item.active > .menu-link,
body[data-theme="dark"] .menu-item.active > .menu-link {
    background-color: #3a3a3a !important;
    color: #ffffff !important;
}

[data-theme="dark"] .app-brand,
html[data-theme="dark"] .app-brand,
body[data-theme="dark"] .app-brand {
    background-color: #2d2d2d !important;
}

[data-theme="dark"] .navbar-nav-right .navbar-nav .nav-link,
html[data-theme="dark"] .navbar-nav-right .navbar-nav .nav-link,
body[data-theme="dark"] .navbar-nav-right .navbar-nav .nav-link {
    color: #e0e0e0 !important;
}

[data-theme="dark"] .content-wrapper,
html[data-theme="dark"] .content-wrapper,
body[data-theme="dark"] .content-wrapper,
[data-theme="dark"] .container-xxl,
html[data-theme="dark"] .container-xxl,
body[data-theme="dark"] .container-xxl {
    background-color: #1a1a1a !important;
}

/* Layout navbar */
[data-theme="dark"] .layout-navbar,
html[data-theme="dark"] .layout-navbar,
body[data-theme="dark"] .layout-navbar {
    background-color: #2d2d2d !important;
    color: #e0e0e0 !important;
}

/* All text in content area */
[data-theme="dark"] .content-wrapper,
html[data-theme="dark"] .content-wrapper,
body[data-theme="dark"] .content-wrapper {
    color: #e0e0e0 !important;
}

/* Force text color inheritance in dark mode for most elements */
[data-theme="dark"] .content-wrapper p,
[data-theme="dark"] .content-wrapper span,
[data-theme="dark"] .content-wrapper div,
[data-theme="dark"] .content-wrapper td,
[data-theme="dark"] .content-wrapper th,
html[data-theme="dark"] .content-wrapper p,
html[data-theme="dark"] .content-wrapper span,
html[data-theme="dark"] .content-wrapper div,
html[data-theme="dark"] .content-wrapper td,
html[data-theme="dark"] .content-wrapper th,
body[data-theme="dark"] .content-wrapper p,
body[data-theme="dark"] .content-wrapper span,
body[data-theme="dark"] .content-wrapper div,
body[data-theme="dark"] .content-wrapper td,
body[data-theme="dark"] .content-wrapper th {
    color: #e0e0e0 !important;
}

/* Override for buttons - keep their colors */
[data-theme="dark"] .content-wrapper .btn,
html[data-theme="dark"] .content-wrapper .btn,
body[data-theme="dark"] .content-wrapper .btn {
    color: inherit !important;
}

/* Override for badges - ensure white text */
[data-theme="dark"] .content-wrapper .badge,
html[data-theme="dark"] .content-wrapper .badge,
body[data-theme="dark"] .content-wrapper .badge {
    color: #ffffff !important;
}

/* DataTables Dark Mode */
[data-theme="dark"] .dataTables_wrapper {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_length,
[data-theme="dark"] .dataTables_wrapper .dataTables_filter,
[data-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate {
    color: var(--text-primary) !important;
}

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

[data-theme="dark"] .page-link:hover {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .page-item.active .page-link {
    background-color: var(--link-color) !important;
    border-color: var(--link-color) !important;
}

/* Product Card Dark Mode */
[data-theme="dark"] .product-card {
    border-color: var(--border-color) !important;
    background-color: var(--card-bg) !important;
}

/* Footer */
[data-theme="dark"] footer {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-top-color: var(--border-color) !important;
}

/* Alerts */
[data-theme="dark"] .alert {
    background-color: var(--bg-tertiary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

/* Breadcrumb */
[data-theme="dark"] .breadcrumb {
    background-color: var(--bg-secondary) !important;
}

[data-theme="dark"] .breadcrumb-item + .breadcrumb-item::before {
    color: var(--text-secondary) !important;
}

/* Badge - ensure text is readable */
[data-theme="dark"] .badge,
html[data-theme="dark"] .badge,
body[data-theme="dark"] .badge {
    color: #ffffff !important;
    font-weight: 500;
    padding: 0.35em 0.65em;
}

/* Badge text should not inherit table colors */
[data-theme="dark"] .badge,
html[data-theme="dark"] .badge,
body[data-theme="dark"] .badge,
[data-theme="dark"] table .badge,
html[data-theme="dark"] table .badge,
body[data-theme="dark"] table .badge {
    color: #ffffff !important;
}

/* Exception for badges with text-danger class */
[data-theme="dark"] .badge.text-danger,
html[data-theme="dark"] .badge.text-danger,
body[data-theme="dark"] .badge.text-danger {
    color: #ff5b5c !important;
    background-color: #3a3a3a !important;
    border-color: #ff5b5c !important;
}

/* Exception for badges with text-success class */
[data-theme="dark"] .badge.text-success,
html[data-theme="dark"] .badge.text-success,
body[data-theme="dark"] .badge.text-success {
    color: #39da8a !important;
}

/* Exception for badges with text-warning class */
[data-theme="dark"] .badge.text-warning,
html[data-theme="dark"] .badge.text-warning,
body[data-theme="dark"] .badge.text-warning {
    color: #fdac41 !important;
}

/* Exception for badges with text-info class */
[data-theme="dark"] .badge.text-info,
html[data-theme="dark"] .badge.text-info,
body[data-theme="dark"] .badge.text-info {
    color: #00cfe8 !important;
}

/* Status badges - keep their original colors */
[data-theme="dark"] .status-hoat-dong,
html[data-theme="dark"] .status-hoat-dong,
body[data-theme="dark"] .status-hoat-dong {
    background-color: #38bfa7 !important;
    color: white !important;
}

[data-theme="dark"] .status-dang-cho,
html[data-theme="dark"] .status-dang-cho,
body[data-theme="dark"] .status-dang-cho {
    background-color: #365367 !important;
    color: white !important;
}

[data-theme="dark"] .status-bi-khoa,
html[data-theme="dark"] .status-bi-khoa,
body[data-theme="dark"] .status-bi-khoa {
    background-color: #fd6574 !important;
    color: white !important;
}

[data-theme="dark"] .status-beta,
html[data-theme="dark"] .status-beta,
body[data-theme="dark"] .status-beta {
    background-color: #3c5aaf !important;
    color: white !important;
}

/* Bootstrap label badges - make them more visible in dark mode */
[data-theme="dark"] .bg-label-primary,
html[data-theme="dark"] .bg-label-primary,
body[data-theme="dark"] .bg-label-primary {
    background-color: #5a8dee !important;
    color: #ffffff !important;
    border: 1px solid #4a7dde;
}

[data-theme="dark"] .bg-label-secondary,
html[data-theme="dark"] .bg-label-secondary,
body[data-theme="dark"] .bg-label-secondary {
    background-color: #6c757d !important;
    color: #ffffff !important;
    border: 1px solid #5c656d;
}

[data-theme="dark"] .bg-label-success,
html[data-theme="dark"] .bg-label-success,
body[data-theme="dark"] .bg-label-success {
    background-color: #39da8a !important;
    color: #ffffff !important;
    border: 1px solid #2dca7a;
}

[data-theme="dark"] .bg-label-danger,
html[data-theme="dark"] .bg-label-danger,
body[data-theme="dark"] .bg-label-danger {
    background-color: #ff5b5c !important;
    color: #ffffff !important;
    border: 1px solid #ff4b4c;
}

[data-theme="dark"] .bg-label-warning,
html[data-theme="dark"] .bg-label-warning,
body[data-theme="dark"] .bg-label-warning {
    background-color: #fdac41 !important;
    color: #ffffff !important;
    border: 1px solid #ed9c31;
}

[data-theme="dark"] .bg-label-info,
html[data-theme="dark"] .bg-label-info,
body[data-theme="dark"] .bg-label-info {
    background-color: #00cfe8 !important;
    color: #ffffff !important;
    border: 1px solid #00bfd8;
}

[data-theme="dark"] .bg-label-dark,
html[data-theme="dark"] .bg-label-dark,
body[data-theme="dark"] .bg-label-dark {
    background-color: #4b5563 !important;
    color: #ffffff !important;
    border: 1px solid #3b4553;
}

[data-theme="dark"] .bg-label-light,
html[data-theme="dark"] .bg-label-light,
body[data-theme="dark"] .bg-label-light {
    background-color: #9ca3af !important;
    color: #1a1a1a !important;
    border: 1px solid #8c939f;
}

/* Custom sell badges */
[data-theme="dark"] .sell-bg-label-success,
html[data-theme="dark"] .sell-bg-label-success,
body[data-theme="dark"] .sell-bg-label-success {
    background-color: #39da8a !important;
    color: #ffffff !important;
    border: 1px solid #2dca7a;
}

[data-theme="dark"] .sell-bg-label-pending,
html[data-theme="dark"] .sell-bg-label-pending,
body[data-theme="dark"] .sell-bg-label-pending {
    background-color: #fdac41 !important;
    color: #ffffff !important;
    border: 1px solid #ed9c31;
}

/* Badge hover effects */
[data-theme="dark"] .badge:hover,
html[data-theme="dark"] .badge:hover,
body[data-theme="dark"] .badge:hover {
    filter: brightness(1.1);
    transform: scale(1.02);
    transition: all 0.2s ease;
}

/* Ensure badges in table rows that are hovered still maintain their colors */
[data-theme="dark"] table tbody tr:hover .badge,
html[data-theme="dark"] table tbody tr:hover .badge,
body[data-theme="dark"] table tbody tr:hover .badge {
    color: #ffffff !important;
}

/* Badge variants - ensure proper contrast */
[data-theme="dark"] .badge-primary,
html[data-theme="dark"] .badge-primary,
body[data-theme="dark"] .badge-primary {
    background-color: #5a8dee !important;
    color: #ffffff !important;
}

[data-theme="dark"] .badge-secondary,
html[data-theme="dark"] .badge-secondary,
body[data-theme="dark"] .badge-secondary {
    background-color: #6c757d !important;
    color: #ffffff !important;
}

[data-theme="dark"] .badge-success,
html[data-theme="dark"] .badge-success,
body[data-theme="dark"] .badge-success {
    background-color: #39da8a !important;
    color: #ffffff !important;
}

[data-theme="dark"] .badge-danger,
html[data-theme="dark"] .badge-danger,
body[data-theme="dark"] .badge-danger {
    background-color: #ff5b5c !important;
    color: #ffffff !important;
}

[data-theme="dark"] .badge-warning,
html[data-theme="dark"] .badge-warning,
body[data-theme="dark"] .badge-warning {
    background-color: #fdac41 !important;
    color: #ffffff !important;
}

[data-theme="dark"] .badge-info,
html[data-theme="dark"] .badge-info,
body[data-theme="dark"] .badge-info {
    background-color: #00cfe8 !important;
    color: #ffffff !important;
}

/* Navbar Toggler */
[data-theme="dark"] .navbar-toggler {
    border-color: var(--border-color) !important;
}

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

/* Authentication Pages */
[data-theme="dark"] .authentication-wrapper {
    background-color: var(--bg-primary) !important;
}

[data-theme="dark"] .authentication-inner .card {
    background-color: var(--card-bg) !important;
    border-color: var(--border-color) !important;
}

/* Store Specific Styles */
[data-theme="dark"] .channel-card {
    background-color: var(--card-bg) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .u-channel {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .notification-box {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .card-container {
    background-color: var(--bg-primary) !important;
}

/* Balance Container */
[data-theme="dark"] .balance-container {
    background-color: var(--bg-tertiary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

/* Overlay and Loading */
[data-theme="dark"] .overlayhmg {
    background-color: rgba(0, 0, 0, 0.8) !important;
}

/* Sidebar Menu */
[data-theme="dark"] .layout-menu {
    background-color: var(--bg-secondary) !important;
}

/* Images - reduce brightness in dark mode for comfort */
[data-theme="dark"] img:not(.dark-mode-toggle img):not(.navbar-brand img):not(.app-brand img):not(.avatar img) {
    opacity: 0.9;
}

/* Code blocks */
[data-theme="dark"] pre,
[data-theme="dark"] code {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* Select2 and other third-party components */
[data-theme="dark"] .select2-container--default .select2-selection--single {
    background-color: var(--input-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .select2-container--default .select2-results__option {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .select2-dropdown {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
}

/* Admin specific overrides - using !important to override inline styles */
[data-theme="dark"] .card-headerz {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .axis text {
    fill: var(--text-primary) !important;
}

[data-theme="dark"] #tooltip {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .tabhmgxxx-button {
    background-color: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .tabhmgxxx-button.active {
    background-color: #004bff !important;
    color: #ffffff !important;
}

/* OVERRIDE TEMPLATE .table COLOR - THIS IS THE ROOT CAUSE */
[data-theme="dark"] .table,
html[data-theme="dark"] .table,
body[data-theme="dark"] .table,
.layout-wrapper[data-theme="dark"] .table {
    color: #e0e0e0 !important;
    --bs-table-striped-color: #e0e0e0 !important;
    --bs-table-hover-color: #ffffff !important;
    --bs-table-active-color: #e0e0e0 !important;
    --bs-table-bg: #2d2d2d !important;
    --bs-table-striped-bg: #3a3a3a !important;
    --bs-table-hover-bg: #3a3a3a !important;
}

/* Override .table > :not(caption) > * > * which has box-shadow */
[data-theme="dark"] .table > :not(caption) > * > *,
html[data-theme="dark"] .table > :not(caption) > * > *,
body[data-theme="dark"] .table > :not(caption) > * > *,
.layout-wrapper[data-theme="dark"] .table > :not(caption) > * > * {
    color: #e0e0e0 !important;
}

/* Table headers with inline styles - MAXIMUM SPECIFICITY */
[data-theme="dark"] table th,
[data-theme="dark"] table thead th,
html[data-theme="dark"] table th,
html[data-theme="dark"] table thead th,
body[data-theme="dark"] table th,
body[data-theme="dark"] table thead th,
[data-theme="dark"] .table th,
[data-theme="dark"] .table thead th {
    color: #e0e0e0 !important;
    background-color: #3a3a3a !important;
}

/* Table body cells - ULTRA MAXIMUM SPECIFICITY - FORCE COLOR EVEN WITH INLINE STYLES */
[data-theme="dark"] table td[style],
[data-theme="dark"] table tbody td[style],
html[data-theme="dark"] table td[style],
html[data-theme="dark"] table tbody td[style],
body[data-theme="dark"] table td[style],
body[data-theme="dark"] table tbody td[style],
[data-theme="dark"] table td,
[data-theme="dark"] table tbody td,
html[data-theme="dark"] table td,
html[data-theme="dark"] table tbody td,
body[data-theme="dark"] table td,
body[data-theme="dark"] table tbody td,
[data-theme="dark"] .table td,
[data-theme="dark"] .table tbody td,
[data-theme="dark"] tbody#key_tableres td,
html[data-theme="dark"] tbody#key_tableres td,
body[data-theme="dark"] tbody#key_tableres td,
.layout-wrapper[data-theme="dark"] table td,
.layout-wrapper[data-theme="dark"] table tbody td {
    color: #e0e0e0 !important;
}

/* Table body cells - ALL nested elements INCLUDING those with inline styles */
[data-theme="dark"] table td[style] *,
html[data-theme="dark"] table td[style] *,
body[data-theme="dark"] table td[style] *,
[data-theme="dark"] table td *,
html[data-theme="dark"] table td *,
body[data-theme="dark"] table td *,
[data-theme="dark"] tbody td span[style],
html[data-theme="dark"] tbody td span[style],
body[data-theme="dark"] tbody td span[style],
[data-theme="dark"] tbody td span,
html[data-theme="dark"] tbody td span,
body[data-theme="dark"] tbody td span,
.layout-wrapper[data-theme="dark"] table td *,
.layout-wrapper[data-theme="dark"] tbody td span {
    color: #e0e0e0 !important;
}

/* Table striped rows */
[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > *,
html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > *,
body[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > *,
.layout-wrapper[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
    color: #e0e0e0 !important;
}

/* Table hover effects */
[data-theme="dark"] .table-hover > tbody > tr:hover > *,
html[data-theme="dark"] .table-hover > tbody > tr:hover > *,
body[data-theme="dark"] .table-hover > tbody > tr:hover > *,
.layout-wrapper[data-theme="dark"] .table-hover > tbody > tr:hover > *,
[data-theme="dark"] .table-hover tbody tr:hover,
html[data-theme="dark"] .table-hover tbody tr:hover,
body[data-theme="dark"] .table-hover tbody tr:hover,
[data-theme="dark"] table tbody tr:hover,
html[data-theme="dark"] table tbody tr:hover,
body[data-theme="dark"] table tbody tr:hover {
    background-color: #3a3a3a !important;
    color: #ffffff !important;
}

[data-theme="dark"] .table-hover tbody tr:hover td,
html[data-theme="dark"] .table-hover tbody tr:hover td,
body[data-theme="dark"] .table-hover tbody tr:hover td,
[data-theme="dark"] table tbody tr:hover td,
html[data-theme="dark"] table tbody tr:hover td,
body[data-theme="dark"] table tbody tr:hover td {
    color: #ffffff !important;
}

[data-theme="dark"] .table-hover tbody tr:hover td *,
html[data-theme="dark"] .table-hover tbody tr:hover td *,
body[data-theme="dark"] .table-hover tbody tr:hover td *,
[data-theme="dark"] table tbody tr:hover td span,
html[data-theme="dark"] table tbody tr:hover td span,
body[data-theme="dark"] table tbody tr:hover td span {
    color: #ffffff !important;
}

/* Nav pills */
[data-theme="dark"] .nav-pills .nav-link {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .nav-pills .nav-link.active {
    background-color: var(--link-color) !important;
    color: #ffffff !important;
}

/* Labels and form labels */
[data-theme="dark"] .form-label,
[data-theme="dark"] label {
    color: var(--text-primary) !important;
}

/* Modal title and headers */
[data-theme="dark"] .modal-title {
    color: var(--text-primary) !important;
}

/* Product card specific */
[data-theme="dark"] .product-card {
    background-color: var(--card-bg) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .product-title {
    color: var(--text-primary) !important;
}

/* Chart grid lines */
[data-theme="dark"] .grid line {
    stroke: var(--border-color) !important;
    stroke-opacity: 0.5 !important;
}

/* Specific heading overrides - MAXIMUM SPECIFICITY */
[data-theme="dark"] h1,
html[data-theme="dark"] h1,
body[data-theme="dark"] h1,
[data-theme="dark"] h2,
html[data-theme="dark"] h2,
body[data-theme="dark"] h2,
[data-theme="dark"] h3,
html[data-theme="dark"] h3,
body[data-theme="dark"] h3,
[data-theme="dark"] h4,
html[data-theme="dark"] h4,
body[data-theme="dark"] h4,
[data-theme="dark"] h5,
html[data-theme="dark"] h5,
body[data-theme="dark"] h5,
[data-theme="dark"] h6,
html[data-theme="dark"] h6,
body[data-theme="dark"] h6 {
    color: #ffffff !important;
}

/* Paragraph text */
[data-theme="dark"] p,
html[data-theme="dark"] p,
body[data-theme="dark"] p {
    color: #e0e0e0 !important;
}

/* Span elements - force readable color */
[data-theme="dark"] span:not(.badge):not(.status-hoat-dong):not(.status-dang-cho):not(.status-bi-khoa):not(.status-beta),
html[data-theme="dark"] span:not(.badge):not(.status-hoat-dong):not(.status-dang-cho):not(.status-bi-khoa):not(.status-beta),
body[data-theme="dark"] span:not(.badge):not(.status-hoat-dong):not(.status-dang-cho):not(.status-bi-khoa):not(.status-beta) {
    color: #e0e0e0 !important;
}

/* Normal text class */
[data-theme="dark"] .normal-text,
html[data-theme="dark"] .normal-text,
body[data-theme="dark"] .normal-text {
    color: #e0e0e0 !important;
}

/* Specific tbody ID targeting for key management table */
[data-theme="dark"] #key_tableres,
html[data-theme="dark"] #key_tableres,
body[data-theme="dark"] #key_tableres {
    color: #e0e0e0 !important;
}

[data-theme="dark"] #key_tableres td,
html[data-theme="dark"] #key_tableres td,
body[data-theme="dark"] #key_tableres td,
[data-theme="dark"] #key_tableres td[style*="font-size"],
html[data-theme="dark"] #key_tableres td[style*="font-size"],
body[data-theme="dark"] #key_tableres td[style*="font-size"] {
    color: #e0e0e0 !important;
}

[data-theme="dark"] #key_tableres td span,
html[data-theme="dark"] #key_tableres td span,
body[data-theme="dark"] #key_tableres td span,
[data-theme="dark"] #key_tableres span[style],
html[data-theme="dark"] #key_tableres span[style],
body[data-theme="dark"] #key_tableres span[style] {
    color: #e0e0e0 !important;
}

/* Email text in table */
[data-theme="dark"] #key_tableres td:last-child,
html[data-theme="dark"] #key_tableres td:last-child,
body[data-theme="dark"] #key_tableres td:last-child {
    color: #e0e0e0 !important;
}

/* Icons in table */
[data-theme="dark"] table i,
html[data-theme="dark"] table i,
body[data-theme="dark"] table i,
[data-theme="dark"] tbody i,
html[data-theme="dark"] tbody i,
body[data-theme="dark"] tbody i,
[data-theme="dark"] td i,
html[data-theme="dark"] td i,
body[data-theme="dark"] td i {
    color: #4da3ff !important;
}

/* Icon containers/borders in action columns */
[data-theme="dark"] td span[style*="border"],
html[data-theme="dark"] td span[style*="border"],
body[data-theme="dark"] td span[style*="border"] {
    border-color: #4da3ff !important;
}

/* Image elements */
[data-theme="dark"] table img,
html[data-theme="dark"] table img,
body[data-theme="dark"] table img {
    opacity: 0.9;
}

/* List items */
[data-theme="dark"] li,
html[data-theme="dark"] li,
body[data-theme="dark"] li {
    color: #e0e0e0 !important;
}

/* Strong and bold text */
[data-theme="dark"] strong,
html[data-theme="dark"] strong,
body[data-theme="dark"] strong,
[data-theme="dark"] b,
html[data-theme="dark"] b,
body[data-theme="dark"] b {
    color: #ffffff !important;
}

/* Small text */
[data-theme="dark"] small,
html[data-theme="dark"] small,
body[data-theme="dark"] small {
    color: #b0b0b0 !important;
}

/* Div text content */
[data-theme="dark"] div,
html[data-theme="dark"] div,
body[data-theme="dark"] div {
    color: #e0e0e0;
}

/* Placeholder text color */
[data-theme="dark"] ::placeholder {
    color: var(--text-secondary) !important;
    opacity: 0.7;
}

[data-theme="dark"] ::-webkit-input-placeholder {
    color: var(--text-secondary) !important;
    opacity: 0.7;
}

[data-theme="dark"] ::-moz-placeholder {
    color: var(--text-secondary) !important;
    opacity: 0.7;
}

/* Search and filter inputs */
[data-theme="dark"] .dataTables_filter input {
    background-color: var(--input-bg) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* DataTables specific */
[data-theme="dark"] .dataTables_length select {
    background-color: var(--input-bg) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

/* Scrollbar styling for dark mode */
[data-theme="dark"] ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 5px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #555;
}

