/*
 * Dark theme for a domain (Super Admin > Domains > Features > "Dark theme").
 * TourPerformance's palette. Added to every page of a domain with the switch on,
 * with <html data-portal-theme="dark" data-bs-theme="dark"> (Bootstrap's own dark mode).
 * This file darkens the layout and the shared components; theme-dark.js catches the
 * light surfaces and dark text that individual pages set in their own styles.
 * The domain's brand colours (accent, sidebar) still come from its Branding settings.
 */
html[data-portal-theme="dark"] {
    color-scheme: dark;
    --td-page: #0D0F14;
    --td-surface: #151821;
    --td-raised: #1B1F2A;
    --td-border: #2A2E3A;
    --td-text: #C9CCDD;
    --td-heading: #FFFFFF;
    --td-muted: #A0A3BD;

    /* the layout's own variables */
    --bg-page: var(--td-page);
    --border: var(--td-border);
    --muted: var(--td-muted);
    --sidebar-text: #A0A3BD;
    --sidebar-section: #6E7287;
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.40);

    /* Bootstrap 5.3 */
    --bs-body-bg: var(--td-page);
    --bs-body-color: var(--td-text);
    --bs-emphasis-color: var(--td-heading);
    --bs-heading-color: var(--td-heading);
    --bs-secondary-color: var(--td-muted);
    --bs-secondary-bg: var(--td-surface);
    --bs-tertiary-bg: var(--td-raised);
    --bs-border-color: var(--td-border);
    --bs-border-color-translucent: rgba(255, 255, 255, 0.08);
}

/* Until theme-dark.js has done its pass the page stays hidden (no white flash);
   if the script never runs, the page shows anyway after 1.2 s. */
html[data-portal-theme="dark"]:not(.theme-dark-ready) body {
    opacity: 0;
    animation: td-reveal 0s linear 1.2s forwards;
}
@keyframes td-reveal { to { opacity: 1; } }

html[data-portal-theme="dark"] body {
    background: var(--td-page) !important;
    color: var(--td-text);
}
html[data-portal-theme="dark"] :is(h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6) { color: var(--td-heading); }
html[data-portal-theme="dark"] hr { border-color: var(--td-border); opacity: 1; }

/* ── header and its menus ── */
html[data-portal-theme="dark"] #p3Header { background: var(--td-surface) !important; border-color: var(--td-border) !important; }
html[data-portal-theme="dark"] #p3HamBtn:hover,
html[data-portal-theme="dark"] .bell-btn,
html[data-portal-theme="dark"] .prof-pill { background: var(--td-raised) !important; color: var(--td-text) !important; }
html[data-portal-theme="dark"] .bell-btn:hover,
html[data-portal-theme="dark"] .prof-pill:hover { background: #232838 !important; }
html[data-portal-theme="dark"] .bell-dot { border-color: var(--td-surface); }
html[data-portal-theme="dark"] .prof-drop { background: var(--td-surface) !important; border-color: var(--td-border) !important; }
html[data-portal-theme="dark"] .prof-drop .dh,
html[data-portal-theme="dark"] .prof-drop .dhr { border-color: var(--td-border) !important; background: transparent; }
html[data-portal-theme="dark"] .prof-drop a.di { color: var(--td-text) !important; }
html[data-portal-theme="dark"] .prof-drop a.di:hover { background: var(--td-raised) !important; }

/* ── cards and panels ── */
html[data-portal-theme="dark"] :is(.card, .stat-card, .info-card, .progress-card, .programs-card, .modal-content, .dropdown-menu,
    .offcanvas, .list-group-item, .accordion-item, .accordion-button, .popover, .toast, .nav-tabs .nav-link.active) {
    background-color: var(--td-surface) !important;
    color: var(--td-text);
    border-color: var(--td-border) !important;
}
html[data-portal-theme="dark"] :is(.card-header, .card-footer, .modal-header, .modal-footer) { background-color: transparent; border-color: var(--td-border) !important; }
html[data-portal-theme="dark"] :is(.info-row, .prog-item, .program-item) { border-color: var(--td-border) !important; }
html[data-portal-theme="dark"] :is(.info-row .info-label, .prog-item .prog-label) { color: var(--td-muted) !important; }
html[data-portal-theme="dark"] .stat-card .stat-icon { background: var(--td-raised) !important; color: var(--td-text) !important; }
html[data-portal-theme="dark"] .dropdown-item { color: var(--td-text); }
html[data-portal-theme="dark"] .dropdown-item:hover { background-color: var(--td-raised); color: var(--td-heading); }
html[data-portal-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* ── utility classes ── */
html[data-portal-theme="dark"] :is(.bg-white, .bg-light, .bg-body, .bg-body-tertiary) { background-color: var(--td-surface) !important; }
html[data-portal-theme="dark"] :is(.text-dark, .text-black, .text-body) { color: var(--td-text) !important; }
html[data-portal-theme="dark"] .text-muted { color: var(--td-muted) !important; }

/* ── tables (Bootstrap + DataTables) ── */
html[data-portal-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--td-text);
    --bs-table-border-color: var(--td-border);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-striped-color: var(--td-text);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05);
    --bs-table-hover-color: var(--td-heading);
    color: var(--td-text);
}
html[data-portal-theme="dark"] :is(table thead th, table thead td, .table > thead > tr > th) {
    background-color: var(--td-raised) !important;
    color: var(--td-muted) !important;
    border-color: var(--td-border) !important;
}
html[data-portal-theme="dark"] :is(table td, table th) { border-color: var(--td-border) !important; }
html[data-portal-theme="dark"] table.dataTable tbody tr { background-color: transparent !important; }
html[data-portal-theme="dark"] :is(.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate .paginate_button) { color: var(--td-text) !important; }
html[data-portal-theme="dark"] .page-link { background-color: var(--td-surface); border-color: var(--td-border); color: var(--td-text); }

/* ── form fields ── */
html[data-portal-theme="dark"] :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=submit]):not([type=button]):not([type=file]),
    select, textarea, .form-control, .form-select, .bw-input, .input-group-text, .select2-container .select2-selection) {
    background-color: var(--td-raised) !important;
    color: var(--td-heading) !important;
    border-color: var(--td-border) !important;
}
html[data-portal-theme="dark"] :is(input, textarea, .form-control)::placeholder { color: #6E7287 !important; opacity: 1; }
html[data-portal-theme="dark"] :is(input, textarea, select):disabled,
html[data-portal-theme="dark"] .form-control[readonly] { background-color: #161922 !important; color: var(--td-muted) !important; }
html[data-portal-theme="dark"] :is(.form-check-input) { background-color: var(--td-raised); border-color: #4A4F60; }
html[data-portal-theme="dark"] :is(label, .form-label, .form-text) { color: var(--td-muted); }
html[data-portal-theme="dark"] input[type=date]::-webkit-calendar-picker-indicator,
html[data-portal-theme="dark"] input[type=datetime-local]::-webkit-calendar-picker-indicator { filter: invert(0.8); }
html[data-portal-theme="dark"] .select2-container .select2-selection__rendered { color: var(--td-heading) !important; }
html[data-portal-theme="dark"] .select2-container .select2-selection__choice { background-color: #232838 !important; border-color: var(--td-border) !important; color: var(--td-heading) !important; }
html[data-portal-theme="dark"] .select2-dropdown { background-color: var(--td-surface) !important; border-color: var(--td-border) !important; color: var(--td-text); }
html[data-portal-theme="dark"] .select2-results__option[aria-selected=true] { background-color: var(--td-raised) !important; }
html[data-portal-theme="dark"] .select2-results__option--highlighted { background-color: var(--accent, #FF1F1F) !important; color: #fff !important; }

/* ── buttons the layout paints light ── */
html[data-portal-theme="dark"] .btn.btn-light:not(.dashboard-send-email):not(.btn-p3-primary):not(.open-email-modal),
html[data-portal-theme="dark"] .btn-outline-secondary,
html[data-portal-theme="dark"] .btn-secondary {
    background-color: var(--td-raised) !important;
    color: var(--td-text) !important;
    border-color: var(--td-border) !important;
}
html[data-portal-theme="dark"] .btn.btn-outline-dark:not(.dashboard-send-email):not(.btn-p3-primary):not(.open-email-modal) { color: var(--td-text) !important; border-color: #4A4F60 !important; }

/* ── pop-ups from the plugins ── */
html[data-portal-theme="dark"] :is(.swal2-popup, .swal-modal, .daterangepicker, .daterangepicker .calendar-table, .daterangepicker .ranges) {
    background-color: var(--td-surface) !important;
    color: var(--td-text) !important;
    border-color: var(--td-border) !important;
}
html[data-portal-theme="dark"] :is(.swal2-title, .swal-title, .swal2-html-container, .swal-text) { color: var(--td-heading) !important; }
html[data-portal-theme="dark"] .daterangepicker td.off { background-color: transparent !important; color: #4A4F60 !important; }
html[data-portal-theme="dark"] .daterangepicker td.available:hover { background-color: var(--td-raised) !important; }
