/*
 * OfficePress Approvals tokens: the Operate family palette in light and dark, keyed on
 * <html data-mode="light|dark"> (light when the attribute is absent), plus the --wf-* remap that
 * lets the r005 structural sheets render in OfficePress. Values are copied from
 * design-drafts/r001-officepress-workspace (DESIGN.md, assets/operate.css, assets/officepress.css,
 * styles.css); hashes in /brand/officepress/manifest.json. Names keep the kit's --op-* spelling.
 * Contrast of every pair listed in reports/officepress-alignment/00001/contrast.md.
 * Load after r005/{tokens,reset,base,wireframe}.css and officepress/fonts.css.
 */

/* Mode-independent: type, spacing, radius, frame and motion. */
:root {
  --op-font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --op-font-mono: ui-monospace, SFMono-Regular, Menlo, "Liberation Mono", monospace;
  --op-text-display: 700 28px/1.2 var(--op-font);
  --op-text-heading: 700 20px/1.25 var(--op-font);
  --op-text-title: 700 16px/1.25 var(--op-font);
  --op-text-body: 400 13px/1.5 var(--op-font);
  --op-text-small: 400 12px/1.5 var(--op-font);
  --op-text-caption: 400 11px/1.5 var(--op-font);

  --op-space-1: 4px;
  --op-space-2: 8px;
  --op-space-3: 12px;
  --op-space-4: 16px;
  --op-space-5: 20px;
  --op-space-6: 24px;
  --op-space-8: 32px;
  --op-space-10: 40px;

  --op-radius-4: 4px;
  --op-radius-8: 8px;
  --op-radius-12: 12px;
  --op-radius-16: 16px;
  --op-radius-full: 999px;

  --op-header-h: 64px;
  --op-header-h-mobile: 56px;
  --op-aside-w: 260px;
  --op-aside-rail-w: 64px;
  --op-aside-mobile-w: 300px;
  --op-control-h: 36px;
  --op-control-compact-h: 32px;
  --op-control-small-h: 28px;
  --op-input-h: 40px;

  --op-focus-width: 2px;
  --op-focus-offset: 3px;

  --op-ease: cubic-bezier(0.2, 0, 0, 1);
  --op-ease-out: cubic-bezier(0, 0, 0.2, 1);
  --op-dur-fast: 150ms;
  --op-dur: 200ms;
}

/* Light (default). Palette from operate.css; feedback roles from officepress.css. */
:root,
[data-mode="light"] {
  color-scheme: light;

  --op-canvas: #F9F6F5;
  --op-toolbar: #F6F0EE;
  --op-column: #F4EEEB;
  --op-surface: #FFFFFF;
  --op-sunken: #F8F3F1;
  --op-border: #ECE1DD;
  --op-border-strong: #E0CFC8;
  --op-text: #352722;
  --op-text-2: #756761;
  --op-accent: #E2551B;
  --op-accent-text: #C74B18;
  --op-accent-strong: #AB4014;
  --op-on-accent: #FFFFFF;
  --op-tint: #FBF3F0;
  --op-tint-2: #F6E4DC;
  --op-on-tint: #B94616;
  --op-nav: #412D25;
  --op-nav-text: #FFFFFF;
  --op-nav-text-2: #CBBAB3;
  --op-nav-active: #FFFFFF1A;
  --op-nav-field: #FFFFFF12;
  --op-nav-border: #FFFFFF1A;
  --op-nav-dot: #3DD68C;

  --op-dot: #087050;
  --op-danger: #C0362C;
  --op-danger-tint: #FDEDEB;
  --op-on-danger: #FFFFFF;
  --op-warning: #8A4B00;
  --op-warning-tint: #FFF4DB;

  --op-scrim: #0B102266;
  --op-shadow-edge: #18244F24;
  --op-shadow-soft: #18244F14;
  --op-shadow-pop: #18244F29;
  --op-image-outline: #0000001A;
}

/* Dark. The document template's <html> cannot carry data-mode, so `:root` follows a scope element that does:
   the page background and scrollbars then match the server-rendered mode before any script runs. */
/* Paper is always light: the dark values are screen-only, so a printed record never inherits them (task 00006). */
@media not print {
  [data-mode="dark"],
  :root:has([data-mode="dark"]) {
    color-scheme: dark;

    --op-canvas: #1C1411;
    --op-toolbar: #251A16;
    --op-column: #251B17;
    --op-surface: #2D211C;
    --op-sunken: #221915;
    --op-border: #4D3A33;
    --op-border-strong: #5F4A42;
    --op-text: #F6EFEC;
    --op-text-2: #B8A9A2;
    --op-accent: #E6622C;
    --op-accent-text: #EA7D50;
    --op-accent-strong: #F1A98C;
    --op-on-accent: #0B1022;
    --op-tint: #533428;
    --op-tint-2: #643F30;
    --op-on-tint: #F2B094;
    --op-nav: #16100D;
    --op-nav-text: #F6EFEC;
    --op-nav-text-2: #AA9992;
    --op-nav-active: #FFFFFF14;
    --op-nav-field: #FFFFFF0D;
    --op-nav-border: #FFFFFF14;
    --op-nav-dot: #3DD68C;

    --op-dot: #3DD68C;
    --op-danger: #F2766B;
    --op-danger-tint: #3A1614;
    /* The preview hard-codes white on the solid danger fill, which fails in dark; use the dark on-accent ink. */
    --op-on-danger: #0B1022;
    --op-warning: #F5C26B;
    --op-warning-tint: #33260C;

    --op-scrim: #00000099;
    --op-shadow-edge: #FFFFFF1A;
    --op-shadow-soft: #00000059;
    --op-shadow-pop: #00000080;
    --op-image-outline: #FFFFFF1A;
  }
}

/*
 * Roles built from the palette, same names in both modes. Where a preview pair misses 4.5:1 (text) or
 * 3:1 (control outline) the role points at the nearest preview token that passes; see contrast.md.
 */
:root,
[data-mode] {
  /* Accent as text: --op-accent-text only on surface; --op-accent-ink (the strong accent) on canvas, tint and selection. */
  /* Elevation resolves with the mode's shadow colours. */
  --op-elev-card: 0 0 1px var(--op-shadow-edge), 0 1px 3px var(--op-shadow-soft);
  --op-elev-card-hover: 0 0 1px var(--op-shadow-edge), 0 4px 12px var(--op-shadow-soft);
  --op-elev-pop: 0 0 1px var(--op-shadow-edge), 0 12px 32px var(--op-shadow-pop);

  --op-accent-ink: var(--op-accent-strong);
  --op-link: var(--op-accent-text);

  /* Focus: accent text colour on pages and panels, white/nav text on the sidebar, accent on field borders. */
  --op-focus: var(--op-accent-text);
  --op-focus-on-nav: var(--op-nav-text);
  --op-focus-field: var(--op-accent);

  --op-selection-bg: var(--op-tint-2);
  --op-selection-text: var(--op-text);
  /* Secondary text drops to primary on a selected row: --op-text-2 on --op-tint-2 misses 4.5:1 in both modes. */
  --op-selection-meta: var(--op-text);

  /* Field and control outlines need 3:1; --op-border-strong is for dividers and dashed slots only. */
  --op-control-border: var(--op-text-2);

  /* Status is always shown with its label or icon, never by colour alone. */
  --op-status-open-bg: var(--op-warning-tint);
  --op-status-open-text: var(--op-warning);
  --op-status-approved-bg: var(--op-tint);
  --op-status-approved-text: var(--op-on-tint);
  --op-status-rejected-bg: var(--op-danger-tint);
  --op-status-rejected-text: var(--op-danger);
  --op-status-warning-bg: var(--op-warning-tint);
  --op-status-warning-text: var(--op-warning);
  --op-status-danger-bg: var(--op-danger-tint);
  --op-status-danger-text: var(--op-danger);
  --op-status-neutral-bg: var(--op-sunken);
  --op-status-neutral-text: var(--op-text-2);
}

/*
 * r005 variable remap. Same variables the old theme layers override, so wireframe.css, workspace.css,
 * composer.css, users.css and app.css resolve to OfficePress. The gray scale is remapped by role
 * (--wf-white is the panel surface, --wf-gray-700 the primary ink), as the old themes did, so it
 * inverts correctly in dark. Selector list re-resolves on any element that carries data-mode.
 */
:root,
[data-mode] {
  --wf-white: var(--op-surface);
  --wf-gray-25: var(--op-sunken);
  --wf-gray-50: var(--op-canvas);
  --wf-gray-100: var(--op-column);
  --wf-gray-200: var(--op-border);
  --wf-gray-300: var(--op-control-border);
  --wf-gray-400: var(--op-control-border);
  --wf-gray-500: var(--op-text-2);
  --wf-gray-600: var(--op-text-2);
  --wf-gray-700: var(--op-text);
  --wf-gray-800: var(--op-text);
  --wf-surface: var(--op-surface);
  --wf-surface-muted: var(--op-sunken);
  --wf-surface-raised: var(--op-surface);
  --wf-border: var(--op-border);
  --wf-border-strong: var(--op-control-border);
  --wf-text: var(--op-text);
  --wf-text-muted: var(--op-text-2);
  --wf-text-subtle: var(--op-text-2);
  --wf-focus: var(--op-focus);
  --wf-emphasis: var(--op-accent-strong);
  --wf-emphasis-hover: color-mix(in srgb, var(--op-accent-strong) 90%, var(--op-text));
  --wf-on-emphasis: var(--op-on-accent);

  --wf-space-1: var(--op-space-1);
  --wf-space-2: var(--op-space-2);
  --wf-space-3: var(--op-space-3);
  --wf-space-4: var(--op-space-4);
  --wf-space-5: var(--op-space-5);
  --wf-space-6: var(--op-space-6);
  --wf-space-8: var(--op-space-8);
  --wf-space-10: var(--op-space-10);

  --wf-radius-1: var(--op-radius-4);
  --wf-radius-2: var(--op-radius-4);
  --wf-radius-3: var(--op-radius-8);
  --wf-radius-4: var(--op-radius-12);
  --wf-shadow-1: var(--op-elev-card);
  --wf-shadow-2: var(--op-elev-pop);

  --wf-font-sans: var(--op-font);
  --wf-font-mono: var(--op-font-mono);
  /* Preview scale: 11 caption, 12 small, 13 body, 16 title, 20 heading. r005 reads --wf-text-md as body. */
  --wf-text-2xs: 11px;
  --wf-text-xs: 12px;
  --wf-text-sm: 13px;
  --wf-text-md: 13px;
  --wf-text-lg: 16px;
  --wf-text-xl: 16px;
  --wf-text-2xl: 20px;
  --wf-line-tight: 1.25;
  --wf-line: 1.5;

  --wf-sidebar-width: var(--op-aside-w);
  --wf-mobile-bar-height: var(--op-header-h-mobile);
  --wf-drawer-width: var(--op-aside-mobile-w);
  --wf-motion-fast: var(--op-dur-fast);
  --wf-motion-medium: var(--op-dur);
  --wf-motion-ease: var(--op-ease);
}
