@custom-variant dark (&:is(.dark *));

@import './actuate-tokens.css';

/*
 * Semantic Tailwind tokens mapped from the ActuateCMS design system.
 * Raw tokens live in actuate-tokens.css; Appearance accent overrides
 * mutate --acc, --primary, --sidebar-primary, etc. at runtime.
 */
.actuate-admin {
  --font-size: var(--fs-body);
  --background: var(--bg);
  --foreground: var(--txt);
  /* --card surface token is defined in actuate-tokens.css */
  --card-foreground: var(--txt);
  --popover: var(--card);
  --popover-foreground: var(--txt);
  --primary: var(--acc);
  --primary-foreground: #ffffff;
  --secondary: var(--acc-l);
  --secondary-foreground: var(--txt);
  /*
   * IMPORTANT: never redefine --muted here. The raw design token --muted
   * (actuate-tokens.css) is a faint TEXT color used by design-parity
   * surfaces via text-[var(--muted)]. The muted SURFACE used by the
   * Tailwind bg-muted utility is a separate private token below.
   */
  --surface-muted: color-mix(in srgb, var(--bdr) 55%, var(--card));
  --muted-foreground: var(--sub);
  --accent: var(--acc-l);
  --accent-foreground: var(--acc);
  --destructive: var(--err);
  --destructive-foreground: #ffffff;
  --success: var(--suc);
  --success-foreground: #ffffff;
  --warning: var(--warn);
  --warning-foreground: var(--txt);
  --info: var(--info);
  --info-foreground: #ffffff;
  --brand: var(--acc);
  --brand-foreground: #ffffff;
  --border: var(--bdr);
  --input: transparent;
  --input-background: var(--card);
  --switch-background: var(--bdr);
  --font-weight-medium: 500;
  --font-weight-normal: 400;
  --ring: var(--acc-m);
  --chart-1: var(--acc);
  --chart-2: var(--info);
  --chart-3: var(--suc);
  --chart-4: var(--warn);
  --chart-5: var(--err);
  --radius: var(--r);
  --sidebar: var(--sb);
  --sidebar-foreground: var(--txt);
  --sidebar-primary: var(--acc);
  --sidebar-primary-foreground: #ffffff;
  --sidebar-accent: var(--acc-l);
  --sidebar-accent-foreground: var(--acc);
  --sidebar-border: var(--bdr);
  --sidebar-ring: var(--acc-m);
  --shadow-card: var(--shd);
  --shadow-elevated: var(--shd2);
}

.dark .actuate-admin,
.actuate-admin.dark {
  --primary-foreground: #0d0c18;
  --secondary-foreground: var(--txt);
  --warning-foreground: var(--txt);
  --brand-foreground: #0d0c18;
  --success-foreground: #0d0c18;
  --info-foreground: #0d0c18;
  --destructive-foreground: #0d0c18;
  --sidebar-primary-foreground: #0d0c18;
  --surface-muted: color-mix(in srgb, var(--bdr) 40%, var(--card));
}

@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--surface-muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-success: var(--success);
  --color-success-foreground: var(--success-foreground);
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);
  --color-info: var(--info);
  --color-info-foreground: var(--info-foreground);
  --color-brand: var(--brand);
  --color-brand-foreground: var(--brand-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-input-background: var(--input-background);
  --color-switch-background: var(--switch-background);
  --color-ring: var(--ring);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --radius-sm: var(--r-sm);
  --radius-md: var(--r-control);
  --radius-lg: var(--r);
  --radius-xl: calc(var(--r) + 2px);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
  --text-2xl: var(--fs-page);
  --text-xl: calc(var(--fs-card) + 4px);
  --text-lg: var(--fs-card);
  --text-base: var(--fs-body);
  --text-sm: var(--fs-sub);
  --text-xs: var(--fs-hint);
}

@layer base {
  .actuate-admin * {
    @apply border-border outline-ring/50;
  }

  /*
   * Base typography is written with doubled `.actuate-admin.actuate-admin`
   * specificity on purpose. Consumer apps commonly import their site
   * stylesheet into the admin route (for the page-editor canvas preview) and
   * those sheets sometimes style `.actuate-admin` or plain `h1`/`body` in
   * their own `@layer base` — with equal specificity, whichever file loads
   * last wins, and the admin shell inherits site fonts/colors ("washed out"
   * admin). Doubling the class wins those same-layer ties without `!important`
   * while Tailwind utilities (a later layer) still override as usual.
   * Consumer styles that should reach the canvas preview belong under
   * `.actuate-admin .actuate-canvas` — see EditorCanvas.
   */
  .actuate-admin.actuate-admin {
    @apply bg-background text-foreground;
    font-family: var(--actuate-admin-font, var(--font-sans)) !important;
    font-size: var(--font-size);
    line-height: 1.5;
    isolation: isolate;
    contain: style;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .actuate-admin.actuate-admin h1 {
    font-size: var(--fs-page);
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.5;
  }

  .actuate-admin.actuate-admin h2 {
    font-size: var(--fs-card);
    font-weight: 600;
    line-height: 1.5;
  }

  .actuate-admin.actuate-admin h3 {
    font-size: var(--fs-card);
    font-weight: 600;
    line-height: 1.5;
  }

  .actuate-admin.actuate-admin h4 {
    font-size: var(--fs-body);
    font-weight: 600;
    line-height: 1.5;
  }

  .actuate-admin.actuate-admin label {
    font-size: var(--fs-body);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
  }

  .actuate-admin.actuate-admin button {
    font-size: var(--fs-body);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
  }

  .actuate-admin.actuate-admin input {
    font-size: var(--fs-body);
    font-weight: var(--font-weight-normal);
    line-height: 1.5;
  }

  .actuate-admin .actuate-section-label {
    font-size: var(--fs-label);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sub);
  }

  /*
   * The sanctioned hook for consumer brand styles inside the editor canvas
   * preview. Anything the site stylesheet must render in the preview should
   * be scoped `.actuate-admin .actuate-canvas …` instead of `.actuate-admin`.
   * The canvas re-establishes the site's typographic context: headings and
   * body text fall back to inheritance rather than the admin scale above.
   */
  .actuate-admin .actuate-canvas :is(h1, h2, h3, h4) {
    font-size: revert-layer;
    font-weight: revert-layer;
    letter-spacing: revert-layer;
    line-height: revert-layer;
  }

  /*
   * Rich-text HTML in the canvas preview (article body, etc.). The TipTap
   * editor styles headings in `.ProseMirror`; the canvas cannot rely on
   * `prose` because @tailwindcss/typography is not bundled, and the revert
   * above strips admin heading scales without substituting site typography.
   */
  .actuate-admin .actuate-canvas .actuate-rich-text {
    color: var(--foreground);
    font-size: 1rem;
    line-height: 1.625;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text :is(h1, h2, h3, h4, h5, h6) {
    color: var(--foreground);
    font-weight: 600;
    line-height: 1.5;
    margin-top: 1.25em;
    margin-bottom: 0.5em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text h1 {
    font-size: 2em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text h2 {
    font-size: 1.5em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text h3 {
    font-size: 1.25em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text h4 {
    font-size: 1.125em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text h5 {
    font-size: 1em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text h6 {
    font-size: 0.875em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text p {
    margin-top: 0.75em;
    margin-bottom: 0.75em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text :is(ul, ol) {
    margin-top: 0.75em;
    margin-bottom: 0.75em;
    padding-left: 1.5rem;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text ul {
    list-style-type: disc;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text ol {
    list-style-type: decimal;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text li {
    margin-top: 0.25em;
    margin-bottom: 0.25em;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text a {
    color: var(--primary);
    text-decoration: underline;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text :is(strong, b) {
    font-weight: 600;
  }

  .actuate-admin .actuate-canvas .actuate-rich-text blockquote {
    border-left: 3px solid var(--border);
    margin: 1em 0;
    padding-left: 1em;
    color: var(--muted-foreground);
  }

  .actuate-admin .actuate-canvas .actuate-rich-text img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 1em 0;
  }
}

.actuate-admin.reduce-motion,
.actuate-admin.reduce-motion *,
.actuate-admin.reduce-motion *::before,
.actuate-admin.reduce-motion *::after {
  animation-duration: 0.001ms;
  animation-iteration-count: 1;
  transition-duration: 0.001ms;
  scroll-behavior: auto;
}
