/*
 * Light / dark mode for the public website.
 *
 * Loaded only for themes listed in WebsiteHelper::COLOR_SCHEME_THEMES (components.shared.color-scheme).
 * Theme and shared CSS use var(--cs-*, <original>) for neutral colors (scripts/color-scheme/tokenize-css.mjs).
 * The tokens exist only under [data-theme="dark"], so light mode renders the original values.
 * See docs/frontend/dark-mode.md.
 */

:root {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;

    /* Palette */
    --cs-bg: #0f1216;
    --cs-surface: #1a1f26;
    --cs-surface-rgb: 26 31 38;
    --cs-surface-2: #20262e;
    --cs-surface-3: #2a313b;
    --cs-text: #e7eaee;
    --cs-text-rgb: 231 234 238;
    --cs-text-muted: #b5bcc6;
    --cs-text-subtle: #8b94a1;
    --cs-border: #323a46;
    --cs-border-strong: #4a5461;
    --cs-line-rgb: 255 255 255;
    /* Pale brand tints keep 14% of their hue over the dark surface; dark brand text is lifted toward white. */
    --cs-mix-bg: 14%;
    --cs-mix-text: 55%;
    /* Brand colors used as text. The head partial replaces these with values computed from the
       site's settings (WebsiteHelper::readableOnDark); these are the fallback for non-hex colors. */
    --cs-primary-text: color-mix(in srgb, var(--primary) 55%, #fff);
    --cs-secondary-text: color-mix(in srgb, var(--secondary) 55%, #fff);

    /* Bootstrap 5.3: data-bs-theme="dark" sets its own palette; align it with ours. */
    --bs-body-bg: var(--cs-bg);
    --bs-body-bg-rgb: 15, 18, 22;
    --bs-body-color: var(--cs-text);
    --bs-body-color-rgb: 231, 234, 238;
    --bs-emphasis-color: #fff;
    --bs-heading-color: var(--cs-text);
    --bs-secondary-color: var(--cs-text-muted);
    --bs-tertiary-color: var(--cs-text-subtle);
    --bs-secondary-bg: var(--cs-surface-2);
    --bs-tertiary-bg: var(--cs-surface-3);
    --bs-border-color: var(--cs-border);
    --bs-border-color-translucent: rgb(255 255 255 / 0.1);

    /* Variables that theme and shared CSS already read */
    --light: var(--cs-surface-2);
    --dark: var(--cs-text);
    --border: 1px dashed var(--cs-border);
    --nfd-text: var(--cs-text);
    --nfd-text-light: var(--cs-text-muted);
    --nfd-border: var(--cs-border);
}

/* Page skeleton loader (website-standards.css) */
:root[data-theme="dark"].app-skeleton-loading {
    --app-skeleton-block: #262c35;
    --app-skeleton-muted: #20252d;
    --app-skeleton-surface: #1a1e25;
    --app-skeleton-wave: linear-gradient(110deg, #232830 8%, #2e353f 18%, #232830 33%);
}

/* Switching: no transitions for one frame, so the page does not animate every color at once. */
:root.cs-switching *,
:root.cs-switching *::before,
:root.cs-switching *::after {
    transition: none !important;
}

/* ---------- Toggle ---------- */

.cs-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--cs-border, #e3e6ea);
    border-radius: 50%;
    background: transparent;
    color: inherit;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.cs-toggle:hover {
    background-color: rgb(var(--cs-line-rgb, 0 0 0) / 0.06);
}

.cs-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Beats components.css ".header-navbar-rht > li svg" (stroke: unset; 26px !important on mobile). */
.cs-toggle svg,
.header-navbar-rht .cs-toggle svg {
    width: 18px !important;
    height: 18px !important;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
}

.cs-toggle__sun,
:root[data-theme="dark"] .cs-toggle__moon {
    display: none;
}

:root[data-theme="dark"] .cs-toggle__sun {
    display: block;
}

/* ---------- Dark: page-level ---------- */

:root[data-theme="dark"] body {
    background-color: var(--cs-bg);
    color: var(--cs-text);
}

:root[data-theme="dark"] h1,
:root[data-theme="dark"] h2,
:root[data-theme="dark"] h3,
:root[data-theme="dark"] h4,
:root[data-theme="dark"] h5,
:root[data-theme="dark"] h6 {
    color: var(--cs-text);
}

/* Logos are drawn for light backgrounds: give header logos a light plate. */
:root[data-theme="dark"] .header .navbar-brand.logo img:not(.pe-3),
:root[data-theme="dark"] .header .logo-small img,
:root[data-theme="dark"] .menu-header .menu-logo img {
    padding: 4px 10px;
    border-radius: 10px;
    background-color: #fff;
}

/* ---------- Dark: Bootstrap utilities that data-bs-theme leaves light ---------- */

:root[data-theme="dark"] .bg-white,
:root[data-theme="dark"] .bg-body {
    background-color: var(--cs-surface) !important;
}

:root[data-theme="dark"] .bg-light,
:root[data-theme="dark"] .bg-body-tertiary,
:root[data-theme="dark"] .bg-body-secondary {
    background-color: var(--cs-surface-2) !important;
}

:root[data-theme="dark"] .text-dark,
:root[data-theme="dark"] .text-black,
:root[data-theme="dark"] .text-body,
:root[data-theme="dark"] .link-dark {
    color: var(--cs-text) !important;
}

:root[data-theme="dark"] .text-black-50 {
    color: rgb(var(--cs-text-rgb) / 0.5) !important;
}

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

:root[data-theme="dark"] .border-light {
    border-color: var(--cs-border) !important;
}

/* Brand color as text: use the readable lift of the site's color (see the head partial). */
:root[data-theme="dark"] .text-primary,
:root[data-theme="dark"] .link-primary {
    color: var(--cs-primary-text) !important;
}

:root[data-theme="dark"] .btn-outline-primary:not(:hover):not(:active):not(.active):not(:focus-visible) {
    color: var(--cs-primary-text);
    border-color: color-mix(in srgb, var(--cs-primary-text) 45%, transparent);
}

:root[data-theme="dark"] .btn-light {
    --bs-btn-color: var(--cs-text);
    --bs-btn-bg: var(--cs-surface-3);
    --bs-btn-border-color: var(--cs-border);
    --bs-btn-hover-color: var(--cs-text);
    --bs-btn-hover-bg: var(--cs-border);
    --bs-btn-hover-border-color: var(--cs-border-strong);
    --bs-btn-active-color: var(--cs-text);
    --bs-btn-active-bg: var(--cs-border);
    --bs-btn-active-border-color: var(--cs-border-strong);
}

:root[data-theme="dark"] .btn-outline-dark,
:root[data-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: var(--cs-text);
    --bs-btn-border-color: var(--cs-border-strong);
    --bs-btn-hover-color: var(--cs-bg);
    --bs-btn-hover-bg: var(--cs-text);
    --bs-btn-hover-border-color: var(--cs-text);
}

:root[data-theme="dark"] .table-light {
    --bs-table-color: var(--cs-text);
    --bs-table-bg: var(--cs-surface-3);
    --bs-table-border-color: var(--cs-border);
}

:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select {
    background-color: var(--cs-surface-2);
    border-color: var(--cs-border);
    color: var(--cs-text);
}

:root[data-theme="dark"] .form-control:disabled,
:root[data-theme="dark"] .form-control[readonly] {
    background-color: var(--cs-surface-3);
}

/* ---------- Dark: third-party widgets ---------- */

/* select2 (bundled in all.css) */
:root[data-theme="dark"] .select2-container--default .select2-selection--single,
:root[data-theme="dark"] .select2-container--default .select2-selection--multiple,
:root[data-theme="dark"] .select2-dropdown,
:root[data-theme="dark"] .select2-container--default .select2-search--dropdown .select2-search__field {
    background-color: var(--cs-surface-2);
    border-color: var(--cs-border);
    color: var(--cs-text);
}

:root[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered,
:root[data-theme="dark"] .select2-results__option {
    color: var(--cs-text);
}

:root[data-theme="dark"] .select2-container--default .select2-results__option[aria-selected=true],
:root[data-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: var(--cs-surface-3);
    border-color: var(--cs-border);
}

/* SweetAlert2 (loaded from CDN) */
:root[data-theme="dark"] .swal2-popup {
    background-color: var(--cs-surface);
    color: var(--cs-text);
}

:root[data-theme="dark"] .swal2-title,
:root[data-theme="dark"] .swal2-html-container {
    color: var(--cs-text);
}

/* intl-tel-input country list */
:root[data-theme="dark"] .iti__country-list,
:root[data-theme="dark"] .iti__dropdown-content {
    background-color: var(--cs-surface);
    border-color: var(--cs-border);
    color: var(--cs-text);
}

:root[data-theme="dark"] .iti__country.iti__highlight {
    background-color: var(--cs-surface-3);
}

/* Payment forms (Moyasar, Tabby) are styled by their providers for light backgrounds. */
:root[data-theme="dark"] .mysr-form,
:root[data-theme="dark"] #tabbyCard,
:root[data-theme="dark"] .tabby-promo {
    color-scheme: light;
    padding: 12px;
    border-radius: 12px;
    background-color: #fff;
    color: #1d1d1d;
}
