/*
 * @file aimeat-daisyui-bridge.css
 * @author Jouni Miikki
 * SPDX-License-Identifier: MIT
 * @description Theme-compat layer so the bundled cortex UI libraries cohere with daisyUI.
 *   (0) Pulls in the AIMEAT daisyUI theme (aimeat-theme.css) so any app already loading this
 *       bridge gets the house palette — coral primary, the designed dark surface ramp and
 *       correct `-content` pairs — without editing the app. Before this, `--color-primary` was
 *       daisyUI's indigo and every branded app hardcoded `#E8564A` by hand.
 *   (1) Maps AIMEAT theme.css variable NAMES to daisyUI 5 theme variables so libs that read
 *       --text / --bg-card / --accent / … follow a daisyUI app's `data-theme` automatically.
 *   (2) Dark-mode polish: a few cortex components hardcode LIGHT colors (no var) — alerts,
 *       badges, table zebra — so the var-mapping can't reach them. We override those with
 *       theme-aware tints (`:root .aui-*` wins on specificity). No changes to the libraries.
 *   Load this AFTER the daisyUI stylesheet. Hardcoded fallbacks keep it working if daisyUI
 *   vars are absent.
 *
 *   NOTE on daisyUI's OWN components: they are not overridden here. With the theme loaded they
 *   are already theme-correct, and daisyUI 5 ships the quiet variants an app usually wants —
 *   `badge-soft`, `alert-soft`, `btn-soft`, `card-border`. Reach for those instead of a solid
 *   `badge-warning`, which is a loud block of amber on a dark page even when it is legible.
 * @usage  <link href="/lib/daisyui@5.css" rel="stylesheet" />
 *         <link href="/lib/aimeat-daisyui-bridge.css" rel="stylesheet" />
 * @version-history
 *   v1.4.0 — 2026-09-13 — The hidden attribute hides again. daisyUI's component classes (.card,
 *     .stats and the rest) set `display`, which beats the browser's own [hidden] rule, so an element
 *     carrying `hidden` stayed on screen. Tailwind's preflight brings the fix, but only after the JIT
 *     has compiled, and never on a page that loads daisyUI without the JIT. The bridge now carries
 *     preflight's rule itself, so it holds from first paint. Measured in Chromium: a hidden .card
 *     computed `display: flex` before and `none` after (appdev pitfall
 *     daisyui-component-defeats-hidden-attribute).
 *   v1.3.0 — 2026-07-25 — FIX the --border collision: the bridge mapped --border to a COLOUR at
 *     :root for the aui-* cortex components, while daisyUI 5 uses the same name as a border WIDTH
 *     inside calc() on nearly every component — the invalid calc collapsed badge/input paddings to
 *     0 and toggles to slivers on every bridge-loading page since v1.0.0. The colour mapping is now
 *     scoped to aui-* elements, with a --border-w restore for daisyUI components nested inside.
 *   v1.2.0 — 2026-07-25 — @import the AIMEAT daisyUI theme, so the house palette reaches every
 *     app that already loads the bridge. Contrast + surface ramp verified by
 *     `pnpm check:theme` (tools/theme-contrast.ts).
 *   v1.1.0 — 2026-06-26 — Map --bg-surface-dim (table zebra) + theme-aware alert/badge tints.
 *   v1.0.0 — 2026-06-26 — Initial bridge (cortex libs follow daisyUI theme).
 */

/* MUST be the first rule: @import is only valid ahead of ordinary rules. Same-origin, cached
   alongside this file, and a no-op duplicate when the app also links the theme directly. */
@import url('/lib/aimeat-theme.css');

/* ── HIDDEN MEANS HIDDEN. Every daisyUI component class sets its own `display`, and an author rule
      with a display beats the browser's [hidden] rule, so `<div class="card" hidden>` rendered.
      Tailwind's preflight carries this exact rule, but it arrives only after the Tailwind JIT has
      compiled, and an app may load daisyUI without the JIT at all. Same selector as preflight, so
      nothing changes once the JIT has run; `until-found` keeps the browser's own find-in-page
      behaviour. !important, so no component class's ordinary `display`, in a layer or out of one,
      can outrank it. ── */
[hidden]:where(:not([hidden='until-found'])) {
  display: none !important;
}

:root {
  --text:           var(--color-base-content, #1A1A2E);
  --text-dim:       color-mix(in oklab, var(--color-base-content, #6B7280) 70%, transparent);
  --text-muted:     color-mix(in oklab, var(--color-base-content, #9CA3AF) 55%, transparent);
  --bg-card:        var(--color-base-100, #ffffff);
  --card:           var(--color-base-100, #ffffff);
  --bg-surface:     var(--color-base-200, #f3f4f6);
  --bg-surface-dim: color-mix(in oklab, var(--color-base-content, #111827) 5%, var(--color-base-100, #ffffff));
  --bg-dim:         var(--color-base-200, #f3f4f6);
  --surface:        var(--color-base-200, #f3f4f6);
  --accent:         var(--color-primary, #e8564a);
  --blue:           var(--color-info, #3b82f6);
  --danger:         var(--color-error, #ef4444);
  --success:        var(--color-success, #10b981);
  --warn:           var(--color-warning, #f59e0b);
  --warning:        var(--color-warning, #f59e0b);
}

/* ── The --border name collision, fixed. The cortex `aui-*` components read `var(--border)` as a
      border COLOUR; daisyUI 5 reads the same name as a border WIDTH in calc() maths on nearly every
      component (`padding-inline: calc(var(--size)/2 - var(--border))` on .badge, toggle geometry,
      input paddings…). Mapping the colour at :root (bridge v1.0.0–v1.2.0) made those calcs invalid
      at computed-value time, so paddings collapsed to 0 and toggles rendered as slivers on EVERY
      page that loaded this bridge. The colour is now scoped to elements that actually carry an
      aui-* class, and daisyUI components nested inside an aui container get the palette's width
      back via --border-w (declared per theme block in aimeat-theme.css). ── */
[class^='aui-'], [class*=' aui-'] {
  --border: var(--color-base-300, #e5e7eb);
}
[class^='aui-'] :where(.btn, .badge, .toggle, .checkbox, .radio, .input, .select, .textarea, .file-input, .range, .tab, .tabs, .card, .alert, .table, .kbd, .status, .divider, .menu, .modal-box, .stats, .progress),
[class*=' aui-'] :where(.btn, .badge, .toggle, .checkbox, .radio, .input, .select, .textarea, .file-input, .range, .tab, .tabs, .card, .alert, .table, .kbd, .status, .divider, .menu, .modal-box, .stats, .progress) {
  --border: var(--border-w, 1px);
}

/* ── Dark-mode polish: override the cortex libs' hardcoded light colors with theme-aware
      tints. `:root .aui-*` (specificity 0,1,1) beats the libs' `.aui-*` (0,1,0) regardless
      of stylesheet order. Tint = subtle wash of the semantic colour over the card bg; text
      stays --color-base-content so it's readable in both light and dark. ── */
:root .aui-alert-info    { background: color-mix(in oklab, var(--color-info,    #3b82f6) 14%, var(--color-base-100, #fff)); color: var(--color-base-content, #1A1A2E); border: 1px solid color-mix(in oklab, var(--color-info,    #3b82f6) 45%, transparent); }
:root .aui-alert-success { background: color-mix(in oklab, var(--color-success, #10b981) 14%, var(--color-base-100, #fff)); color: var(--color-base-content, #1A1A2E); border: 1px solid color-mix(in oklab, var(--color-success, #10b981) 45%, transparent); }
:root .aui-alert-warn    { background: color-mix(in oklab, var(--color-warning, #f59e0b) 16%, var(--color-base-100, #fff)); color: var(--color-base-content, #1A1A2E); border: 1px solid color-mix(in oklab, var(--color-warning, #f59e0b) 45%, transparent); }
:root .aui-alert-error   { background: color-mix(in oklab, var(--color-error,   #ef4444) 14%, var(--color-base-100, #fff)); color: var(--color-base-content, #1A1A2E); border: 1px solid color-mix(in oklab, var(--color-error,   #ef4444) 45%, transparent); }

:root .aui-badge-info    { background: color-mix(in oklab, var(--color-info,    #3b82f6) 22%, var(--color-base-100, #fff)); color: var(--color-base-content, #1A1A2E); }
:root .aui-badge-success { background: color-mix(in oklab, var(--color-success, #10b981) 22%, var(--color-base-100, #fff)); color: var(--color-base-content, #1A1A2E); }
:root .aui-badge-warn    { background: color-mix(in oklab, var(--color-warning, #f59e0b) 24%, var(--color-base-100, #fff)); color: var(--color-base-content, #1A1A2E); }
:root .aui-badge-danger  { background: color-mix(in oklab, var(--color-error,   #ef4444) 22%, var(--color-base-100, #fff)); color: var(--color-base-content, #1A1A2E); }
