# Web style organization

The global CSS mirrors the component tree: styling a component means opening one file, named after it.

```
apps/web/app/
  globals.css       entry: tailwindcss → design → themes → styles
  styles/
    index.css       imports the global layer in cascade order
    design/         design tokens and Tailwind's names for them
    themes/         colour values, one file per theme (+ fallback.css)
    base/           document, focus, list row, shell layout, scrollbar,
                    sidebar, desktop chrome, motion, canvas drag, phone
    chat/           pane/ messages/ cards/ execution/ composer/ welcome/
    dag/            graph/ panels/
    right-dock/     right-sidebar panels
```

`index.css` cascade: base, chat, right-dock, dag, then `base/phone.css` last ([phone layout](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/phone-layout.html)). Tokens and tiers: [Design tokens](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/visual-system/design-tokens.html).

## Rules

| Rule | Detail |
| --- | --- |
| One component, one file | Opens with a comment naming the component and its source path. New components get new files. |
| Placement follows the tree | `dag/graph/nodes.css` for the drawer in `lib/runtime-bridge/dag/render/nodes.ts`; `chat/messages/bubbles.css` for a chat bubble |
| Global stays global | Tokens in `design/`, theme values in `themes/`, the shell in `base/`. `chat/pane/layout.css` (`.main`, `#chatView`) is the one deliberately cross-component file. |
| Module CSS stays | Components on `*.module.css` (the composer) keep it; this tree is the global layer only |
| Style tests | Read the per-component file through postcss, as `apps/web/tests/tabs/canvas/canvas-css-geometry.test.mjs` does for the center-tabs modules |

## No native scrollbars

`base/scrollbar.css` hides them at zero specificity, because macOS Chromium flashes one whenever the pointer enters a scrollable box. `lib/runtime-bridge/dom/scrollbar.ts` installs a thin floating thumb the first time a box scrolls.

| Aspect | Behaviour |
| --- | --- |
| Shows | Only while the box scrolls or the thumb is held; fades 900ms later. Vertical, and horizontal when the box overflows sideways. |
| Never shows for | Hovering, resizing, content changes. A faded thumb takes no pointer events. |
| Layout | Takes no width |
| Layer | The layer of its box: the z-index of the box's outermost layered ancestor (a dialog, a popover, a drawer), or the sticky layer for a box in the page, so a menu opened over a scrolling box covers its thumb. `data-scrollbar-layer="content"` keeps it above the box's rows and under a control on its edge (Agent list, Agent grid). |
| Press | A press on the thumb stays with the thumb. The thumb is a child of `<body>`, outside any menu or dialog, so a menu or dialog would otherwise read the press as one outside it and close. |
| Shadow root | Hides its own bar and calls `attachOverlayScrollbar` |
| No thumb | `data-scrollbar="none"` on a box that must show none: the message rail, whose ticks are its position |

## Type

| Aspect | Rule |
| --- | --- |
| Sizes | Nine tiers in `design/type.css`, `--fs-2xs` (11px) to `--fs-display` (30px); assignment under [Type](https://fzkuji.github.io/OpenProgram/docs/reference/design/ui/visual-system/design-tokens.html#type). `apps/web/scripts/ui/check-design-tokens.mjs` (in `npm run check`) refuses any other size. |
| Faces | Inter and JetBrains Mono Latin files through `next/font` (`app/fonts.ts`): preloaded, `display: block`, so no fallback paint and reflow. Other scripts use `@fontsource`. |
| Language | Exported HTML is English. For another locale the head script marks `<html data-locale-pending>`, hiding the body; `useTranslation` switches in a layout effect before paint and removes the mark. Without the script, the page shows after 1.5s. |
