/* ============================================================================
   kx-buttons.css — app-wide DxButton label contrast.

   The DevExpress / Bootstrap themes this app switches between give several
   coloured buttons labels that cannot be read (measured, WCAG AA needs 4.5:1):
     blazing-berry  warning white-on-yellow 1.6, info white-on-cyan 2.0,
                    outline warning / info 1.6 / 2.0
     purple         success white-on-green 3.0
     blazing-dark   success 3.0
     office-white   primary white-on-orange 2.6
   Every theme keeps its own button colours; only the LABEL colour changes.

   1. Filled (contained) buttons: the label is black or white, whichever reads
      better on that button's own fill — computed by the browser from
      --dxbl-btn-bg / -hover-bg / -active-bg, so it is right in every theme
      and on hover / press too. (`l` is the fill's OKLCH lightness; below 0.6
      the label is white, above it black.)
   2. Outline / text buttons: the label keeps the button's own colour (its hover
      fill, the closest variable both outline and text buttons define) and only
      its lightness moves — capped at 0.52 on light themes, raised to at least
      0.8 on dark ones. A colour that already reads (berry primary, danger) is
      barely touched. Dark themes are the ones whose page is dark: Bootstrap's
      data-bs-theme="dark" (default-dark) or a dark theme stylesheet loaded
      (blazing-dark, cyborg, solar, superhero — theme-controller.js swaps the
      <link>, it does not flag these dark). On hover / press these buttons fill,
      so rule 1b takes over the label.

   Selectors are three classes deep on purpose: the theme stylesheet loads AFTER
   this file and its own rules (.dxbl-btn-standalone.dxbl-btn-warning) are two
   classes deep, so a two-class rule here ties and loses.
   ========================================================================== */

/* Fallback for browsers without relative colour syntax: the two worst cases. */
.dxbl-btn.dxbl-btn-standalone:is(.dxbl-btn-warning, .dxbl-btn-info),
.dxbl-btn:is(.dxbl-btn-warning, .dxbl-btn-info):not(.dxbl-btn-standalone) {
    --dxbl-btn-color: rgb(var(--bs-black-rgb));
    --dxbl-btn-hover-color: rgb(var(--bs-black-rgb));
    --dxbl-btn-active-color: rgb(var(--bs-black-rgb));
    --dxbl-btn-focus-color: rgb(var(--bs-black-rgb));
    --dxbl-btn-disabled-color: rgb(var(--bs-black-rgb));
}

@supports (color: oklch(from red l c h)) {
    /* 1. Filled buttons — black or white label from the fill. */
    .dxbl-btn.dxbl-btn-standalone:is(.dxbl-btn-primary, .dxbl-btn-success, .dxbl-btn-info, .dxbl-btn-warning, .dxbl-btn-danger),
    .dxbl-btn:is(.dxbl-btn-primary, .dxbl-btn-success, .dxbl-btn-info, .dxbl-btn-warning, .dxbl-btn-danger):not(.dxbl-btn-standalone) {
        --dxbl-btn-color: oklch(from var(--dxbl-btn-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
        --dxbl-btn-focus-color: oklch(from var(--dxbl-btn-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
        --dxbl-btn-disabled-color: oklch(from var(--dxbl-btn-disabled-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
    }

    /* 1b. Hover / press fill every coloured button (filled, outline and text). */
    .dxbl-btn.dxbl-btn-standalone:is(.dxbl-btn-primary, .dxbl-btn-success, .dxbl-btn-info, .dxbl-btn-warning, .dxbl-btn-danger,
                                     .dxbl-btn-outline-primary, .dxbl-btn-outline-success, .dxbl-btn-outline-info, .dxbl-btn-outline-warning, .dxbl-btn-outline-danger,
                                     .dxbl-btn-text-primary, .dxbl-btn-text-success, .dxbl-btn-text-info, .dxbl-btn-text-warning, .dxbl-btn-text-danger),
    .dxbl-btn:is(.dxbl-btn-primary, .dxbl-btn-success, .dxbl-btn-info, .dxbl-btn-warning, .dxbl-btn-danger,
                 .dxbl-btn-outline-primary, .dxbl-btn-outline-success, .dxbl-btn-outline-info, .dxbl-btn-outline-warning, .dxbl-btn-outline-danger,
                 .dxbl-btn-text-primary, .dxbl-btn-text-success, .dxbl-btn-text-info, .dxbl-btn-text-warning, .dxbl-btn-text-danger):not(.dxbl-btn-standalone) {
        --dxbl-btn-hover-color: oklch(from var(--dxbl-btn-hover-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
        --dxbl-btn-active-color: oklch(from var(--dxbl-btn-active-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
    }
}

/* 3. Disabled filled buttons on DARK themes (Alfa #120 T12, 2026-11-12). blazing-dark gives every disabled fill a
   pale tint of its colour (secondary #495057 → #adb5bd, primary → light lilac, …) — on a dark page the disabled
   button is the BRIGHTEST one and reads as highlighted, and white-on-#adb5bd fails contrast. On a dark page a
   disabled button keeps its own fill and label and is faded instead (Bootstrap's own disabled look, opacity 0.65,
   the same value the outline rule below uses). Light themes keep their pale disabled fills, which do read as faded
   on a white page. Same dark-theme switch as kx-tokens.css. */
:root:is([data-bs-theme="dark"],
         :has(link[href*="blazing-dark"], link[href*="/themes/cyborg/"], link[href*="/themes/solar/"], link[href*="/themes/superhero/"]))
    :is(.dxbl-btn.dxbl-btn-standalone, .dxbl-btn:not(.dxbl-btn-standalone)):is(.dxbl-btn-primary, .dxbl-btn-secondary, .dxbl-btn-success, .dxbl-btn-info, .dxbl-btn-warning, .dxbl-btn-danger, .dxbl-btn-dark) {
    --dxbl-btn-disabled-bg: var(--dxbl-btn-bg);
    --dxbl-btn-disabled-border-color: var(--dxbl-btn-border-color);
    --dxbl-btn-disabled-color: var(--dxbl-btn-color);
    --dxbl-btn-disabled-opacity: 0.65;
}

/* 4. Filled SECONDARY buttons on DARK themes (Alfa #127 live test, 2026-11-17). Rule 1 leaves secondary out, and
   blazing-dark paints its #495057 fill with a #343a40 label (1.4:1) — the delete dialog's Annuller, the journal
   message boxes' Annuller, ConfirmDialogBox's deny button all read as an empty grey block. On dark themes only, the
   label is black or white from the fill exactly as rule 1 does (white here); light themes are not touched. */
@supports (color: oklch(from red l c h)) {
    :root:is([data-bs-theme="dark"],
             :has(link[href*="blazing-dark"], link[href*="/themes/cyborg/"], link[href*="/themes/solar/"], link[href*="/themes/superhero/"]))
        :is(.dxbl-btn.dxbl-btn-standalone, .dxbl-btn:not(.dxbl-btn-standalone)).dxbl-btn-secondary {
        --dxbl-btn-color: oklch(from var(--dxbl-btn-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
        --dxbl-btn-focus-color: oklch(from var(--dxbl-btn-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
        --dxbl-btn-hover-color: oklch(from var(--dxbl-btn-hover-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
        --dxbl-btn-active-color: oklch(from var(--dxbl-btn-active-bg) clamp(0, (0.6 - l) * 1000, 1) 0 0);
    }
}

/* 2. Outline / text buttons — own colour, lightness kept inside [--kx-label-l-min, --kx-label-l-max]
   (defined with the light/dark-theme switch in kx-tokens.css). */
@supports (color: oklch(from red l c h)) {
    .dxbl-btn.dxbl-btn-standalone:is(.dxbl-btn-outline-primary, .dxbl-btn-outline-success, .dxbl-btn-outline-info, .dxbl-btn-outline-warning, .dxbl-btn-outline-danger,
                 .dxbl-btn-text-primary, .dxbl-btn-text-success, .dxbl-btn-text-info, .dxbl-btn-text-warning, .dxbl-btn-text-danger),
    .dxbl-btn:is(.dxbl-btn-outline-primary, .dxbl-btn-outline-success, .dxbl-btn-outline-info, .dxbl-btn-outline-warning, .dxbl-btn-outline-danger,
                 .dxbl-btn-text-primary, .dxbl-btn-text-success, .dxbl-btn-text-info, .dxbl-btn-text-warning, .dxbl-btn-text-danger):not(.dxbl-btn-standalone) {
        --dxbl-btn-color: oklch(from var(--dxbl-btn-hover-bg) clamp(var(--kx-label-l-min), l, var(--kx-label-l-max)) min(c, var(--kx-label-c-max)) h);
        --dxbl-btn-disabled-color: oklch(from var(--dxbl-btn-hover-bg) clamp(var(--kx-label-l-min), l, var(--kx-label-l-max)) min(c, var(--kx-label-c-max)) h);
        --dxbl-btn-disabled-opacity: 0.65;
    }
}
