# Urban OS component contracts

## Naming

`UOS / Category / Component / Variant / State`

Examples:

- `UOS/Button/Primary/Default`
- `UOS/Field/Text/Error`
- `UOS/Shell/Workspace/Default`
- `UOS/Spatial/HUD/Loading`

## Universal states

Every interactive component documents applicable states:

- default;
- hover;
- focus-visible;
- active or selected;
- disabled;
- loading or processing;
- error;
- success;
- empty;
- offline;
- stale;
- permission denied;
- conflict.

## Buttons and links

- Button performs an action; link changes location.
- One primary action per decision area.
- Default action labels stay on one line. A necessary long label may use at most two balanced lines with `height: auto`, intact horizontal padding and a minimum 44 px target.
- Do not shrink all interface text to solve one overflow. Use 13–14 px for ordinary buttons, 11–12 px for compact utility controls and shorten the verb before reducing legibility.
- At narrow widths, long primary actions normally become full-width. Never crop a verb, arrow or status suffix.
- Loading keeps the original label or accessible name and exposes progress.
- Disabled controls explain why when the reason is not obvious.
- Destructive actions use explicit verbs and require confirmation at action time.

## Theme switch

- The visible label and icon describe the destination, not the current state.
- In light mode show `Тёмная` with a moon; in dark mode show `Светлая` with a sun.
- The accessible name also states the action, while `aria-pressed` exposes the current dark-mode state.
- Theme choice uses the canonical storage key and remains synchronized between shells.

## Lifecycle stage color

- Reuse the 12 ordered values from `UrbanOSDesignSystem.stageColors` or `design-tokens.json`; do not invent a local stage palette.
- Always pair the color with the two-digit stage number and a visible stage name or status.
- Stage color marks navigation, progress, chips and lightweight accents; it does not replace semantic success, warning or error colors.
- Test every stage accent on both canonical themes and never place small body copy directly in a stage color without a contrast check.

## Guided product tour

- Load `/shared/uos-tour.css` and `/shared/uos-tour.js`, add `data-uos-tour-launch` to the help trigger and create the tour with `window.UOSTour.create()`.
- Every step names a stable page selector, a short outcome-led title and one concise description. A tour must explain the workflow, not every visible control.
- Preserve visible progress, Back, Next/Finish, Skip and Close. Escape closes; Left/Right move between steps; Tab stays inside the tour card.
- The spotlight never blocks the described element from view. Compact layouts use a bottom sheet; RTL and reduced motion are inherited automatically.
- Closing restores focus to the launcher. Never launch automatically after the user has already completed or dismissed the tour unless onboarding policy explicitly requires it.

## Global shell and IVA

- Load `/shared/uos-shell.css` and `/shared/uos-shell.js`; mount with `data-uos-shell` and do not create a route-local header, locale selector, theme switch, sign-in dialog or profile menu.
- The shell reads the real session from `/1/api/profile.php`, uses real Google, Telegram and VK ID start routes, and shows the developer workspace only when `canDeveloperCabinet` is true.
- Product dictionaries listen for `uos:localechange`; they do not write another locale storage key. Product themes inherit tokens and may listen for `uos:themechange`; they do not create another theme key.
- Load `/shared/uos-assistant.css` and `/shared/uos-assistant.js`. Configure page/stage/quick-question context. Guest mode provides honest navigation help; authenticated AI uses `/1/api/assistant.php`.
- Omitting the shared shell or IVA requires a recorded accessibility, performance or security exception with an owner and removal condition.

## Spatial workspace

- A 3D specimen is a digital-twin workspace, not a decorative model.
- Show real object identity, source/verification, selectable objects, camera presets, zoom and controllable analytical layers.
- Architecture uses façade rhythm, materials, landscape, mobility and site context; avoid anonymous low-poly blocks.
- Preserve a text equivalent, keyboard camera control, reduced motion, performance limits and static fallback.

## Fields and forms

- Persistent visible label; placeholder is optional help.
- Error is associated with the field and explains recovery.
- Required/optional is stated consistently.
- Preserve user input after validation or server failure.
- International phone, address, name and number formats must not assume Russia-only input.

## Tables and collections

- Header, sort, filters, result count and selection state are explicit.
- Long identifiers truncate visually but remain copyable.
- Empty, loading and error states occupy the collection region.
- Mobile uses scoped horizontal scrolling or a documented card representation.

## Menus, dialogs and overlays

- Trigger exposes expanded state.
- Focus enters and returns correctly.
- Escape closes non-destructive overlays.
- Dialog title describes the decision.
- Background click never confirms an action.

## Files, artifacts and versions

Required metadata:

- file or artifact identifier;
- format and size;
- source and author;
- created/updated time;
- processing status;
- version and lineage;
- license/publicity where applicable;
- compatible modules;
- real download or explicitly disabled/planned action.

## Async jobs

Canonical states: `queued`, `processing`, `paused`, `failed`, `canceled`, `completed`.

Show object, stage, progress, time estimate, last update and available recovery. Do not invent progress when the server provides none; use indeterminate loading.

## Roles and permissions

Canonical access levels: `viewer`, `editor`, `manager`, `owner`.

The server is authoritative. The client may hide or disable actions for clarity but must handle a server denial. Use 403 for absent access and 409 for conflicting versions.

## Feedback

- Toast confirms secondary events and never contains the only copy of an error.
- Inline alert stays near the affected workflow.
- Notification center contains durable user events.
- Audit history records consequential actions.

## Accessibility

- Body text target contrast: 4.5:1.
- Large text and non-text UI: 3:1.
- Target size: normally 44×44 CSS px.
- Do not encode state with color alone.
- Support keyboard, screen reader name/role/state, RTL and reduced motion.
