/* ── Dark mode ────────────────────────────────────────────────────────
   Switched on by data-bs-theme="dark" on <html> (the moon/sun button in the top bar; the choice is kept in
   localStorage, see _Layout). Bootstrap 5.3 has dark colours of its own, but AdminKit (app.css) redeclares the
   light ones on :root and hard-codes many light colours, so they're set again here with html[...] to win. */

html[data-bs-theme=dark] {
    color-scheme: dark;

    --wh-page-bg: #151b23;
    --wh-surface: #1e2630;
    --wh-surface-2: #252e3a;
    --wh-surface-3: #2d3745;
    --wh-border: #354151;
    --wh-text: #d6dbe1;
    --wh-text-strong: #f1f3f5;
    --wh-muted: #95a0ab;

    --bs-body-bg: var(--wh-page-bg);
    --bs-body-bg-rgb: 21, 27, 35;
    --bs-body-color: var(--wh-text);
    --bs-body-color-rgb: 214, 219, 225;
    --bs-emphasis-color: var(--wh-text-strong);
    --bs-emphasis-color-rgb: 241, 243, 245;
    --bs-heading-color: var(--wh-text-strong);
    --bs-secondary-color: var(--wh-muted);
    --bs-secondary-color-rgb: 149, 160, 171;
    --bs-secondary-bg: var(--wh-surface-2);
    --bs-secondary-bg-rgb: 37, 46, 58;
    --bs-tertiary-color: rgba(214, 219, 225, .5);
    --bs-tertiary-bg: var(--wh-surface-2);
    --bs-tertiary-bg-rgb: 37, 46, 58;
    --bs-border-color: var(--wh-border);
    --bs-border-color-translucent: rgba(255, 255, 255, .12);
    --bs-link-color: #6ea8fe;
    --bs-link-color-rgb: 110, 168, 254;
    --bs-link-hover-color: #9ec5fe;
    --bs-link-hover-color-rgb: 158, 197, 254;
    --bs-light-rgb: 45, 55, 69;
    --bs-white-rgb: 30, 38, 48;
    --bs-dark-rgb: 241, 243, 245;
    --bs-code-color: #e685b5;
}

html[data-bs-theme=dark] body { background-color: var(--wh-page-bg); color: var(--wh-text); }

/* ── Page frame ── */
html[data-bs-theme=dark] .main { background: var(--wh-page-bg); }
html[data-bs-theme=dark] .navbar-bg,
html[data-bs-theme=dark] .footer { background: var(--wh-surface); }
html[data-bs-theme=dark] .navbar .nav-link,
html[data-bs-theme=dark] .navbar .nav-icon,
html[data-bs-theme=dark] .footer a,
html[data-bs-theme=dark] .footer .text-muted { color: var(--wh-muted) !important; }
html[data-bs-theme=dark] .hamburger,
html[data-bs-theme=dark] .hamburger:after,
html[data-bs-theme=dark] .hamburger:before { background: var(--wh-text); }
html[data-bs-theme=dark] h1, html[data-bs-theme=dark] h2, html[data-bs-theme=dark] h3,
html[data-bs-theme=dark] h4, html[data-bs-theme=dark] h5, html[data-bs-theme=dark] h6,
html[data-bs-theme=dark] .h1, html[data-bs-theme=dark] .h2, html[data-bs-theme=dark] .h3,
html[data-bs-theme=dark] .h4, html[data-bs-theme=dark] .h5, html[data-bs-theme=dark] .h6 { color: var(--wh-text-strong); }

/* ── Cards ── */
html[data-bs-theme=dark] .card {
    --bs-card-bg: var(--wh-surface);
    --bs-card-cap-bg: var(--wh-surface);
    --bs-card-color: var(--wh-text);
    --bs-card-title-color: var(--wh-muted);
    background-color: var(--wh-surface);
    box-shadow: none;
}
html[data-bs-theme=dark] .card-header,
html[data-bs-theme=dark] .card-footer { background-color: var(--wh-surface); border-color: var(--wh-border); }

/* ── Text helpers ── */
html[data-bs-theme=dark] .text-muted { color: var(--wh-muted) !important; }
html[data-bs-theme=dark] .text-dark:not(.badge) { color: var(--wh-text-strong) !important; }
html[data-bs-theme=dark] .bg-white { background-color: var(--wh-surface) !important; }
html[data-bs-theme=dark] .bg-light { background-color: var(--wh-surface-3) !important; }
html[data-bs-theme=dark] .border,
html[data-bs-theme=dark] .border-top,
html[data-bs-theme=dark] .border-bottom,
html[data-bs-theme=dark] hr { border-color: var(--wh-border) !important; }
html[data-bs-theme=dark] .badge.bg-light { color: var(--wh-text) !important; }

/* ── Forms ── */
html[data-bs-theme=dark] .form-control,
html[data-bs-theme=dark] .form-select,
html[data-bs-theme=dark] .input-group-text {
    background-color: var(--wh-surface-2);
    border-color: var(--wh-border);
    color: var(--wh-text);
}
html[data-bs-theme=dark] .form-control::placeholder { color: #7d8894; }
/* Floating labels stand in for the placeholder, so keep it hidden there (as Bootstrap does). */
html[data-bs-theme=dark] .form-floating > .form-control::placeholder { color: transparent; }
html[data-bs-theme=dark] .form-control:focus,
html[data-bs-theme=dark] .form-select:focus { background-color: var(--wh-surface-2); color: var(--wh-text-strong); }
html[data-bs-theme=dark] .form-control:disabled,
html[data-bs-theme=dark] .form-control[readonly],
html[data-bs-theme=dark] .form-select:disabled { background-color: var(--wh-surface-3); color: var(--wh-muted); }
html[data-bs-theme=dark] .form-select {
    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='%23d6dbe1' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
html[data-bs-theme=dark] .form-check-input { background-color: var(--wh-surface-2); border-color: #55616f; }
html[data-bs-theme=dark] .form-check-input:checked { background-color: #3b7ddd; border-color: #3b7ddd; }
html[data-bs-theme=dark] .form-label,
html[data-bs-theme=dark] .form-check-label { color: var(--wh-text); }
html[data-bs-theme=dark] input[type=date]::-webkit-calendar-picker-indicator,
html[data-bs-theme=dark] input[type=time]::-webkit-calendar-picker-indicator { filter: invert(.85); }

/* ── Tables and lists ── */
html[data-bs-theme=dark] .table {
    --bs-table-color: var(--wh-text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--wh-border);
    --bs-table-striped-color: var(--wh-text);
    --bs-table-striped-bg: rgba(255, 255, 255, .03);
    --bs-table-hover-color: var(--wh-text-strong);
    --bs-table-hover-bg: rgba(255, 255, 255, .05);
    --bs-table-active-bg: rgba(255, 255, 255, .07);
    color: var(--wh-text);
    border-color: var(--wh-border);
}
html[data-bs-theme=dark] .table > :not(caption) > * > * { border-bottom-color: var(--wh-border); }
html[data-bs-theme=dark] .table-light,
html[data-bs-theme=dark] .table-light > tr > th,
html[data-bs-theme=dark] thead.table-light th {
    --bs-table-bg: var(--wh-surface-2);
    --bs-table-color: var(--wh-text-strong);
    background-color: var(--wh-surface-2) !important;
    color: var(--wh-text-strong) !important;
    border-color: var(--wh-border);
}
html[data-bs-theme=dark] .list-group {
    --bs-list-group-bg: var(--wh-surface);
    --bs-list-group-color: var(--wh-text);
    --bs-list-group-border-color: var(--wh-border);
    --bs-list-group-action-hover-bg: var(--wh-surface-2);
    --bs-list-group-action-hover-color: var(--wh-text-strong);
}

/* ── Menus, modals, alerts, nav ── */
html[data-bs-theme=dark] .dropdown-menu {
    --bs-dropdown-bg: var(--wh-surface-2);
    --bs-dropdown-color: var(--wh-text);
    --bs-dropdown-link-color: var(--wh-text);
    --bs-dropdown-link-hover-bg: var(--wh-surface-3);
    --bs-dropdown-link-hover-color: var(--wh-text-strong);
    --bs-dropdown-border-color: var(--wh-border);
    --bs-dropdown-divider-bg: var(--wh-border);
    background-color: var(--wh-surface-2);
}
html[data-bs-theme=dark] .dropdown-item { color: var(--wh-text); }
html[data-bs-theme=dark] .dropdown-item:hover,
html[data-bs-theme=dark] .dropdown-item:focus { background-color: var(--wh-surface-3); color: var(--wh-text-strong); }
html[data-bs-theme=dark] .modal {
    --bs-modal-bg: var(--wh-surface);
    --bs-modal-color: var(--wh-text);
    --bs-modal-border-color: var(--wh-border);
    --bs-modal-header-border-color: var(--wh-border);
    --bs-modal-footer-border-color: var(--wh-border);
}
html[data-bs-theme=dark] .modal-content { background-color: var(--wh-surface); color: var(--wh-text); border-color: var(--wh-border); }
html[data-bs-theme=dark] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
html[data-bs-theme=dark] .alert-success { background-color: #0f3d2e; border-color: #17573f; color: #8fe3c3; }
html[data-bs-theme=dark] .alert-danger { background-color: #4a1c22; border-color: #6c2a32; color: #f3a9b1; }
html[data-bs-theme=dark] .alert-warning { background-color: #4a3a12; border-color: #6b551c; color: #f6d98a; }
html[data-bs-theme=dark] .alert-info { background-color: #10394a; border-color: #1a536b; color: #8fd4ef; }
html[data-bs-theme=dark] .alert-secondary,
html[data-bs-theme=dark] .alert-light { background-color: var(--wh-surface-2); border-color: var(--wh-border); color: var(--wh-text); }
html[data-bs-theme=dark] .nav-tabs { border-color: var(--wh-border); }
html[data-bs-theme=dark] .nav-tabs .nav-link.active { background-color: var(--wh-surface); border-color: var(--wh-border) var(--wh-border) var(--wh-surface); color: var(--wh-text-strong); }
html[data-bs-theme=dark] .page-link { background-color: var(--wh-surface-2); border-color: var(--wh-border); color: var(--wh-text); }
html[data-bs-theme=dark] .page-item.disabled .page-link { background-color: var(--wh-surface); color: var(--wh-muted); }

/* ── Buttons that assume a light page ── */
html[data-bs-theme=dark] .btn-light { background-color: var(--wh-surface-3); border-color: var(--wh-border); color: var(--wh-text); }
html[data-bs-theme=dark] .btn-outline-secondary { color: #b9c1ca; border-color: #5b6673; }
html[data-bs-theme=dark] .btn-outline-secondary:hover,
html[data-bs-theme=dark] .btn-check:checked + .btn-outline-secondary { background-color: #5b6673; color: #fff; }
html[data-bs-theme=dark] .btn-outline-dark { color: var(--wh-text); border-color: var(--wh-text); }
html[data-bs-theme=dark] .btn-link { color: var(--bs-link-color); }

/* ── Wheelhouse pages (site.css) ── */
html[data-bs-theme=dark] .profile-avatar { background: #1f3a5f; color: #9ec5fe; }
html[data-bs-theme=dark] .profile-contact a,
html[data-bs-theme=dark] .profile-contact span { color: var(--wh-text); }
html[data-bs-theme=dark] .profile-contact a:hover { color: #9ec5fe; }
html[data-bs-theme=dark] .profile-contact svg { color: var(--wh-muted); }
html[data-bs-theme=dark] .code-chip { background: var(--wh-surface-3); color: var(--wh-text); }
html[data-bs-theme=dark] .section-card .card-header { border-bottom-color: var(--wh-border); }
html[data-bs-theme=dark] .section-card .card-header .card-title { color: var(--wh-text-strong); }
html[data-bs-theme=dark] .section-card .card-header > svg { color: #6ea8fe; }
html[data-bs-theme=dark] .info-list dt,
html[data-bs-theme=dark] .stat-tile .stat-label { color: var(--wh-muted); }
html[data-bs-theme=dark] .info-list dd,
html[data-bs-theme=dark] .stat-tile .stat-value { color: var(--wh-text-strong); }
html[data-bs-theme=dark] .info-list .empty { color: #6c7783; }
html[data-bs-theme=dark] .stat-tile { background: var(--wh-surface); border-color: var(--wh-border); }
html[data-bs-theme=dark] .stat-tile .stat-value small { color: var(--wh-muted); }
html[data-bs-theme=dark] .check-item.no { color: var(--wh-muted); }
html[data-bs-theme=dark] .check-item.no svg { color: #55616f; }
html[data-bs-theme=dark] .note-block + .note-block,
html[data-bs-theme=dark] .form-actions-bar { border-top-color: var(--wh-border); }

/* ── DayPilot calendars (calendar_default theme, which reads these variables) ──
   Cells the pages colour themselves (today, an availability range) pick a dark colour with window.themeColor. */
html[data-bs-theme=dark] .calendar_default_main {
    --dp-calendar-border-color: var(--wh-border);
    --dp-calendar-cell-bg-color: #1a212a;
    --dp-calendar-cell-business-bg-color: var(--wh-surface);
    --dp-calendar-cell-border-color: #2b3440;
    --dp-calendar-header-bg-color: var(--wh-surface-2);
    --dp-calendar-header-color: var(--wh-text);
    --dp-calendar-scroll-bg-color: var(--wh-surface-2);
    --dp-calendar-event-bg-top-color: var(--wh-surface-3);
    --dp-calendar-event-bg-bottom-color: var(--wh-surface-3);
    --dp-calendar-event-bg-top-color-hover: #364152;
    --dp-calendar-event-bg-bottom-color-hover: #364152;
    --dp-calendar-event-border-color: #4a5666;
    --dp-calendar-event-color: var(--wh-text-strong);
    --dp-calendar-allday-event-bg-top-color: var(--wh-surface-3);
    --dp-calendar-allday-event-bg-bottom-color: var(--wh-surface-3);
    --dp-calendar-allday-event-color: var(--wh-text-strong);
    --dp-calendar-selected-event-bg-color: #364152;
    --dp-calendar-shadow-color: #4a5666;
}
html[data-bs-theme=dark] .calendar_default_event_inner a { color: #9ec5fe; }
/* Withdrawn availability (Availability/Index) is striped grey. */
html[data-bs-theme=dark] .Withdrawn .calendar_default_event_inner {
    background: repeating-linear-gradient(45deg, #262e38, #262e38 6px, #2e3743 6px, #2e3743 12px) !important;
    color: var(--wh-muted) !important;
}

/* ── The theme switch ── */
.theme-toggle .theme-icon-dark { display: none; }
html[data-bs-theme=dark] .theme-toggle .theme-icon-light { display: none; }
html[data-bs-theme=dark] .theme-toggle .theme-icon-dark { display: inline-block; }

/* DayPilot's month picker (Schedule) sets its colours on .navigator_default_main. */
html[data-bs-theme=dark] .navigator_default_main {
    --dp-nav-border-color: var(--wh-border);
    --dp-nav-title-color: var(--wh-text-strong);
    --dp-nav-title-bg-color: var(--wh-surface-2);
    --dp-nav-dayheader-color: var(--wh-muted);
    --dp-nav-dayheader-bg-color: var(--wh-surface);
    --dp-nav-weeknumber-color: var(--wh-muted);
    --dp-nav-weeknumber-bg-color: var(--wh-surface);
    --dp-nav-day-color: var(--wh-text);
    --dp-nav-day-bg-color: var(--wh-surface);
    --dp-nav-dayother-color: #6c7783;
    --dp-nav-dayother-bg-color: var(--wh-surface);
    --dp-nav-weekend-bg-color: var(--wh-surface-2);
    --dp-nav-select-bg-color: #5a4a22;
    background-color: var(--wh-surface);
}
