/* =============================================================================
 * @intelliui/tokens — theme.css
 * -----------------------------------------------------------------------------
 * The Agent Desktop design language, ported VERBATIM from
 * agent-desktop/src/styles/_tokens.scss under the --iui-* namespace.
 *
 * Brand model: supply ONE seed (--iui-brand). The full 50–900 scale + alphas +
 * surface tints are DERIVED via color-mix(in oklch). Re-theme a tenant by
 * changing one value. Default seed = Tetherfi Violet #732B90.
 *
 * This is the STANDALONE/default theme. For a widget embedded in Agent Desktop
 * that should inherit the host brand, load `ad-adapter.css` instead (or as well).
 * ========================================================================== */

:root {
  /* --- Brand seed (runtime-overridable) ---------------------------------- */
  --iui-brand: #732b90;
  --iui-brand-contrast: #ffffff;

  /* --- Derived brand scale (auto from --iui-brand) ----------------------- */
  --iui-brand-50: color-mix(in oklch, var(--iui-brand) 8%, white);
  --iui-brand-100: color-mix(in oklch, var(--iui-brand) 16%, white);
  --iui-brand-200: color-mix(in oklch, var(--iui-brand) 30%, white);
  --iui-brand-300: color-mix(in oklch, var(--iui-brand) 46%, white);
  --iui-brand-400: color-mix(in oklch, var(--iui-brand) 70%, white);
  --iui-brand-500: var(--iui-brand);
  --iui-brand-600: color-mix(in oklch, var(--iui-brand) 86%, black);
  --iui-brand-700: color-mix(in oklch, var(--iui-brand) 72%, black);
  --iui-brand-800: color-mix(in oklch, var(--iui-brand) 58%, black);
  --iui-brand-900: color-mix(in oklch, var(--iui-brand) 44%, black);

  /* --- Neutrals ---------------------------------------------------------- */
  --iui-bg: #ffffff;
  --iui-surface: #ffffff;
  --iui-surface-2: #f6f5f9;
  --iui-surface-3: #efedf4;
  --iui-ink: #1c1a22;
  --iui-ink-2: #4a4754;
  --iui-muted: #6f6b7a;
  --iui-line: #e6e3ec;
  --iui-line-2: #d6d2e0;

  /* --- Status (hue-distinct from brand) ---------------------------------- */
  --iui-success: #1f9d6b;
  --iui-warning: #d98a00;
  --iui-error: #d6453d;
  --iui-info: var(--iui-brand-500);
  --iui-success-bg: color-mix(in oklch, var(--iui-success) 12%, white);
  --iui-warning-bg: color-mix(in oklch, var(--iui-warning) 14%, white);
  --iui-error-bg: color-mix(in oklch, var(--iui-error) 12%, white);
  --iui-info-bg: var(--iui-brand-50);
  /* Status colours as small text on surfaces — darkened to clear AA (4.5:1) on white. */
  --iui-success-text: color-mix(in oklch, var(--iui-success) 82%, black);
  --iui-warning-text: color-mix(in oklch, var(--iui-warning) 74%, black);
  --iui-error-text: color-mix(in oklch, var(--iui-error) 86%, black);

  /* --- Brand alpha helpers (overlays, hovers, focus rings) --------------- */
  --iui-brand-a08: color-mix(in oklch, var(--iui-brand) 8%, transparent);
  --iui-brand-a12: color-mix(in oklch, var(--iui-brand) 12%, transparent);
  --iui-brand-a20: color-mix(in oklch, var(--iui-brand) 20%, transparent);
  --iui-brand-a40: color-mix(in oklch, var(--iui-brand) 40%, transparent);
  --iui-focus-ring: 0 0 0 3px var(--iui-brand-a40);

  /* --- Radius ------------------------------------------------------------ */
  --iui-r-xs: 4px;
  --iui-r-sm: 8px;
  --iui-r-md: 12px;
  --iui-r-lg: 16px;
  --iui-r-xl: 22px;
  --iui-r-pill: 999px;

  /* --- Elevation --------------------------------------------------------- */
  --iui-shadow-1: 0 1px 2px rgb(28 26 34 / 6%), 0 1px 3px rgb(28 26 34 / 8%);
  --iui-shadow-2: 0 2px 8px rgb(28 26 34 / 8%), 0 4px 16px rgb(28 26 34 / 6%);
  --iui-shadow-3: 0 8px 24px rgb(28 26 34 / 12%), 0 16px 48px rgb(28 26 34 / 10%);

  /* --- Motion ------------------------------------------------------------ */
  --iui-ease: cubic-bezier(0.2, 0, 0, 1);
  --iui-dur-1: 120ms;
  --iui-dur-2: 200ms;
  --iui-dur-3: 320ms;

  /* --- Z-index scale ----------------------------------------------------- */
  --iui-z-rail: 100;
  --iui-z-topbar: 200;
  --iui-z-overlay: 1000;
  --iui-z-toast: 1100;
  --iui-z-modal: 1200;
  --iui-z-fullscreen: 99999;

  /* --- Fluid type scale — clamp(min, vw, max) ---------------------------- */
  --iui-fs-3xs: clamp(0.625rem, 0.6rem + 0.1vw, 0.6875rem);
  --iui-fs-2xs: clamp(0.6875rem, 0.66rem + 0.12vw, 0.75rem);
  --iui-fs-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --iui-fs-sm: clamp(0.8125rem, 0.78rem + 0.18vw, 0.875rem);
  --iui-fs-md: clamp(0.875rem, 0.84rem + 0.2vw, 1rem);
  --iui-fs-lg: clamp(1rem, 0.95rem + 0.3vw, 1.1875rem);
  --iui-fs-xl: clamp(1.25rem, 1.15rem + 0.5vw, 1.625rem);
  --iui-fs-2xl: clamp(1.625rem, 1.4rem + 1vw, 2.25rem);

  --iui-lh-tight: 1.15;
  --iui-lh-snug: 1.3;
  --iui-lh-base: 1.5;

  --iui-fw-regular: 400;
  --iui-fw-medium: 500;
  --iui-fw-semibold: 600;
  --iui-fw-bold: 700;

  --iui-font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --iui-font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* --- Fluid spacing scale ----------------------------------------------- */
  --iui-sp-1: clamp(0.25rem, 0.24rem + 0.05vw, 0.3125rem);
  --iui-sp-2: clamp(0.5rem, 0.46rem + 0.15vw, 0.625rem);
  --iui-sp-3: clamp(0.75rem, 0.68rem + 0.25vw, 1rem);
  --iui-sp-4: clamp(1rem, 0.9rem + 0.4vw, 1.5rem);
  --iui-sp-5: clamp(1.5rem, 1.3rem + 0.6vw, 2.25rem);
  --iui-sp-6: clamp(2rem, 1.7rem + 1vw, 3.5rem);

  /* --- Control sizing ---------------------------------------------------- */
  --iui-control-h: clamp(2.25rem, 2.1rem + 0.6vw, 2.75rem);
  --iui-card-min: clamp(15rem, 22vw, 21rem);
  --iui-page-gutter: var(--iui-sp-3);
  --iui-scrollbar-size: 0.375rem;

  /* --- Signature recipes (from the IntelliAgent widget design language) --- */
  /* The orb: 3-stop brand gradient + soft brand glow. */
  --iui-orb-gradient: linear-gradient(
    135deg,
    color-mix(in oklch, var(--iui-brand) 55%, white),
    var(--iui-brand),
    color-mix(in oklch, var(--iui-brand) 80%, black)
  );
  --iui-orb-gradient-success: linear-gradient(
    135deg,
    color-mix(in oklch, var(--iui-success) 55%, white),
    var(--iui-success),
    color-mix(in oklch, var(--iui-success) 75%, black)
  );
  --iui-orb-gradient-warning: linear-gradient(
    135deg,
    color-mix(in oklch, var(--iui-warning) 55%, white),
    var(--iui-warning),
    color-mix(in oklch, var(--iui-warning) 75%, black)
  );
  --iui-orb-gradient-error: linear-gradient(
    135deg,
    color-mix(in oklch, var(--iui-error) 55%, white),
    var(--iui-error),
    color-mix(in oklch, var(--iui-error) 75%, black)
  );
  --iui-brand-glow: 0 6px 16px -8px var(--iui-brand);
  --iui-brand-glow-lg: 0 10px 24px -8px var(--iui-brand);
  /* The one gradient hero per screen. */
  --iui-hero-gradient: linear-gradient(150deg, var(--iui-brand-600), var(--iui-brand-800) 70%);
  --iui-hero-glow: var(--iui-brand-300);
  /* On-gradient accessories (white text on brand only). */
  --iui-on-brand: #ffffff;
  --iui-on-brand-2: rgb(255 255 255 / 85%);
  --iui-on-brand-3: rgb(255 255 255 / 75%);
  --iui-glass: rgb(255 255 255 / 16%);
  --iui-glass-2: rgb(255 255 255 / 12%);
  --iui-on-brand-good: #7ef0bb;
  --iui-on-brand-warn: #ffd58a;
  --iui-on-brand-bad: #ffb1a8;
  /* Overlay scrim (sheet / modal / drawer). */
  --iui-scrim: color-mix(in oklch, var(--iui-ink) 42%, transparent);
  --iui-scrim-blur: 2px;
  /* Floating surfaces (toast / popover / menu). */
  --iui-shadow-float: 0 18px 44px -14px rgb(15 18 38 / 30%), 0 2px 6px rgb(15 18 38 / 6%);
  /* Skeleton shimmer. */
  --iui-shimmer: linear-gradient(
    90deg,
    var(--iui-surface-3) 25%,
    color-mix(in oklch, var(--iui-surface-3) 40%, var(--iui-surface)) 42%,
    var(--iui-surface-3) 60%
  );
  /* Card accent bars. */
  --iui-accent-bar: linear-gradient(180deg, var(--iui-brand-400), var(--iui-brand-700));
  /* Brand-tinted text/bg that stays readable in both themes (chips, subtle buttons). */
  --iui-brand-text: var(--iui-brand-700);
  --iui-brand-tint: var(--iui-brand-50);
  color-scheme: light;
}

/* =============================================================================
 * DARK THEME — applied via [data-iui-theme="dark"] on any ancestor (parallels
 * Agent Desktop's [data-theme="dark"]). Only neutrals + surfaces + shadows flip;
 * the brand seed stays tenant-controlled.
 * ========================================================================== */
:root[data-iui-theme='dark'],
[data-iui-theme='dark'] {
  --iui-bg: #14121a;
  --iui-surface: #1d1a25;
  --iui-surface-2: #24212e;
  --iui-surface-3: #2c2838;
  --iui-ink: #f3f1f8;
  --iui-ink-2: #c7c2d4;
  --iui-muted: #938da3;
  --iui-line: #332f40;
  --iui-line-2: #423d52;
  --iui-brand-contrast: #ffffff;

  --iui-shadow-1: 0 1px 2px rgb(0 0 0 / 40%);
  --iui-shadow-2: 0 2px 8px rgb(0 0 0 / 45%), 0 4px 16px rgb(0 0 0 / 35%);
  --iui-shadow-3: 0 8px 24px rgb(0 0 0 / 55%), 0 16px 48px rgb(0 0 0 / 45%);

  --iui-success-bg: color-mix(in oklch, var(--iui-success) 22%, var(--iui-surface));
  --iui-warning-bg: color-mix(in oklch, var(--iui-warning) 22%, var(--iui-surface));
  --iui-error-bg: color-mix(in oklch, var(--iui-error) 22%, var(--iui-surface));
  --iui-info-bg: color-mix(in oklch, var(--iui-brand) 24%, var(--iui-surface));
  --iui-success-text: color-mix(in oklch, var(--iui-success) 72%, white);
  --iui-warning-text: color-mix(in oklch, var(--iui-warning) 76%, white);
  --iui-error-text: color-mix(in oklch, var(--iui-error) 72%, white);

  /* The only per-component dark swaps the design language allows: brand tints. */
  --iui-brand-text: var(--iui-brand-200);
  --iui-brand-tint: var(--iui-brand-a20);
  --iui-shadow-float: 0 18px 44px -14px rgb(0 0 0 / 60%), 0 2px 6px rgb(0 0 0 / 30%);
  --iui-scrim: color-mix(in oklch, #000 55%, transparent);
  color-scheme: dark;
}

/* =============================================================================
 * Global motion keyframes — the same names components use inside their shadow
 * roots, exposed to page/block CSS: `animation: iui-fade-up var(--iui-dur-3)
 * var(--iui-ease) both;` Killed under prefers-reduced-motion.
 * ========================================================================== */
@keyframes iui-fade-up {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes iui-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes iui-spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes iui-breathe {
  0%,
  100% {
    transform: scale(1);
    box-shadow: var(--iui-brand-glow);
  }
  50% {
    transform: scale(1.06);
    box-shadow: var(--iui-brand-glow-lg);
  }
}
@keyframes iui-shimmer {
  from {
    background-position: 130% 0;
  }
  to {
    background-position: -90% 0;
  }
}
@keyframes iui-ping {
  0% {
    transform: scale(1);
    opacity: 0.8;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  [class*='iui-'],
  [class*='blk-'] {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
