/* ════════════════════════════════════════════════════════════════════════════════
   LIGHT MODE OVERRIDES FOR THIRD-PARTY LIBRARIES & PAGE PANELS
   Ensures toastr, parsley, datatables, and glass-panel views work in light mode
   ════════════════════════════════════════════════════════════════════════════════ */

/* ──────────────────────────────────────────────────────────────────────────────
   GLOBAL CANVAS — soften pure white for less glare / better contrast
   Cards & panels stay lighter than the page so content still stands out.
   ────────────────────────────────────────────────────────────────────────────── */

[data-bs-theme="light"] {
    --bs-body-bg: #dde1e6;
    --bs-body-bg-rgb: 221, 225, 230;
    --bs-body-color: #1a1d21;
    --bs-body-color-rgb: 26, 29, 33;
    --bs-emphasis-color: #111417;
    --bs-emphasis-color-rgb: 17, 20, 23;
    --bs-secondary-color: #4b5563;
    --bs-secondary-color-rgb: 75, 85, 99;
    --bs-tertiary-color: #6b7280;
    --bs-tertiary-color-rgb: 107, 114, 128;
    --bs-secondary-bg: #eef0f3;
    --bs-secondary-bg-rgb: 238, 240, 243;
    --bs-tertiary-bg: #d0d5db;
    --bs-tertiary-bg-rgb: 208, 213, 219;
    --bs-border-color: #c0c6ce;
    --bs-border-color-translucent: rgba(0, 0, 0, 0.14);
    --bs-heading-color: #111417;
}

[data-bs-theme="light"] body,
[data-bs-theme="light"].main-body,
body[data-bs-theme="light"] {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
}

/* Readable body/muted text on shaded light canvas — never force black onto dark fills */
[data-bs-theme="light"] .text-muted,
[data-bs-theme="light"] .text-secondary,
[data-bs-theme="light"] .text-body-secondary,
[data-bs-theme="light"] .text-body-tertiary,
[data-bs-theme="light"] .form-text,
[data-bs-theme="light"] .form-label,
[data-bs-theme="light"] .pp-breadcrumb,
[data-bs-theme="light"] .dataTables_info,
[data-bs-theme="light"] .dataTables_length label,
[data-bs-theme="light"] .dataTables_filter label {
    color: var(--bs-secondary-color) !important;
}

[data-bs-theme="light"] .pp-page-title {
    color: var(--bs-emphasis-color) !important;
}

[data-bs-theme="light"] .table,
[data-bs-theme="light"] .table > :not(caption) > * > *,
[data-bs-theme="light"] table.dataTable,
[data-bs-theme="light"] table.dataTable thead th,
[data-bs-theme="light"] table.dataTable tbody td {
    color: var(--bs-body-color);
}

/* Solid badge fills must keep contrasting text (never inherit forced body black).
   NOTE: this theme's palette — info = dark navy #033c73, warning = burnt orange
   #dd5600 (both need WHITE text); secondary = light gray #e9ecef (needs DARK text). */
[data-bs-theme="light"] .badge.bg-primary,
[data-bs-theme="light"] .badge.bg-success,
[data-bs-theme="light"] .badge.bg-danger,
[data-bs-theme="light"] .badge.bg-dark,
[data-bs-theme="light"] .badge.bg-info,
[data-bs-theme="light"] .badge.bg-warning,
[data-bs-theme="light"] .badge.bg-info.text-dark,
[data-bs-theme="light"] .badge.bg-warning.text-dark,
[data-bs-theme="light"] .badge.text-bg-primary,
[data-bs-theme="light"] .badge.text-bg-success,
[data-bs-theme="light"] .badge.text-bg-danger,
[data-bs-theme="light"] .badge.text-bg-dark,
[data-bs-theme="light"] .badge.text-bg-info,
[data-bs-theme="light"] .badge.text-bg-warning,
[data-bs-theme="light"] .summary-chip.bg-info,
[data-bs-theme="light"] .summary-chip.bg-warning {
    color: #fff !important;
}

[data-bs-theme="light"] .badge.bg-secondary,
[data-bs-theme="light"] .badge.bg-light,
[data-bs-theme="light"] .badge.text-bg-secondary,
[data-bs-theme="light"] .badge.text-bg-light {
    color: #212529 !important;
}

/* ── NO LIGHT TEXT ON LIGHT FILLS ─────────────────────────────────────────────
   This theme's bg-secondary is LIGHT gray (#e9ecef); bg-light / bg-white are
   also light. Any text-white/text-light paired with them must go dark. */
[data-bs-theme="light"] .bg-secondary.text-white,
[data-bs-theme="light"] .bg-secondary.text-light,
[data-bs-theme="light"] .bg-light.text-white,
[data-bs-theme="light"] .bg-light.text-light,
[data-bs-theme="light"] .bg-white.text-white,
[data-bs-theme="light"] .bg-white.text-light,
[data-bs-theme="light"] .card.bg-secondary,
[data-bs-theme="light"] .card-header.bg-secondary,
[data-bs-theme="light"] .modal-header.bg-secondary,
[data-bs-theme="light"] .summary-chip.bg-secondary,
[data-bs-theme="light"] .card.bg-secondary .card-body,
[data-bs-theme="light"] .card.bg-secondary .card-title,
[data-bs-theme="light"] .card.bg-secondary .card-text {
    color: #212529 !important;
}

/* White close button is invisible on light-gray headers */
[data-bs-theme="light"] .bg-secondary .btn-close-white,
[data-bs-theme="light"] .bg-light .btn-close-white,
[data-bs-theme="light"] .bg-white .btn-close-white {
    filter: none !important;
}

/* Light progress-bar fills need dark labels */
[data-bs-theme="light"] .progress-bar.bg-secondary,
[data-bs-theme="light"] .progress-bar.bg-light {
    color: #212529 !important;
}

/* Forms / inputs: keep a slightly lighter field than the page canvas */
[data-bs-theme="light"] .form-control,
[data-bs-theme="light"] .form-select,
[data-bs-theme="light"] .input-group-text {
    background-color: #f1f3f5;
}

[data-bs-theme="light"] .form-control:focus,
[data-bs-theme="light"] .form-select:focus {
    background-color: #f8f9fa;
}

[data-bs-theme="light"] .card,
[data-bs-theme="light"] .modal-content,
[data-bs-theme="light"] .dropdown-menu,
[data-bs-theme="light"] .list-group-item,
[data-bs-theme="light"] .accordion-item {
    --bs-card-bg: var(--bs-secondary-bg);
    background-color: var(--bs-secondary-bg);
}

/* ──────────────────────────────────────────────────────────────────────────────
   PARSLEY VALIDATION - LIGHT MODE
   ────────────────────────────────────────────────────────────────────────────── */

[data-bs-theme="light"] input.parsley-success,
[data-bs-theme="light"] select.parsley-success,
[data-bs-theme="light"] textarea.parsley-success {
    color: #198754;
    background-color: rgba(25, 135, 84, 0.08);
    border-color: #198754;
}

[data-bs-theme="light"] input.parsley-error,
[data-bs-theme="light"] select.parsley-error,
[data-bs-theme="light"] textarea.parsley-error {
    color: #dc3545;
    background-color: rgba(220, 53, 69, 0.08);
    border-color: #dc3545;
}

[data-bs-theme="light"] .parsley-errors-list,
[data-bs-theme="light"] .parsley-error-list {
    color: #dc3545;
}

/* ──────────────────────────────────────────────────────────────────────────────
   DATATABLES - LIGHT MODE
   ────────────────────────────────────────────────────────────────────────────── */

[data-bs-theme="light"] .dataTables_wrapper {
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .dataTables_length,
[data-bs-theme="light"] .dataTables_filter,
[data-bs-theme="light"] .dataTables_info,
[data-bs-theme="light"] .dataTables_paginate {
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .dataTables_filter input,
[data-bs-theme="light"] .dataTables_length select {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    border: 1px solid var(--bs-border-color);
}

[data-bs-theme="light"] table.dataTable thead th,
[data-bs-theme="light"] table.dataTable thead td {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-body-color);
    border-color: var(--bs-border-color);
}

[data-bs-theme="light"] table.dataTable tbody tr {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
}

[data-bs-theme="light"] table.dataTable tbody tr:hover {
    background-color: var(--bs-tertiary-bg);
}

[data-bs-theme="light"] table.dataTable tbody th,
[data-bs-theme="light"] table.dataTable tbody td {
    border-color: var(--bs-border-color);
}

[data-bs-theme="light"] .dataTables_paginate .paginate_button {
    background-color: var(--bs-secondary-bg);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color) !important;
}

[data-bs-theme="light"] .dataTables_paginate .paginate_button:hover {
    background-color: var(--bs-tertiary-bg);
    color: var(--bs-body-color) !important;
    border-color: var(--bs-border-color);
}

[data-bs-theme="light"] .dataTables_paginate .paginate_button.current,
[data-bs-theme="light"] .dataTables_paginate .paginate_button.active {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
    color: #fff !important;
}

[data-bs-theme="light"] .dataTables_paginate .paginate_button.disabled {
    opacity: 0.5;
    color: var(--bs-secondary-color) !important;
}

[data-bs-theme="light"] table.dataTable.fixedHeader-floating,
[data-bs-theme="light"] table.dataTable.fixedHeader-locked {
    background-color: var(--bs-secondary-bg);
}

/* ──────────────────────────────────────────────────────────────────────────────
   TOASTR - LIGHT MODE (ensure readable on light backgrounds)
   ────────────────────────────────────────────────────────────────────────────── */

[data-bs-theme="light"] .toast-container > .toast {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    border: 1px solid var(--bs-border-color);
}

[data-bs-theme="light"] .toast-header {
    background-color: var(--bs-secondary-bg);
    border-bottom: 1px solid var(--bs-border-color);
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .toast-body {
    color: var(--bs-body-color);
}

/* ──────────────────────────────────────────────────────────────────────────────
   IMPORT / ORDER PAGE PANELS (theme-aware via CSS vars in view)
   ────────────────────────────────────────────────────────────────────────────── */

[data-bs-theme="light"] .drop-zone {
    border-color: var(--bs-border-color);
    background: var(--bs-secondary-bg);
}

[data-bs-theme="light"] .drop-zone .dz-icon {
    color: var(--bs-secondary-color);
}

[data-bs-theme="light"] .drop-zone .dz-label {
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .drop-zone .dz-sub {
    color: var(--bs-secondary-color);
}

[data-bs-theme="light"] .stat-card {
    background: var(--bs-secondary-bg);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .stat-card .stat-label {
    color: var(--bs-secondary-color);
}

[data-bs-theme="light"] .warn-table th,
[data-bs-theme="light"] .log-table th,
[data-bs-theme="light"] .preview-table th {
    color: var(--bs-secondary-color);
}

[data-bs-theme="light"] .warn-table tbody tr:not(:last-child) td,
[data-bs-theme="light"] .log-table tbody tr:not(:last-child) td,
[data-bs-theme="light"] .preview-table tbody tr:not(:last-child) td {
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="light"] .result-meta,
[data-bs-theme="light"] .preview-meta {
    color: var(--bs-secondary-color);
}

[data-bs-theme="light"] .lookup-chip {
    background: rgba(var(--bs-primary-rgb), 0.12);
    color: var(--bs-primary);
}

[data-bs-theme="light"] .preview-changes-list {
    color: var(--bs-body-color);
}

[data-bs-theme="light"] tr.preview-row-nochange td {
    color: var(--bs-secondary-color);
}

/* ──────────────────────────────────────────────────────────────────────────────
   PLANNER ASSIGNMENT PANELS
   ────────────────────────────────────────────────────────────────────────────── */

[data-bs-theme="light"] .pa-panel-hdr {
    color: var(--bs-secondary-color);
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="light"] .pa-panel-hdr strong {
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .lines-table th,
[data-bs-theme="light"] .stock-table th,
[data-bs-theme="light"] .asgn-table th {
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="light"] .lines-table td,
[data-bs-theme="light"] .stock-table td {
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="light"] .lines-table tbody tr:hover {
    background: var(--bs-tertiary-bg);
}

[data-bs-theme="light"] .pa-right-empty {
    color: var(--bs-secondary-color);
}

[data-bs-theme="light"] .line-summary {
    background: var(--bs-secondary-bg);
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="light"] .line-summary .ls-chip {
    color: var(--bs-secondary-color);
}

[data-bs-theme="light"] .line-summary .ls-chip strong,
[data-bs-theme="light"] .line-summary .ls-title {
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .fulfil-strip {
    background: var(--bs-secondary-bg);
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="light"] .fulfil-bar,
[data-bs-theme="light"] .mini-bar {
    background: var(--bs-border-color);
}

[data-bs-theme="light"] .pa-left {
    border-right-color: var(--bs-border-color);
}

/* ──────────────────────────────────────────────────────────────────────────────
   PACK MATERIAL ADMIN TABS
   ────────────────────────────────────────────────────────────────────────────── */

[data-bs-theme="light"] .tab-btn {
    border-color: var(--bs-border-color);
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .tab-btn.active {
    background: rgba(var(--bs-primary-rgb), 0.12);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

[data-bs-theme="light"] .tab-btn:hover:not(.active) {
    background: var(--bs-tertiary-bg);
}

[data-bs-theme="light"] .card-section {
    background: var(--bs-secondary-bg);
    border-color: var(--bs-border-color);
}

[data-bs-theme="light"] .tbl th {
    color: var(--bs-secondary-color);
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="light"] .tbl td {
    border-bottom-color: var(--bs-border-color);
}

[data-bs-theme="light"] .tbl tbody tr:hover {
    background: var(--bs-tertiary-bg);
}

[data-bs-theme="light"] .section-label,
[data-bs-theme="light"] .kpi-lbl {
    color: var(--bs-secondary-color);
}

[data-bs-theme="light"] .capture-card,
[data-bs-theme="light"] .chart-card,
[data-bs-theme="light"] .dispatch-panel,
[data-bs-theme="light"] .order-section-card,
[data-bs-theme="light"] .section-header {
    background: var(--bs-secondary-bg) !important;
    border-color: var(--bs-border-color) !important;
    color: var(--bs-body-color);
}

[data-bs-theme="light"] .section-header {
    border-left-color: var(--bs-primary) !important;
    color: var(--bs-secondary-color) !important;
}

/* ──────────────────────────────────────────────────────────────────────────────
   PROJECT-WIDE ENFORCEMENT — shaded light surfaces, no pure-white canvas
   Catch Bootstrap utilities + inline whites. Print/label paper stays excluded.
   ────────────────────────────────────────────────────────────────────────────── */

[data-bs-theme="light"] .bg-white:not(.badge):not(.btn):not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet),
[data-bs-theme="light"] .card-header.bg-white,
[data-bs-theme="light"] .card.bg-white {
    background-color: var(--bs-secondary-bg) !important;
    color: var(--bs-body-color) !important;
}

[data-bs-theme="light"] .bg-light:not(.badge):not(.btn),
[data-bs-theme="light"] .card-header.bg-light,
[data-bs-theme="light"] .card.bg-light,
[data-bs-theme="light"] .footer.bg-light {
    background-color: var(--bs-tertiary-bg) !important;
    color: var(--bs-body-color) !important;
}

/* Inline pure-white panels → shaded secondary surface */
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background: white"],
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background:#fff"],
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background: #fff"],
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background-color: white"],
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background-color:#fff"],
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background-color: #fff"],
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background: #ffffff"],
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background-color: #ffffff"],
[data-bs-theme="light"] *:not(.label-paper):not(.label-preview-inner):not(.qc-form):not(.sb-form):not(.doc-sheet):not(#labelCanvas)[style*="background:#ffffff"] {
    background-color: var(--bs-secondary-bg) !important;
    color: var(--bs-body-color);
}

/* Hard-coded mid-gray labels → theme secondary */
[data-bs-theme="light"] *[style*="color: #666"],
[data-bs-theme="light"] *[style*="color:#666"],
[data-bs-theme="light"] *[style*="color: #999"],
[data-bs-theme="light"] *[style*="color:#999"] {
    color: var(--bs-secondary-color) !important;
}

/* Outline buttons stay readable on shaded light canvas */
[data-bs-theme="light"] .btn-outline-secondary,
[data-bs-theme="light"] .btn-outline-primary,
[data-bs-theme="light"] .btn-outline-dark {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-border-color: var(--bs-border-color);
    --bs-btn-hover-bg: var(--bs-tertiary-bg);
    --bs-btn-hover-border-color: var(--bs-border-color);
    --bs-btn-hover-color: var(--bs-body-color);
}
