/*
 * Aisle13 design tokens: palette "Amethyst and Saffron" (ADR 0030, UI-STANDARD, BLOCK-O.md O16).
 * Load AFTER vendor/css/core.css and theme-tokens.css: it re-points the Bootstrap/Sneat variables and the older
 * --app-* tokens to this system, so every screen picks it up without a view change.
 * Rules: views never hard-code a colour, size, shadow, duration or curve; they use the job aliases below
 * (--color-*, --text-*, --surface-*, --space-*, --motion-*). Every text/surface pair the screens use is listed in
 * tests/Aisle13.ArchitectureTests/DesignTokenContrastTests.cs and measured against WCAG 2.2 (body 7:1, other text 4.5:1).
 */

/* Scale rem-based screen text and controls from the browser's default size. */
@media screen {
  :root[data-a13-text-size] { font-size: 100%; }
  :root[data-a13-text-size="115"] { font-size: 115%; }
  :root[data-a13-text-size="125"] { font-size: 125%; }
}

/* ---------- Scales (theme-independent raw shades; screens use the aliases, not these) ---------- */
:root {
  /* Dominant: Amethyst */
  --amethyst-50: #f4f3ff;   /* Wash: selected row */
  --amethyst-100: #ecebff;  /* Tint: icon tile */
  --amethyst-200: #d9d8ff;  /* Outline: focus, chip border */
  --amethyst-300: #bcbcff;  /* Soft: disabled fill */
  --amethyst-400: #8d8fff;  /* Glow: brand in dark */
  --amethyst-500: #696cff;  /* Brand: logo, icons, charts; not text on white */
  --amethyst-600: #5457e6;  /* Action: buttons, links */
  --amethyst-700: #4143b8;  /* Press: hover, pressed */
  --amethyst-800: #33358f;  /* Deep: text on tint */

  /* Secondary: Ink (neutrals tinted purple) */
  --ink-50: #f6f5fb;   /* Canvas */
  --ink-100: #efeef6;  /* Mist: row hover */
  --ink-200: #dfdde9;  /* Line: borders */
  --ink-300: #c3c1d3;  /* Divider */
  --ink-400: #aeacc4;  /* Muted dark: muted text in dark */
  --ink-500: #8a88a3;  /* Icon: inactive icons only */
  --ink-600: #64627d;  /* Muted */
  --ink-700: #3b3a52;  /* Body */
  --ink-800: #24233a;  /* Heading */

  /* Accent: Saffron */
  --saffron-50: #fff8eb;   /* Cream */
  --saffron-100: #feefc7;  /* Halo: badge background */
  --saffron-200: #fddc8a;  /* Soft: chart fill */
  --saffron-300: #fbcb6a;  /* Shine */
  --saffron-400: #f7b955;  /* Gold dark: gold text in dark */
  --saffron-500: #f5a524;  /* Saffron: premium fill, dark text on it */
  --saffron-600: #d98a0f;  /* Amber */
  --saffron-700: #9a6410;  /* Gold text on light */
  --saffron-800: #7a4d0e;  /* Bronze: text on cream */

  /* Dark-theme surfaces (ink-violet, never pure black) */
  --night-900: #16151f;  /* page */
  --night-800: #1f1e2b;  /* surface */
  --night-700: #292838;  /* raised */
  --night-600: #2d2b4d;  /* primary-subtle in dark */
  --night-500: #37354a;  /* border */
  --night-sidebar: #1b1a2e;

  /* Sidebar: the same dark ink panel in both themes */
  --sidebar-bg: var(--night-sidebar);
  --sidebar-toggle-bg: var(--amethyst-500);
  --sidebar-text: #d9d8ea;
  --sidebar-muted: var(--ink-400);
  --text-on-dark: #ffffff;           /* text on the sidebar and on action-shade fills */
  --sidebar-active-from: var(--amethyst-600);  /* active entry pill: white text 5.41:1 (brand 500 is only 4.05) */
  --sidebar-active-to: var(--amethyst-700);
  --gradient-nav-active: linear-gradient(135deg, var(--sidebar-active-from) 0%, var(--sidebar-active-to) 100%);

  /* Type (UI-STANDARD §2: compact scale; tabular figures for money and quantities) */
  --font-ui: "Open Sans", -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --font-numeric: tabular-nums lining-nums;
  --fs-xs: 0.75rem;     /* 12 px: badges, captions */
  --fs-sm: 0.8125rem;   /* 13 px: tables, form labels */
  --fs-md: 0.875rem;    /* 14 px: body */
  --fs-lg: 1rem;        /* 16 px: card titles */
  --fs-xl: 1.125rem;    /* 18 px: page title */
  --fs-2xl: 1.5rem;     /* 24 px: stat figures */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --lh-tight: 1.25;
  --lh-body: 1.45;

  /* Spacing: 4 px scale (Fluent 2 ramp, Carbon/Atlassian small tokens for dense UI) */
  --space-0: 0;
  --space-1: 0.25rem;  /* 4 */
  --space-2: 0.5rem;   /* 8 */
  --space-3: 0.75rem;  /* 12 */
  --space-4: 1rem;     /* 16 */
  --space-5: 1.25rem;  /* 20 */
  --space-6: 1.5rem;   /* 24 */
  --space-8: 2rem;     /* 32 */

  /* Density: compact is the default (Carbon "sm" 32 px rows); data-density="comfortable" on <html> widens it */
  --row-height: 2rem;          /* 32 px table row */
  --cell-pad-y: 0.3125rem;     /* 5 px */
  --cell-pad-x: 0.5rem;        /* 8 px (O16b: 10 px overflowed 13 columns at 1366 with the full sidebar) */
  --control-height: 2rem;      /* 32 px inputs, selects, buttons */
  --control-pad-x: 0.625rem;
  --card-pad: 0.875rem;        /* 14 px */
  --header-band: 2.875rem;     /* 46 px page header band */

  /* Shell (O16 shell increment): sidebar, icon rail and the slim navbar */
  --sidebar-w: 15rem;          /* 240 px expanded sidebar */
  --sidebar-rail: 5.25rem;     /* Sneat's collapsed width: its rail icons and brand are laid out for it */
  --navbar-h: 3rem;            /* 48 px top bar */
  --menu-link-h: 2.125rem;     /* 34 px sidebar entry */

  /* Shape and elevation (soft layered shadows, tinted with ink, not grey) */
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.625rem;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(36, 35, 58, 0.06), 0 1px 3px rgba(36, 35, 58, 0.08);
  --shadow-2: 0 2px 4px rgba(36, 35, 58, 0.06), 0 4px 12px rgba(36, 35, 58, 0.10);
  --shadow-3: 0 4px 8px rgba(36, 35, 58, 0.08), 0 12px 28px rgba(36, 35, 58, 0.16);

  /* Motion (Carbon productive/expressive curves and duration tokens; UI-STANDARD "Motion") */
  --ease-standard: cubic-bezier(0.2, 0, 0.38, 0.9);   /* productive: most UI */
  --ease-entrance: cubic-bezier(0, 0, 0.38, 0.9);     /* ease-out: things arriving, user input */
  --ease-exit: cubic-bezier(0.2, 0, 1, 0.9);          /* ease-in: things leaving */
  --ease-expressive: cubic-bezier(0.4, 0.14, 0.3, 1); /* rare, significant moments (dashboard reveal) */
  --motion-instant: 70ms;   /* button press, toggle */
  --motion-fast: 110ms;     /* hover, fade, micro-interactions */
  --motion-base: 150ms;     /* small expand, row detail */
  --motion-medium: 240ms;   /* panel expand, toast, offcanvas */
  --motion-slow: 400ms;     /* large expand, chart reveal */
  --motion-spin: 1000ms;    /* one turn of a busy spinner; kept under reduced motion (it is the only busy cue) */
  --stagger-step: 30ms;     /* staggered entrances, max 8 items */
}

/* ---------- Light theme: job aliases ---------- */
:root,
[data-bs-theme="light"] {
  --color-brand: var(--amethyst-500);
  --color-brand-rgb: 105, 108, 255;
  --color-action: var(--amethyst-600);
  --color-action-rgb: 84, 87, 230;
  --color-action-press: var(--amethyst-700);
  --color-on-action: #ffffff;
  --color-primary-subtle: var(--amethyst-100);
  --color-selected: var(--amethyst-50);
  --color-focus: var(--amethyst-200);
  --color-on-subtle: var(--amethyst-800);
  --gradient-brand: linear-gradient(135deg, #696cff 0%, #8f5cff 100%);

  --color-accent: var(--saffron-500);
  --color-on-accent: #1f1e2b;
  --color-accent-subtle: var(--saffron-100);
  --color-on-accent-subtle: var(--saffron-800); /* --text-accent on the halo is 4.37:1 (M5) */
  --text-accent: var(--saffron-700);

  --color-teal: #0b7a70;
  --color-teal-fill: #14b8a6;
  --color-success: #1a8754;
  --color-warning: #a15c07;
  --color-warning-fill: #f59e0b;
  --color-danger: #d93848;
  --color-info: #0369a1;
  --color-info-fill: #0ea5e9;
  --color-plum: #a21caf;
  --color-rose: #c2255c;
  --color-slate: var(--ink-600);

  /* Chart series (O12 part 4): the parts of a donut, in this fixed order; checked for colour-blind separation
     (dataviz validator, adjacent pairs). 3, 4 and 5 are under 3:1 on white: the legend and the table name every part. */
  --chart-1: #2a78d6;
  --chart-2: #eb6834;
  --chart-3: #1baf7a;
  --chart-4: #eda100;
  --chart-5: #e87ba4;
  --chart-6: #008300;

  --surface-page: var(--ink-50);
  --surface-card: #ffffff;
  --surface-raised: #ffffff;
  --surface-hover: var(--ink-100);
  --border-color: var(--ink-200);
  --divider-color: var(--ink-300);

  --text-heading: var(--ink-800);
  --text-body: var(--ink-700);
  --text-muted: var(--ink-600);
  --text-icon: var(--ink-500);
  --text-link: var(--amethyst-600);

  /* Bootstrap / Sneat variables re-pointed to the tokens */
  --bs-primary: var(--color-action);
  --bs-primary-rgb: var(--color-action-rgb);
  --bs-primary-bg-subtle: var(--color-primary-subtle);
  --bs-primary-text-emphasis: var(--color-on-subtle);
  --bs-body-bg: var(--surface-page);
  --bs-body-bg-rgb: 246, 245, 251;
  --bs-body-color: var(--text-body);
  --bs-body-color-rgb: 59, 58, 82;
  --bs-heading-color: var(--text-heading);
  --bs-emphasis-color: var(--text-heading);
  --bs-secondary-color: var(--text-muted);
  --bs-secondary-color-rgb: 100, 98, 125;
  --bs-paper-bg: var(--surface-card);
  --bs-paper-bg-rgb: 255, 255, 255;
  --bs-border-color: var(--border-color);
  --bs-link-color: var(--text-link);
  --bs-link-color-rgb: var(--color-action-rgb);
  --bs-link-hover-color: var(--color-action-press);
  --bs-link-hover-color-rgb: 65, 67, 184;
  --bs-box-shadow: var(--shadow-2);

  /* Older Core tokens (theme-tokens.css) re-pointed, until O16 rolls every screen over */
  --app-primary: var(--color-action);
  --app-primary-rgb: var(--color-action-rgb);
  --app-primary-subtle: var(--color-primary-subtle);
  --app-on-primary: var(--color-on-action);
  --app-bg: var(--surface-page);
  --app-paper: var(--surface-card);
  --app-text: var(--text-body);
  --app-heading: var(--text-heading);
  --app-border: var(--border-color);
  --app-muted: var(--text-muted);
  --app-font: var(--font-ui);
  --app-font-mono: var(--font-mono);
  --app-shadow: var(--shadow-2);
  --app-focus-ring: 0 0 0 0.1875rem rgba(var(--color-brand-rgb), 0.35);
}

/* ---------- Dark theme: deep ink-violet, near-white text, desaturated accents ---------- */
:root[data-bs-theme="dark"],
[data-bs-theme="dark"] {
  --color-brand: var(--amethyst-400);
  --color-brand-rgb: 141, 143, 255;
  --color-action: #9b9dff;
  --color-action-rgb: 155, 157, 255;
  --color-action-press: #adafff;
  --color-on-action: var(--night-800);
  --color-primary-subtle: var(--night-600);
  --color-selected: var(--night-600);
  --color-focus: var(--amethyst-400);
  --color-on-subtle: #e2e1ec;

  --color-accent: var(--saffron-400);
  --color-on-accent: var(--night-800);
  --color-accent-subtle: #3a3020;
  --color-on-accent-subtle: var(--saffron-400);
  --text-accent: var(--saffron-400);

  --color-teal: #3cc7b6;
  --color-teal-fill: #3cc7b6;
  --color-success: #4cc38a;
  --color-warning: #f7b955;
  --color-warning-fill: #f7b955;
  --color-danger: #ff6b78;
  --color-info: #5cc3f5;
  --color-info-fill: #5cc3f5;
  --color-plum: #e07bf0;
  --color-rose: #ff7aa8;
  --color-slate: var(--ink-400);

  --chart-1: #3987e5;
  --chart-2: #d95926;
  --chart-3: #199e70;
  --chart-4: #c98500;
  --chart-5: #d55181;
  --chart-6: #0ca30c;

  --surface-page: var(--night-900);
  --surface-card: var(--night-800);
  --surface-raised: var(--night-700);
  --surface-hover: var(--night-700);
  --border-color: var(--night-500);
  --divider-color: var(--night-500);

  --text-heading: #f5f4fa;
  --text-body: #e2e1ec;
  --text-muted: var(--ink-400);
  --text-icon: var(--ink-500);
  --text-link: #9b9dff;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.32);
  --shadow-3: 0 8px 24px rgba(0, 0, 0, 0.40);

  --bs-primary: var(--color-action);
  --bs-primary-rgb: var(--color-action-rgb);
  --bs-primary-bg-subtle: var(--color-primary-subtle);
  --bs-primary-text-emphasis: var(--color-on-subtle);
  --bs-body-bg: var(--surface-page);
  --bs-body-bg-rgb: 22, 21, 31;
  --bs-body-color: var(--text-body);
  --bs-body-color-rgb: 226, 225, 236;
  --bs-heading-color: var(--text-heading);
  --bs-emphasis-color: var(--text-heading);
  --bs-secondary-color: var(--text-muted);
  --bs-secondary-color-rgb: 174, 172, 196;
  --bs-paper-bg: var(--surface-card);
  --bs-paper-bg-rgb: 31, 30, 43;
  --bs-border-color: var(--border-color);
  --bs-link-color: var(--text-link);
  --bs-link-color-rgb: var(--color-action-rgb);
  --bs-link-hover-color: var(--color-action-press);
  --bs-link-hover-color-rgb: 173, 175, 255;
  --bs-box-shadow: var(--shadow-2);

  --app-primary: var(--color-action);
  --app-primary-rgb: var(--color-action-rgb);
  --app-primary-subtle: var(--color-primary-subtle);
  --app-on-primary: var(--color-on-action);
  --app-bg: var(--surface-page);
  --app-paper: var(--surface-card);
  --app-text: var(--text-body);
  --app-heading: var(--text-heading);
  --app-border: var(--border-color);
  --app-muted: var(--text-muted);
  --app-shadow: var(--shadow-2);
}

/* The sidebar is always the dark ink panel, whatever the page theme */
.layout-menu[data-bs-theme="dark"] {
  --bs-body-bg: var(--sidebar-bg);
  --bs-paper-bg: var(--sidebar-bg);
  --bs-paper-bg-rgb: 27, 26, 46;
  --bs-body-color: var(--sidebar-text);
  --bs-heading-color: #f5f4fa;
  --bs-secondary-color: var(--sidebar-muted);
}

/* Comfortable density, per user (switch comes with the shell increment) */
[data-density="comfortable"] {
  --row-height: 2.5rem;
  --cell-pad-y: 0.625rem;
  --cell-pad-x: 1rem;
  --control-height: 2.375rem;
  --control-pad-x: 0.875rem;
  --card-pad: 1.25rem;
  --header-band: 3.5rem;
}

/* Buttons: brand action shade (white text 5.41:1; #5457e6 replaces #696cff, which is 4.05:1 on white) */
.btn-primary {
  --bs-btn-color: var(--color-on-action);
  --bs-btn-bg: var(--color-action);
  --bs-btn-border-color: var(--color-action);
  --bs-btn-hover-color: var(--color-on-action);
  --bs-btn-hover-bg: var(--color-action-press);
  --bs-btn-hover-border-color: var(--color-action-press);
  --bs-btn-active-color: var(--color-on-action);
  --bs-btn-active-bg: var(--color-action-press);
  --bs-btn-active-border-color: var(--color-action-press);
  --bs-btn-disabled-color: var(--color-on-action);
  --bs-btn-disabled-bg: var(--color-action);
  --bs-btn-disabled-border-color: var(--color-action);
  transition: background-color var(--motion-fast) var(--ease-standard), transform var(--motion-instant) var(--ease-entrance);
}
.btn-primary:active { transform: translateY(1px); }

/* Figures line up: tabular numerals wherever numbers are right-aligned */
.text-end, .bo-num, td.num, th.num { font-variant-numeric: var(--font-numeric); }

/* Reduced motion: every token duration collapses, nothing moves */
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-instant: 0ms;
    --motion-fast: 0ms;
    --motion-base: 0ms;
    --motion-medium: 0ms;
    --motion-slow: 0ms;
    --stagger-step: 0ms;
  }
  .btn-primary:active { transform: none; }
}
