# Layout Rules first, then patterns to copy. All values come from `assets/tokens.css`. ## Rules - Spacing between siblings comes from `gap` on a flex/grid parent. Margins only for one-off offsets. - One side gutter, set once on the outer wrapper: `padding-inline: var(--gutter)`. Use `padding-block` for vertical padding so the sides never get zeroed by a shorthand. - Design at ~400px and ~1280px, then check 768px. Rows wrap or stack to one column on phones. - Flex/grid children that hold text, code or tables get `min-width: 0`. - Only tables, code blocks and diagrams may be wider than the screen, each inside an `overflow-x: auto` wrapper. - Size heroes to their content, never `100vh`. For full-screen apps, use `height: 100dvh` on the shell (or `100%` from `html`/`body`), not `100vh`. - Let content set heights. Don't stretch cards over empty space. Choose column counts the items fill. - Left-align by default. Center only short, self-contained things (an empty state, a one-line hero on a launch page). - Vertical rhythm: inside a component `--space-2` to `--space-4`; between components `--space-6` to `--space-8`; between page sections `--space-12` to `--space-24`. ## Page container ```css .page { padding-inline: var(--gutter); padding-block: var(--space-8) var(--space-16); } .container { max-width: var(--content-max); margin-inline: auto; } .prose { max-width: var(--prose-max); } .stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--space-4)); } .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--space-3)); } ``` ## Auto-fitting grid (cards, galleries) ```css .grid-auto { display: grid; gap: var(--space-6); grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); } ``` ## Sidebar + content (docs, settings) ```css .with-sidebar { display: grid; gap: var(--space-8); grid-template-columns: 1fr; } @media (min-width: 900px) { .with-sidebar { grid-template-columns: 15rem minmax(0, 1fr); } } .with-sidebar > aside { position: sticky; top: var(--space-6); align-self: start; } ``` ## App shell (tools, dashboards) ```css .app { display: grid; height: 100dvh; grid-template-rows: auto 1fr; grid-template-columns: 1fr; } @media (min-width: 900px) { .app { grid-template-columns: 15rem minmax(0, 1fr); grid-template-areas: "nav top" "nav main"; } .app > nav { grid-area: nav; border-right: 1px solid var(--border); } .app > header { grid-area: top; } .app > main { grid-area: main; } } .app > header { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--gutter); border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: var(--z-sticky); } .app > main { overflow: auto; padding: var(--space-6) var(--gutter); } ``` On phones the nav becomes a top bar with a menu button or a bottom tab bar (max 5 items). ## Dashboard - Order: page title and time range → the 3 to 5 numbers that matter → the main chart → supporting tables. - KPI row: `grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr))`. Each tile shows label, value (`tabular-nums`), change vs. previous period with a semantic color, and optionally a sparkline. - Status shown in form: a colored dot or pill plus a word, never color alone. - Tables: sticky header, right-aligned numbers, muted secondary columns, row hover in `--surface-2`. ## Editorial / landing page - The hero states the thesis: the subject's most characteristic thing (a headline set big, a live demo, a striking image), sized to content. - Break the grid on purpose once: an oversized type moment, a full-bleed band, an asymmetric 7/5 split. Keep the rest on a calm 12-column grid: ```css .grid-12 { display: grid; gap: var(--space-6); grid-template-columns: repeat(12, minmax(0, 1fr)); } .span-7 { grid-column: span 7; } .span-5 { grid-column: span 5; } @media (max-width: 800px) { .grid-12 > * { grid-column: 1 / -1; } } ``` - Full-bleed bands keep the gutter on their inner wrapper, not the band itself. - Section headings are left-aligned with a short lead paragraph. No eyebrow on every section; use one only when it encodes something (a category, a step). - End with one clear call to action, not three. ## Forms - One column. Labels above inputs. Group related fields with a heading, not a box around each. - Inputs width by expected content (a ZIP code field is short), max ~32rem for text fields. - Primary action at the end, left-aligned with the fields; secondary actions as quieter buttons next to it. - Validate on blur and on submit; inline errors under the field in `--danger` with an icon and text.