/* VENDORED from the TreatHealth OS design system (ths-ds v3). Treat as read-only: re-vendor on an upstream change
   rather than editing here, so this file stays diffable against the suite's copy. One deviation, marked below: the
   Google Fonts @import is dropped because app/layout.tsx self-hosts Source Serif 4 with next/font and re-points
   --font-serif at it (app/globals.css). Everything else is byte-for-byte upstream. */

/* =============================================================================
   TreatHealth OS — Design tokens v3 ("Broadsheet × M3")
   Portable: plain CSS custom properties, no build step, no framework.
   Names are a SUPERSET of app/app/ths-v2.css — every v2 name keeps its meaning,
   so the billing app can swap this file in for the v2 :root block unchanged.

   Scope: :root AND [data-ths] so it works globally (C-Suite, Tailwind 4) or
   scoped per subtree (Billing, Tailwind 3 opt-in like today's data-ths='v2').
   Theme:  [data-theme='dark'] on <html> or any subtree.
   Tenant: [data-tenant='bxr' | 'indigo'] sets --tenant.
   ========================================================================== */
/* upstream line dropped here: @import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:...') */

:root,
[data-ths] {
  color-scheme: light;

  /* ---- Ground (Broadsheet paper) -------------------------------------- */
  --color-bg: #f5f1eb;                    /* was #f3f2f2 — warm paper, the dashboard's original ground, same lightness */
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-surface-sunk: #ede8e1;          /* was #ebeae9 — warmed with the ground; wells, seg tracks, rail-adjacent */
  --color-surface-inverse: #0e3a3a;       /* brand deep — rail, tape */
  --color-on-inverse: #ffffff;
  --color-text: #1b2b2a;

  /* ---- Accent: brand teal (unchanged from v2) ------------------------- */
  --color-accent: #135e5a;
  --color-on-accent: #ffffff;
  --color-accent-100: #e8fcf7;
  --color-accent-200: #c2f6eb;
  --color-accent-300: #8cecdb;
  --color-accent-400: #41e0c6;
  --color-accent-500: #2dbda9;
  --color-accent-600: #1c8b82;
  --color-accent-700: #135e5a;
  --color-accent-800: #0e3a3a;
  --color-accent-900: #0a2625;

  /* ---- Accent 2: coral — decoration only, never severity -------------- */
  --color-accent-2: #bf533a;
  --color-accent-2-100: #fff4f1;
  --color-accent-2-200: #ffe2db;
  --color-accent-2-300: #fec9bc;
  --color-accent-2-400: #feac98;
  --color-accent-2-500: #f18065;
  --color-accent-2-600: #bf533a;
  --color-accent-2-700: #873421;

  /* ---- Neutrals (light-legal values from v2) -------------------------- */
  --color-neutral-100: #f2f5f4;
  --color-neutral-200: #e4e9e6;
  --color-neutral-300: #3a4544;   /* body · 9.4:1 */
  --color-neutral-400: #4d5454;   /* secondary · 7.3:1 */
  --color-neutral-500: #5c6664;   /* labels · 5.6:1 — content floor */
  --color-neutral-600: #737b7b;   /* disabled only */
  --color-divider: color-mix(in srgb, var(--color-text) 12%, transparent);
  --color-hairline: color-mix(in srgb, var(--color-text) 7%, transparent);

  /* ---- Status -------------------------------------------------------- */
  --color-ok: #027351;     /* was #027c57 — lowest as text on its tints 4.15:1, now 4.64 */
  --color-warn: #875d00;   /* was #9a6a00 — lowest 3.80:1, now 4.64 */
  --color-danger: #bb3029; /* was #d23a33 — lowest 3.78:1, now 4.61. Same hues, darker: AA (4.5:1) as text */
  --color-info: #007397;

  /* ---- Tenants ------------------------------------------------------- */
  --tenant-bxr: #1a1a2e;
  --tenant-indigo: #5b2a9e;
  --tenant: var(--color-accent);

  /* ---- Chart series (each ≥3:1 on surface) ---------------------------- */
  /* Eight hues, the dashboard's original categorical palette, re-stepped to pass the data-viz palette checks (lightness
     band, chroma, CVD separation ≥8 adjacent, contrast ≥3:1 on the surface) in this theme and in dark. Was six:
     accent-600, accent-2-600, #007397, #9a6a00, accent-700, accent-2-700. */
  --chart-1: #0fa08f;   /* teal */
  --chart-2: #e2674f;   /* coral */
  --chart-3: #3b5fd9;   /* royal blue */
  --chart-4: #a87400;   /* amber */
  --chart-5: #a93fa0;   /* magenta */
  --chart-6: #6e8f16;   /* olive */
  --chart-7: #2e86b5;   /* sky */
  --chart-8: #b5563f;   /* brick */
  --chart-track: color-mix(in srgb, var(--color-text) 6%, transparent);
  --chart-grid: color-mix(in srgb, var(--color-text) 8%, transparent);

  /* ---- Type: Source Serif 4 everywhere -------------------------------- */
  --font-serif: 'Source Serif 4', 'Iowan Old Style', Georgia, serif;
  --font-heading: var(--font-serif);
  --font-body: var(--font-serif);
  --font-num: var(--font-serif);        /* always with tabular-nums */
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace; /* codes only */
  --text-display: 40px;   /* page title, expanded header */
  --text-headline: 28px;  /* KPI value */
  --text-title: 19px;     /* card / section title */
  --text-body: 14.5px;
  --text-control: 13.5px;
  --text-label: 12.5px;
  --text-kicker: 11px;    /* small-caps kicker */

  /* ---- Space (compact, v2 scale kept; 10/12 added for layout) -------- */
  --space-1: 2.8px;
  --space-2: 5.6px;
  --space-3: 8.4px;
  --space-4: 11.2px;
  --space-6: 16.8px;
  --space-8: 22.4px;
  --space-10: 32px;
  --space-12: 48px;

  /* ---- Shape: M3 corner scale ---------------------------------------- */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 28px;
  --radius-pill: 999px;

  /* ---- Elevation: hairline ring + soft teal-tinted shadow ------------ */
  --shadow-sm: 0 0 0 1px var(--color-hairline), 0 1px 2px rgba(14, 58, 58, 0.04);
  --shadow-md: 0 0 0 1px var(--color-hairline), 0 6px 20px -4px rgba(14, 58, 58, 0.12);
  --shadow-lg: 0 0 0 1px var(--color-hairline), 0 24px 56px -12px rgba(14, 58, 58, 0.24);

  /* ---- M3 state layers (opacity of currentColor / accent overlay) ---- */
  --state-hover: 0.08;
  --state-focus: 0.12;
  --state-pressed: 0.12;
  --state-dragged: 0.16;

  /* ---- Motion (M3 emphasized + standard) ----------------------------- */
  --ease: cubic-bezier(0.2, 0, 0, 1);                 /* standard */
  --ease-emphasized: cubic-bezier(0.2, 0, 0, 1);
  --ease-decel: cubic-bezier(0.05, 0.7, 0.1, 1);      /* enter */
  --ease-accel: cubic-bezier(0.3, 0, 0.8, 0.15);      /* exit */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);   /* tiny overshoot — chips, toggles */
  --dur-1: 120ms;   /* state layers, color */
  --dur-2: 220ms;   /* hover lift, tooltips */
  --dur-3: 400ms;   /* rail, dialogs, shared element */
  --dur-4: 700ms;   /* reveal, chart draw */
  --stagger: 45ms;

  /* ---- Layout -------------------------------------------------------- */
  --rail-collapsed: 80px;
  --rail-expanded: 264px;
  --header-expanded: 112px;
  --header-collapsed: 60px;
  --size-control: 36px;
  --size-row: 44px;
}

[data-tenant='bxr'] { --tenant: var(--tenant-bxr); }
[data-tenant='indigo'] { --tenant: var(--tenant-indigo); }

/* ---- Dark — values from the TreatHealthOS Figma "Dark" mode ------------- */
[data-theme='dark'] {
  color-scheme: dark;
  --color-bg: #131c1d;
  --color-surface: #1b2728;
  --color-surface-raised: #22302f;
  --color-surface-sunk: #0f1718;
  --color-surface-inverse: #0a2625;
  --color-text: #e7edec;
  --color-accent: #41e0c6;
  --color-on-accent: #0a2625;
  --color-accent-2: #feac98;
  --color-neutral-100: #22302f;
  --color-neutral-200: #2d3434;
  --color-neutral-300: #d3d9d9;
  --color-neutral-400: #bec6c6;
  --color-neutral-500: #9ea6a7;
  --color-neutral-600: #737b7b;
  --color-ok: #44d49e;
  --color-warn: #f3bc3d;
  --color-danger: #ff6b5e;
  --color-info: #66c3eb;
  --tenant-bxr: #a9b4e8;
  --tenant-indigo: #c4a4f2;
  /* The same eight hues, stepped for the dark surface. Was six: #41e0c6, #feac98, #66c3eb, #f3bc3d, #2dbda9, #f18065. */
  --chart-1: #1faa98;
  --chart-2: #e26c55;
  --chart-3: #5f80ea;
  --chart-4: #b98710;
  --chart-5: #c05fb6;
  --chart-6: #80a428;
  --chart-7: #4a9bcd;
  --chart-8: #c6654c;
  --shadow-sm: 0 0 0 1px var(--color-hairline);
  --shadow-md: 0 0 0 1px var(--color-hairline), 0 8px 24px -6px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 0 0 1px var(--color-hairline), 0 28px 64px -12px rgba(0, 0, 0, 0.65);
}

@media (prefers-reduced-motion: reduce) {
  :root, [data-ths] { --dur-2: 1ms; --dur-3: 1ms; --dur-4: 1ms; --stagger: 0ms; }
}
