/* The back office's base (surface.css, first translated from the design system's app.css). Two
 * independent modes, each set by the app on <html>: `data-density="compact"` (spacing) and
 * `data-surface="app"` (the app's colours). A page with neither renders exactly as a website.
 *
 * Compact density: back-office spacing for forms and tables. The app sets
 * `data-density="compact"` on its root. Density only sets component hooks (`--wi-btn-*` for
 * Button; `--wi-field-*` for TextField, SelectTrigger/Select, PhoneInput and TextArea;
 * `--wi-pagination-*` for Pagination), never a
 * global token, so nothing outside those components changes. Each component reads its hooks with
 * today's website values as fallbacks: a page without the attribute (or without this file) renders
 * exactly as before.
 *
 * In compact, fields get almost no block padding: `min-height` sets the height and the content is
 * centred, so a field stays 40px whatever it holds (text, a pill, an inline 32px Button).
 *
 * Values: compact Button decided by Stan (2026-10-21) — 8px corners, 32/40px; compact fields
 * decided by Yannick (2026-10-21) — 40px in forms, 32px in tables, 8px corners.
 * Figma follows (token question bundled for Sarah). */

/* `:root[…]`: the app sets both modes on <html>, and the extra specificity keeps these winning over
   tokens.css's `:root` whatever order the stylesheets load in. */
:root[data-density='compact'] {
  /* Button: 32/40px instead of 36/44, square-cornered instead of a pill. */
  --wi-btn-height-sm: var(--size-control-sm);
  --wi-btn-height-md: var(--size-control-md);
  --wi-btn-radius: var(--radius-md);
  --wi-btn-padding-x-sm: var(--space-3);
  --wi-btn-padding-x-md: var(--space-4);
  --wi-btn-font-size-md: var(--font-size-sm);
  --wi-btn-line-height-md: var(--font-line-height-sm);

  /* Fields: md 40px instead of 48 (forms), sm 32px instead of 36 (table cells). */
  --wi-field-height-md: var(--size-control-md);
  --wi-field-height-sm: var(--size-control-sm);
  --wi-field-radius: var(--radius-md);
  --wi-field-padding-block: var(--space-0-5);
  --wi-field-padding-inline: var(--space-3);
  --wi-field-font-size: var(--font-size-sm);
  --wi-field-line-height: var(--font-line-height-sm);

  /* Pagination: 32px like the table rows it pages and the controls in their cells, 8px corners like
     the app's buttons and fields, instead of 40px pills. */
  --wi-pagination-height: var(--size-control-sm);
  --wi-pagination-radius: var(--radius-md);
}

/* Touch screens: iOS Safari zooms into any input under 16px on focus, so compact fields keep the
   website text size there. Heights and corners stay compact. */
@media (pointer: coarse) {
  :root[data-density='compact'] {
    --wi-field-font-size: var(--font-size-base);
    --wi-field-line-height: var(--font-line-height-base);
  }
}

/* App surface: the app's colours. The turquoise action must meet WCAG AA, and white on the website
 * turquoise (turquoise-600) is only 3.7:1, so inside the app the turquoise semantic tokens move one
 * step darker: white on turquoise-700 is 5.3:1. Every user of these tokens in the app follows (the
 * `secondary` Button, the current SidebarNav and BottomTabBar items). The success and warning
 * feedback text colours and the focus rings move the same way. Websites keep their tokens until they are fixed for everyone (decided by Yannick, 2026-10-21; Figma follows). */
:root[data-surface='app'] {
  --brand-secondary-bg: var(--turquoise-700);
  --brand-secondary-bg-hover: var(--turquoise-800);
  --brand-secondary-bg-pressed: var(--turquoise-900);

  /* The app's canvas (decided by Axel, 2026-11-25, WI-12448): one light navy tint behind the sidebar and the page, with
     no band behind a header, so nothing changes colour as the page scrolls; white cards and tables sit on it, ringed
     by its edge. `edge` is its line and its hover. A page without the app surface has neither: each reader keeps its
     own colour as the fallback. */
  --wi-app-canvas: var(--blue-gray-50);
  --wi-app-canvas-edge: var(--blue-gray-100);
  --wi-card-shadow: 0 0 0 var(--border-1) var(--wi-app-canvas-edge), var(--shadow-sm);

  /* The app's own sidebar width (decided by Axel, 2026-11-26; narrowed to 220px by Stan the same day, WI-12461): room
     for a tree with its labels on one line. AppShell's grid reads it with tokens.css's --layout-sidebar as the
     fallback. */
  --wi-app-sidebar-width: 220px;

  /* Feedback text on its tinted background (Badge, Notice): success and warning fail AA on the
     website tokens (4.2:1 and 2.8:1); one step darker passes (5.9:1 and 6.5:1). */
  --feedback-success-fg: var(--green-700);
  --feedback-warning-fg: var(--amber-800);

  /* Focus indicators need 3:1 against what they sit on (WCAG 1.4.11); the website turquoise-500 is
     1.9:1 on white. The rings keep their shape (a 2px light gap, then 2px of colour), in
     turquoise-700: 5.3:1 on white. On navy the inverse ring stays light, so it is not changed. */
  --border-focus: var(--turquoise-700);
  --focus-ring: 0 0 0 var(--border-2) var(--background-surface),
    0 0 0 calc(2 * var(--border-2)) var(--turquoise-700);
  --focus-ring-gray: 0 0 0 var(--border-2) var(--background-sunken),
    0 0 0 calc(2 * var(--border-2)) var(--turquoise-700);

  /* Field state hooks, read by the field components with the website values as fallbacks. Error
     border (TextField, TextArea, PhoneInput, SelectTrigger, Checkbox, Radio): the website colour
     (--feedback-error-border) is too faint to see in a dense form, so the app uses the error text
     colour. Hover border (TextField, TextArea, PhoneInput, SelectTrigger): the website value is
     kept; TextField, TextArea and PhoneInput have no hover on websites, so this is where the app
     gets one. Checkbox box hover: brand colour instead of border-strong. */
  --wi-field-error-border: var(--feedback-error-fg);
  --wi-field-hover-border: var(--border-strong);

  --wi-checkbox-hover-border: var(--brand-primary);

  /* A form field's focus (TextField, a multiline one too, Combobox's and DatePicker's fields, SelectTrigger, CodeBoxes),
     instead of the ring buttons keep: a 2px edge, the border and an inset line of its colour, and a thin soft halo of
     it around (`shadow`, the two together; a code box's border is 2px already: it takes the colour and the `halo`).
     The edge shows the focus: 2px of the focus colour (turquoise-700, 5.3:1 on white) meets WCAG 2.4.13, which a 1px
     border doesn't and the halo can't. In error the edge stays red, now 2px, and the halo turns red, so a field in
     error still shows when it has the focus. A menu's own search (a Combobox's sheet, a FilterSelect) keeps its
     quieter line: it is the only field there. */
  --wi-field-focus-border: var(--border-focus);
  --wi-field-focus-halo: 0 0 0 calc(3 * var(--border-1)) color-mix(in srgb, var(--border-focus) 25%, transparent);
  --wi-field-focus-shadow: inset 0 0 0 var(--border-1) var(--border-focus), var(--wi-field-focus-halo);
  --wi-field-error-focus-halo: 0 0 0 calc(3 * var(--border-1)) color-mix(in srgb, var(--wi-field-error-border) 25%, transparent);
  --wi-field-error-focus-shadow: inset 0 0 0 var(--border-1) var(--wi-field-error-border), var(--wi-field-error-focus-halo);

  /* Pagination: hovered like a field (a stronger border and a sunken fill, no lift), and the
     current page in the app's selected state, as SidebarNav's current item: the light accent fill,
     with turquoise text and border (turquoise-700 on turquoise-50 is 5.0:1). The website's navy
     pill would be the only inverse fill in the app. */
  --wi-pagination-hover-border: var(--border-strong);
  --wi-pagination-hover-bg: var(--background-sunken);
  --wi-pagination-hover-shadow: none;
  --wi-pagination-current-bg: var(--background-accent-subtle);
  --wi-pagination-current-fg: var(--text-link);
  --wi-pagination-current-border: var(--brand-secondary-bg);
  --wi-pagination-current-weight: var(--font-weight-semibold);
}
