/* Post Box Express — design tokens.
   Source of truth: docs/design.md §3 and docs/09-audit/frontend-audit.md.
   Components reference these names, never a raw brand hex.
   Loaded first on every page, before components.css and any page stylesheet. */

/* Inter (variable, 400–700), self-hosted so the declared UI face is real in
   every deployment. Two subsets keep the payload at ~130 KB. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light;

  /* ── Type ─────────────────────────────────────────────────────────────
     One face, one ladder. Weights 400/500/600/700 are the only reachable
     steps: the face above declares 400–700, so 750 and 800 clamp silently
     (frontend audit UI-012). */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco,
    Consolas, "Liberation Mono", monospace;

  --font-size-2xs: 11px;   /* uppercase table headers, badges, meta */
  --font-size-xs: 12px;    /* secondary table text, help text */
  --font-size-sm: 13px;    /* body, controls, table cells */
  --font-size-md: 14px;    /* emphasised body, panel titles */
  --font-size-lg: 16px;    /* section headings */
  --font-size-xl: 18px;    /* page title, dense registers */
  --font-size-2xl: 22px;   /* page title, standard */
  --font-size-3xl: 28px;   /* display figures */

  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  --line-height-tight: 1.2;
  --line-height-snug: 1.35;
  --line-height-normal: 1.5;

  --letter-spacing-tight: -0.011em;
  --letter-spacing-caps: 0.06em;

  /* ── Space (2 px base; every value is a multiple of 2) ───────────────── */
  --space-2: 2px;
  --space-4: 4px;
  --space-6: 6px;
  --space-8: 8px;
  --space-10: 10px;
  --space-12: 12px;
  --space-14: 14px;
  --space-16: 16px;
  --space-18: 18px;
  --space-20: 20px;
  --space-24: 24px;
  --space-32: 32px;
  --space-40: 40px;
  --space-48: 48px;
  --space-64: 64px;

  /* ── Radius ─────────────────────────────────────────────────────────── */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --radius-circle: 50%;

  /* ── Elevation ──────────────────────────────────────────────────────── */
  --shadow-xs: 0 1px 2px color-mix(in srgb, var(--color-text-primary) 6%, transparent);
  --shadow-sm: 0 1px 3px color-mix(in srgb, var(--color-text-primary) 8%, transparent);
  --shadow-md: 0 8px 20px color-mix(in srgb, var(--color-text-primary) 10%, transparent);
  --shadow-lg: 0 18px 40px color-mix(in srgb, var(--color-text-primary) 14%, transparent);
  --shadow-focus: 0 0 0 3px color-mix(in srgb, var(--color-focus-ring) 22%, transparent);

  /* ── Controls ───────────────────────────────────────────────────────── */
  --control-height-3xs: 24px;
  --control-height-2xs: 26px;
  --control-height-xs: 28px;
  --control-height-sm: 32px;
  --control-height: 36px;
  --control-height-lg: 40px;
  --control-padding-x: var(--space-10);

  /* ── Motion ─────────────────────────────────────────────────────────── */
  --duration-fast: 120ms;
  --duration-base: 160ms;
  --duration-slow: 240ms;
  --easing-standard: cubic-bezier(0.2, 0, 0, 1);

  /* ── Layers ─────────────────────────────────────────────────────────── */
  --z-base: 0;
  --z-content: 1;
  --z-content-raised: 2;
  --z-menu: 5;
  --z-raised: 10;
  --z-desk-index: 24;
  --z-panel: 30;
  --z-topbar: 40;
  --z-shell-scrim: 45;
  --z-sidebar: 50;
  --z-desk-popover: 81;
  --z-desk-sticky: 90;
  --z-sticky: 100;
  /* Popovers (dropdowns, pickers) must cover in-page sticky layers — the desk
     section index sits at 24 and the desk action bar at 100 — and still lose to
     a dialog. `PostBox_Enterprise_Design_System.md` names this step
     `--z-dropdown`; it documents 200, which here collides with `--z-nav`. */
  --z-dropdown: 150;
  --z-nav: 200;
  --z-scrim: 300;
  --z-dialog: 400;
  --z-toast: 500;

  /* ── Breakpoints ────────────────────────────────────────────────────────
     Media queries cannot read custom properties; these document the six
     widths the product uses. Write the literals in `@media`:
       640px (sm) · 768px (md) · 1024px (lg) · 1280px (xl) · 1440px (2xl) ·
       1560px (3xl) */
  --bp-sm: 640px;
  --bp-md: 768px;
  --bp-lg: 1024px;
  --bp-xl: 1280px;
  --bp-2xl: 1440px;
  --bp-3xl: 1560px;

  /* ── Brand ────────────────────────────────────────────────────────────
     Anchored to the logo pair: botanical green #409078 and transport blue
     #3080C0. The interactive primary is the logo green taken down in
     lightness (hue held at the mark's 162°) so white labels clear AA; the
     logo tone itself stays available as the light primary tint and as
     illustration. The logo blue is the non-text accent; secondary and link
     are its accessible darker steps. */
  --color-primary: #1E6B54;
  --color-primary-hover: #175743;
  --color-primary-light: #E3F1EA;
  --color-secondary: #2A72A6;
  --color-secondary-hover: #205C88;
  --color-accent: #3080C0;
  --color-accent-light: #E7F1F9;

  /* ── Section header band ────────────────────────────────────────────────
     The logo blue (#3080C0) taken down to a page-scale tint: the AWB desks
     paint each section header with it, so the entry reads as a live surface
     while the field body stays on white. `-border` is the band's bottom
     hairline. */
  --color-accent-wash: #E7F0FA;
  --color-accent-wash-border: #C9DDEF;

  /* ── Brand panel band ───────────────────────────────────────────────────
     The logo's own deep blue (#0063AC), sampled from `static/img/logo.png`,
     for section heads that carry the brand colour instead of the pale wash.
     The band is self-contained: white ink reads 6.21 : 1 on the fill and the
     muted tint 4.74 : 1, so the same names work in both themes. */
  --color-brand-band: #0063AC;
  --color-brand-band-hover: #00518D;
  --color-brand-band-ink: #FFFFFF;
  --color-brand-band-ink-muted: #CFE3FB;

  /* ── Shell navigation ────────────────────────────────────────────────────
     The rail is a pale blue slab (#E8F2FF) carrying the brand's deep pine ink,
     with the light-surface logo artwork on it. Side link labels use
     --color-nav-text (#10382F, 11.41 : 1 on the rail); hover and current group
     headings use --color-nav-text-bright (#0B2B22, 13.43 : 1). Rows lift to
     --color-nav-hover (#CFE3FB) and the current page is a --color-nav-selected
     deep-pine pill with --color-nav-selected-text mint ink (11.09 : 1).
     --color-nav-active stays green: admin.css uses it for selected rows. */
  --color-nav-background: #E8F2FF;
  --color-nav-text: #10382F;
  --color-nav-text-bright: #0B2B22;
  --color-nav-hover: #CFE3FB;
  --color-nav-selected: #10382F;
  --color-nav-selected-text: #E4F1EA;
  --color-nav-active: #E4F1EA;
  --color-nav-border: #A8C6E8;
  --color-nav-group: #3F5B78;

  /* ── Surfaces ─────────────────────────────────────────────────────────
     Tinted a trace toward the logo green (hue 150) so gray reads authored
     next to the brand rather than borrowed from a neutral SaaS palette. */
  --color-background: #FFFFFF;
  --color-background-secondary: #F6F9F7;
  --color-surface: #FFFFFF;
  --color-section: #F0F6F3;
  --color-surface-elevated: #FFFFFF;
  --color-overlay: #0E2A22D9;

  /* ── Three-layer surface elevation (hairline-only, no heavy shadows) ──
     Use --bg-canvas for the page substrate, --bg-surface for cards/panels
     that sit on it, --bg-elevated for elements that lift above a surface
     (e.g. a sticky toolbar, an inline detail pane). Each level is separated
     by a 1px --border-subtle hairline rather than a drop shadow so dense
     data tables stay uncluttered. */
  --bg-canvas:   #F5F8F6;   /* page background in app shell          */
  --bg-surface:  #FFFFFF;   /* panels, cards, table bodies           */
  --bg-elevated: #FAFCFB;   /* topbar sticky band, raised sections   */
  --border-subtle: color-mix(in srgb, var(--color-border) 55%, transparent);

  /* ── Semantic shipment-status pill tokens ────────────────────────────
     Every shipment status badge and manifest-row pill reads from these
     pairs. bg is the muted fill; fg is the high-contrast text that clears
     WCAG AA on the fill. Add new statuses here — never hard-code tones in
     module CSS. */
  --status-booked-bg:   var(--color-information-soft);
  --status-booked-fg:   var(--color-information);
  --status-transit-bg:  var(--color-warning-soft);
  --status-transit-fg:  var(--color-warning);
  --status-hold-bg:     color-mix(in srgb, var(--color-warning-soft) 60%, var(--color-error-soft));
  --status-hold-fg:     var(--color-warning);
  --status-delivered-bg: var(--color-success-soft);
  --status-delivered-fg: var(--color-success);
  --status-failed-bg:   var(--color-error-soft);
  --status-failed-fg:   var(--color-error);
  --status-draft-bg:    var(--color-neutral-soft);
  --status-draft-fg:    var(--color-text-muted);
  --status-cancelled-bg: var(--color-neutral-soft);
  --status-cancelled-fg: var(--color-text-muted);

  /* ── Tabular-nums shorthand ──────────────────────────────────────────
     Applied to any cell carrying an AWB number, weight, dimension or
     monetary value so digits align vertically in the register columns. */
  --font-numeric: tabular-nums slashed-zero;

  /* ── Ink ────────────────────────────────────────────────────────────────
     All three steps clear WCAG AA on white, on --color-section and on
     --color-background-secondary (frontend audit UI-006). The top step is a
     green-cast near-black so headings sit in the logo family. */
  --color-text-primary: #12241E;    /* 16.19 : 1 on white, 15.28 on bg-2 */
  --color-text-secondary: #5A6F67;  /* 5.38 : 1 on white, 5.07 on bg-2 */
  --color-text-muted: #5A6F67;      /* the secondary step; hierarchy is size */
  --color-text-inverse: #FFFFFF;
  --color-link: #1E6A9B;            /* 5.85 : 1 on white */

  /* ── Lines ──────────────────────────────────────────────────────────────
     --color-input-border is a UI boundary, so it must clear 3 : 1 against
     the surface behind it (WCAG 1.4.11). #BFCFC7 measured 1.62 : 1. */
  --color-border: #DFE9E4;
  --color-divider: #ECF2EF;
  --color-input-background: #FFFFFF;
  --color-input-border: #74877F;        /* 3.81 : 1 on white, 3.59 on bg-2 */
  --color-input-border-strong: #647A72;
  --color-focus-ring: #1E6B54;
  --color-button-background: #1E6B54;
  --color-button-text: #FFFFFF;         /* 6.39 : 1 on the button fill */

  /* ── Selection ──────────────────────────────────────────────────────────
     Text selection is a brand role, not the browser default. Without it the
     OS blue clashes with the green/blue pair and changes between platforms.
     The fill is the same 6.39 : 1 pairing as the primary button. */
  --color-selection-background: #1E6B54;
  --color-selection-text: #FFFFFF;

  /* ── Status ─────────────────────────────────────────────────────────────
     Text tones clear AA on white; the -soft tones are fills behind text of
     the matching tone, never colour-only signals. */
  --color-success: #1C7048;
  --color-success-soft: #E4F2EA;
  --color-success-border: #B2D9C3;
  --color-warning: #8A540C;
  --color-warning-soft: #FBF0DF;
  --color-warning-border: #E7CDA2;
  --color-error: #B0363E;
  --color-error-soft: #FBEBEB;
  --color-error-border: #EBBDC0;
  --color-information: #206E9B;
  --color-information-soft: #E7F1F8;
  --color-information-border: #B8D6E9;
  --color-neutral-soft: #EDF2EF;
  --color-neutral-border: #D8E5DF;
}

/* ── Dark theme ──────────────────────────────────────────────────────────
   The same semantic names, resolved for a dark surface. Switching the
   `data-theme` attribute on <html> is the only thing the shell does; every
   component keeps reading the token it already read, so a screen cannot be
   half-converted. Text tones clear WCAG AA on the surface beside them. */
html[data-theme="dark"] {
  color-scheme: dark;

  /* The logo pair lifted for a dark surface: the same hue, less chroma so
     the accent does not glow, and a lighter mint that clears AA on the dark
     canvas instead of the light theme's deep pine. */
  --color-primary: #6FD3B0;
  --color-primary-hover: #8BE0C4;
  --color-primary-light: #102B22;
  --color-secondary: #7CB9E2;
  --color-secondary-hover: #9BCDEF;
  --color-accent: #7CB9E2;
  --color-accent-light: #102A38;

  --color-accent-wash: #0F2130;
  --color-accent-wash-border: #204157;

  /* The brand band is theme-independent: the logo blue and its inverse ink
     keep their ratios on the dark canvas, so the same names resolve. */
  --color-brand-band: #0063AC;
  --color-brand-band-hover: #00518D;
  --color-brand-band-ink: #FFFFFF;
  --color-brand-band-ink-muted: #CFE3FB;

  /* The rail follows the theme: a deep green-black slab lifted off the page
     canvas (#0A1210, 1.19 : 1) and distinct from --color-surface (#0F1A16,
     1.12 : 1), carrying mint-grey ink. --color-nav-text (#B9CCC4) is 9.47 : 1
     on the rail; --color-nav-text-bright (#EAF5F0) is 14.27 : 1. Rows lift to
     a darker --color-nav-hover (#17332B) instead of a light wash, and the
     current page is the theme's mint --color-nav-selected (#6FD3B0) with dark
     ink --color-nav-selected-text (#04120D, 10.59 : 1). --color-nav-active is
     the dark admin selected-row fill: light admin text clears it at
     12.12 : 1. --color-nav-group (#93ABA3) is 6.52 : 1 on the rail. */
  --color-nav-background: #10261F;
  --color-nav-text: #B9CCC4;
  --color-nav-text-bright: #EAF5F0;
  --color-nav-hover: #17332B;
  --color-nav-selected: #6FD3B0;
  --color-nav-selected-text: #04120D;
  --color-nav-active: #143026;
  --color-nav-border: #22392F;
  --color-nav-group: #93ABA3;

  --color-background: #0A1210;
  --color-background-secondary: #080F0D;
  --color-surface: #0F1A16;
  --color-section: #13211C;
  --color-surface-elevated: #17251F;
  --color-overlay: #00000099;

  --bg-canvas:   #080F0D;
  --bg-surface:  #0F1A16;
  --bg-elevated: #16241E;
  --border-subtle: color-mix(in srgb, var(--color-border) 55%, transparent);

  --status-booked-bg:    var(--color-information-soft);
  --status-booked-fg:    var(--color-information);
  --status-transit-bg:   var(--color-warning-soft);
  --status-transit-fg:   var(--color-warning);
  --status-hold-bg:      color-mix(in srgb, var(--color-warning-soft) 60%, var(--color-error-soft));
  --status-hold-fg:      var(--color-warning);
  --status-delivered-bg: var(--color-success-soft);
  --status-delivered-fg: var(--color-success);
  --status-failed-bg:    var(--color-error-soft);
  --status-failed-fg:    var(--color-error);
  --status-draft-bg:     var(--color-neutral-soft);
  --status-draft-fg:     var(--color-text-muted);
  --status-cancelled-bg: var(--color-neutral-soft);
  --status-cancelled-fg: var(--color-text-muted);

  --font-numeric: tabular-nums slashed-zero;

  --color-text-primary: #E7EFEB;
  --color-text-secondary: #A6B8B0;
  --color-text-muted: #96A9A1;
  --color-text-inverse: #07110D;
  --color-link: #86C8EE;

  --color-border: #243630;
  --color-divider: #1B2A25;
  --color-input-background: #0A1210;
  --color-input-border: #6B8078;
  --color-input-border-strong: #859A92;
  --color-focus-ring: #6FD3B0;
  --color-button-background: #46B492;
  --color-button-text: #04120D;

  /* Mint on the deep rail, not an inverted light fill: a light selection band
     flashing on a dark sheet is the loudest thing on the screen. */
  --color-selection-background: #6FD3B0;
  --color-selection-text: #04120D;

  --color-success: #74D6A4;
  --color-success-soft: #0F2A1F;
  --color-success-border: #2D6B4E;
  --color-warning: #E9B36A;
  --color-warning-soft: #2C2213;
  --color-warning-border: #6B5227;
  --color-error: #F18C92;
  --color-error-soft: #2E1618;
  --color-error-border: #6E3438;
  --color-information: #82C3E9;
  --color-information-soft: #0F2633;
  --color-information-border: #2C556E;
  --color-neutral-soft: #1A2622;
  --color-neutral-border: #2B3B35;

  /* Elevation reads as shade, not as a light halo, once the ink is light. */
  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.42);
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.5);
  --shadow-md: 0 8px 20px rgb(0 0 0 / 0.55);
  --shadow-lg: 0 18px 40px rgb(0 0 0 / 0.6);
}

/* A document preview is paper, not chrome: it keeps the light palette in a
   dark session so the sheet on screen matches the PDF the operator prints.
   Only the preview surface carries `data-paper`; the generated PDF has no
   theme attribute and resolves `:root` directly. */
html[data-theme="dark"] [data-paper] {
  color-scheme: light;

  --color-primary: #1E6B54;
  --color-primary-hover: #175743;
  --color-primary-light: #E3F1EA;
  --color-secondary: #2A72A6;
  --color-secondary-hover: #205C88;
  --color-accent: #3080C0;
  --color-accent-light: #E7F1F9;
  --color-accent-wash: #E7F0FA;
  --color-accent-wash-border: #C9DDEF;

  --color-brand-band: #0063AC;
  --color-brand-band-hover: #00518D;
  --color-brand-band-ink: #FFFFFF;
  --color-brand-band-ink-muted: #CFE3FB;

  --color-nav-background: #E8F2FF;
  --color-nav-text: #10382F;
  --color-nav-text-bright: #0B2B22;
  --color-nav-hover: #CFE3FB;
  --color-nav-selected: #10382F;
  --color-nav-selected-text: #E4F1EA;
  --color-nav-active: #E4F1EA;
  --color-nav-border: #A8C6E8;
  --color-nav-group: #3F5B78;

  --color-background: #FFFFFF;
  --color-background-secondary: #F6F9F7;
  --color-surface: #FFFFFF;
  --color-section: #F0F6F3;
  --color-surface-elevated: #FFFFFF;
  --color-overlay: #0E2A22D9;

  --color-text-primary: #12241E;
  --color-text-secondary: #5A6F67;
  --color-text-muted: #5A6F67;
  --color-text-inverse: #FFFFFF;
  --color-link: #1E6A9B;

  --color-border: #DFE9E4;
  --color-divider: #ECF2EF;
  --color-input-background: #FFFFFF;
  --color-input-border: #74877F;
  --color-input-border-strong: #647A72;
  --color-focus-ring: #1E6B54;
  --color-button-background: #1E6B54;
  --color-button-text: #FFFFFF;

  --color-selection-background: #1E6B54;
  --color-selection-text: #FFFFFF;

  --color-success: #1C7048;
  --color-success-soft: #E4F2EA;
  --color-success-border: #B2D9C3;
  --color-warning: #8A540C;
  --color-warning-soft: #FBF0DF;
  --color-warning-border: #E7CDA2;
  --color-error: #B0363E;
  --color-error-soft: #FBEBEB;
  --color-error-border: #EBBDC0;
  --color-information: #206E9B;
  --color-information-soft: #E7F1F8;
  --color-information-border: #B8D6E9;
  --color-neutral-soft: #EDF2EF;
  --color-neutral-border: #D8E5DF;
}
