# Colors

import Link from "next/link";
import { Callout } from "fumadocs-ui/components/callout";
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
import { Step, Steps } from "fumadocs-ui/components/steps";
import { Tabs, Tab } from "fumadocs-ui/components/tabs";
import { Badge } from "@pycolors/ui";
import {
  Blocks,
  CircleDot,
  Layers3,
  Palette,
  Sparkles,
  Type,
} from "lucide-react";
import { DocsLinks } from "@/components/docs/docs-links";
import { DocsFeatureGrid } from "@/components/docs/docs-feature-grid";

## Overview

Colors in PyColors UI are designed as **semantic product roles**, not decorative values.

The system gives every interface layer a stable meaning: page surfaces, cards, text, actions, states, borders, form controls, sidebars, and charts. Components consume those roles through utilities like `bg-card`, `text-foreground`, `text-muted-foreground`, `bg-primary`, and `border-border` instead of hardcoding visual values locally.

At the end of this page, you will understand how PyColors structures color roles, how light and dark mode remain predictable, and how to apply color decisions without creating theme drift.

<Callout title="Why this matters">
  Color consistency is one of the fastest signals of product quality. A semantic
  color system keeps dashboards, marketing pages, documentation, forms, and
  reusable components visually aligned without forcing every component to
  reinvent its own palette.
</Callout>

### Principles

<DocsFeatureGrid
  columns={3}
  tone="platform"
  items={[
  {
    eyebrow: "Role first",
    title: "Describe intent",
    description:
      "Use tokens that explain product meaning: surface, text, action, state, input, and data.",
  },
  {
    eyebrow: "Theme safe",
    title: "Change centrally",
    description:
      "Map CSS variables into Tailwind utilities so components stay stable when themes evolve.",
  },
  {
    eyebrow: "Production ready",
    title: "Scale consistently",
    description:
      "Keep reusable components, dashboards, docs, and commercial pages visually coherent.",
  },
]}
/>

## What you’ll do

<Steps>
  <Step>
    \#### Understand the semantic role model behind PyColors colors.
  </Step>

  <Step>
    #### Map CSS variables to Tailwind utilities through the token layer.
  </Step>

  <Step>
    #### Apply colors in components without raw values or one-off overrides.
  </Step>

  <Step>
    #### Use decision rules to keep UI colors, state colors, and chart colors

    separate.
  </Step>
</Steps>

### Architecture

PyColors uses an **OKLCH-based color system** exposed through CSS variables and mapped into Tailwind semantic utilities.

OKLCH gives the token layer more predictable control over perceived lightness, contrast, and theme balance than raw RGB or one-off HSL values. That matters when a product must support light mode, dark mode, reusable UI components, long documentation pages, dashboards, settings screens, and commercial surfaces.

<Callout type="info" title="Core principle">
  Components should consume color roles. The token layer should decide how those
  roles look.
</Callout>

<Callout type="info" title="Generate a semantic starting point">
  Need a concrete starting set of light and dark semantic values? Use the
  <Link href="/tools/theme-builder">PyColors Theme Builder</Link> to generate
  client-side CSS overrides, then review the result in your complete product
  context.
</Callout>

<Tabs items={["Theme mapping", "Component usage", "Theme values"]}>
  <Tab value="Theme mapping">
    ```css title="tokens.css" {2-11}
    @theme inline {
      --color-background: var(--background);
      --color-foreground: var(--foreground);
      --color-card: var(--card);
      --color-card-foreground: var(--card-foreground);
      --color-primary: var(--primary);
      --color-primary-foreground: var(--primary-foreground);
      --color-muted: var(--muted);
      --color-muted-foreground: var(--muted-foreground);
      --color-border: var(--border);
      --color-ring: var(--ring);
    }
    ```
  </Tab>

  <Tab value="Component usage">
    ```tsx title="example-card.tsx" {3-7}
    export function ExampleCard() {
      return (
        <div className="rounded-2xl border border-border bg-card p-5 text-card-foreground">
          <p className="text-sm font-medium text-foreground">Semantic surface</p>
          <p className="mt-1 text-sm text-muted-foreground">
            This component uses product roles instead of raw color values.
          </p>
        </div>
      );
    }
    ```
  </Tab>

  <Tab value="Theme values">
    ```css title="themes.css" {1,8}
    :root {
      --background: oklch(1 0 0);
      --foreground: oklch(0.141 0.005 285.823);
      --primary: oklch(0.21 0.006 285.885);
      --primary-foreground: oklch(0.985 0 0);
    }

    .dark {
      --background: oklch(0.141 0.005 285.823);
      --foreground: oklch(0.985 0 0);
      --primary: oklch(0.92 0.004 286.32);
      --primary-foreground: oklch(0.21 0.006 285.885);
    }
    ```
  </Tab>
</Tabs>

This keeps the component API stable while allowing the underlying theme to evolve centrally. Components keep the same classes, token meaning stays stable, and the theme layer handles contrast and visual balance.

## Role model

PyColors groups colors by product responsibility. This keeps the system easier to reason about and prevents the table of contents from becoming noisy.

| Category | Tokens                                              | Used for                                            |
| -------- | --------------------------------------------------- | --------------------------------------------------- |
| Surfaces | `background`, `card`, `popover`, `sidebar`          | Page layers, cards, overlays, navigation            |
| Text     | `foreground`, `muted-foreground`, `card-foreground` | Primary copy, secondary copy, surface-specific text |
| Actions  | `primary`, `secondary`, `accent`, `muted`           | Buttons, emphasis, subtle interaction areas         |
| States   | `destructive`, `success`, `warning`                 | Product feedback, validation, risk, confirmation    |
| Inputs   | `border`, `input`, `ring`                           | Forms, focus states, separators, control outlines   |
| Charts   | `chart-1` to `chart-5`                              | Data visualization only                             |

<Callout title="Why this matters">
  Separating UI roles from chart roles prevents data visualization colors from
  leaking into product states. A chart palette should not become the source of
  truth for buttons, alerts, or destructive actions.
</Callout>

<div className="not-prose mt-8 grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4">
  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      background
    </div>

    <div className="h-11 rounded-xl border border-border bg-background" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      card
    </div>

    <div className="h-11 rounded-xl border border-border bg-card" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      primary
    </div>

    <div className="h-11 rounded-xl bg-primary" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      secondary
    </div>

    <div className="h-11 rounded-xl bg-secondary" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      accent
    </div>

    <div className="h-11 rounded-xl bg-accent" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      muted
    </div>

    <div className="h-11 rounded-xl bg-muted" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      destructive
    </div>

    <div className="h-11 rounded-xl bg-destructive" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      success
    </div>

    <div className="h-11 rounded-xl bg-success" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      warning
    </div>

    <div className="h-11 rounded-xl bg-warning" />
  </div>

  <div className="rounded-2xl border border-border/60 bg-card p-4">
    <div className="mb-3 text-xs font-medium text-muted-foreground">
      border
    </div>

    <div className="h-11 rounded-xl border border-border bg-background" />
  </div>
</div>

## Implementation

Use semantic utilities in every reusable component.

```tsx title="recommended.tsx" {3-8}
export function ProductNotice() {
  return (
    <div className="rounded-2xl border border-border bg-card p-5 text-card-foreground">
      <p className="text-sm font-medium text-foreground">
        Production-ready surface
      </p>
      <p className="mt-1 text-sm text-muted-foreground">
        The visual intent comes from the design system, not from local
        overrides.
      </p>
    </div>
  );
}
```

Avoid raw values inside reusable UI.

```tsx title="avoid.tsx" {3-5}
export function ProductNotice() {
  return (
    <div className="rounded-2xl border border-[#e5e7eb] bg-[#ffffff] p-5 text-[#111827]">
      <p className="text-sm text-[#6b7280]">This creates theme drift.</p>
    </div>
  );
}
```

<Callout type="warn" title="Common pitfall">
  Do not solve repeated color needs with local overrides. If the same visual
  intent appears in multiple places, define or adjust the semantic role instead.
</Callout>

## Decision guide

Use PyColors semantic color roles when:

* the component is reusable
* the UI must support light and dark mode
* the surface appears in dashboards, docs, marketing, or settings
* the same visual meaning should remain stable across the product
* theme updates should happen centrally

Avoid local raw values when:

* the component belongs to the design system
* the value represents a product state
* the color affects text contrast or focus visibility
* the color will likely be reused elsewhere
* the value needs to survive future theme changes

<Callout title="Inline CTA">
  Ready to move from visual consistency to a production-shaped SaaS foundation?
  Explore <Link href="/docs/starter-pro">Starter Pro</Link> for auth, billing,
  backend, and delivery patterns built on top of PyColors UI.
</Callout>

## Common mistakes

<Accordions type="single">
  <Accordion title="Using raw hex values in reusable components">
    Raw values create theme drift, make dark mode harder to maintain, and hide visual decisions inside component implementation. Prefer utilities such as `bg-card`, `text-muted-foreground`, and `border-border`.
  </Accordion>

  <Accordion title="Reusing chart colors for product states">
    Chart colors are for data visualization. Product states such as success,
    warning, and destructive actions need dedicated semantic roles so feedback
    stays consistent.
  </Accordion>

  <Accordion title="Treating accent as decoration">
    `accent` should communicate intentional emphasis. If every section invents a
    different accent behavior, the product starts to feel inconsistent.
  </Accordion>

  <Accordion title="Fixing one screen instead of the token layer">
    Local fixes solve the current screen but create long-term maintenance cost. If
    the need repeats, update the semantic role centrally.
  </Accordion>

  <Accordion title="Skipping contrast checks in dark mode">
    Every role used for text, actions, inputs, and states must remain readable in both light and dark mode before shipping.
  </Accordion>
</Accordions>

## Next steps

<DocsLinks
  variant="grid"
  tone="platform"
  items={[
  {
    title: "Typography",
    href: "/docs/design-system/typography",
    description:
      "Continue with readable hierarchy, rhythm, and semantic text structure.",
    icon: Type,
  },
  {
    title: "Design tokens",
    href: "/docs/design-system/tokens",
    description:
      "Understand the token layer that keeps PyColors UI consistent across products.",
    icon: Layers3,
  },
  {
    title: "Theme Builder",
    href: "/tools/theme-builder",
    description:
      "Generate contrast-aware semantic overrides and review them in a production-shaped preview.",
    icon: Palette,
  },
  {
    title: "UI components",
    href: "/docs/ui",
    description:
      "See how primitives consume semantic roles across real product interfaces.",
    icon: Blocks,
  },
  {
    title: "Starter Pro",
    href: "/docs/starter-pro",
    description:
      "Move from UI consistency to production foundations with auth, billing, and backend structure.",
    icon: Sparkles,
  },
]}
/>