/*
 * The project's design tokens (--ec-*), loaded on every page right after
 * Tabler (templates/index.html). Tabler's own variables (--tblr-*) stay the
 * base; a token exists only where Tabler has no value that works in both
 * themes. Every colour is written with light-dark(), so it follows the
 * theme without a [data-bs-theme="dark"] override.
 *
 * Guide: docs/tecnica/interfaz.md, "Tokens".
 */

:root {
    /* The lightness of a coloured text in each theme. Tabler's green,
       yellow and red used as text stay under 4.5:1 on white (≈2.9, 2.1
       and 4.2:1): the text keeps the hue and the chroma of its colour and
       takes this lightness instead. Measured in the browser on a card with
       the 10% tint of the label: 48% gives at least 5.2:1 in light mode and
       76% at least 5.2:1 in dark mode, for every Tabler colour. */
    --ec-text-lightness-light: 48%;
    --ec-text-lightness-dark: 76%;

    /* Coloured text that has to read (status labels, the danger item of a
       menu, a warning icon): the same hue as the Tabler colour, at the
       lightness above. The pure Tabler colour stays for the dots, the
       borders and the fills. */
    --ec-text-primary: light-dark(
        oklch(from var(--tblr-primary) var(--ec-text-lightness-light) c h),
        oklch(from var(--tblr-primary) var(--ec-text-lightness-dark) c h)
    );
    --ec-text-secondary: light-dark(
        oklch(from var(--tblr-secondary) var(--ec-text-lightness-light) c h),
        oklch(from var(--tblr-secondary) var(--ec-text-lightness-dark) c h)
    );
    --ec-text-success: light-dark(
        oklch(from var(--tblr-success) var(--ec-text-lightness-light) c h),
        oklch(from var(--tblr-success) var(--ec-text-lightness-dark) c h)
    );
    --ec-text-info: light-dark(
        oklch(from var(--tblr-info) var(--ec-text-lightness-light) c h),
        oklch(from var(--tblr-info) var(--ec-text-lightness-dark) c h)
    );
    --ec-text-warning: light-dark(
        oklch(from var(--tblr-warning) var(--ec-text-lightness-light) c h),
        oklch(from var(--tblr-warning) var(--ec-text-lightness-dark) c h)
    );
    --ec-text-danger: light-dark(
        oklch(from var(--tblr-danger) var(--ec-text-lightness-light) c h),
        oklch(from var(--tblr-danger) var(--ec-text-lightness-dark) c h)
    );

    /* A quiet fill behind a counter or a chip: the text colour of the page
       at 8%, so it darkens the light surface and lightens the dark one. */
    --ec-fill-subtle: color-mix(in oklab, var(--tblr-body-color) 8%, transparent);

    /* The border of a field (inputs, selects, checkboxes, Tom Select).
       Tabler's border colour is a divider, not the edge of a control:
       gray-200 on white is 1.25:1 and gray-700 on the dark field 1.7:1,
       under the 3:1 that WCAG asks of a control. Gray-500 reaches 3:1 in
       both themes (measured values: docs/tecnica/interfaz.md, "Tokens"). */
    --ec-input-border: var(--tblr-gray-500);

    /* The border and the ring of a focused control. Tabler's ring is the
       primary at 25% (about 2:1 on white): the pure primary in light mode,
       and in dark mode the primary at the lightness of the readable text,
       because the pure blue on the dark field stays under 3:1. */
    --ec-focus-color: light-dark(
        var(--tblr-primary),
        oklch(from var(--tblr-primary) var(--ec-text-lightness-dark) c h)
    );
}

/* The status labels (components/_status.html, TableCells.status and
   TableCells.badge): the label takes the readable variant of its colour,
   the dot keeps the pure one. The variable is computed here, on the label,
   because --tblr-status-color is set by the .status-<colour> class of the
   element (a token on :root would see the default grey). */
.status {
    --ec-status-text: light-dark(
        oklch(from var(--tblr-status-color) var(--ec-text-lightness-light) c h),
        oklch(from var(--tblr-status-color) var(--ec-text-lightness-dark) c h)
    );
    color: var(--ec-status-text);
}
