/**
 * Day / Night theme — shared variables + readable overrides site-wide.
 */

/* ---- Light mode tokens (explicit defaults) ---- */
:root,
[data-theme="light"] {
    --app-bg: #f8f9fa;
    --app-surface: #ffffff;
    --app-surface-raised: #ffffff;
    --app-surface-muted: #f1f5f9;
    --app-text: #111827;
    --app-text-secondary: #4b5563;
    --app-text-muted: #55657a;
    --app-border: #e5e7eb;
    --app-border-strong: #cbd5e1;
    --app-input-bg: #ffffff;
    --app-hover: #f3f4f6;
    --app-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    --app-shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.12);
    --app-link: #0066cc;
    --app-focus-ring: rgba(0, 102, 204, 0.25);
    --app-table-head: #f8fafc;
    --app-table-stripe: #f8fafc;
    --app-code-bg: #f1f5f9;
    --empty-state-icon: #9ca3af;
    --empty-state-text: #4b5563;
    color-scheme: light;
}

/* Bridge existing custom properties */
:root,
[data-theme="light"] {
    --light-bg: var(--app-bg);
    --dark-text: #212529;
    --border-color: var(--app-border);
    --main-bg: var(--app-bg);
    --card-bg: var(--app-surface);
    --text-primary: var(--app-text);
    --text-secondary: var(--app-text-secondary);
}

/* ---- Dark mode tokens ---- */
[data-theme="dark"],
html.dark-mode,
body.dark-mode {
    --app-bg: #0f172a;
    --app-surface: #1e293b;
    --app-surface-raised: #243044;
    --app-surface-muted: #172033;
    --app-text: #f8fafc;
    --app-text-secondary: #cbd5e1;
    --app-text-muted: #a8b8cc;
    --app-border: #334155;
    --app-border-strong: #475569;
    --app-input-bg: #0f172a;
    --app-hover: #334155;
    --app-table-hover: #3d4f66;
    --app-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    --app-shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.45);
    --app-link: #60a5fa;
    --app-focus-ring: rgba(96, 165, 250, 0.28);
    --app-table-head: #1e293b;
    --app-table-stripe: #172033;
    --app-code-bg: #0f172a;
    --empty-state-icon: #94a3b8;
    --empty-state-text: #e2e8f0;
    color-scheme: dark;

    --light-bg: var(--app-bg);
    --dark-text: var(--app-text);
    --border-color: var(--app-border);
    --main-bg: var(--app-bg);
    --card-bg: var(--app-surface);
    --text-primary: var(--app-text);
    --text-secondary: var(--app-text-secondary);

    /* Bootstrap 5 — keep components readable in night mode */
    --bs-body-color: #f8fafc;
    --bs-body-bg: #0f172a;
    --bs-emphasis-color: #ffffff;
    --bs-secondary-color: #cbd5e1;
    --bs-secondary-bg: #1e293b;
    --bs-tertiary-color: #a8b8cc;
    --bs-tertiary-bg: #172033;
    --bs-heading-color: #f8fafc;
    --bs-link-color: #60a5fa;
    --bs-link-hover-color: #93c5fd;
    --bs-border-color: #334155;
    --bs-card-bg: #1e293b;
    --bs-card-color: #f8fafc;
    --bs-table-color: #f8fafc;
    --bs-table-bg: transparent;
    --bs-table-border-color: #334155;
    --bs-dropdown-bg: #1e293b;
    --bs-dropdown-color: #f8fafc;
    --bs-dropdown-link-color: #f8fafc;
    --bs-dropdown-link-hover-color: #ffffff;
    --bs-dropdown-link-hover-bg: rgba(255, 255, 255, 0.08);
    --bs-modal-bg: #1e293b;
    --bs-modal-color: #f8fafc;
    --bs-form-control-bg: #0f172a;
    --bs-form-control-color: #f8fafc;
    --bs-input-group-addon-bg: #172033;
    --bs-input-group-addon-color: #cbd5e1;
}

/* Report palette — dark */
[data-theme="dark"],
html.dark-mode {
    --report-accent: #2dd4bf;
    --report-accent-soft: rgba(45, 212, 191, 0.12);
    --report-header-bg: #1e3a5f;
    --report-header-text: #e2e8f0;
    --report-header-border: #334155;
    --report-row-bg: #1e293b;
    --report-row-alt: #172033;
    --report-row-hover: #243044;
    --report-row-border: #334155;
    --report-opening-bg: #243044;
    --report-total-bg: #334155;
    --report-total-border: #475569;
    --report-body-text: #f1f5f9;
    --report-muted-text: #94a3b8;
    --report-label-text: #cbd5e1;
    --report-card-border: #334155;
    --report-section-border: #475569;
}

/* ---- Theme toggle ---- */
.theme-toggle-btn .theme-icon-night {
    color: #fbbf24;
}

.theme-toggle-btn .theme-icon-day {
    color: #f59e0b;
}

.theme-toggle-floating {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1200;
    width: 42px;
    height: 42px;
    border: 1px solid var(--app-border);
    border-radius: 50%;
    background: var(--app-surface);
    color: var(--app-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--app-shadow-lg);
    transition: background 0.2s ease, transform 0.2s ease;
}

.theme-toggle-floating:hover {
    background: var(--app-hover);
    transform: scale(1.04);
}

.theme-toggle-btn--portal {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: rgba(255, 255, 255, 0.92);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.15rem;
    transition: background 0.2s ease, transform 0.2s ease;
}

.theme-toggle-btn--portal:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.theme-toggle-btn--portal:active {
    transform: scale(0.96);
}

/* ---- Base layout ---- */
[data-theme="dark"] body,
body.dark-mode {
    background-color: var(--app-bg);
    color: var(--app-text);
}

[data-theme="dark"] body.has-sidebar,
body.dark-mode.has-sidebar {
    background-color: var(--app-bg);
}

[data-theme="dark"] .main-content,
body.dark-mode .main-content {
    background-color: var(--app-bg);
    color: var(--app-text);
}

/* ---- Bootstrap text / background utilities ---- */
[data-theme="dark"] .text-dark,
body.dark-mode .text-dark {
    color: var(--app-text) !important;
}

[data-theme="dark"] .text-muted,
body.dark-mode .text-muted {
    color: var(--app-text-muted) !important;
}

[data-theme="dark"] .text-body,
body.dark-mode .text-body {
    color: var(--app-text) !important;
}

[data-theme="dark"] .text-secondary,
body.dark-mode .text-secondary {
    color: var(--app-text-secondary) !important;
}

[data-theme="dark"] .bg-white,
body.dark-mode .bg-white,
[data-theme="dark"] .bg-light,
body.dark-mode .bg-light {
    background-color: var(--app-surface-muted) !important;
    color: var(--app-text);
}

[data-theme="dark"] .border,
body.dark-mode .border,
[data-theme="dark"] .border-top,
body.dark-mode .border-top,
[data-theme="dark"] .border-bottom,
body.dark-mode .border-bottom {
    border-color: var(--app-border) !important;
}

/* ---- Cards & panels ---- */
[data-theme="dark"] .card,
body.dark-mode .card {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
    box-shadow: var(--app-shadow);
}

[data-theme="dark"] .card-header,
body.dark-mode .card-header {
    background-color: transparent;
    border-bottom-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .card-footer,
body.dark-mode .card-footer {
    background-color: var(--app-surface-muted);
    border-top-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .stat-card,
body.dark-mode .stat-card {
    background: var(--app-surface);
    color: var(--app-text);
}

[data-theme="dark"] .stat-card .stat-label,
body.dark-mode .stat-card .stat-label {
    color: var(--app-text-secondary);
}

/* ---- Forms ---- */
[data-theme="dark"] .form-label,
body.dark-mode .form-label {
    color: var(--app-text);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
body.dark-mode .form-control,
body.dark-mode .form-select {
    background-color: var(--app-input-bg);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .form-control::placeholder,
body.dark-mode .form-control::placeholder {
    color: #64748b;
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus,
body.dark-mode .form-control:focus,
body.dark-mode .form-select:focus {
    background-color: var(--app-input-bg);
    border-color: #60a5fa;
    color: var(--app-text);
    box-shadow: 0 0 0 0.2rem var(--app-focus-ring);
}

[data-theme="dark"] .form-control:disabled,
[data-theme="dark"] .form-select:disabled,
body.dark-mode .form-control:disabled,
body.dark-mode .form-select:disabled {
    background-color: #1a2332;
    color: var(--app-text-secondary);
}

[data-theme="dark"] .input-group-text,
body.dark-mode .input-group-text {
    background-color: var(--app-surface-muted);
    border-color: var(--app-border);
    color: var(--app-text-secondary);
}

[data-theme="dark"] .form-check-label,
body.dark-mode .form-check-label {
    color: var(--app-text);
}

[data-theme="dark"] .form-text,
body.dark-mode .form-text {
    color: var(--app-text-secondary);
}

/* ---- Tables ---- */
[data-theme="dark"] .table,
body.dark-mode .table {
    --bs-table-bg: var(--app-surface);
    --bs-table-color: var(--app-text);
    --bs-table-border-color: var(--app-border);
    --bs-table-striped-bg: var(--app-table-stripe);
    --bs-table-striped-color: var(--app-text);
    --bs-table-hover-bg: var(--app-table-hover);
    --bs-table-hover-color: var(--app-text);
    --bs-table-accent-bg: transparent;
    --bs-table-active-bg: var(--app-hover);
    --bs-table-active-color: var(--app-text);
    color: var(--app-text);
}

/* Bootstrap 5 paints row color via inset box-shadow — reset for night mode */
[data-theme="dark"] .table > :not(caption) > * > *,
body.dark-mode .table > :not(caption) > * > * {
    --bs-table-bg-type: var(--app-surface);
    --bs-table-bg-state: var(--app-surface);
    --bs-table-color-type: var(--app-text);
    --bs-table-color-state: var(--app-text);
    --bs-table-accent-bg: transparent;
    background-color: var(--app-surface) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] .table thead th,
[data-theme="dark"] .table thead.table-light th,
body.dark-mode .table thead th,
body.dark-mode .table thead.table-light th {
    --bs-table-bg: var(--app-table-head);
    --bs-table-bg-type: var(--app-table-head);
    --bs-table-bg-state: var(--app-table-head);
    --bs-table-color: var(--app-text);
    --bs-table-color-type: var(--app-text);
    --bs-table-color-state: var(--app-text);
    --bs-table-accent-bg: transparent;
    background: var(--app-table-head) !important;
    background-color: var(--app-table-head) !important;
    color: var(--app-text) !important;
    border-color: var(--app-border) !important;
    box-shadow: none !important;
}

[data-theme="dark"] .table tbody td,
[data-theme="dark"] .table tbody th,
[data-theme="dark"] .table td,
[data-theme="dark"] .table th,
body.dark-mode .table tbody td,
body.dark-mode .table tbody th,
body.dark-mode .table td,
body.dark-mode .table th {
    border-color: var(--app-border);
    color: var(--app-text) !important;
}

[data-theme="dark"] .table tbody td .fw-semibold,
[data-theme="dark"] .table tbody td .fw-bold,
[data-theme="dark"] .table tbody td span,
[data-theme="dark"] .table tbody td small,
[data-theme="dark"] .table tbody td .text-break,
body.dark-mode .table tbody td .fw-semibold,
body.dark-mode .table tbody td .fw-bold,
body.dark-mode .table tbody td span,
body.dark-mode .table tbody td small,
body.dark-mode .table tbody td .text-break {
    color: var(--app-text) !important;
}

[data-theme="dark"] .table tbody td .text-muted,
[data-theme="dark"] .table thead th .text-muted,
body.dark-mode .table tbody td .text-muted,
body.dark-mode .table thead th .text-muted {
    color: var(--app-text-muted) !important;
}

/* style.css paints rows white — override for night mode readability */
[data-theme="dark"] .table tbody tr,
body.dark-mode .table tbody tr {
    background-color: var(--app-surface) !important;
}

[data-theme="dark"] .table tbody tr:nth-child(even),
body.dark-mode .table tbody tr:nth-child(even) {
    background-color: var(--app-table-stripe) !important;
}

[data-theme="dark"] .table tbody tr:hover,
[data-theme="dark"] .table.table-hover tbody tr:hover,
body.dark-mode .table tbody tr:hover,
body.dark-mode .table.table-hover tbody tr:hover {
    background-color: var(--app-table-hover) !important;
}

[data-theme="dark"] .table tbody tr:hover > td,
[data-theme="dark"] .table tbody tr:hover > th,
[data-theme="dark"] .table.table-hover tbody tr:hover > td,
[data-theme="dark"] .table.table-hover tbody tr:hover > th,
body.dark-mode .table tbody tr:hover > td,
body.dark-mode .table tbody tr:hover > th,
body.dark-mode .table.table-hover tbody tr:hover > td,
body.dark-mode .table.table-hover tbody tr:hover > th {
    --bs-table-bg-state: var(--app-table-hover);
    --bs-table-color-state: var(--app-text);
    background-color: var(--app-table-hover) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] .table tbody tr:hover > td span,
[data-theme="dark"] .table tbody tr:hover > td .fw-bold,
[data-theme="dark"] .table tbody tr:hover > td .fw-semibold,
[data-theme="dark"] .table tbody tr:hover > td .text-break,
[data-theme="dark"] .table tbody tr:hover > td small,
[data-theme="dark"] .table.table-hover tbody tr:hover > td span,
[data-theme="dark"] .table.table-hover tbody tr:hover > td .fw-bold,
[data-theme="dark"] .table.table-hover tbody tr:hover > td .fw-semibold,
[data-theme="dark"] .table.table-hover tbody tr:hover > td .text-break,
body.dark-mode .table tbody tr:hover > td span,
body.dark-mode .table tbody tr:hover > td .fw-bold,
body.dark-mode .table tbody tr:hover > td .fw-semibold,
body.dark-mode .table tbody tr:hover > td .text-break,
body.dark-mode .table tbody tr:hover > td small,
body.dark-mode .table.table-hover tbody tr:hover > td span,
body.dark-mode .table.table-hover tbody tr:hover > td .fw-bold,
body.dark-mode .table.table-hover tbody tr:hover > td .fw-semibold,
body.dark-mode .table.table-hover tbody tr:hover > td .text-break {
    color: var(--app-text) !important;
}

[data-theme="dark"] .table tbody tr:hover > td .text-muted,
[data-theme="dark"] .table.table-hover tbody tr:hover > td .text-muted,
body.dark-mode .table tbody tr:hover > td .text-muted,
body.dark-mode .table.table-hover tbody tr:hover > td .text-muted {
    color: var(--app-text-muted) !important;
}

[data-theme="dark"] .table tbody tr:hover > td.text-danger,
[data-theme="dark"] .table tbody tr:hover > td .text-danger,
[data-theme="dark"] .table.table-hover tbody tr:hover > td.text-danger,
[data-theme="dark"] .table.table-hover tbody tr:hover > td .text-danger,
body.dark-mode .table tbody tr:hover > td.text-danger,
body.dark-mode .table tbody tr:hover > td .text-danger,
body.dark-mode .table.table-hover tbody tr:hover > td.text-danger,
body.dark-mode .table.table-hover tbody tr:hover > td .text-danger {
    color: #f87171 !important;
}

[data-theme="dark"] .table tbody tr:hover > td.text-success,
[data-theme="dark"] .table tbody tr:hover > td .text-success,
[data-theme="dark"] .table.table-hover tbody tr:hover > td.text-success,
[data-theme="dark"] .table.table-hover tbody tr:hover > td .text-success,
body.dark-mode .table tbody tr:hover > td.text-success,
body.dark-mode .table tbody tr:hover > td .text-success,
body.dark-mode .table.table-hover tbody tr:hover > td.text-success,
body.dark-mode .table.table-hover tbody tr:hover > td .text-success {
    color: #4ade80 !important;
}

[data-theme="dark"] .table.table-bordered,
body.dark-mode .table.table-bordered {
    border-color: var(--app-border) !important;
}

[data-theme="dark"] .table-hover > tbody > tr:hover > *,
[data-theme="dark"] table.table.dataTable.table-hover > tbody > tr:hover > *,
body.dark-mode .table-hover > tbody > tr:hover > *,
body.dark-mode table.table.dataTable.table-hover > tbody > tr:hover > * {
    --bs-table-bg-state: var(--app-table-hover);
    --bs-table-color-state: var(--app-text);
    background-color: var(--app-table-hover) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > *,
body.dark-mode .table-striped > tbody > tr:nth-of-type(odd) > * {
    --bs-table-bg-type: var(--app-table-stripe);
    --bs-table-bg-state: var(--app-table-stripe);
    background-color: var(--app-table-stripe) !important;
    box-shadow: none !important;
}

[data-theme="dark"] .table-info,
body.dark-mode .table-info {
    --bs-table-bg: rgba(59, 130, 246, 0.15);
    --bs-table-color: var(--app-text);
}

/* ---- DataTables ---- */
[data-theme="dark"] .dataTables_wrapper,
body.dark-mode .dataTables_wrapper {
    color: var(--app-text);
}

[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,
body.dark-mode .dataTables_wrapper .dataTables_length,
body.dark-mode .dataTables_wrapper .dataTables_filter,
body.dark-mode .dataTables_wrapper .dataTables_info,
body.dark-mode .dataTables_wrapper .dataTables_paginate {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select,
body.dark-mode .dataTables_wrapper .dataTables_filter input,
body.dark-mode .dataTables_wrapper .dataTables_length select {
    background-color: var(--app-input-bg);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .page-link,
body.dark-mode .page-link {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .page-item.active .page-link,
body.dark-mode .page-item.active .page-link {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

[data-theme="dark"] .page-item.disabled .page-link,
body.dark-mode .page-item.disabled .page-link {
    background-color: var(--app-surface-muted);
    border-color: var(--app-border);
    color: var(--app-text-secondary);
}

/* ---- Dropdowns / modals / offcanvas ---- */
[data-theme="dark"] .dropdown-menu,
body.dark-mode .dropdown-menu {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
    box-shadow: var(--app-shadow-lg);
}

[data-theme="dark"] .dropdown-item,
body.dark-mode .dropdown-item {
    color: var(--app-text);
}

[data-theme="dark"] .dropdown-item:hover,
[data-theme="dark"] .dropdown-item:focus,
body.dark-mode .dropdown-item:hover,
body.dark-mode .dropdown-item:focus {
    background-color: var(--app-hover);
    color: var(--app-text);
}

[data-theme="dark"] .modal-content,
body.dark-mode .modal-content {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer,
body.dark-mode .modal-header,
body.dark-mode .modal-footer {
    border-color: var(--app-border);
}

[data-theme="dark"] .offcanvas,
body.dark-mode .offcanvas {
    background-color: var(--app-surface);
    color: var(--app-text);
}

[data-theme="dark"] .btn-close,
body.dark-mode .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* ---- Buttons (outline variants) ---- */
[data-theme="dark"] .btn-outline-secondary,
body.dark-mode .btn-outline-secondary {
    color: var(--app-text);
    border-color: var(--app-border-strong);
}

[data-theme="dark"] .btn-outline-secondary:hover,
body.dark-mode .btn-outline-secondary:hover {
    background-color: var(--app-hover);
    color: var(--app-text);
    border-color: var(--app-border-strong);
}

[data-theme="dark"] .btn-light,
body.dark-mode .btn-light {
    background-color: var(--app-surface-muted);
    border-color: var(--app-border);
    color: var(--app-text);
}

/* ---- Topbar chrome ---- */
[data-theme="dark"] .topbar,
body.dark-mode .topbar {
    background: var(--app-surface);
    border-bottom-color: var(--app-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .sidebar-toggle,
body.dark-mode .sidebar-toggle {
    background: var(--app-surface-raised);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .sidebar-toggle:hover,
[data-theme="dark"] .sidebar-toggle-mobile:hover,
[data-theme="dark"] .topbar-icon-btn:hover,
body.dark-mode .sidebar-toggle:hover,
body.dark-mode .sidebar-toggle-mobile:hover,
body.dark-mode .topbar-icon-btn:hover {
    background: var(--app-hover);
    color: var(--app-text);
}

[data-theme="dark"] .sidebar-toggle-mobile,
body.dark-mode .sidebar-toggle-mobile {
    color: var(--app-text);
}

[data-theme="dark"] .search-input,
body.dark-mode .search-input {
    background: var(--app-input-bg);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .search-input:focus,
body.dark-mode .search-input:focus {
    background: var(--app-input-bg);
}

[data-theme="dark"] .main-footer,
body.dark-mode .main-footer {
    background: var(--app-surface);
    border-top-color: var(--app-border);
}

/* ---- Notification & user menus ---- */
[data-theme="dark"] .notification-item:hover,
[data-theme="dark"] .user-menu-item:hover,
body.dark-mode .notification-item:hover,
body.dark-mode .user-menu-item:hover {
    background: var(--app-hover);
}

[data-theme="dark"] .notification-close:hover,
body.dark-mode .notification-close:hover {
    background: var(--app-hover);
    color: var(--app-text);
}

/* ---- Tom Select / searchable selects ---- */
[data-theme="dark"] .ts-wrapper.single .ts-control,
body.dark-mode .ts-wrapper.single .ts-control {
    background-color: var(--app-input-bg);
    border-color: var(--app-border);
    color: var(--app-text);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

[data-theme="dark"] .ts-wrapper.single .ts-control .item,
body.dark-mode .ts-wrapper.single .ts-control .item {
    color: var(--app-text);
}

[data-theme="dark"] .ts-wrapper .ts-dropdown,
body.dark-mode .ts-wrapper .ts-dropdown {
    background: var(--app-surface);
    border-color: var(--app-border);
}

[data-theme="dark"] .ts-wrapper .ts-dropdown .dropdown-input,
body.dark-mode .ts-wrapper .ts-dropdown .dropdown-input {
    background: var(--app-input-bg);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .ts-wrapper .ts-dropdown .option,
body.dark-mode .ts-wrapper .ts-dropdown .option {
    color: var(--app-text);
}

[data-theme="dark"] .ts-wrapper .ts-dropdown .option.active,
body.dark-mode .ts-wrapper .ts-dropdown .option.active {
    background-color: rgba(96, 165, 250, 0.18);
    color: var(--app-text);
}

[data-theme="dark"] .payment-row-select-wrap.single .ts-control,
body.dark-mode .payment-row-select-wrap.single .ts-control {
    background-color: var(--app-input-bg);
    border-color: var(--app-border);
}

[data-theme="dark"] .payment-row-select-wrap.single .ts-control .item,
body.dark-mode .payment-row-select-wrap.single .ts-control .item {
    color: var(--app-text);
}

[data-theme="dark"] body > .ts-dropdown.payment-row-select-dropdown,
body.dark-mode body > .ts-dropdown.payment-row-select-dropdown {
    background: var(--app-surface);
    border-color: var(--app-border);
}

[data-theme="dark"] body > .ts-dropdown.payment-row-select-dropdown .dropdown-input-wrap,
body.dark-mode body > .ts-dropdown.payment-row-select-dropdown .dropdown-input-wrap {
    background: var(--app-surface-muted);
    border-bottom-color: var(--app-border);
}

/* ---- Report module tables ---- */
[data-theme="dark"] .report-export-root .card > .card-header,
body.dark-mode .report-export-root .card > .card-header {
    background: var(--app-surface);
    border-bottom-color: var(--app-border-strong);
    color: var(--report-accent);
}

[data-theme="dark"] .report-export-root .report-module-table thead th,
body.dark-mode .report-export-root .report-module-table thead th {
    background: var(--report-header-bg);
    color: var(--report-header-text);
    border-color: var(--report-header-border);
}

[data-theme="dark"] .report-export-root .report-module-table tbody td,
body.dark-mode .report-export-root .report-module-table tbody td {
    background: var(--report-row-bg);
    color: var(--report-body-text);
    border-color: var(--report-row-border);
}

[data-theme="dark"] .report-export-root .report-module-table tbody tr:nth-child(even) td,
body.dark-mode .report-export-root .report-module-table tbody tr:nth-child(even) td {
    background: var(--report-row-alt);
}

/* ---- Dashboard KPI / account cards ---- */
[data-theme="dark"] .kpi-card,
[data-theme="dark"] .account-card,
[data-theme="dark"] .quick-action-card,
body.dark-mode .kpi-card,
body.dark-mode .account-card,
body.dark-mode .quick-action-card {
    background: var(--app-surface);
    border-color: var(--app-border);
}

[data-theme="dark"] .kpi-label,
[data-theme="dark"] .kpi-value,
body.dark-mode .kpi-label,
body.dark-mode .kpi-value {
    color: var(--app-text);
}

/* ---- Purchase / financial blocks ---- */
[data-theme="dark"] .purchase-financial-block,
body.dark-mode .purchase-financial-block {
    background: var(--app-surface-muted);
    border-color: var(--app-border);
}

[data-theme="dark"] #rate_right option:disabled,
body.dark-mode #rate_right option:disabled {
    background-color: var(--app-surface-muted);
    color: var(--app-text-secondary);
}

/* ---- Login pages ---- */
[data-theme="dark"] .login-container--staff,
body.dark-mode .login-container--staff {
    background: linear-gradient(135deg, #1e1b4b 0%, #0f172a 55%, #312e81 100%);
}

[data-theme="dark"] .login-container--customer,
body.dark-mode .login-container--customer {
    background: linear-gradient(145deg, #042f2e 0%, #0f766e 40%, #134e4a 75%, #022c22 100%);
}

[data-theme="dark"] .login-container--supplier,
body.dark-mode .login-container--supplier {
    background: linear-gradient(145deg, #0c1a3a 0%, #1e3a8a 40%, #1d4ed8 75%, #172554 100%);
}

[data-theme="dark"] .login-header--customer,
body.dark-mode .login-header--customer {
    background: linear-gradient(135deg, #0f766e 0%, #115e59 50%, #134e4a 100%);
}

[data-theme="dark"] .login-header--supplier,
body.dark-mode .login-header--supplier {
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 50%, #1e3a8a 100%);
}

[data-theme="dark"] .login-card,
body.dark-mode .login-card {
    background: var(--app-surface);
    color: var(--app-text);
}

[data-theme="dark"] .login-body,
body.dark-mode .login-body {
    color: var(--app-text);
}

[data-theme="dark"] .login-body a,
body.dark-mode .login-body a {
    color: var(--app-link);
}

[data-theme="dark"] .login-portal-section,
body.dark-mode .login-portal-section {
    border-top-color: var(--app-border);
}

[data-theme="dark"] .login-portal-label,
body.dark-mode .login-portal-label {
    color: var(--app-text-muted);
}

[data-theme="dark"] .login-portal-btn,
body.dark-mode .login-portal-btn {
    background: var(--app-surface-elevated, #1e293b);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .login-portal-btn:hover,
[data-theme="dark"] .login-portal-btn:focus-visible,
body.dark-mode .login-portal-btn:hover,
body.dark-mode .login-portal-btn:focus-visible {
    background: var(--app-surface);
    border-color: var(--primary-color, #3b82f6);
    color: var(--app-text);
}

[data-theme="dark"] .login-portal-btn-sub,
body.dark-mode .login-portal-btn-sub {
    color: var(--app-text-muted);
}

/* ---- Customer & supplier portals (topbar stays branded blue) ---- */
[data-theme="dark"] .supplier-portal-body,
[data-theme="dark"] .customer-portal-body,
body.dark-mode .supplier-portal-body,
body.dark-mode .customer-portal-body {
    background: var(--app-bg);
    color: var(--app-text);
}

[data-theme="dark"] .supplier-portal-main-wrap,
body.dark-mode .supplier-portal-main-wrap {
    background: transparent;
}

[data-theme="dark"] .portal-page-title,
body.dark-mode .portal-page-title {
    color: var(--app-text);
}

[data-theme="dark"] .portal-page-subtitle,
body.dark-mode .portal-page-subtitle {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .portal-site-footer,
body.dark-mode .portal-site-footer {
    background: var(--app-surface);
    border-top-color: var(--app-border);
    color: var(--app-text-secondary);
}

[data-theme="dark"] .portal-site-footer-sep,
body.dark-mode .portal-site-footer-sep {
    color: var(--app-border-strong);
}

[data-theme="dark"] .supplier-portal-content .card,
body.dark-mode .supplier-portal-content .card {
    background: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .supplier-portal-content .card-header.bg-white,
body.dark-mode .supplier-portal-content .card-header.bg-white {
    background: var(--app-surface-muted) !important;
    color: var(--app-text);
    border-bottom-color: var(--app-border);
}

[data-theme="dark"] .supplier-portal-content .card-title,
body.dark-mode .supplier-portal-content .card-title {
    color: var(--app-text);
}

[data-theme="dark"] .supplier-portal-content .card-body,
body.dark-mode .supplier-portal-content .card-body {
    color: var(--app-text);
}

[data-theme="dark"] .supplier-portal-content .table,
[data-theme="dark"] .customer-portal-body .table,
body.dark-mode .supplier-portal-content .table,
body.dark-mode .customer-portal-body .table {
    --bs-table-bg: var(--app-surface);
    --bs-table-color: var(--app-text);
    --bs-table-accent-bg: transparent;
}

[data-theme="dark"] .supplier-portal-content .table > :not(caption) > * > *,
[data-theme="dark"] .customer-portal-body .table > :not(caption) > * > *,
body.dark-mode .supplier-portal-content .table > :not(caption) > * > *,
body.dark-mode .customer-portal-body .table > :not(caption) > * > * {
    background-color: var(--app-surface) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] .supplier-portal-content .table-light,
[data-theme="dark"] .supplier-portal-content thead.table-light th,
[data-theme="dark"] .customer-portal-body thead.table-light th,
body.dark-mode .supplier-portal-content .table-light,
body.dark-mode .supplier-portal-content thead.table-light th,
body.dark-mode .customer-portal-body thead.table-light th {
    --bs-table-bg: var(--app-table-head);
    --bs-table-color: var(--app-text);
    --bs-table-border-color: var(--app-border);
    background-color: var(--app-table-head) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] .supplier-portal-content .table th,
[data-theme="dark"] .supplier-portal-content .table td,
[data-theme="dark"] .customer-portal-body .table th,
[data-theme="dark"] .customer-portal-body .table td,
body.dark-mode .supplier-portal-content .table th,
body.dark-mode .supplier-portal-content .table td,
body.dark-mode .customer-portal-body .table th,
body.dark-mode .customer-portal-body .table td {
    color: var(--app-text) !important;
    border-color: var(--app-border) !important;
}

[data-theme="dark"] .supplier-portal-content .table-hover > tbody > tr:hover > *,
[data-theme="dark"] .customer-portal-body .table-hover > tbody > tr:hover > *,
body.dark-mode .supplier-portal-content .table-hover > tbody > tr:hover > *,
body.dark-mode .customer-portal-body .table-hover > tbody > tr:hover > * {
    background-color: var(--app-hover) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] .supplier-portal-content .table .text-success,
[data-theme="dark"] .customer-portal-body .table .text-success,
body.dark-mode .supplier-portal-content .table .text-success,
body.dark-mode .customer-portal-body .table .text-success {
    color: #4ade80 !important;
}

[data-theme="dark"] .supplier-portal-content .table .text-danger,
[data-theme="dark"] .customer-portal-body .table .text-danger,
body.dark-mode .supplier-portal-content .table .text-danger,
body.dark-mode .customer-portal-body .table .text-danger {
    color: #f87171 !important;
}

[data-theme="dark"] .supplier-portal-content a.small:not(.btn),
body.dark-mode .supplier-portal-content a.small:not(.btn) {
    color: var(--app-link);
}

[data-theme="dark"] .supplier-portal-content strong,
body.dark-mode .supplier-portal-content strong {
    color: var(--app-text);
}

[data-theme="dark"] .supplier-portal-offcanvas,
body.dark-mode .supplier-portal-offcanvas {
    background: var(--app-surface);
    color: var(--app-text);
}

[data-theme="dark"] .supplier-portal-offcanvas .offcanvas-header,
body.dark-mode .supplier-portal-offcanvas .offcanvas-header {
    border-bottom-color: var(--app-border);
}

[data-theme="dark"] .supplier-portal-offcanvas .offcanvas-title,
body.dark-mode .supplier-portal-offcanvas .offcanvas-title {
    color: var(--app-text);
}

[data-theme="dark"] .supplier-portal-offcanvas hr,
body.dark-mode .supplier-portal-offcanvas hr {
    border-color: var(--app-border);
    opacity: 1;
}

[data-theme="dark"] .supplier-portal-topbar-right,
body.dark-mode .supplier-portal-topbar-right {
    gap: 0.65rem;
}

/* ---- Alerts (keep semantic colors, improve contrast) ---- */
[data-theme="dark"] .alert-success,
body.dark-mode .alert-success {
    background-color: rgba(25, 135, 84, 0.18);
    border-color: rgba(25, 135, 84, 0.45);
    color: #86efac;
}

[data-theme="dark"] .alert-danger,
body.dark-mode .alert-danger {
    background-color: rgba(220, 53, 69, 0.18);
    border-color: rgba(220, 53, 69, 0.45);
    color: #fca5a5;
}

[data-theme="dark"] .alert-warning,
body.dark-mode .alert-warning {
    background-color: rgba(255, 193, 7, 0.14);
    border-color: rgba(255, 193, 7, 0.4);
    color: #fde68a;
}

[data-theme="dark"] .alert-info,
body.dark-mode .alert-info {
    background-color: rgba(13, 202, 240, 0.14);
    border-color: rgba(13, 202, 240, 0.4);
    color: #a5f3fc;
}

/* ---- Toasts ---- */
[data-theme="dark"] .app-toast-success,
body.dark-mode .app-toast-success {
    background-color: rgba(25, 135, 84, 0.22);
    color: #bbf7d0;
}

[data-theme="dark"] .app-toast-danger,
body.dark-mode .app-toast-danger {
    background-color: rgba(220, 53, 69, 0.22);
    color: #fecaca;
}

[data-theme="dark"] .app-toast-warning,
body.dark-mode .app-toast-warning {
    background-color: rgba(255, 193, 7, 0.18);
    color: #fef08a;
}

[data-theme="dark"] .app-toast-info,
body.dark-mode .app-toast-info {
    background-color: rgba(13, 202, 240, 0.18);
    color: #cffafe;
}

/* ---- List group / badges ---- */
[data-theme="dark"] .list-group-item,
body.dark-mode .list-group-item {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .badge.bg-light.text-dark,
body.dark-mode .badge.bg-light.text-dark {
    background-color: var(--app-surface-muted) !important;
    color: var(--app-text) !important;
}

[data-theme="dark"] .bg-warning.text-dark,
body.dark-mode .bg-warning.text-dark {
    color: #1e293b !important;
}

/* ---- Reports hub ---- */
[data-theme="dark"] .reports-hub-pill,
body.dark-mode .reports-hub-pill {
    background: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .reports-hub-link,
body.dark-mode .reports-hub-link {
    background: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .reports-hub-link:hover,
body.dark-mode .reports-hub-link:hover {
    background: var(--app-hover);
    color: var(--app-text);
}

/* ---- Empty states (DataTables + static tables) ---- */
.dataTables_empty,
td.dataTables_empty,
td.empty-state-cell,
.empty-state-cell {
    color: var(--empty-state-text) !important;
    background-color: transparent !important;
}

.dataTables_empty .empty-state-text,
.dataTables_empty p,
.empty-state-text,
td.empty-state-cell p,
td.empty-state-cell .empty-state-text {
    color: var(--empty-state-text) !important;
}

.dataTables_empty .empty-state-icon,
.dataTables_empty i.bi,
.empty-state-icon,
td.empty-state-cell i.bi {
    color: var(--empty-state-icon) !important;
    opacity: 1 !important;
}

table.dataTable tbody tr:has(> td.dataTables_empty),
table.dataTable tbody tr.empty-state-row {
    background-color: transparent !important;
}

table.dataTable tbody tr:has(> td.dataTables_empty) td,
table.dataTable tbody tr.empty-state-row td {
    color: var(--empty-state-text) !important;
    background-color: transparent !important;
}

[data-theme="dark"] table.dataTable tbody tr.odd,
[data-theme="dark"] table.dataTable tbody tr.even,
[data-theme="dark"] table.dataTable.stripe tbody tr.odd,
[data-theme="dark"] table.dataTable.stripe tbody tr.even,
[data-theme="dark"] table.dataTable.display tbody tr.odd,
[data-theme="dark"] table.dataTable.display tbody tr.even,
body.dark-mode table.dataTable tbody tr.odd,
body.dark-mode table.dataTable tbody tr.even,
body.dark-mode table.dataTable.stripe tbody tr.odd,
body.dark-mode table.dataTable.stripe tbody tr.even,
body.dark-mode table.dataTable.display tbody tr.odd,
body.dark-mode table.dataTable.display tbody tr.even {
    background-color: transparent !important;
}

[data-theme="dark"] table.dataTable tbody tr.odd > td,
body.dark-mode table.dataTable tbody tr.odd > td {
    background-color: var(--app-surface) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] table.dataTable tbody tr.even > td,
body.dark-mode table.dataTable tbody tr.even > td {
    background-color: var(--app-table-stripe) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover,
[data-theme="dark"] table.dataTable.table-hover tbody tr:hover,
[data-theme="dark"] table.dataTable.display tbody tr:hover,
body.dark-mode table.dataTable tbody tr:hover,
body.dark-mode table.dataTable.table-hover tbody tr:hover,
body.dark-mode table.dataTable.display tbody tr:hover {
    background-color: var(--app-table-hover) !important;
}

[data-theme="dark"] table.dataTable tbody tr.odd:hover > td,
[data-theme="dark"] table.dataTable tbody tr.even:hover > td,
[data-theme="dark"] table.dataTable.table-hover tbody tr.odd:hover > td,
[data-theme="dark"] table.dataTable.table-hover tbody tr.even:hover > td,
[data-theme="dark"] table.dataTable.display.table-hover tbody tr:hover > td,
[data-theme="dark"] table.table.dataTable.table-hover.display tbody tr:hover > td,
body.dark-mode table.dataTable tbody tr.odd:hover > td,
body.dark-mode table.dataTable tbody tr.even:hover > td,
body.dark-mode table.dataTable.table-hover tbody tr.odd:hover > td,
body.dark-mode table.dataTable.table-hover tbody tr.even:hover > td,
body.dark-mode table.dataTable.display.table-hover tbody tr:hover > td,
body.dark-mode table.table.dataTable.table-hover.display tbody tr:hover > td {
    --bs-table-bg-state: var(--app-table-hover);
    --bs-table-color-state: var(--app-text);
    background-color: var(--app-table-hover) !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover > td.sorting_1,
[data-theme="dark"] table.dataTable tbody tr:hover > td.sorting_2,
[data-theme="dark"] table.dataTable tbody tr:hover > td.sorting_3,
body.dark-mode table.dataTable tbody tr:hover > td.sorting_1,
body.dark-mode table.dataTable tbody tr:hover > td.sorting_2,
body.dark-mode table.dataTable tbody tr:hover > td.sorting_3 {
    background-color: var(--app-table-hover) !important;
    color: var(--app-text) !important;
}

[data-theme="dark"] table.dataTable tbody td .fw-bold,
[data-theme="dark"] table.dataTable tbody td .fw-semibold,
[data-theme="dark"] table.dataTable tbody td span,
[data-theme="dark"] table.dataTable tbody td .text-break,
body.dark-mode table.dataTable tbody td .fw-bold,
body.dark-mode table.dataTable tbody td .fw-semibold,
body.dark-mode table.dataTable tbody td span,
body.dark-mode table.dataTable tbody td .text-break {
    color: var(--app-text) !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover > td span,
[data-theme="dark"] table.dataTable tbody tr:hover > td .fw-bold,
[data-theme="dark"] table.dataTable tbody tr:hover > td .fw-semibold,
[data-theme="dark"] table.dataTable tbody tr:hover > td .text-break,
[data-theme="dark"] table.dataTable tbody tr:hover > td small,
body.dark-mode table.dataTable tbody tr:hover > td span,
body.dark-mode table.dataTable tbody tr:hover > td .fw-bold,
body.dark-mode table.dataTable tbody tr:hover > td .fw-semibold,
body.dark-mode table.dataTable tbody tr:hover > td .text-break,
body.dark-mode table.dataTable tbody tr:hover > td small {
    color: var(--app-text) !important;
}

[data-theme="dark"] table.dataTable tbody td .text-muted,
body.dark-mode table.dataTable tbody td .text-muted {
    color: var(--app-text-muted) !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover > td .text-muted,
body.dark-mode table.dataTable tbody tr:hover > td .text-muted {
    color: var(--app-text-muted) !important;
}

[data-theme="dark"] table.dataTable tbody td.text-danger,
[data-theme="dark"] table.dataTable tbody td .text-danger,
body.dark-mode table.dataTable tbody td.text-danger,
body.dark-mode table.dataTable tbody td .text-danger {
    color: #f87171 !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover > td.text-danger,
[data-theme="dark"] table.dataTable tbody tr:hover > td .text-danger,
body.dark-mode table.dataTable tbody tr:hover > td.text-danger,
body.dark-mode table.dataTable tbody tr:hover > td .text-danger {
    color: #f87171 !important;
}

[data-theme="dark"] table.dataTable tbody td.text-success,
[data-theme="dark"] table.dataTable tbody td .text-success,
body.dark-mode table.dataTable tbody td.text-success,
body.dark-mode table.dataTable tbody td .text-success {
    color: #4ade80 !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover > td.text-success,
[data-theme="dark"] table.dataTable tbody tr:hover > td .text-success,
body.dark-mode table.dataTable tbody tr:hover > td.text-success,
body.dark-mode table.dataTable tbody tr:hover > td .text-success {
    color: #4ade80 !important;
}

[data-theme="dark"] .app-list-dt-wrap table.dataTable tbody tr:hover > td,
[data-theme="dark"] .dataTables_wrapper.dt-app-list-wrap table.dataTable tbody tr:hover > td,
body.dark-mode .app-list-dt-wrap table.dataTable tbody tr:hover > td,
body.dark-mode .dataTables_wrapper.dt-app-list-wrap table.dataTable tbody tr:hover > td {
    max-height: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
}

[data-theme="dark"] table.dataTable tbody tr.odd > td.dataTables_empty,
[data-theme="dark"] table.dataTable tbody tr.even > td.dataTables_empty,
body.dark-mode table.dataTable tbody tr.odd > td.dataTables_empty,
body.dark-mode table.dataTable tbody tr.even > td.dataTables_empty {
    color: var(--empty-state-text) !important;
}

[data-theme="dark"] .import-list-dt-wrap table.dataTable tbody tr.odd,
[data-theme="dark"] .import-list-dt-wrap table.dataTable tbody tr.even,
[data-theme="dark"] .inventory-list-dt-wrap table.dataTable tbody tr.odd,
[data-theme="dark"] .inventory-list-dt-wrap table.dataTable tbody tr.even,
[data-theme="dark"] .app-list-dt-wrap table.dataTable tbody tr.odd,
[data-theme="dark"] .app-list-dt-wrap table.dataTable tbody tr.even,
body.dark-mode .import-list-dt-wrap table.dataTable tbody tr.odd,
body.dark-mode .import-list-dt-wrap table.dataTable tbody tr.even,
body.dark-mode .inventory-list-dt-wrap table.dataTable tbody tr.odd,
body.dark-mode .inventory-list-dt-wrap table.dataTable tbody tr.even,
body.dark-mode .app-list-dt-wrap table.dataTable tbody tr.odd,
body.dark-mode .app-list-dt-wrap table.dataTable tbody tr.even {
    background-color: transparent !important;
}

[data-theme="dark"] .sl-empty-state,
body.dark-mode .sl-empty-state {
    color: var(--empty-state-text) !important;
    background: var(--app-surface-muted) !important;
}

[data-theme="dark"] .sl-empty-title,
body.dark-mode .sl-empty-title {
    color: var(--app-text) !important;
}

[data-theme="dark"] .sl-empty-hint,
[data-theme="dark"] .sl-empty-icon,
body.dark-mode .sl-empty-hint,
body.dark-mode .sl-empty-icon {
    color: var(--empty-state-icon) !important;
    opacity: 1 !important;
}

/* ---- Links ---- */
[data-theme="dark"] a:not(.btn):not(.nav-item):not(.nav-submenu a):not(.sidebar-brand):not(.supplier-portal-brand):not(.supplier-portal-nav-link):not(.reports-hub-link):not(.notification-item):not(.user-menu-item),
body.dark-mode a:not(.btn):not(.nav-item):not(.nav-submenu a):not(.sidebar-brand):not(.supplier-portal-brand):not(.supplier-portal-nav-link):not(.reports-hub-link):not(.notification-item):not(.user-menu-item) {
    color: var(--app-link);
}

/* ---- Pre / code ---- */
[data-theme="dark"] pre,
[data-theme="dark"] code,
body.dark-mode pre,
body.dark-mode code {
    background: var(--app-code-bg);
    color: var(--app-text);
}

/* ---- Ledger statement pages ---- */
[data-theme="dark"] .supplier-ledger-page,
[data-theme="dark"] .supplier-ledger-report,
body.dark-mode .supplier-ledger-page,
body.dark-mode .supplier-ledger-report {
    --sl-border: #334155;
    --sl-muted: #94a3b8;
}

[data-theme="dark"] .sl-statement-filter,
[data-theme="dark"] .sl-statement-card,
[data-theme="dark"] .alr-report-header,
body.dark-mode .sl-statement-filter,
body.dark-mode .sl-statement-card,
body.dark-mode .alr-report-header {
    background: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .sl-statement-filter .sl-f select,
[data-theme="dark"] .sl-statement-filter .sl-f input[type="date"],
body.dark-mode .sl-statement-filter .sl-f select,
body.dark-mode .sl-statement-filter .sl-f input[type="date"] {
    background: var(--app-input-bg);
    border-color: var(--app-border);
    color: var(--app-text);
}

[data-theme="dark"] .btn-sl-ghost,
body.dark-mode .btn-sl-ghost {
    color: var(--app-text);
    border-color: var(--app-border-strong);
}

[data-theme="dark"] .btn-sl-ghost:hover,
body.dark-mode .btn-sl-ghost:hover {
    background: var(--app-hover);
    color: var(--app-text);
    border-color: var(--app-border-strong);
}

[data-theme="dark"] .alr-header-balance-label,
body.dark-mode .alr-header-balance-label {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .supplier-ledger-table .sl-td-balance.text-danger,
body.dark-mode .supplier-ledger-table .sl-td-balance.text-danger {
    color: #fca5a5 !important;
}

[data-theme="dark"] .supplier-ledger-table .sl-td-balance.text-success,
body.dark-mode .supplier-ledger-table .sl-td-balance.text-success {
    color: #86efac !important;
}

/* ---- Portal sidebar (content area only; topbar stays branded) ---- */
[data-theme="dark"] .supplier-portal-sidebar,
[data-theme="dark"] .portal-sidebar,
body.dark-mode .supplier-portal-sidebar,
body.dark-mode .portal-sidebar {
    background: linear-gradient(180deg, #1e293b 0%, #172033 100%);
    border-right-color: var(--app-border);
}

[data-theme="dark"] .supplier-portal-sidebar-head,
body.dark-mode .supplier-portal-sidebar-head {
    border-bottom-color: var(--app-border);
}

[data-theme="dark"] .supplier-portal-sidebar-title,
body.dark-mode .supplier-portal-sidebar-title {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .supplier-portal-sidebar-subtitle,
body.dark-mode .supplier-portal-sidebar-subtitle {
    color: var(--app-text);
}

[data-theme="dark"] .supplier-portal-nav-link,
body.dark-mode .supplier-portal-nav-link {
    color: #cbd5e1;
}

[data-theme="dark"] .supplier-portal-nav-link:hover,
body.dark-mode .supplier-portal-nav-link:hover {
    background: rgba(96, 165, 250, 0.12);
    color: #93c5fd;
    border-color: rgba(96, 165, 250, 0.25);
}

[data-theme="dark"] .supplier-portal-nav-link.active,
body.dark-mode .supplier-portal-nav-link.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.28) 0%, rgba(59, 130, 246, 0.14) 100%);
    color: #dbeafe;
    border-color: rgba(96, 165, 250, 0.35);
}

/* ---- Reports hub category accents (dark-friendly) ---- */
[data-theme="dark"] .reports-hub-link-purchase:hover,
[data-theme="dark"] .reports-hub-link-sale:hover,
[data-theme="dark"] .reports-hub-link-customer:hover,
[data-theme="dark"] .reports-hub-link-supplier:hover,
[data-theme="dark"] .reports-hub-link-bank:hover,
[data-theme="dark"] .reports-hub-link-inventory:hover,
[data-theme="dark"] .reports-hub-link-workbook:hover,
[data-theme="dark"] .reports-hub-link-financial:hover,
[data-theme="dark"] .reports-hub-link-combined:hover,
body.dark-mode .reports-hub-link-purchase:hover,
body.dark-mode .reports-hub-link-sale:hover,
body.dark-mode .reports-hub-link-customer:hover,
body.dark-mode .reports-hub-link-supplier:hover,
body.dark-mode .reports-hub-link-bank:hover,
body.dark-mode .reports-hub-link-inventory:hover,
body.dark-mode .reports-hub-link-workbook:hover,
body.dark-mode .reports-hub-link-financial:hover,
body.dark-mode .reports-hub-link-combined:hover {
    background: var(--app-hover);
}

/* ============================================================
   READABILITY — headings, labels, semantic colors, overrides
   ============================================================ */

[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] h6,
[data-theme="dark"] .h1,
[data-theme="dark"] .h2,
[data-theme="dark"] .h3,
[data-theme="dark"] .h4,
[data-theme="dark"] .h5,
[data-theme="dark"] .h6,
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6,
body.dark-mode .h1,
body.dark-mode .h2,
body.dark-mode .h3,
body.dark-mode .h4,
body.dark-mode .h5,
body.dark-mode .h6 {
    color: var(--app-text);
}

[data-theme="dark"] .card-title,
[data-theme="dark"] .card-text,
[data-theme="dark"] .fw-semibold,
[data-theme="dark"] .fw-bold,
[data-theme="dark"] label,
[data-theme="dark"] .small,
body.dark-mode .card-title,
body.dark-mode .card-text,
body.dark-mode .fw-semibold,
body.dark-mode .fw-bold,
body.dark-mode label,
body.dark-mode .small {
    color: inherit;
}

[data-theme="dark"] .text-success,
body.dark-mode .text-success {
    color: #4ade80 !important;
}

[data-theme="dark"] .text-danger,
body.dark-mode .text-danger {
    color: #f87171 !important;
}

[data-theme="dark"] .text-primary,
body.dark-mode .text-primary {
    color: #60a5fa !important;
}

[data-theme="dark"] .text-info,
body.dark-mode .text-info {
    color: #22d3ee !important;
}

[data-theme="dark"] .text-warning,
body.dark-mode .text-warning {
    color: #fbbf24 !important;
}

[data-theme="dark"] .btn-outline-primary,
body.dark-mode .btn-outline-primary {
    color: #60a5fa;
    border-color: #60a5fa;
}

[data-theme="dark"] .btn-outline-primary:hover,
body.dark-mode .btn-outline-primary:hover {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

[data-theme="dark"] .dataTables_wrapper label,
[data-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-theme="dark"] .dataTables_wrapper .dataTables_length,
[data-theme="dark"] .dataTables_wrapper .dataTables_filter,
body.dark-mode .dataTables_wrapper label,
body.dark-mode .dataTables_wrapper .dataTables_info,
body.dark-mode .dataTables_wrapper .dataTables_length,
body.dark-mode .dataTables_wrapper .dataTables_filter {
    color: var(--app-text-secondary) !important;
}

[data-theme="dark"] .dataTables_wrapper .dt-toolbar-row .dataTables_length label,
[data-theme="dark"] .dataTables_wrapper .dt-toolbar-row .dataTables_filter label,
body.dark-mode .dataTables_wrapper .dt-toolbar-row .dataTables_length label,
body.dark-mode .dataTables_wrapper .dt-toolbar-row .dataTables_filter label {
    color: var(--app-text-secondary) !important;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select,
body.dark-mode .dataTables_wrapper .dataTables_filter input,
body.dark-mode .dataTables_wrapper .dataTables_length select {
    color: var(--app-text) !important;
}

[data-theme="dark"] .notification-header h6,
[data-theme="dark"] .notification-title,
[data-theme="dark"] .notification-message,
[data-theme="dark"] .user-name,
[data-theme="dark"] .user-email,
[data-theme="dark"] .user-menu-item,
body.dark-mode .notification-header h6,
body.dark-mode .notification-title,
body.dark-mode .notification-message,
body.dark-mode .user-name,
body.dark-mode .user-email,
body.dark-mode .user-menu-item {
    color: var(--app-text);
}

[data-theme="dark"] .notification-message,
[data-theme="dark"] .notification-time,
[data-theme="dark"] .user-email,
body.dark-mode .notification-message,
body.dark-mode .notification-time,
body.dark-mode .user-email {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .notification-item.read,
body.dark-mode .notification-item.read {
    opacity: 1;
}

[data-theme="dark"] .notification-item.read .notification-title,
body.dark-mode .notification-item.read .notification-title {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .quick-action-card,
body.dark-mode .quick-action-card {
    background: var(--app-surface);
    color: var(--app-text);
}

[data-theme="dark"] .quick-action-label,
body.dark-mode .quick-action-label {
    color: var(--app-text);
}

[data-theme="dark"] .quick-action-card:hover,
body.dark-mode .quick-action-card:hover {
    color: var(--app-text);
}

[data-theme="dark"] .reports-hub-section,
body.dark-mode .reports-hub-section {
    background: var(--app-surface);
    border-color: var(--app-border);
}

[data-theme="dark"] .reports-hub-section-header,
body.dark-mode .reports-hub-section-header {
    background: var(--app-surface-muted);
    border-bottom-color: var(--app-border);
}

[data-theme="dark"] .reports-hub-section-title,
[data-theme="dark"] .reports-hub-link-title,
body.dark-mode .reports-hub-section-title,
body.dark-mode .reports-hub-link-title {
    color: var(--app-text) !important;
}

[data-theme="dark"] .reports-hub-section-desc,
[data-theme="dark"] .reports-hub-link-desc,
[data-theme="dark"] .reports-hub-section-count,
body.dark-mode .reports-hub-section-desc,
body.dark-mode .reports-hub-link-desc,
body.dark-mode .reports-hub-section-count {
    color: var(--app-text-secondary) !important;
}

[data-theme="dark"] .reports-hub-section-count,
body.dark-mode .reports-hub-section-count {
    background: var(--app-surface-raised);
    border-color: var(--app-border);
}

[data-theme="dark"] .reports-hub-link-arrow,
body.dark-mode .reports-hub-link-arrow {
    color: var(--app-text-muted);
}

[data-theme="dark"] .reports-hub-section-featured,
body.dark-mode .reports-hub-section-featured {
    border-color: var(--app-border-strong);
}

/* Account ledger statement — override hardcoded light text */
[data-theme="dark"] .sl-statement-filter .sl-f label,
body.dark-mode .sl-statement-filter .sl-f label {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .sl-account-ledger-report .alr-meta-label,
body.dark-mode .sl-account-ledger-report .alr-meta-label {
    color: var(--report-label-text);
}

[data-theme="dark"] .sl-account-ledger-report .alr-meta-value,
[data-theme="dark"] .sl-statement-table.sl-statement-table--account-ledger tbody td,
[data-theme="dark"] .sl-statement-table.sl-statement-table--account-ledger .sl-col-ref strong,
[data-theme="dark"] .sl-statement-table.sl-statement-table--account-ledger .sl-col-dr,
[data-theme="dark"] .sl-statement-table.sl-statement-table--account-ledger .sl-col-cr,
[data-theme="dark"] .sl-statement-table.sl-statement-table--account-ledger .sl-col-bal,
body.dark-mode .sl-account-ledger-report .alr-meta-value,
body.dark-mode .sl-statement-table.sl-statement-table--account-ledger tbody td,
body.dark-mode .sl-statement-table.sl-statement-table--account-ledger .sl-col-ref strong,
body.dark-mode .sl-statement-table.sl-statement-table--account-ledger .sl-col-dr,
body.dark-mode .sl-statement-table.sl-statement-table--account-ledger .sl-col-cr,
body.dark-mode .sl-statement-table.sl-statement-table--account-ledger .sl-col-bal {
    color: var(--report-body-text) !important;
}

[data-theme="dark"] .sl-statement-table.sl-statement-table--account-ledger .sl-col-opening-label,
[data-theme="dark"] .sl-statement-table.sl-statement-table--account-ledger .sl-col-closing-label,
body.dark-mode .sl-statement-table.sl-statement-table--account-ledger .sl-col-opening-label,
body.dark-mode .sl-statement-table.sl-statement-table--account-ledger .sl-col-closing-label {
    color: var(--report-label-text) !important;
}

[data-theme="dark"] .alr-report-title,
[data-theme="dark"] .alr-header-balance-value,
body.dark-mode .alr-report-title,
body.dark-mode .alr-header-balance-value {
    color: var(--report-accent) !important;
}

[data-theme="dark"] .supplier-ledger-page .card-header,
[data-theme="dark"] .ledger-statement-page .card-header,
body.dark-mode .supplier-ledger-page .card-header,
body.dark-mode .ledger-statement-page .card-header {
    color: var(--app-text);
}

[data-theme="dark"] .ts-wrapper .ts-dropdown .no-results,
[data-theme="dark"] .ts-wrapper.single .ts-control .item[data-value=""],
body.dark-mode .ts-wrapper .ts-dropdown .no-results,
body.dark-mode .ts-wrapper.single .ts-control .item[data-value=""] {
    color: var(--app-text-muted) !important;
}

[data-theme="dark"] .payment-row-select-wrap.single .ts-control .item[data-value=""],
body.dark-mode .payment-row-select-wrap.single .ts-control .item[data-value=""] {
    color: var(--app-text-muted) !important;
}

[data-theme="dark"] body > .ts-dropdown.payment-row-select-dropdown .option,
body.dark-mode body > .ts-dropdown.payment-row-select-dropdown .option {
    color: var(--app-text);
}

[data-theme="dark"] body > .ts-dropdown.payment-row-select-dropdown .option.active,
body.dark-mode body > .ts-dropdown.payment-row-select-dropdown .option.active {
    color: var(--app-text);
}

/* Portal — day mode hardcoded titles; night mode inherits variables */
[data-theme="dark"] .portal-page-title,
body.dark-mode .portal-page-title {
    color: var(--app-text) !important;
}

[data-theme="dark"] .supplier-portal-content .text-muted,
[data-theme="dark"] .supplier-portal-content .small.text-muted,
body.dark-mode .supplier-portal-content .text-muted,
body.dark-mode .supplier-portal-content .small.text-muted {
    color: var(--app-text-muted) !important;
}

[data-theme="dark"] .supplier-portal-content .card-header .fw-semibold,
[data-theme="dark"] .supplier-portal-content .card-header span,
body.dark-mode .supplier-portal-content .card-header .fw-semibold,
body.dark-mode .supplier-portal-content .card-header span {
    color: var(--app-text);
}

[data-theme="dark"] .footer-text p,
[data-theme="dark"] .footer-links span,
body.dark-mode .footer-text p,
body.dark-mode .footer-links span {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .main-content,
[data-theme="dark"] .main-content p,
[data-theme="dark"] .main-content li,
[data-theme="dark"] .main-content td,
[data-theme="dark"] .main-content th,
body.dark-mode .main-content,
body.dark-mode .main-content p,
body.dark-mode .main-content li,
body.dark-mode .main-content td,
body.dark-mode .main-content th {
    color: inherit;
}

[data-theme="dark"] .card-header span,
[data-theme="dark"] .card-header .mb-0,
body.dark-mode .card-header span,
body.dark-mode .card-header .mb-0 {
    color: var(--app-text);
}

[data-theme="dark"] .form-control::placeholder,
body.dark-mode .form-control::placeholder {
    color: #94a3b8;
    opacity: 1;
}

/* Inventory / list tables — tinted rows readable at night */
[data-theme="dark"] .inventory-list-page .inventory-list-dt-wrap table.inventory-list-table tbody tr.inventory-row-purchase > td,
body.dark-mode .inventory-list-page .inventory-list-dt-wrap table.inventory-list-table tbody tr.inventory-row-purchase > td {
    background-color: rgba(59, 130, 246, 0.14) !important;
    color: var(--app-text) !important;
}

[data-theme="dark"] .inventory-list-page .inventory-list-dt-wrap table.inventory-list-table tbody tr.inventory-row-direct-market > td,
body.dark-mode .inventory-list-page .inventory-list-dt-wrap table.inventory-list-table tbody tr.inventory-row-direct-market > td {
    background-color: rgba(245, 158, 11, 0.12) !important;
    color: var(--app-text) !important;
}

[data-theme="dark"] .inventory-list-dt-wrap .dt-inventory-list-wrap .dataTables_length label,
[data-theme="dark"] .inventory-list-dt-wrap .dt-inventory-list-wrap .dataTables_filter label,
body.dark-mode .inventory-list-dt-wrap .dt-inventory-list-wrap .dataTables_length label,
body.dark-mode .inventory-list-dt-wrap .dt-inventory-list-wrap .dataTables_filter label {
    color: var(--app-text-secondary) !important;
}

/* Day mode — ensure muted labels stay readable on white cards */
[data-theme="light"] .text-muted,
[data-theme="light"] .small.text-muted,
body:not(.dark-mode) .text-muted,
body:not(.dark-mode) .small.text-muted {
    color: var(--app-text-muted) !important;
}

[data-theme="light"] .portal-page-subtitle,
[data-theme="light"] .supplier-portal-content .text-muted,
body:not(.dark-mode) .portal-page-subtitle,
body:not(.dark-mode) .supplier-portal-content .text-muted {
    color: var(--app-text-muted) !important;
}

[data-theme="light"] .dataTables_wrapper label,
[data-theme="light"] .dataTables_wrapper .dataTables_info,
body:not(.dark-mode) .dataTables_wrapper label,
body:not(.dark-mode) .dataTables_wrapper .dataTables_info {
    color: var(--app-text-secondary) !important;
}

[data-theme="dark"] .kpi-change.positive,
body.dark-mode .kpi-change.positive {
    color: #4ade80;
    background: rgba(74, 222, 128, 0.14);
}

[data-theme="dark"] .kpi-change.negative,
body.dark-mode .kpi-change.negative {
    color: #f87171;
    background: rgba(248, 113, 113, 0.14);
}

[data-theme="dark"] .kpi-change.neutral,
body.dark-mode .kpi-change.neutral {
    color: var(--app-text-secondary);
    background: rgba(148, 163, 184, 0.14);
}

[data-theme="dark"] .activity-name,
[data-theme="dark"] .activity-action,
[data-theme="dark"] .activity-time,
body.dark-mode .activity-name,
body.dark-mode .activity-action,
body.dark-mode .activity-time {
    color: var(--app-text);
}

[data-theme="dark"] .activity-action,
[data-theme="dark"] .activity-time,
body.dark-mode .activity-action,
body.dark-mode .activity-time {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .card-header-modern h5,
[data-theme="dark"] .card-header-modern small,
body.dark-mode .card-header-modern h5,
body.dark-mode .card-header-modern small {
    color: var(--app-text);
}

[data-theme="dark"] .card-header-modern small,
body.dark-mode .card-header-modern small {
    color: var(--app-text-secondary);
}

[data-theme="dark"] .login-body .text-muted,
[data-theme="dark"] .login-body .form-check-label,
body.dark-mode .login-body .text-muted,
body.dark-mode .login-body .form-check-label {
    color: var(--app-text-secondary) !important;
}
