/*
 * @bilo-io/ui design tokens — exposed as `@bilo-io/ui/styles`.
 *
 * The shadcn-style HSL custom properties + the `.dark` override block: the
 * single source of truth for the design system's color + radius tokens.
 * Consumers `import '@bilo-io/ui/styles'` and theme via the `.dark` class on
 * `<html>` (the `@bilo-io/ui/theme` runtime toggles it). Values are bare HSL
 * triplets (`H S% L%`), consumed as `hsl(var(--token))`.
 *
 * Framework-agnostic on purpose (no `@layer`/`@tailwind`) so a non-Tailwind
 * consumer (e.g. a future docs app) can use them too. `src/tokens/index.ts`
 * mirrors these as typed TS constants for JS consumers.
 */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 38%;  /* raised from 46.1% for WCAG AA (≥4.5:1 on white) */
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 36%;
  --success-foreground: 0 0% 98%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;

  /* status hues (H S%) — paired with L via utility classes */
  --status-backlog: 240 4% 50%;
  --status-todo: 217 91% 60%;
  --status-wip: 38 92% 50%;
  --status-waiting: 280 65% 60%;
  --status-done: 142 71% 45%;
  --status-abandoned: 0 0% 60%;

  --kind-bug: 0 84% 60%;
  --kind-feature: 262 83% 58%;
  --kind-question: 217 91% 60%;
  --kind-chore: 240 4% 46%;
  --kind-unknown: 240 4% 60%;

  /* workflow node category accents */
  --node-trigger: 217 91% 60%;
  --node-action: 262 83% 58%;
  --node-logic: 38 92% 50%;
  --node-data: 173 80% 40%;
  --node-storage: 333 80% 52%;

  /* pointer effect tokens — follows --foreground (text color) across all themes */
  --pointer: var(--foreground);
  --pointer-glow: var(--foreground);
  --pointer-alpha: 0.88;
  --pointer-blend: normal;
}

.dark {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 5.5%;
  --card-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 72% 60%;  /* raised from 30.6% for WCAG AA as text on dark backgrounds */
  --destructive-foreground: 0 0% 98%;
  --success: 142 65% 48%;
  --success-foreground: 0 0% 98%;
  --popover: 240 10% 7%;
  --popover-foreground: 0 0% 98%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;

  --status-backlog: 240 5% 65%;
  --status-todo: 217 91% 68%;
  --status-wip: 38 92% 60%;
  --status-waiting: 280 65% 70%;
  --status-done: 142 71% 55%;
  --status-abandoned: 0 0% 50%;

  --kind-bug: 0 84% 65%;
  --kind-feature: 262 83% 68%;
  --kind-question: 217 91% 68%;
  --kind-chore: 240 5% 60%;
  --kind-unknown: 240 5% 55%;

  --node-trigger: 217 91% 68%;
  --node-action: 262 83% 68%;
  --node-logic: 38 92% 60%;
  --node-data: 173 70% 50%;
  --node-storage: 333 75% 62%;

  --pointer: var(--foreground);
  --pointer-glow: var(--foreground);
  --pointer-alpha: 0.92;
  --pointer-blend: normal;
}

/* ───────────────────────────────────────────────────────────────────────────
   Gradient glow — the app's signature animated border + blurred halo
   (Phase 66 Theme B). Promoted from web's globals.css so `web` and `docs` share
   one source; the `<GradientGlow>` primitive applies these classes and the raw
   classes stay usable directly. `--gradient-angle` + the `gradient-border-spin`
   keyframe also back web's workflow-node backgrounds + the reconnect orbit, so
   they live here (imported first) for every consumer to resolve.

   Triggers: base `.gradient-border` lights on `:focus-within`; add
   `--hover` to light on `:hover`, or `--always` to light unconditionally.
   ─────────────────────────────────────────────────────────────────────────── */

@property --gradient-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

@keyframes gradient-border-spin {
  to {
    --gradient-angle: 360deg;
  }
}

/* Breathing glow — pairs with the spin so the halo slowly swells and settles
   rather than sitting at a flat intensity. */
@keyframes gradient-border-glow-pulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.9;
  }
}

.gradient-border {
  position: relative;
  isolation: isolate;
  /* A real, pixel-snapped border rather than a masked halo straddling the box
     edge: the conic gradient fills the border-box while the card colour fills
     the padding-box, so the frame is exactly even on every side. Dim + thin at
     rest; brightens, thickens, and spins when triggered. */
  border: 1px solid transparent;
  background:
    linear-gradient(hsl(var(--card)), hsl(var(--card))) padding-box,
    conic-gradient(
        from var(--gradient-angle),
        rgba(244, 63, 94, 0.4),
        rgba(245, 158, 11, 0.4),
        rgba(16, 185, 129, 0.4),
        rgba(59, 130, 246, 0.4),
        rgba(139, 92, 246, 0.4),
        rgba(236, 72, 153, 0.4),
        rgba(244, 63, 94, 0.4)
      )
      border-box;
  transition: border-width 0.25s ease-out;
}

.gradient-border:focus-within,
.gradient-border--hover:hover,
.gradient-border--always {
  border-width: 2px;
  background:
    linear-gradient(hsl(var(--card)), hsl(var(--card))) padding-box,
    conic-gradient(
        from var(--gradient-angle),
        #f43f5e,
        #f59e0b,
        #10b981,
        #3b82f6,
        #8b5cf6,
        #ec4899,
        #f43f5e
      )
      border-box;
  animation: gradient-border-spin 4s linear infinite;
}

.gradient-border::after {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: inherit;
  background: conic-gradient(
    from var(--gradient-angle),
    #f43f5e,
    #f59e0b,
    #10b981,
    #3b82f6,
    #8b5cf6,
    #ec4899,
    #f43f5e
  );
  filter: blur(26px);
  opacity: 0;
  transition: opacity 0.4s ease-out;
  pointer-events: none;
  z-index: -2;
}

.gradient-border:focus-within::after,
.gradient-border--hover:hover::after,
.gradient-border--always::after {
  opacity: 0.7;
  animation:
    gradient-border-spin 4s linear infinite,
    gradient-border-glow-pulse 2.6s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  html:not([data-motion='full']) .gradient-border:focus-within,
  html:not([data-motion='full']) .gradient-border:focus-within::after,
  html:not([data-motion='full']) .gradient-border--hover:hover,
  html:not([data-motion='full']) .gradient-border--hover:hover::after,
  html:not([data-motion='full']) .gradient-border--always,
  html:not([data-motion='full']) .gradient-border--always::after {
    animation: none;
  }
}

/* ───────────────────────────────────────────────────────────────────────────
   PointerTrail — theme-aware cursor follower & variants (trail, fluid, aurora, ring)
   ─────────────────────────────────────────────────────────────────────────── */

@keyframes pointer-fluid-morph {
  0%,
  100% {
    border-radius: 56% 44% 62% 38% / 45% 55% 45% 55%;
  }
  33% {
    border-radius: 42% 58% 40% 60% / 58% 42% 58% 42%;
  }
  66% {
    border-radius: 60% 40% 46% 54% / 42% 60% 40% 58%;
  }
}

.pointer-fx {
  --pointer: var(--foreground);
  --pointer-glow: var(--foreground);
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  display: none;
}

.pointer-fx[data-contained] {
  position: absolute;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  border-radius: inherit;
}

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .pointer-fx[data-ready] {
    display: block;
  }
}

.pointer-dot,
.pointer-trail,
.pointer-ring {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 9999px;
  opacity: 0;
  transform: translate3d(var(--x, 0px), var(--y, 0px), 0) translate(-50%, -50%);
  transition: opacity 0.3s ease-out;
  will-change: transform;
}

.pointer-dot,
.pointer-trail {
  background: hsl(var(--pointer, var(--foreground)));
  mix-blend-mode: var(--pointer-blend, normal);
}

.pointer-dot {
  width: 18px;
  height: 18px;
  box-shadow:
    0 0 14px hsl(var(--pointer-glow, var(--foreground)) / 0.35),
    0 0 28px hsl(var(--pointer-glow, var(--foreground)) / 0.18);
  transition: opacity 0.3s ease-out, transform 0s, width 0.2s, height 0.2s;
}

.pointer-trail {
  width: calc(7px * (1 - var(--n, 0) * 0.8));
  height: calc(7px * (1 - var(--n, 0) * 0.8));
  box-shadow: 0 0 10px hsl(var(--pointer-glow, var(--foreground)) / 0.28);
}

.pointer-fx[data-active] .pointer-dot {
  opacity: var(--pointer-alpha, 0.88);
}

.pointer-fx[data-active] .pointer-trail {
  opacity: calc((1 - var(--n, 0)) * var(--pointer-alpha, 0.88));
}

.pointer-fx[data-down] .pointer-dot {
  width: 36px;
  height: 36px;
}

/* Tone: gradient (or Variant: fluid) — animated primary brand gradient that swirls & morphs like fluid */
.pointer-fx[data-tone='gradient'] .pointer-dot,
.pointer-fx[data-tone='gradient'] .pointer-trail,
.pointer-fx[data-variant='fluid'] .pointer-dot,
.pointer-fx[data-variant='fluid'] .pointer-trail {
  background: var(
    --accent-gradient,
    conic-gradient(
      from var(--gradient-angle),
      hsl(var(--node-trigger, 217 91% 60%)),
      hsl(var(--node-action, 262 83% 62%)),
      hsl(var(--node-storage, 333 80% 58%)),
      hsl(var(--node-data, 173 80% 45%)),
      hsl(var(--node-trigger, 217 91% 60%))
    )
  );
  mix-blend-mode: normal;
  box-shadow:
    0 0 20px hsl(var(--node-action, 262 83% 62%) / 0.55),
    0 0 38px hsl(var(--node-trigger, 217 91% 60%) / 0.35);
  animation:
    gradient-border-spin 2.8s linear infinite,
    pointer-fluid-morph 3.2s ease-in-out infinite;
}

.pointer-fx[data-variant='fluid'] .pointer-dot {
  width: 22px;
  height: 22px;
}

.pointer-fx[data-variant='fluid'] .pointer-trail {
  width: calc(14px * (1 - var(--n, 0) * 0.72));
  height: calc(14px * (1 - var(--n, 0) * 0.72));
  animation-delay: calc(var(--n, 0) * -1.4s);
  box-shadow: 0 0 14px hsl(var(--node-action, 262 83% 62%) / 0.45);
}

.pointer-fx[data-variant='fluid'][data-down] .pointer-dot {
  width: 40px;
  height: 40px;
}

/* Variant: aurora — blue -> violet -> pink rotating aurora orb & trailing sparkles */
.pointer-fx[data-variant='aurora'] .pointer-dot {
  width: 18px;
  height: 18px;
  background: conic-gradient(
    from var(--gradient-angle),
    #3b82f6,
    #8b5cf6 35%,
    #ec4899 70%,
    #6366f1 90%,
    #3b82f6
  );
  mix-blend-mode: normal;
  box-shadow: 0 0 22px rgb(139 92 246 / 0.55), 0 0 42px rgb(236 72 153 / 0.35);
  animation: gradient-border-spin 3.6s linear infinite;
}

.pointer-fx[data-variant='aurora'] .pointer-trail {
  background: conic-gradient(from var(--gradient-angle), #3b82f6, #8b5cf6, #ec4899, #3b82f6);
  mix-blend-mode: normal;
  box-shadow: 0 0 12px rgb(139 92 246 / 0.45);
  animation: gradient-border-spin 3.6s linear infinite;
  animation-delay: calc(var(--n, 0) * -1.2s);
}

.pointer-fx[data-variant='aurora'][data-down] .pointer-dot {
  width: 34px;
  height: 34px;
}

/* Variant: ring — precision inner dot + lagging outer ring */
.pointer-fx[data-variant='ring'] .pointer-dot {
  width: 7px;
  height: 7px;
  mix-blend-mode: normal;
  box-shadow: 0 0 10px hsl(var(--pointer-glow, var(--foreground)) / 0.45);
}

.pointer-fx[data-variant='ring'] .pointer-ring {
  width: 34px;
  height: 34px;
  border: 1.5px solid hsl(var(--pointer, var(--foreground)) / 0.65);
  box-shadow: 0 0 18px hsl(var(--pointer-glow, var(--foreground)) / 0.25);
  transition: opacity 0.3s ease-out, transform 0s, width 0.2s, height 0.2s, border-color 0.2s;
}

.pointer-fx[data-variant='ring'][data-tone='gradient'] .pointer-ring {
  border: 2px solid transparent;
  background:
    conic-gradient(
        from var(--gradient-angle),
        hsl(var(--node-trigger, 217 91% 60%)),
        hsl(var(--node-action, 262 83% 62%)),
        hsl(var(--node-storage, 333 80% 58%)),
        hsl(var(--node-data, 173 80% 45%)),
        hsl(var(--node-trigger, 217 91% 60%))
      )
      border-box;
  -webkit-mask:
    linear-gradient(#fff 0 0) padding-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: gradient-border-spin 3.2s linear infinite;
}

.pointer-fx[data-variant='ring'][data-active] .pointer-ring {
  opacity: 0.9;
}

.pointer-fx[data-variant='ring'][data-down] .pointer-dot {
  width: 10px;
  height: 10px;
}

.pointer-fx[data-variant='ring'][data-down] .pointer-ring {
  width: 48px;
  height: 48px;
  border-color: hsl(var(--pointer, var(--foreground)) / 0.9);
}
