/* Liquid Glass (décision D-40) : la matière d'Apple (iOS 26, macOS Tahoe) en CSS natif, d'après le
   composant LiquidButton (shadcn) : liseré en couches d'ombres internes, filtre SVG de distorsion
   appliqué au fond (index.html, #lg-control et #lg-surface), capsules, croissance au survol.
   Trois épaisseurs, comme chez Apple :
   - claire, pour les commandes (onglets, boutons, pastilles) : le fond se réfracte au travers ;
   - normale, pour les surfaces de contenu (cartes, compositeurs, bulles) : flou plus fort ;
   - épaisse, pour ce qui flotte au-dessus de tout (menus, palette, boîtes, panneau, notifications).
   La matière d'une commande ou d'une surface est peinte par ::before, sous le contenu : un élément
   qui porte lui-même un backdrop-filter empêche ses enfants de voir la page derrière lui, et une
   carte en verre contient des boutons en verre. Chaque rôle ne pose que des variables (--lg-*) ;
   la règle de peinture, unique, les lit.
   Couleurs : jetons --lg-* de tokens.css et blanc translucide uniquement. */

@property --lg-glow { syntax: "<number>"; inherits: true; initial-value: 0; }

.lg-defs { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }

/* ======================================================================================
   Peinture commune. La liste des éléments en verre est répétée trois fois : valeurs par défaut
   (spécificité nulle, chaque rôle les remplace), élément, matière.
   ====================================================================================== */

:where(
  .lbtn, .glass, .nav__end, .secure, .ghead__state, .rsuggest__item,
  body:not([data-route="page"]) .content :is(.card, .kpis, .pills, .btn--secondary, .btn--primary, .btn--ink, .callout:not(.callout--violet), .composer, .trust__item, .sum, .fact:not(.is-missing), .ask__bar, .gcomposer, .rmsg__bubble)
) {
  position: relative;
  --lg-fill: var(--lg-fill-regular);
  --lg-sheen: linear-gradient(180deg, rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0) 46%);
  --lg-rim-x: var(--lg-rim);
  --lg-drop-x: var(--lg-drop-surface);
  --lg-ring: 0 0 0 0 transparent;
  --lg-filter: blur(22px) saturate(1.8);
}

:is(
  .lbtn, .glass, .nav__end, .secure, .ghead__state, .rsuggest__item,
  body:not([data-route="page"]) .content :is(.card, .kpis, .pills, .btn--secondary, .btn--primary, .btn--ink, .callout:not(.callout--violet), .composer, .trust__item, .sum, .fact:not(.is-missing), .ask__bar, .gcomposer, .rmsg__bubble)
) {
  isolation: isolate; border: 0; background: transparent;
  box-shadow: var(--lg-ring), var(--lg-drop-x);
}

:is(
  .lbtn, .glass, .nav__end, .secure, .ghead__state, .rsuggest__item,
  body:not([data-route="page"]) .content :is(.card, .kpis, .pills, .btn--secondary, .btn--primary, .btn--ink, .callout:not(.callout--violet), .composer, .trust__item, .sum, .fact:not(.is-missing), .ask__bar, .gcomposer, .rmsg__bubble)
)::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  /* Lumière du geste (au point d'appui, js/liquid-glass.js), reflet du haut, remplissage. */
  background:
    radial-gradient(circle 120px at var(--lg-x, 50%) var(--lg-y, 30%), rgba(255, 255, 255, calc(var(--lg-glow) * 0.55)), rgba(255, 255, 255, 0) 72%),
    var(--lg-sheen),
    var(--lg-fill);
  box-shadow: var(--lg-rim-x);
  -webkit-backdrop-filter: var(--lg-filter); backdrop-filter: var(--lg-filter);
}

/* ======================================================================================
   Commandes : verre clair, réfraction du fond (navigateurs Chromium), capsule qui grandit au
   survol et s'illumine sous le doigt.
   ====================================================================================== */

.lbtn, .nav__end, .secure, .ghead__state, .rsuggest__item,
body:not([data-route="page"]) .content :is(.pills, .btn--secondary) {
  --lg-fill: var(--lg-fill-clear);
  --lg-drop-x: var(--lg-drop);
  --lg-filter: blur(10px) saturate(1.8) brightness(1.04);
}
html.lg-refract :is(.lbtn, .nav__end, .secure, .ghead__state, .rsuggest__item),
html.lg-refract body:not([data-route="page"]) .content :is(.pills, .btn--secondary) {
  --lg-filter: url("#lg-control") saturate(1.7) brightness(1.04);
}

/* Action principale : verre teinté (violet, ou noir pour l'action forte secondaire). */
body:not([data-route="page"]) .content :is(.btn--primary, .btn--ink),
body:not([data-route="page"]) .content .rmsg--user .rmsg__bubble {
  --lg-fill: var(--lg-fill-tint);
  --lg-sheen: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 50%);
  --lg-rim-x: var(--lg-rim-tint);
  --lg-drop-x: var(--lg-drop-tint);
  --lg-filter: blur(10px) saturate(1.6);
}
body:not([data-route="page"]) .content .btn--ink { --lg-fill: var(--lg-fill-ink); --lg-drop-x: var(--lg-drop); }
body:not([data-route="page"]) .content .btn--primary:disabled { --lg-fill: var(--lg-fill-tint-off); --lg-drop-x: 0 0 0 0 transparent; }
body:not([data-route="page"]) .content .gcomposer__send:disabled { --lg-fill: var(--lg-fill-off); --lg-rim-x: var(--lg-rim); --lg-drop-x: 0 0 0 0 transparent; }

.lbtn, .rsuggest__item, body:not([data-route="page"]) .content :is(.btn--secondary, .btn--primary, .btn--ink) {
  transform: none;
  transition: scale 340ms var(--lg-ease-spring), --lg-glow 280ms var(--ease-out), color var(--dur-fast) var(--ease-in-out);
}
@media (hover: hover) {
  .rsuggest__item:hover:not(:disabled),
  body:not([data-route="page"]) .content :is(.btn--secondary, .btn--primary, .btn--ink):hover:not(:disabled) { scale: 1.03; }
  .lbtn:hover:not(:disabled) { scale: 1.05; }
  .rsuggest__item:hover:not(:disabled), body:not([data-route="page"]) .content .btn--secondary:hover:not(:disabled) { --lg-fill: rgba(255, 255, 255, 0.5); }
  body:not([data-route="page"]) .content .btn--primary:hover:not(:disabled) { --lg-fill: var(--lg-fill-tint-hover); }
  body:not([data-route="page"]) .content .btn--ink:hover:not(:disabled) { --lg-fill: var(--lg-fill-ink-hover); }
}
.lbtn:active:not(:disabled), .rsuggest__item:active:not(:disabled),
body:not([data-route="page"]) .content :is(.btn--secondary, .btn--primary, .btn--ink):active:not(:disabled) { scale: 1.06; --lg-glow: 1; }

/* --- Barre du haut : trois groupes flottants, voile flou au défilement -------------------- */

.nav::before {
  content: ""; position: absolute; z-index: -1; inset: 0 0 -28px; pointer-events: none; opacity: 0;
  background: linear-gradient(to bottom, var(--lg-scrim), transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.6); backdrop-filter: blur(14px) saturate(1.6);
  -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent); mask-image: linear-gradient(to bottom, black 50%, transparent);
  transition: opacity var(--dur-base) var(--ease-in-out);
}
.nav.is-scrolled::before { opacity: 1; }

.nav__end { padding: 3px; gap: 2px; border-radius: var(--radius-full); }
.nav__end .icon-btn { width: 34px; height: 34px; }
.nav__end .switch { height: 34px; border-color: transparent; background: transparent; }
.nav__end :is(.icon-btn, .switch):hover { background: rgba(255, 255, 255, 0.6); border-color: transparent; }
.nav__end .icon-btn:active { background: rgba(255, 255, 255, 0.8); }
/* Écran moyen : le groupe de droite reste dans sa colonne, sans recouvrir les onglets. */
@media (max-width: 1080px) {
  .nav__end .switch__label { display: none; }
  .nav__end .switch { padding: 0 9px; }
}

/* Pastille des onglets de page (pas ceux du haut, restés en blanc) : une lentille de verre qui s'étire en glissant (js : classe is-moving). */
body:not([data-route="page"]) .content .pills__thumb {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.72));
  box-shadow: var(--lg-rim), var(--lg-drop);
}
body:not([data-route="page"]) .content .pills__btn[aria-selected="true"] { color: var(--ink); font-weight: 600; }
body:not([data-route="page"]) .content .pills__btn:not([aria-selected="true"], [aria-pressed="true"]) { color: var(--fg-secondary); }
body:not([data-route="page"]) .tabbar { padding: 6px 12px 12px; margin-bottom: 14px; }

/* ======================================================================================
   Surfaces : verre normal. Les compositeurs flottent plus haut et réfractent aussi le fond.
   ====================================================================================== */

.glass, body:not([data-route="page"]) .content :is(.composer, .gcomposer, .run) { --lg-drop-x: var(--lg-drop-float); }
html.lg-refract :is(.glass, body:not([data-route="page"]) .content :is(.composer, .gcomposer)) { --lg-filter: url("#lg-surface") saturate(1.8); }

.gcomposer:focus-within { --lg-ring: 0 0 0 5px var(--violet-ring); --lg-fill: rgba(255, 255, 255, 0.64); }
body:not([data-route="page"]) .content .ask__bar:focus-within { --lg-ring: 0 0 0 4px var(--violet-ring); }
body[data-route="home"] .content .composer.is-over { --lg-ring: 0 0 0 5px var(--violet-ring); --lg-fill: linear-gradient(180deg, var(--violet-area), var(--violet-area)), var(--lg-fill-regular); }
body[data-route="home"] .content .run.is-done { --lg-ring: 0 0 0 5px var(--violet-ring); }

/* Surfaces teintées : un voile violet sur le verre. */
body[data-route="glass"] .content .card.veille-run { --lg-fill: linear-gradient(120deg, var(--violet-area), transparent 55%), var(--lg-fill-regular); }
body[data-route="glass"] .content .card.reco--alt { --lg-fill: linear-gradient(180deg, var(--violet-area), transparent 140px), var(--lg-fill-regular); }
body[data-route="glass"] .content .card.scn-matrix { --lg-fill: linear-gradient(160deg, var(--violet-area), transparent 70%), var(--lg-fill-regular); }

/* Verre posé sur du verre : plus couvrant, sans second flou. */
body:not([data-route="page"]) .content .card :is(.callout:not(.callout--violet), .rmsg--bot .rmsg__bubble) { --lg-fill: rgba(255, 255, 255, 0.58); --lg-filter: none; --lg-drop-x: 0 0 0 0 transparent; }
body:not([data-route="page"]) .content .card .gcomposer { --lg-fill: rgba(255, 255, 255, 0.6); --lg-drop-x: var(--lg-drop); }

/* Fiches de veille : la carte se soulève au survol. */
body[data-route="glass"] .content .card.fiche { transition: translate var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out); }
body[data-route="glass"] .content .card.fiche:hover { translate: 0 -2px; --lg-drop-x: var(--lg-drop-float); }

/* Champs : creusés dans le verre plutôt que posés dessus. */
body:not([data-route="page"]) .content :is(.input, .select, .search) { background-color: rgba(255, 255, 255, 0.58); }
body:not([data-route="page"]) .content :is(.input, .select, .search):not(:focus, :focus-within, [aria-expanded="true"]) {
  border-color: rgba(255, 255, 255, 0.9); box-shadow: inset 0 1px 2px var(--violet-area);
}

/* ======================================================================================
   Au-dessus de tout : verre épais (menus, palette, boîtes, panneau d'un point, notifications).
   Ils ne contiennent pas d'autre verre : la matière est posée sur l'élément lui-même.
   ====================================================================================== */

.menu, .cmdk, .dialog, .sheet, .tip, .toast {
  background: var(--lg-fill-thick); border-color: transparent;
  -webkit-backdrop-filter: blur(30px) saturate(1.9); backdrop-filter: blur(30px) saturate(1.9);
  box-shadow: var(--lg-rim), var(--lg-drop-float);
}
.cmdk__foot { background: rgba(255, 255, 255, 0.4); }
.toast { color: var(--ink); }
.toast--ready .icon, .toast--progress .icon { color: var(--violet-700); }

/* ======================================================================================
   LiquidButton (js/liquid-glass.js, liquidButton) : le composant shadcn porté sans React.
   Variantes default, destructive, outline, secondary, ghost, link ; tailles default, sm, lg,
   xl, xxl (par défaut), icon.
   ====================================================================================== */

.lbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex: none;
  border-radius: var(--radius-full); color: var(--violet-700); font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
  line-height: 1; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.lbtn__label { position: relative; z-index: 1; display: inline-flex; align-items: center; gap: inherit; pointer-events: none; }
.lbtn .icon { width: 16px; height: 16px; }
.lbtn:disabled { opacity: .5; cursor: default; }
.lbtn--size-default { height: 36px; padding: 0 16px; }
.lbtn--size-sm { height: 32px; padding: 0 16px; gap: 6px; font-size: 12.5px; }
.lbtn--size-lg { height: 40px; padding: 0 24px; }
.lbtn--size-xl { height: 48px; padding: 0 30px; font-size: 15px; }
.lbtn--size-xxl { height: 56px; padding: 0 38px; font-size: 16px; }
.lbtn--size-icon { width: 36px; height: 36px; padding: 0; }
.lbtn--secondary { --lg-fill: var(--lg-fill-regular); color: var(--ink); }
.lbtn--outline { --lg-rim-x: var(--lg-rim), inset 0 0 0 1px var(--stroke-subtle); color: var(--ink); }
.lbtn--destructive { --lg-fill: var(--lg-fill-danger); --lg-rim-x: var(--lg-rim-tint); color: var(--white); }
.lbtn--ghost, .lbtn--link { --lg-fill: transparent; --lg-sheen: linear-gradient(transparent, transparent); --lg-rim-x: 0 0 0 0 transparent; --lg-drop-x: 0 0 0 0 transparent; --lg-filter: none; }
html.lg-refract :is(.lbtn--ghost, .lbtn--link) { --lg-filter: none; }
.lbtn--ghost:hover { --lg-fill: rgba(255, 255, 255, 0.55); --lg-rim-x: var(--lg-rim); }
.lbtn--link:hover { scale: 1; text-decoration: underline; text-underline-offset: 4px; }

/* ======================================================================================
   Accessibilité : transparence réduite (verre opaque), contraste élevé (liseré marqué).
   ====================================================================================== */

@media (prefers-reduced-transparency: reduce) {
  :root { --lg-fill-clear: rgba(255, 255, 255, 0.94); --lg-fill-regular: rgba(255, 255, 255, 0.96); --lg-fill-thick: rgba(255, 255, 255, 0.98); }
  :is(
    .lbtn, .glass, .nav__end, .secure, .ghead__state, .rsuggest__item,
    body:not([data-route="page"]) .content :is(.card, .kpis, .pills, .btn--secondary, .btn--primary, .btn--ink, .callout:not(.callout--violet), .composer, .trust__item, .sum, .fact:not(.is-missing), .ask__bar, .gcomposer, .rmsg__bubble)
  )::before,
  .menu, .cmdk, .dialog, .sheet, .tip, .toast, .nav::before { -webkit-backdrop-filter: none; backdrop-filter: none; }
}

@media (prefers-contrast: more) {
  :is(
    .lbtn, .glass, .nav__end, .secure, .ghead__state, .rsuggest__item,
    body:not([data-route="page"]) .content :is(.card, .kpis, .pills, .btn--secondary, .btn--primary, .btn--ink, .callout:not(.callout--violet), .composer, .trust__item, .sum, .fact:not(.is-missing), .ask__bar, .gcomposer, .rmsg__bubble)
  )::before { box-shadow: var(--lg-rim-x), inset 0 0 0 1px var(--stroke-strong); }
}
