.entity_tree .fancytree-selected,
.entity_tree .fancytree-selected a,
.entity_tree .fancytree-selected .btn-link {
    color: var(--tblr-primary-fg);
}

/*
 * GLPI 12 replaced the fancytree entity selector with a Vue component
 * (templates/layout/parts/profile_selector.html.twig -> EntitySelector/EntitySelector),
 * so the rule above no longer matches anything on 12.x. That component paints the
 * selected node with an inline `background-color: var(--tblr-primary)` and never pairs
 * it with a foreground color, leaving the label on --tblr-list-group-color
 * (--tblr-body-color): #1E293B on the KEI green is only 2.67:1. Apply the primary
 * foreground explicitly.
 * shortcut: keyed on the inline style the component emits; re-check when GLPI changes it.
 */
[data-testid="entity-menu-dropdown"] .list-group-item[style*="--tblr-primary"] {
    color: var(--tblr-primary-fg);
}

/*
 * The selected node also renders expand/collapse and "select children" action
 * buttons. `.btn-ghost-secondary` sets its own `--tblr-btn-color` to
 * --tblr-secondary (#6C757D light / #606F91 dark), which is only 1.17:1 /
 * 1.09:1 on the KEI green. Re-point the button tokens at the primary
 * foreground. The hover/active backgrounds remain --tblr-secondary, so white
 * text still clears AA there (4.69:1 light, 5.02:1 dark).
 */
[data-testid="entity-menu-dropdown"] .list-group-item[style*="--tblr-primary"] .btn-ghost-secondary {
    --tblr-btn-color: var(--tblr-primary-fg);
    --tblr-btn-hover-color: var(--tblr-primary-fg);
    --tblr-btn-active-color: var(--tblr-primary-fg);
}

:root:not([data-glpi-theme-dark="1"]) {
    --tblr-primary: #007A37;
    --tblr-primary-rgb: 0, 122, 55;
    --tblr-primary-fg: #FFFFFF;
    --tblr-secondary: #6C757D;
    --tblr-secondary-rgb: 108, 117, 125;
    --tblr-secondary-fg: #FFFFFF;
    --tblr-tertiary: #6B7280; /* placeholder / muted text: 4.83:1 on white (GLPI default #8a97ab was 2.96:1) */
    --tblr-info: #2563EB;
    --tblr-info-rgb: 37, 99, 235;
    --tblr-info-fg: #FFFFFF;
    --tblr-success: #166534;
    --tblr-success-rgb: 22, 101, 52;
    --tblr-success-fg: #FFFFFF;
    --tblr-warning: #F59E0B;
    --tblr-warning-rgb: 245, 158, 11;
    --tblr-warning-fg: #1E293B;
    --tblr-danger: #DC2626;
    --tblr-danger-rgb: 220, 38, 38;
    --tblr-danger-fg: #FFFFFF;
    --tblr-body-bg: #F5F7F9;
    --tblr-bg-surface: #FFFFFF;
    --tblr-body-color: #1E293B;
    --tblr-body-color-rgb: 30, 41, 59;
    --tblr-link-color: #007A37;
    --tblr-link-color-rgb: 0, 122, 55;
    --tblr-link-hover-color: #00622C; /* 7.03:1 on body bg */
    --tblr-link-hover-color-rgb: 0, 98, 44;
    --tblr-bg-surface-secondary: #F8FAFB;

    --glpi-mainmenu-bg: #1F2937;
    --glpi-mainmenu-fg: #FFFFFF;
    --glpi-mainmenu-fg-muted: #FFFFFF99;
    --glpi-mainmenu-active-bg: #007A37;
    --glpi-form-header-fg: #007A37;
    --glpi-helpdesk-header: #E8F5E9;

    --glpi-timeline-itil-content-bg: #E8F5E9;
    --glpi-timeline-itil-content-fg: #1B5E20;
    --glpi-timeline-itil-content-border-color: #A5D6A7;
    --glpi-timeline-fup-bg: #FEF3C7;
    --glpi-timeline-fup-fg: #78350F;
    --glpi-timeline-fup-border-color: #FCD34D;
    --glpi-timeline-task-bg: #DBEAFE;
    --glpi-timeline-task-fg: #1E40AF;
    --glpi-timeline-task-border-color: #93C5FD;
    --glpi-timeline-solution-bg: #D1FAE5;
    --glpi-timeline-solution-fg: #065F46;
    --glpi-timeline-solution-border-color: #6EE7B7;
    --glpi-timeline-document-bg: #CCF8E1;
    --glpi-timeline-document-fg: #047857;
    --glpi-timeline-document-border-color: #6EE7B7;

    --glpi-palette-color-1: #009944;
    --glpi-palette-color-2: #007A37;
    --glpi-palette-color-3: #00C853;
    --glpi-palette-color-4: #1F2937;
}

:root[data-glpi-theme-dark="1"] {
    --tblr-primary: #007A37;
    --tblr-primary-rgb: 0, 122, 55;
    --tblr-primary-fg: #FFFFFF;
    --tblr-link-color: #00C853;
    --tblr-link-color-rgb: 0, 200, 83;
    --tblr-link-hover-color: #00E676; /* 12.58:1 on dark bg */
    --tblr-link-hover-color-rgb: 0, 230, 118;
    --glpi-mainmenu-active-bg: #007A37;
    --glpi-form-header-fg: #00C853;

    --glpi-palette-color-1: #009944;
    --glpi-palette-color-2: #007A37;
    --glpi-palette-color-3: #00C853;
    --glpi-palette-color-4: #1F2937;
}

/* Primary fills stay dark green for white text. Transparent primary buttons
   instead need the bright text accent on dark surfaces (the fill green is only
   3.84:1 on black). Keep Tabler's white-on-green hover/active/focus states. */
:root[data-glpi-theme-dark="1"] :is(
    .btn-outline-primary,
    .btn-outline.btn-primary,
    .btn-ghost-primary,
    .btn-ghost.btn-primary
) {
    --tblr-btn-color: var(--tblr-link-color);
    --tblr-btn-disabled-color: var(--tblr-link-color);
}

:root[data-glpi-theme-dark="1"] :is(.btn-outline-primary, .btn-outline.btn-primary) {
    --tblr-btn-border-color: var(--tblr-link-color);
    --tblr-btn-disabled-border-color: var(--tblr-link-color);
}

/* Match the utility's !important and preserve its text-opacity support. */
:root[data-glpi-theme-dark="1"] .text-primary {
    color: color-mix(in srgb, var(--tblr-link-color) calc(var(--tblr-text-opacity) * 100%), transparent) !important;
}

/* Selectgroups focus the hidden input, not the visible label. Keep the same
   specificity as Tabler so boxed selected labels still inherit body text.
   Their selected titles need the text accent too; indicator fills stay green. */
:where(:root[data-glpi-theme-dark="1"]) .form-selectgroup-input:is(:checked, :focus) + .form-selectgroup-label {
    color: var(--tblr-link-color);
    border-color: var(--tblr-link-color);
}

:where(:root[data-glpi-theme-dark="1"]) .form-selectgroup-boxes .form-selectgroup-input:checked + .form-selectgroup-label .form-selectgroup-title {
    color: var(--tblr-link-color);
}

/* Tabler's primary link utility is !important and its hover shade is compiled
   blue, so ordinary link tokens alone cannot brand it or keep it legible in dark
   mode. Preserve the utility's separate text/underline opacity controls. */
.link-primary {
    color: color-mix(in srgb, var(--tblr-link-color) calc(var(--tblr-link-opacity, 1) * 100%), transparent) !important;
    text-decoration-color: color-mix(in srgb, var(--tblr-link-color) calc(var(--tblr-link-underline-opacity, 1) * 100%), transparent) !important;
}

.link-primary:hover,
.link-primary:focus {
    color: color-mix(in srgb, var(--tblr-link-hover-color) calc(var(--tblr-link-opacity, 1) * 100%), transparent) !important;
    text-decoration-color: color-mix(in srgb, var(--tblr-link-hover-color) calc(var(--tblr-link-underline-opacity, 1) * 100%), transparent) !important;
}

/* GLPI sets .badge color to --glpi-badge-fg; solid bg-* needs contrasting text mapped to design tokens */
.badge.bg-primary {
    color: var(--tblr-primary-fg);
}

.badge.bg-secondary {
    color: var(--tblr-secondary-fg);
}

.badge.bg-success {
    color: var(--tblr-success-fg);
}

.badge.bg-info {
    color: var(--tblr-info-fg);
}

.badge.bg-danger {
    color: var(--tblr-danger-fg);
}

.badge.bg-dark {
    color: #FFFFFF;
}

.badge.bg-warning {
    color: var(--tblr-warning-fg);
}

/*
 * WCAG 1.4.11 (non-text contrast): form-field boundaries and focus indicators
 * must reach >= 3:1 against adjacent surfaces. Scoped to controls instead of
 * overriding the global --tblr-border-color, which also draws tables, cards,
 * and dividers. Light mode only; dark mode keeps GLPI's own borders.
 */
:root:not([data-glpi-theme-dark="1"]) :is(
    .form-control,
    .form-select,
    .form-selectgroup-label,
    .input-group-text,
    input:not(.form-control):not([type="submit"]):not([type="color"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not(.select2-search__field):not(.numInput):not(.tox-textfield),
    select:not(.form-select),
    textarea:not(.form-control),
    .select2-selection,
    .select2-selection__choice,
    .select2-dropdown,
    .select2-search__field
) {
    --tblr-border-color: #868E96; /* 3.32:1 vs white, 3.09:1 vs body bg */
}

/*
 * Checkbox/radio borders read --tblr-border-color-translucent, not
 * --tblr-border-color, so they are not covered by the rule above. Checked inputs
 * drop their border (GLPI sets `border: none`), so this only widens the unchecked
 * boundary from Tabler's rgba(4, 32, 69, 0.1) (~1.2:1) to 3:1.
 */
:root:not([data-glpi-theme-dark="1"]) .form-check-input {
    --tblr-border-color-translucent: #868E96;
}

/* Keep specificity below Tabler's validation selectors so focus does not
   turn invalid fields green or erase valid-state feedback. */
:where(:root:not([data-glpi-theme-dark="1"])) :is(
    .form-control,
    .form-select,
    .form-check-input,
    .form-selectgroup-label,
    .input-group-text
):focus:where(:not(.is-invalid, .is-valid, .was-validated *)) {
    border-color: var(--tblr-primary); /* 5.47:1 focus indicator */
}

/* Legacy GLPI controls use more specific selectors than Tabler's classes.
   Match their border scope on focus too, rather than restoring the 50% white
   primary mix (only 2.17:1 on white). Keep this separate from the class-based
   rule so the legacy input selector cannot increase its specificity. */
:root:not([data-glpi-theme-dark="1"]) :is(
    input:not(.form-control):not([type="submit"]):not([type="color"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not(.select2-search__field):not(.numInput):not(.tox-textfield),
    select:not(.form-select),
    textarea:not(.form-control)
):focus:where(:not(.is-invalid, .is-valid, .was-validated *)) {
    border-color: var(--tblr-primary);
}

/* Select2 renders its own focused box; GLPI tints it with a 50% primary mix (~2.2:1) */
:root:not([data-glpi-theme-dark="1"]) .select2-container--focus .select2-selection {
    border-color: var(--tblr-primary); /* 5.47:1 focus indicator */
}

/* GLPI ties .btn-group outline-secondary borders to the input border token
   (css/includes/components/_buttons-group.scss), so they need the same fix */
:root:not([data-glpi-theme-dark="1"]) .btn-group .btn-outline-secondary {
    --tblr-border-color: #868E96;
}
