/* ═══════════════════════════════════════════════════════════════════════════
   MarketSync Design System — Phase 1 foundation
   ═══════════════════════════════════════════════════════════════════════════

   WHY THIS FILE EXISTS
   MarketSync had no design system to normalize. Styling lives in ~22,700
   inline Tailwind utility-class decisions across 50 JS modules and 59 HTML
   pages; the hand-written CSS on top of that is mostly override layers (733
   !important declarations) that accumulated per-page. The result is 66
   distinct box-shadows, 43 radii, 157 hex literals and 227 rgba literals
   expressing what should be about a dozen decisions.

   This file is the CONSOLIDATION TARGET, not a second design system. It is
   loaded last so semantic classes win on cascade order rather than by
   escalating specificity, and each migration phase moves surfaces onto these
   primitives and deletes the override rules they replace. Staged coexistence
   is deliberate and temporary: the alternative is one unreviewable rewrite of
   a live product.

   PHASE 1 IS ADDITIVE ON PURPOSE. Nothing here restyles an existing selector,
   so this file changes no pixel until a surface opts in. Phase 2 begins that
   adoption, starting with making Liquid Glass opt-in instead of a blanket
   `.bg-white:not(...)` selector that currently force-glasses all 1,297
   bg-white call sites — the root cause of the flat, uniformly-translucent
   hierarchy this system exists to fix.

   PRINCIPLE
   Masonry communicates IMPORTANCE. Glass communicates FUNCTIONAL LAYER.
   Neither is decoration. A surface's size and material must be derived from
   what it means operationally, never chosen for looks.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────────────────────
   1. SEMANTIC TOKENS
   Built ON TOP of the existing --ms-blue-* / --ms-gray-* / --ms-dark-*
   primitives in marketsync-theme.css rather than redeclaring colour values.
   Primitives answer "what colour is Market Blue 600"; these answer "what is
   an elevated surface" — only the latter belongs in component CSS.
   ─────────────────────────────────────────────────────────────────────────── */
:root {
  /* — Surfaces (light) ——————————————————————————————————————————————
     Base is deliberately NOT #fff: a white page behind white cards is why
     light mode reads as "white on white fog" with no depth to speak of. */
  --ms-s-base: #F5F7F9;
  --ms-s-base-alt: #F7F8FA;
  --ms-s-solid: #FFFFFF;
  --ms-s-elevated: rgba(255, 255, 255, 0.88);
  --ms-s-glass: rgba(255, 255, 255, 0.60);
  --ms-s-sunken: #EDF0F4;

  /* — Text (light) —
     Secondary/tertiary are the WCAG floor for their roles: #667085 is 5.4:1
     on --ms-s-solid, #98A2B3 is 2.9:1 and therefore permitted for meta text
     only, never for body copy. See §6 contrast guards below. */
  --ms-t-primary: #0F172A;
  --ms-t-secondary: #667085;
  --ms-t-tertiary: #98A2B3;
  --ms-t-inverse: #FFFFFF;

  /* — Lines (light) — */
  --ms-line: rgba(15, 23, 42, 0.08);
  --ms-line-strong: rgba(15, 23, 42, 0.14);
  --ms-divider: rgba(15, 23, 42, 0.06);

  /* — Brand + status (aliases onto existing primitives) — */
  --ms-accent-brand: var(--ms-blue-500, #2563EB);
  --ms-accent-hover: var(--ms-blue-600, #1F4ED8);
  --ms-accent-quiet: var(--ms-blue-50, #eff6ff);
  /* Aliases the existing warning primitive so there is still one definition
     of the amber this product uses to mean "a person needs to look at this". */
  --ms-accent-warn: var(--ms-warning-600, #D97706);
  --ms-st-success: #059669;
  --ms-st-warning: #D97706;
  --ms-st-danger: #DC2626;
  --ms-st-info: var(--ms-blue-500, #2563EB);

  /* — Department accents —
     Subtle wayfinding only. Market Blue remains the product's identity; a
     department accent tints an eyebrow or a status dot, never a whole card. */
  --ms-dept-sales: #D97706;
  --ms-dept-inventory: #2563EB;
  --ms-dept-fni: #059669;
  --ms-dept-service: #0891B2;
  --ms-dept-parts: #7C3AED;
  --ms-dept-accounting: #4F46E5;
  --ms-dept-marketing: #DB2777;
  --ms-dept-people: #EA580C;

  /* — Spacing — one 4px-based scale; no more magic values in page CSS. */
  --ms-sp-1: 4px;
  --ms-sp-2: 8px;
  --ms-sp-3: 12px;
  --ms-sp-4: 16px;
  --ms-sp-5: 20px;
  --ms-sp-6: 24px;
  --ms-sp-8: 32px;
  --ms-sp-10: 40px;
  --ms-sp-12: 48px;
  --ms-sp-16: 64px;

  /* — Radii — replaces 43 distinct observed values with 5 + pill. */
  --ms-r-xs: 8px;
  --ms-r-sm: 10px;
  --ms-r-md: 14px;
  --ms-r-lg: 18px;
  --ms-r-xl: 22px;
  --ms-r-hero: 26px;
  --ms-r-pill: 999px;

  /* — Elevation — replaces 66 distinct observed shadows with 5 steps.
     Depth is a hierarchy signal: if everything floats, nothing does. */
  --ms-e-flat: none;
  --ms-e-subtle: 0 1px 2px rgba(15, 23, 42, 0.05),
    0 1px 3px rgba(15, 23, 42, 0.04);
  --ms-e-raised: 0 2px 4px rgba(15, 23, 42, 0.04),
    0 6px 16px -6px rgba(15, 23, 42, 0.10);
  --ms-e-float: 0 4px 10px -4px rgba(15, 23, 42, 0.08),
    0 16px 32px -12px rgba(15, 23, 42, 0.14);
  --ms-e-modal: 0 8px 24px -8px rgba(15, 23, 42, 0.18),
    0 32px 64px -24px rgba(15, 23, 42, 0.28);

  /* — Glass —
     A material, not a background colour: transparency + blur + saturation +
     a top highlight + an ambient shadow. Saturation is what stops glass
     looking like grey fog over a colourful page. */
  --ms-g-blur: 22px;
  --ms-g-saturate: 140%;
  --ms-g-border: rgba(255, 255, 255, 0.55);
  --ms-g-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.60);
  --ms-g-shadow: 0 8px 32px -8px rgba(15, 23, 42, 0.16);

  /* — Type scale — */
  --ms-f-page: clamp(1.5rem, 1.2rem + 1.1vw, 2rem);
  /* 24 → 32 */
  --ms-f-section: clamp(1.125rem, 1.1rem + 0.4vw, 1.25rem);
  /* 18 → 20 */
  --ms-f-card: 1rem;
  /* 16      */
  --ms-f-body: 1rem;
  --ms-f-meta: 0.875rem;
  /* 14      */
  --ms-f-caption: 0.875rem;
  /* 14      */
  --ms-f-eyebrow: 0.8125rem;
  /* 13      */
  --ms-f-metric: clamp(1.375rem, 1.1rem + 1.2vw, 1.875rem);
  /* 22 → 30 */
  --ms-f-hero: clamp(1.875rem, 1.4rem + 2.2vw, 2.75rem);
  /* 30 → 44 */
  --ms-lh-tight: 1.2;
  --ms-lh-body: 1.5;

  /* — Motion — restrained; 160–240ms reads as responsive, not animated. */
  --ms-m-fast: 120ms;
  --ms-m-normal: 180ms;
  --ms-m-slow: 240ms;
  --ms-m-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ms-m-lift: -2px;

  /* — Grid — */
  --ms-grid-cols: 12;
  --ms-grid-gap: var(--ms-sp-5);
  --ms-grid-row: 88px;
}

/* — Dark mode —
   Not pure black. #0F1114 keeps ambient depth readable; true black flattens
   every shadow to nothing and makes elevation impossible to express. */
:root.dark,
.dark {
  --ms-s-base: #0F1114;
  --ms-s-base-alt: #101216;
  --ms-s-solid: #171A1E;
  --ms-s-elevated: rgba(24, 27, 32, 0.88);
  --ms-s-glass: rgba(18, 21, 26, 0.62);
  --ms-s-sunken: #0B0D10;

  --ms-t-primary: #F7F8FA;
  --ms-t-secondary: #98A2B3;
  --ms-t-tertiary: #6B7480;
  --ms-t-inverse: #0F172A;

  --ms-line: rgba(255, 255, 255, 0.08);
  --ms-line-strong: rgba(255, 255, 255, 0.14);
  --ms-divider: rgba(255, 255, 255, 0.06);

  --ms-accent-quiet: rgba(37, 99, 235, 0.14);
  /* The 600 is tuned for white; on a dark panel the 500 carries the edge. */
  --ms-accent-warn: var(--ms-warning-500, #F59E0B);
  --ms-st-success: #34D399;
  --ms-st-warning: #FBBF24;
  --ms-st-danger: #F87171;

  --ms-e-subtle: 0 1px 2px rgba(0, 0, 0, 0.30);
  --ms-e-raised: 0 2px 6px rgba(0, 0, 0, 0.34),
    0 8px 20px -8px rgba(0, 0, 0, 0.44);
  --ms-e-float: 0 6px 14px -6px rgba(0, 0, 0, 0.40),
    0 20px 40px -16px rgba(0, 0, 0, 0.55);
  --ms-e-modal: 0 12px 32px -10px rgba(0, 0, 0, 0.55),
    0 40px 80px -30px rgba(0, 0, 0, 0.70);

  --ms-g-border: rgba(255, 255, 255, 0.10);
  --ms-g-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --ms-g-shadow: 0 8px 32px -8px rgba(0, 0, 0, 0.50);
}

/* ───────────────────────────────────────────────────────────────────────────
   2. THREE-LAYER MATERIAL SYSTEM
   Every surface belongs to exactly one layer. Which layer is a statement
   about function, not appearance.

   CONTENT  — the record itself: tables, forms, timelines, ROs, journal rows.
              Solid. Never glass: dense text over a blurred backdrop is the
              single fastest way to make an operational product feel cheap.
   ELEVATED — grouped operational panels: KPI cards, charts, queues.
   GLASS    — surfaces that genuinely float ABOVE content: navigation, command
              palette, modal shells, floating toolbars, intelligence overlays.
   ─────────────────────────────────────────────────────────────────────────── */
.ms-surface {
  border-radius: var(--ms-r-md);
  border: 1px solid var(--ms-line);
  color: var(--ms-t-primary);
}

.ms-surface--content {
  background: var(--ms-s-solid);
  box-shadow: var(--ms-e-subtle);
}

.ms-surface--elevated {
  background: var(--ms-s-elevated);
  box-shadow: var(--ms-e-raised);
}

.ms-surface--glass {
  background: var(--ms-s-glass);
  border-color: var(--ms-g-border);
  box-shadow: var(--ms-g-shadow), var(--ms-g-highlight);
  -webkit-backdrop-filter: blur(var(--ms-g-blur)) saturate(var(--ms-g-saturate));
  backdrop-filter: blur(var(--ms-g-blur)) saturate(var(--ms-g-saturate));
}

.ms-surface--sunken {
  background: var(--ms-s-sunken);
  box-shadow: none;
}

/* Glass is expensive to composite. Below the tablet breakpoint, and wherever
   the platform reports no backdrop-filter support, degrade to an opaque
   elevated surface rather than shipping a transparent panel with unreadable
   text behind it. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ms-surface--glass {
    background: var(--ms-s-elevated);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

/* ───────────────────────────────────────────────────────────────────────────
   3. SEMANTIC MASONRY GRID
   12 columns desktop / 6 tablet / 2 mobile. Card SIZE is assigned from
   operational tier, never chosen per page — that is what stops a dashboard
   degenerating into a wall of equal Bootstrap cards.
   ─────────────────────────────────────────────────────────────────────────── */
.ms-board {
  display: grid;
  grid-template-columns: repeat(var(--ms-grid-cols), minmax(0, 1fr));
  grid-auto-rows: minmax(var(--ms-grid-row), auto);
  gap: var(--ms-grid-gap);
  align-items: start;
  /* Dense packing backfills the pocket a tall card leaves beside it; without
     it CSS Grid's sparse algorithm strands later cards past the gap. */
  grid-auto-flow: row dense;
}

/* Semantic spans — declared ONCE. Card variants below reuse these selectors
   rather than redeclaring grid-column, so every responsive override is written
   in exactly one place. (Duplicating spans onto .ms-c--* is precisely how hero
   and feature cards end up keeping desktop spans on a 390px phone.)

   COLUMNS ONLY — deliberately. These spans used to reserve rows too (hero
   span 3, feature span 2, tall span 3). Measured against the first real content
   ever put through this grid (the Service Pulse, phase 4), that reservation
   stranded a block of dead space roughly 230px tall under the hero: the card
   claimed three rows, its six record rows filled about one and a half, and
   nothing could backfill the rest because the rows were already claimed. Dense
   packing cannot rescue space that is spoken for.

   Height already communicates itself — a card holding more rows is taller,
   because grid-auto-rows is minmax(row, auto). Importance is carried by COLUMN
   span, padding, radius and elevation, none of which strand anything. Removing
   the row reservations cut the board from 936px to 856px on a 1440 viewport
   with no loss of hierarchy. */
/* SCOPING (fix): these semantic spans are written for the 12-column .ms-board
   grid ONLY. Unscoped, `grid-column: span 4` also applied to every .ms-c--compact
   /--standard/--feature card placed in an ordinary Tailwind grid — e.g. the KPI
   strips built by engKpi() inside `grid grid-cols-2 lg:grid-cols-4`. In a
   4-column grid "span 4" means the whole row, so every KPI card rendered as a
   full-width bar and an 8-KPI strip became 8 stacked rows ~818px tall instead of
   two tidy rows. Measured on MarketSync HQ Pulse at 1440px: 13 of 17 cards were
   full-bleed. Scoping to .ms-board restores the intended behaviour in the board
   and lets the surrounding grid decide placement everywhere else. */
.ms-board .ms-span-hero,
.ms-board .ms-c--hero
{
  grid-column: span 8;
}

.ms-board .ms-span-feature,
  .ms-board .ms-c--feature {
  grid-column: span 4;
}

.ms-board .ms-span-wide,
  .ms-board .ms-c--wide {
  grid-column: span 8;
}

.ms-board .ms-span-tall,
  .ms-board .ms-c--tall {
  grid-column: span 4;
}

.ms-board .ms-span-standard,
  .ms-board .ms-c--standard {
  grid-column: span 4;
}

.ms-board .ms-span-compact,
  .ms-board .ms-c--compact {
  grid-column: span 4;
}

.ms-board .ms-span-full,
  .ms-board .ms-c--full {
  grid-column: 1 / -1;
}

/* Multi-column masonry container for variable-height cards across all dashboard pages */
.ms-masonry,
.ms-masonry-grid {
  column-count: 1;
  column-gap: var(--ms-grid-gap, 1.25rem);
  width: 100%;
}

@media (min-width: 768px) {

  .ms-masonry,
  .ms-masonry-grid {
    column-count: 2;
  }
}

@media (min-width: 1280px) {

  .ms-masonry,
  .ms-masonry-grid {
    column-count: 3;
  }
}

.ms-masonry>*,
.ms-masonry-grid>*,
.ms-masonry-item {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: var(--ms-grid-gap, 1.25rem);
  display: inline-block;
  width: 100%;
  box-sizing: border-box;
}

/* List rows and action buttons inline alignment */
.ms-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  gap: var(--ms-sp-3, 0.75rem);
  width: 100%;
  padding: 0.625rem 0.875rem;
  border-radius: var(--ms-r-md, 0.75rem);
  reports is so border-block-end: ;
  border: 1px solid var(--ms-line);
  background: var(--ms-s-glass);
  box-sizing: border-box;
  transition: background var(--ms-m-fast, 0.15s) ease, border-color var(--ms-m-fast, 0.15s) ease;
}

.dark .ms-list-row {
  border-color: rgba(30, 41, 59, 0.6);
  background: rgba(15, 23, 42, 0.35);
}

.ms-list-row:hover {
  background: rgba(241, 245, 249, 0.8);
}

.dark .ms-list-row:hover {
  background: rgba(30, 41, 59, 0.6);
}

.ms-list-row>* {
  text-align: left;
}

.ms-list-row .ms-btn,
.ms-list-row button {
  flex-shrink: 0;
  white-space: nowrap;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ───────────────────────────────────────────────────────────────────────────
   4. CARD SYSTEM
   Card = material + span + internal hierarchy. Variants map to operational
   tier so importance is decided once, centrally, and cannot drift per page.
   ─────────────────────────────────────────────────────────────────────────── */
.ms-board>.ms-c {
  height: 100%;
}

.ms-c {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  gap: var(--ms-sp-2);
  min-width: 0;
  /* lets truncation work inside grid */
  padding: var(--ms-sp-5);
  border-radius: var(--ms-r-lg);
  border: 1px solid var(--ms-line);
  background: var(--ms-s-solid);
  box-shadow: var(--ms-e-subtle);
  color: var(--ms-t-primary);
  transition: box-shadow var(--ms-m-normal) var(--ms-m-ease),
    transform var(--ms-m-normal) var(--ms-m-ease),
    border-color var(--ms-m-normal) var(--ms-m-ease);
}

.ms-c>*,
.ms-c>div,
.ms-c>ul,
.ms-c>ol,
.ms-c>dl,
.ms-c>p,
.ms-c>header,
.ms-c>section,
.ms-c .ms-c__body,
.ms-c .ms-c__content,
.ms-c [class*="space-y"] {
  text-align: left;
  align-self: stretch;
}

.ms-c ul,
.ms-c ol,
.ms-c dl,
.ms-c li {
  text-align: left;
}

/* Tier 1 — critical. Bigger radius and elevation because it should read as
   the first thing on the page before a single label is parsed. */
.ms-c--hero {
  padding: var(--ms-sp-6);
  border-radius: var(--ms-r-hero);
  box-shadow: var(--ms-e-float);
}

.ms-c--feature {
  padding: var(--ms-sp-6);
  border-radius: var(--ms-r-xl);
  box-shadow: var(--ms-e-raised);
}

/* Tier 2 — primary operating state. */
.ms-c--wide,
.ms-c--tall {
  box-shadow: var(--ms-e-raised);
}

/* Tier 3 / 4 — secondary metrics and utilities. */
.ms-c--compact {
  padding: var(--ms-sp-4);
  border-radius: var(--ms-r-md);
}

/* Material overrides — orthogonal to size. */
.ms-c--glass {
  background: var(--ms-s-glass);
  border-color: var(--ms-g-border);
  box-shadow: var(--ms-g-shadow), var(--ms-g-highlight);
  -webkit-backdrop-filter: blur(var(--ms-g-blur)) saturate(var(--ms-g-saturate));
  backdrop-filter: blur(var(--ms-g-blur)) saturate(var(--ms-g-saturate));
}

.ms-c--elevated {
  background: var(--ms-s-elevated);
  box-shadow: var(--ms-e-raised);
}

.ms-c--solid {
  background: var(--ms-s-solid);
}

.ms-c--quiet {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  padding: 0;
}

/* An empty metric must not occupy a hero. Collapsing it is a hierarchy fix,
   not a cosmetic one: a large card reading "0" claims importance it lacks
   and pushes real signal below the fold. */
.ms-c[data-empty="true"] {
  /* This used to force grid-row: span 1 !important, purely to claw back the rows
     a hero or feature reserved. Nothing reserves rows any more (see §3), so an
     empty card is already one row tall and the override is dead weight — and the
     design system does not keep !important it has stopped needing. */
  min-height: 0;
}

.ms-board .ms-c--hero[data-empty="true"],
  .ms-board .ms-c--feature[data-empty="true"] {
  grid-column: span 4;
  /* stay on the 4-track so rows always tile */
  padding: var(--ms-sp-4);
  border-radius: var(--ms-r-md);
  box-shadow: var(--ms-e-subtle);
}

/* Attention state — raises emphasis without inventing a new card size, so
   dynamic priority stays inside the approved vocabulary (brief §17). */
.ms-c[data-priority="critical"] {
  border-color: color-mix(in srgb, var(--ms-st-danger) 45%, var(--ms-line));
}

.ms-c[data-priority="warning"] {
  border-color: color-mix(in srgb, var(--ms-st-warning) 45%, var(--ms-line));
}

/* Interactive cards only. A non-interactive card that lifts on hover is a
   false affordance. */
.ms-c--interactive {
  cursor: pointer;
}

.ms-c--interactive:hover {
  transform: translateY(var(--ms-m-lift));
  box-shadow: var(--ms-e-float);
  border-color: var(--ms-line-strong);
}

.ms-c--interactive:active {
  transform: translateY(0);
}

.ms-c--interactive:focus-visible {
  outline: 2px solid var(--ms-accent-brand);
  outline-offset: 2px;
}

/* ───────────────────────────────────────────────────────────────────────────
   5. CARD INTERNAL ANATOMY
   Eyebrow → title → value → context → body → action. Giving cards a fixed
   internal grammar is what prevents them decaying into text containers.
   ─────────────────────────────────────────────────────────────────────────── */
.ms-c__eyebrow {
  font-size: var(--ms-f-eyebrow);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ms-t-secondary);
}

.ms-c__title {
  font-size: var(--ms-f-card);
  font-weight: 650;
  line-height: var(--ms-lh-tight);
  color: var(--ms-t-primary);
}

.ms-c__value {
  font-size: var(--ms-f-metric);
  font-weight: 750;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ms-t-primary);
}

.ms-c--hero .ms-c__value {
  font-size: var(--ms-f-hero);
}

.ms-c__context {
  font-size: var(--ms-f-meta);
  font-weight: 500;
  color: var(--ms-t-secondary);
}

.ms-c__body {
  font-size: var(--ms-f-body);
  line-height: var(--ms-lh-body);
  color: var(--ms-t-secondary);
  min-height: 0;
  flex: 1;
}

.ms-c__footer {
  margin-top: auto;
  padding-top: var(--ms-sp-2);
}

/* ───────────────────────────────────────────────────────────────────────────
   6. TYPOGRAPHY + CONTRAST GUARDS
   ─────────────────────────────────────────────────────────────────────────── */
.ms-title-page {
  font-size: var(--ms-f-page);
  font-weight: 750;
  line-height: var(--ms-lh-tight);
  letter-spacing: -0.02em;
  color: var(--ms-t-primary);
}

.ms-title-section {
  font-size: var(--ms-f-section);
  font-weight: 700;
  line-height: var(--ms-lh-tight);
  letter-spacing: -0.015em;
  color: var(--ms-t-primary);
}

.ms-text-body {
  font-size: var(--ms-f-body);
  font-weight: 450;
  line-height: var(--ms-lh-body);
  color: var(--ms-t-primary);
}

.ms-text-muted {
  font-size: var(--ms-f-body);
  font-weight: 450;
  line-height: var(--ms-lh-body);
  color: var(--ms-t-secondary);
}

.ms-text-meta {
  font-size: var(--ms-f-meta);
  font-weight: 500;
  color: var(--ms-t-secondary);
}

.ms-text-caption {
  font-size: var(--ms-f-caption);
  font-weight: 500;
  color: var(--ms-t-tertiary);
}

/* Tertiary text is 2.9:1 and fails WCAG AA for body copy. It is legitimate
   for incidental meta only, so it is barred from the two elements where it
   would actually harm someone reading a record. */
p.ms-text-caption,
.ms-c__body .ms-text-caption {
  color: var(--ms-t-secondary);
}

/* Text sitting ON glass must not inherit glass's contrast loss. */
.ms-surface--glass .ms-c__body,
.ms-c--glass .ms-c__body {
  color: var(--ms-t-primary);
}

/* ───────────────────────────────────────────────────────────────────────────
   7. ACCESSIBILITY + MOTION
   ─────────────────────────────────────────────────────────────────────────── */
.ms-focusable:focus-visible,
.ms-c__footer :focus-visible {
  outline: 2px solid var(--ms-accent-brand);
  outline-offset: 2px;
  border-radius: var(--ms-r-xs);
}

/* 44px is the comfortable-touch floor; applied via a class so it can be
   opted into on the controls that need it without inflating dense tables. */
.ms-touch { min-height: 44px; min-width: 44px; }

@media (prefers-reduced-motion: reduce) {

  .ms-c,
  .ms-c--interactive:hover {
    transition: none;
    transform: none;
  }
}

/* Windows High Contrast / forced-colors: translucency and custom shadows are
   discarded by the OS anyway — give these surfaces a real border so they do
   not collapse into the page. */
@media (forced-colors: active) {

  .ms-c,
  .ms-surface {
    border: 1px solid CanvasText;
  }

  .ms-c--glass,
  .ms-surface--glass {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: Canvas;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   8. PULSE KPI HIERARCHY
   ═══════════════════════════════════════════════════════════════════════════
   The Pulse tile row is where "everything looks equally important" does the
   most damage. Five identical tiles meant the one item needing a human today
   read exactly like a count of deliveries that needs nobody.

   Emphasis here is DATA-DRIVEN, not decorative. The renderer stamps
   data-emphasis on each tile from that tile's own value:

     lead   — actionable and non-zero: the reason to open this page at all
     alert  — a watch metric that is currently non-zero
     normal — an informational count
     quiet  — a zero: true, worth showing, worth nobody's attention

   A tile is only large while its number earns it. When the store is calm the
   row flattens back to equals — which is the honest picture of a calm store,
   not a layout that shouts at an empty queue. This is the masonry principle
   applied literally: size communicates importance, and importance comes from
   the data.

   The column counts assume the five-tile Running-today row; a sixth tile
   simply wraps and stays aligned. pulse-kpi-hierarchy.test.js pins the count
   so the assumption cannot drift silently.
   ═══════════════════════════════════════════════════════════════════════════ */

.pulse-summary-grid {
  display: grid;
  /* No lead tile means nothing is wrong: five equal tiles, one clean row. */
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--ms-sp-3, .75rem);
  width: 100%;
  min-width: 0;
  align-items: stretch;
}

/* A lead tile takes two tracks, so the row needs a sixth to stay flush. */
.pulse-summary-grid:has([data-emphasis="lead"]) {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.pulse-summary-grid>* {
  min-width: 0;
  grid-column: span 1;
}

.pulse-summary-grid>[data-emphasis="lead"] {
  grid-column: span 2;
}

/* Size is the primary signal; weight and colour reinforce it rather than
   replace it, so the hierarchy still reads in forced-colors mode. */
.ms-kpi__value {
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* A fixed 48 / 36 / 30 / 24 scale rather than vw clamps. Clamps looked right at
   1440 but bottomed out below it — alert and normal both landed on 30px, so the
   middle tier silently stopped existing at exactly the widths where the board is
   tightest and the distinction matters most. */
[data-emphasis="lead"] .ms-kpi__value {
  font-size: 3rem;
}

[data-emphasis="alert"] .ms-kpi__value {
  font-size: 2.25rem;
}

[data-emphasis="normal"] .ms-kpi__value {
  font-size: 1.875rem;
}

/* A zero is still a fact, so it keeps the same size as a normal count —
   shrinking it made a calm tile look like a different component. */
[data-emphasis="quiet"] .ms-kpi__value {
  font-size: 1.875rem;
  font-weight: 900;
}

.ms-kpi__label {
  font-size: .75rem;
  font-weight: 700;
  margin-top: .35rem;
}

[data-emphasis="lead"] .ms-kpi__label {
  font-size: .8125rem;
}

/* The records behind a count. A tile answers "how many"; this answers "which
   ones", in place, so nobody has to leave the page and re-find them. */
.ms-kpi-panel {
  border-top: 1px solid var(--ms-border, rgba(15, 23, 42, .10));
  padding-top: var(--ms-sp-3, .75rem);
}

/* A record row carries a person's name and their vehicle. Cramped against the
   border it reads as a dense list to skim past; these are the individual
   customers and units someone is about to act on, so they get room to breathe. */
.ms-kpi-record {
  padding: var(--ms-sp-4, 1rem) calc(var(--ms-sp-4, 1rem) + 2px);
}

.ms-kpi-record .ms-kpi-record__meta {
  margin-top: .25rem;
}

.ms-kpi__hint {
  letter-spacing: .01em;
}

/* The lead tile is the one thing on the page asking for a decision, so it gets
   a real edge rather than a slightly darker border. */
.pulse-summary-grid>[data-emphasis="lead"] {
  box-shadow: inset 0 0 0 1px var(--ms-accent-warn, #D97706),
    0 6px 20px rgba(217, 119, 6, .12);
}

/* ───────────────────────────────────────────────────────────────────────────
   9. RESPONSIVE
   Every breakpoint override lives HERE, at the end of the file, deliberately.
   Media queries do not add specificity — they only win by source order — so
   overrides written next to their component get silently beaten by any later
   rule for the same selector. Keeping them last means a breakpoint rule always
   wins, and there is exactly one place to look when a layout misbehaves at a
   given width.
   ─────────────────────────────────────────────────────────────────────────── */

/* — Tablet / small desktop: 12 → 6 columns — */
@media (max-width: 1279px) {
  .ms-board {
    --ms-grid-cols: 6;
  }

  .ms-board .ms-span-hero,
  .ms-board .ms-c--hero { grid-column: span 6; }

  .ms-board .ms-span-feature,
  .ms-board .ms-c--feature {
    grid-column: span 3;
  }

  .ms-board .ms-span-wide,
  .ms-board .ms-c--wide {
    grid-column: span 6;
  }

  .ms-board .ms-span-tall,
  .ms-board .ms-c--tall {
    grid-column: span 3;
  }

  .ms-board .ms-span-standard,
  .ms-board .ms-c--standard {
    grid-column: span 3;
  }

  .ms-board .ms-span-compact,
  .ms-board .ms-c--compact {
    grid-column: span 3;
  }

  /* A collapsed empty card may never be wider than the grid it sits in — a
     span wider than the column count silently creates implicit columns and
     breaks the whole board's alignment. */
  .ms-board .ms-c--hero[data-empty="true"] { grid-column: span 3; }
  .ms-board .ms-c--feature[data-empty="true"] { grid-column: span 3; }

  /* Below 1280 the board column is roughly 700px once the 240px department rail
     and the 300px operations rail are taken out, so six tracks would be ~117px —
     narrower than the labels. Four tracks, and the attention tile takes the full
     width whatever its emphasis.

     That last part is deliberate: five tiles do not divide by four, so letting
     emphasis decide the span here produced a half-empty second row with two dead
     tracks — the same phantom-column failure the board grid already learned once.
     Giving the first tile the whole row makes both cases tile exactly: 1 + 4.

     The cost, stated plainly: a calm store gets a full-width tile reading "0
     items needing attention". Area stops tracking importance at this width
     because five tiles will not divide four ways any other way that tiles
     evenly. Emphasis is still carried here by type size (30px quiet/normal
     against 36px lead) and by the amber edge, which only a real lead tile gets. */
  .pulse-summary-grid,
  .pulse-summary-grid:has([data-emphasis="lead"]) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .pulse-summary-grid> :first-child {
    grid-column: 1 / -1;
  }

  [data-emphasis="lead"] .ms-kpi__value {
    font-size: 2.25rem;
  }
}

/* — Phone: 6 → 2 columns — */
@media (max-width: 767px) {
  .ms-board {
    --ms-grid-cols: 2;
    --ms-grid-gap: var(--ms-sp-3);
    grid-auto-rows: minmax(0, auto);
  }

  /* Anything with internal structure goes full width; only micro-KPIs pair up.
     Preserving desktop spans on a 390px phone is what produces the cramped
     half-cards and clipped labels this system exists to replace. */
  .ms-board .ms-span-hero,
  .ms-board .ms-c--hero,
  .ms-board .ms-span-feature,
  .ms-board .ms-c--feature,
  .ms-board .ms-span-wide,
  .ms-board .ms-c--wide,
  .ms-board .ms-span-tall,
  .ms-board .ms-c--tall,
  .ms-board .ms-span-standard,
  .ms-board .ms-c--standard {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .ms-board .ms-span-compact,
  .ms-board .ms-c--compact {
    grid-column: span 1;
    grid-row: auto;
  }

  /* Two columns means a collapsed empty card is at most one of them. */
  .ms-board .ms-c--hero[data-empty="true"] { grid-column: span 1; }
  .ms-board .ms-c--feature[data-empty="true"] { grid-column: span 1; }

  /* Hero/feature padding and radius are desktop-scaled; on a phone that eats
     horizontal space the content needs. */
  .ms-c--hero,
  .ms-c--feature {
    padding: var(--ms-sp-4);
    border-radius: var(--ms-r-lg);
  }

  /* Blur is the expensive part of glass. Halve it on the devices least able
     to composite it — applies to BOTH spellings of a glass surface. */
  .ms-surface--glass,
  .ms-c--glass { --ms-g-blur: 14px; }

  /* Two tracks. The lead takes the full width — a phone has no room to make a
     tile "twice as important" and still fit its number. */
  .pulse-summary-grid,
  .pulse-summary-grid:has([data-emphasis="lead"]) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* 1 + 2 + 2: three full rows, no dead tracks. */
  .pulse-summary-grid> :first-child {
    grid-column: 1 / -1;
  }

  [data-emphasis="lead"] .ms-kpi__value {
    font-size: 2.25rem;
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   BATCH 1 — ownership, materials, buttons, inputs, modal
   This file owns tokens + primitives. marketsync-theme.css composes surfaces.
   dashboard-nav.css owns nav layout only. dashboard-brand-repaint.css is a
   temporary indigo→Market Blue utility map and must not grow new features.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --ms-market-blue: #2563EB;
  --ms-dealer-blue: #1F4ED8;
  --ms-deep-blue: #153AA6;
  --ms-graphite: #17191F;
  --ms-warm-white: #F7F8FA;
  --ms-steel: #6B7280;
  --ms-dark-canvas: #121318;
  --ms-dark-raised: #1A1D24;
  --ms-dark-border: #2B303A;
  --ms-dark-muted: #A5ACB8;
  --ms-mat-content: var(--ms-warm-white);
  --ms-mat-structure: #FFFFFF;
  --ms-mat-raised: #FFFFFF;
  --ms-mat-glass: rgba(255, 255, 255, .62);
  --ms-mat-glass-strong: rgba(255, 255, 255, .78);
  --ms-mat-glass-clear: rgba(255, 255, 255, .42);
  --ms-mat-overlay: rgba(18, 19, 24, .46);
}

html.dark,
.dark {
  --ms-mat-content: var(--ms-dark-canvas);
  --ms-mat-structure: var(--ms-dark-raised);
  --ms-mat-raised: #22262F;
  --ms-mat-glass: rgba(26, 29, 36, .62);
  --ms-mat-glass-strong: rgba(26, 29, 36, .82);
  --ms-mat-glass-clear: rgba(26, 29, 36, .38);
  --ms-mat-overlay: rgba(0, 0, 0, .55);
}

.ms-mat-content {
  background: var(--ms-mat-content);
  color: var(--ms-graphite);
}

.dark .ms-mat-content {
  color: var(--ms-warm-white);
}

.ms-mat-structure {
  background: var(--ms-mat-structure);
  border: 1px solid rgba(23, 25, 31, .10);
}

.dark .ms-mat-structure {
  border-color: var(--ms-dark-border);
}

.ms-mat-raised {
  background: var(--ms-mat-raised);
  box-shadow: 0 8px 24px rgba(23, 25, 31, .06);
}

.ms-mat-overlay {
  background: var(--ms-mat-overlay);
}

.ms-glass,
.ms-glass-nav,
.ms-glass-toolbar,
.ms-glass-popover,
.ms-glass-dropdown,
.ms-glass-action,
.ms-glass-float,
.ms-glass-command {
  background: var(--ms-mat-glass);
  border: 1px solid rgba(23, 25, 31, .10);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.ms-glass-strong {
  background: var(--ms-mat-glass-strong);
}

.ms-glass-clear {
  background: var(--ms-mat-glass-clear);
}

.dark .ms-glass,
.dark .ms-glass-nav,
.dark .ms-glass-toolbar,
.dark .ms-glass-popover,
.dark .ms-glass-dropdown,
.dark .ms-glass-action,
.dark .ms-glass-float,
.dark .ms-glass-command {
  border-color: var(--ms-dark-border);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {

  .ms-glass,
  .ms-glass-nav,
  .ms-glass-toolbar,
  .ms-glass-popover,
  .ms-glass-dropdown,
  .ms-glass-action,
  .ms-glass-float,
  .ms-glass-command,
  .ms-glass-strong,
  .ms-glass-clear {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: var(--ms-mat-structure);
  }
}

@media (prefers-reduced-transparency: reduce) {

  .ms-glass,
  .ms-glass-nav,
  .ms-glass-toolbar,
  .ms-glass-popover,
  .ms-glass-dropdown,
  .ms-glass-action,
  .ms-glass-float,
  .ms-glass-command,
  .ms-glass-strong,
  .ms-glass-clear {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: var(--ms-mat-structure);
  }
}

@media (prefers-reduced-motion: reduce) {

  .ms-glass,
  .ms-btn,
  .ms-modal {
    transition: none;
  }
}

.ms-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 44px;
  padding: .6rem 1rem;
  border-radius: 12px;
  font-family: var(--font-ui, Inter, sans-serif);
  font-weight: 800;
  font-size: .875rem;
  border: 1px solid transparent;
  cursor: pointer;
}

.ms-btn--primary {
  background: var(--ms-market-blue);
  color: #fff;
}

.ms-btn--primary:hover {
  background: var(--ms-dealer-blue);
}

.ms-btn--secondary {
  background: rgba(37, 99, 235, .08);
  color: var(--ms-market-blue);
  border-color: rgba(37, 99, 235, .2);
}

.ms-btn--tertiary,
.ms-btn--ghost {
  background: transparent;
  color: var(--ms-graphite);
}

.dark .ms-btn--tertiary,
.dark .ms-btn--ghost {
  color: var(--ms-warm-white);
}

.ms-btn--danger {
  background: #DC2626;
  color: #fff;
}

.ms-btn--icon {
  min-width: 44px;
  padding: .6rem;
}

.ms-input,
.ms-select,
.ms-textarea {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  padding: .65rem .85rem;
  border: 1px solid #D9DEE8;
  background: #fff;
  color: var(--ms-graphite);
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 1rem;
}

.dark .ms-input,
.dark .ms-select,
.dark .ms-textarea {
  background: var(--ms-dark-canvas);
  color: var(--ms-warm-white);
  border-color: var(--ms-dark-border);
}

.ms-input:focus,
.ms-select:focus,
.ms-textarea:focus {
  outline: 2px solid var(--ms-market-blue);
  outline-offset: 1px;
  border-color: var(--ms-market-blue);
}

.ms-textarea {
  min-height: 96px;
}

.ms-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--ms-mat-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.ms-modal {
  width: 100%;
  max-width: 32rem;
  border-radius: 20px;
  background: var(--ms-mat-structure);
  color: var(--ms-graphite);
  border: 1px solid rgba(23, 25, 31, .10);
  box-shadow: 0 24px 60px rgba(23, 25, 31, .18);
}

.dark .ms-modal {
  color: var(--ms-warm-white);
  border-color: var(--ms-dark-border);
}

.ms-modal__header,
.ms-modal__footer {
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.ms-modal__body {
  padding: 0 1.1rem 1.1rem;
}

.ms-modal__close {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: inherit;
}

#nav-more-panel,
#nav-more-menu .ms-more-sheet {
  background: var(--ms-mat-glass-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.ms-acc-text {
  color: #2563EB;
}

.dark .ms-acc-text,
html.dark .ms-acc-text {
  color: #93C5FD;
}

.ms-acc-bg {
  background: #EFF6FF;
}

.dark .ms-acc-bg,
html.dark .ms-acc-bg {
  background: rgba(37, 99, 235, .16);
}

.ms-acc-solid {
  background: #2563EB;
  color: #fff;
}

.ms-acc-solid:hover {
  background: #1F4ED8;
}


/* Department identity colours. These are restrained navigation/wayfinding
   accents, not status colours, so a page does not become monochrome when its
   live metrics happen to be zero. */
.ms-acc-indigo-text { color:#4F46E5; } .ms-acc-indigo-bg { background:#EEF2FF; } .ms-acc-indigo-solid { background:#4F46E5; color:#fff; }
.ms-acc-violet-text { color:#7C3AED; } .ms-acc-violet-bg { background:#F5F3FF; } .ms-acc-violet-solid { background:#7C3AED; color:#fff; }
.ms-acc-sky-text { color:#0284C7; } .ms-acc-sky-bg { background:#F0F9FF; } .ms-acc-sky-solid { background:#0284C7; color:#fff; }
.ms-acc-emerald-text { color:#059669; } .ms-acc-emerald-bg { background:#ECFDF5; } .ms-acc-emerald-solid { background:#059669; color:#fff; }
.ms-acc-amber-text { color:#D97706; } .ms-acc-amber-bg { background:#FFFBEB; } .ms-acc-amber-solid { background:#D97706; color:#fff; }
.ms-acc-rose-text { color:#E11D48; } .ms-acc-rose-bg { background:#FFF1F2; } .ms-acc-rose-solid { background:#E11D48; color:#fff; }
.ms-acc-cyan-text { color:#0891B2; } .ms-acc-cyan-bg { background:#ECFEFF; } .ms-acc-cyan-solid { background:#0891B2; color:#fff; }
.ms-acc-teal-text { color:#0F766E; } .ms-acc-teal-bg { background:#F0FDFA; } .ms-acc-teal-solid { background:#0F766E; color:#fff; }

html.dark .ms-acc-indigo-text { color:#A5B4FC; } html.dark .ms-acc-indigo-bg { background:rgba(79,70,229,.18); }
html.dark .ms-acc-violet-text { color:#C4B5FD; } html.dark .ms-acc-violet-bg { background:rgba(124,58,237,.18); }
html.dark .ms-acc-sky-text { color:#7DD3FC; } html.dark .ms-acc-sky-bg { background:rgba(2,132,199,.18); }
html.dark .ms-acc-emerald-text { color:#6EE7B7; } html.dark .ms-acc-emerald-bg { background:rgba(5,150,105,.18); }
html.dark .ms-acc-amber-text { color:#FCD34D; } html.dark .ms-acc-amber-bg { background:rgba(217,119,6,.18); }
html.dark .ms-acc-rose-text { color:#FDA4AF; } html.dark .ms-acc-rose-bg { background:rgba(225,29,72,.18); }
html.dark .ms-acc-cyan-text { color:#67E8F9; } html.dark .ms-acc-cyan-bg { background:rgba(8,145,178,.18); }
html.dark .ms-acc-teal-text { color:#5EEAD4; } html.dark .ms-acc-teal-bg { background:rgba(15,118,110,.18); }

[data-accent="market"] { --ms-local-accent:#2563EB; --ms-local-tint:#EFF6FF; }
[data-accent="indigo"] { --ms-local-accent:#4F46E5; --ms-local-tint:#EEF2FF; }
[data-accent="violet"] { --ms-local-accent:#7C3AED; --ms-local-tint:#F5F3FF; }
[data-accent="sky"] { --ms-local-accent:#0284C7; --ms-local-tint:#F0F9FF; }
[data-accent="emerald"] { --ms-local-accent:#059669; --ms-local-tint:#ECFDF5; }
[data-accent="amber"] { --ms-local-accent:#D97706; --ms-local-tint:#FFFBEB; }
[data-accent="rose"] { --ms-local-accent:#E11D48; --ms-local-tint:#FFF1F2; }
[data-accent="cyan"] { --ms-local-accent:#0891B2; --ms-local-tint:#ECFEFF; }
[data-accent="teal"] { --ms-local-accent:#0F766E; --ms-local-tint:#F0FDFA; }

html.dark [data-accent="market"] { --ms-local-tint:rgba(37,99,235,.16); }
html.dark [data-accent="indigo"] { --ms-local-tint:rgba(79,70,229,.18); }
html.dark [data-accent="violet"] { --ms-local-tint:rgba(124,58,237,.18); }
html.dark [data-accent="sky"] { --ms-local-tint:rgba(2,132,199,.18); }
html.dark [data-accent="emerald"] { --ms-local-tint:rgba(5,150,105,.18); }
html.dark [data-accent="amber"] { --ms-local-tint:rgba(217,119,6,.18); }
html.dark [data-accent="rose"] { --ms-local-tint:rgba(225,29,72,.18); }
html.dark [data-accent="cyan"] { --ms-local-tint:rgba(8,145,178,.18); }
html.dark [data-accent="teal"] { --ms-local-tint:rgba(15,118,110,.18); }

/* ── The KPI strip ───────────────────────────────────────────────────────────
 * One class for every page's KPI row, so the tiles break at the same widths and
 * stand the same height everywhere. engKpiGrid() in dashboard-part10.js is the
 * only thing that writes it.
 *
 * grid-auto-rows: 1fr is the whole point: without it a row whose labels wrap to
 * two lines ("Monthly recurring revenue") stands taller than the row beneath it,
 * and eight tiles read as two different components rather than one grid. It is
 * a plain rule rather than Tailwind's `auto-rows-fr` because this project ships
 * a PREBUILT stylesheet — that utility is not in it and silently does nothing.
 */
.ms-kpi-grid {
  display: grid;
  grid-auto-rows: 1fr;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .ms-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .ms-kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ── Shared hierarchy pass: the existing shell and components keep their hooks.
   Navigation carries the glass layer; working content uses calm solid surfaces. */
html[data-ms-glass="global"] #dashboard-nav {
  background: rgba(231, 238, 248, .94);
  border-color: var(--ms-line-strong);
  box-shadow: inset -1px 0 0 var(--ms-line), 0 8px 24px rgba(15, 23, 42, .04);
  backdrop-filter: blur(12px) saturate(115%);
  -webkit-backdrop-filter: blur(12px) saturate(115%);
}
html[data-ms-glass="global"].dark #dashboard-nav {
  background: rgba(11, 24, 42, .95);
  border-color: rgba(148, 163, 184, .2);
  box-shadow: inset -1px 0 0 rgba(148, 163, 184, .12);
}
html.dark #ext-cta-banner {
  background: #172744;
  border-color: rgba(147, 197, 253, .3);
}
html.dark #ext-cta-banner p { color: #e2e8f0; }
html.dark #ext-cta-banner > div > div:first-child { color: #bfdbfe; }
#dept-nav .dept-nav-item { min-height: 40px; margin-block: 2px; }
#dept-nav .dept-nav-item[aria-current="page"] {
  background: var(--ms-accent-quiet);
  color: var(--ms-blue-700);
  box-shadow: inset 3px 0 0 var(--ms-accent-brand);
}
html.dark #dept-nav .dept-nav-item[aria-current="page"] {
  color: var(--ms-blue-300);
  background: rgba(37, 99, 235, .18);
}

.ms-page-header.ms-engine-header {
  /* Scoped !important values intentionally beat the legacy generic
     .ms-engine-header editorial rules in marketsync-theme.css. Only the canonical
     page header is compact; other engine surfaces keep their own sizing. */
  min-height: 0 !important;
  padding: var(--ms-sp-4) var(--ms-sp-6) !important;
  margin-bottom: var(--ms-sp-6) !important;
  align-items: center !important;
  border-radius: var(--ms-r-lg) !important;
  background:
    linear-gradient(90deg, var(--ms-local-tint, #EFF6FF), transparent 46%),
    var(--ms-s-solid);
  border: 1px solid var(--ms-line) !important;
  border-left: 4px solid var(--ms-local-accent, #2563EB) !important;
  box-shadow: var(--ms-e-subtle) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
.ms-page-header.ms-engine-header > div:first-child { gap: var(--ms-sp-3) !important; }
.ms-page-header .ms-engine-mark {
  width: 44px !important;
  height: 44px !important;
  border-radius: var(--ms-r-sm) !important;
  border: 0 !important;
  background: var(--ms-local-accent, #2563EB) !important;
  color: #fff !important;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--ms-local-accent, #2563EB) 24%, transparent) !important;
}
.ms-page-header .ms-engine-mark svg {
  width: 22px !important;
  height: 22px !important;
  color: #fff !important;
  stroke: currentColor !important;
}
.ms-page-header .ms-engine-title {
  font-size: clamp(1.5rem, 1.3rem + .8vw, 2rem) !important;
  line-height: 1.12 !important;
  letter-spacing: -.035em !important;
}
.ms-page-header .ms-engine-title + p {
  font-size: var(--ms-f-meta);
  line-height: 1.35;
  margin-top: var(--ms-sp-1);
  font-weight: 500;
  color: var(--ms-t-secondary);
}

.ms-dept-tab {
  border-radius: 10px 10px 0 0;
}
.ms-dept-tab svg { flex:0 0 auto; opacity:.92; }
.ms-dept-identity > span:first-child {
  border:1px solid color-mix(in srgb, currentColor 18%, transparent);
}

.ms-kpi-label,
.ms-section-title,
.ms-card-title {
  display:flex;
  align-items:center;
  gap:.5rem;
  min-width:0;
}
.ms-mini-mark {
  display:inline-flex;
  width:26px;
  height:26px;
  flex:0 0 26px;
  align-items:center;
  justify-content:center;
  border-radius:8px;
  background:var(--ms-local-tint, #EFF6FF);
  color:var(--ms-local-accent, #2563EB);
  border:1px solid color-mix(in srgb, var(--ms-local-accent, #2563EB) 18%, transparent);
}
.ms-mini-mark svg { width:14px; height:14px; stroke-width:2; }

.ms-kpi-tile,
.ms-section-card,
.ms-overview-card {
  position:relative;
  overflow:hidden;
  border-color:color-mix(in srgb, var(--ms-local-accent, #2563EB) 18%, var(--ms-line));
}
.ms-kpi-tile::before,
.ms-section-card::before,
.ms-overview-card::before {
  content:"";
  position:absolute;
  inset:0 auto auto 0;
  width:100%;
  height:3px;
  background:var(--ms-local-accent, #2563EB);
  opacity:.9;
  pointer-events:none;
}
.ms-kpi-tile {
  background:
    linear-gradient(135deg, var(--ms-local-tint, #EFF6FF), transparent 48%),
    var(--ms-s-solid);
}
.ms-section-card > summary,
.ms-overview-card > :first-child {
  position:relative;
  z-index:1;
}

.ms-settings-icon-action {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex: 0 0 36px !important;
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 10px !important;
  background: transparent !important;
  background-image: none !important;
  color: var(--ms-t-primary) !important;
  box-shadow: none !important;
  transform: none !important;
  cursor: pointer;
  transition: background var(--ms-m-fast), color var(--ms-m-fast);
}
.ms-settings-icon-action svg {
  display: block !important;
  width: 18px !important;
  height: 18px !important;
  color: inherit !important;
  stroke: currentColor !important;
  stroke-width: 1.8 !important;
  fill: none !important;
  transform: none !important;
}
.ms-settings-icon-action:hover {
  background: var(--ms-accent-quiet) !important;
  color: var(--ms-accent-brand) !important;
}
.ms-settings-icon-action:focus-visible { outline: 2px solid var(--ms-accent-brand); outline-offset: 2px; }

.ms-engine-tabs {
  padding: 0 var(--ms-sp-1);
  border: 0;
  border-bottom: 1px solid var(--ms-line-strong);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.ms-engine-tabs .ms-engine-tab {
  min-height: 44px;
  border-radius: 0;
  box-shadow: none;
}
.ms-engine-tabs .ms-engine-tab[aria-selected="true"] {
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--ms-accent-brand);
  box-shadow: none;
  color: var(--ms-accent-brand);
}

[data-engine-body] .ms-c--glass,
.ms-kpi-grid .ms-c--glass {
  background: var(--ms-s-solid);
  border-color: var(--ms-line);
  box-shadow: var(--ms-e-subtle);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.ms-kpi-grid { gap: var(--ms-sp-4); }
.ms-kpi-grid > .ms-c { min-height: 104px; padding: var(--ms-sp-4) var(--ms-sp-6); }
.ms-kpi-grid > .ms-c > div:first-child { align-items: flex-start; flex-direction: column; gap: var(--ms-sp-2); }
.ms-kpi-grid > .ms-c > div:first-child > span:first-child {
  color: var(--ms-t-secondary);
  font-size: var(--ms-f-eyebrow);
  font-weight: 650;
  letter-spacing: .03em;
}
.ms-kpi-grid > .ms-c > div:first-child > span:last-child {
  font-size: clamp(1.65rem, 1.2rem + 1.2vw, 2rem);
  line-height: 1.08;
  letter-spacing: -.035em;
  font-variant-numeric: tabular-nums;
}
[data-engine-rail] > details { box-shadow: none; border-color: var(--ms-line); }
[data-engine-rail] > details[data-rail-section="next-actions"] {
  background: var(--ms-s-solid);
  border-color: var(--ms-line-strong);
  box-shadow: var(--ms-e-subtle);
}
[data-engine-rail] > details[data-rail-section="reports"],
[data-engine-rail] > details[data-rail-section="quick-actions"] {
  background: transparent;
}

[data-page-content="profile"] > .ms-c--hero {
  padding: 0 0 var(--ms-sp-4);
  border: 0;
  border-bottom: 1px solid var(--ms-line-strong);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}
[data-page-content="profile"] .settings-cols.is-multi { gap: var(--ms-sp-6); }

/* Team & Access composes Staff, dealer management and lead-routing as sibling
   sections inside one host. They need real separation; otherwise their borders
   touch and read as one broken card. */
#settings-team > #dealer-view-panel,
#settings-team > #lead-routing-card {
  margin-top: var(--ms-sp-6) !important;
}
#settings-team > #dealer-view-panel.hidden,
#settings-team > #lead-routing-card.hidden {
  margin-top: 0 !important;
}

@media (min-width: 1024px) and (max-width: 1279px) {
  .ms-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  [data-page-content="profile"] .settings-cols.is-multi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  .ms-page-header.ms-engine-header { padding: var(--ms-sp-3) var(--ms-sp-4) !important; }
  .ms-page-header .ms-engine-mark { width: 40px !important; height: 40px !important; }
  .ms-page-header .ms-engine-title { font-size: 1.5rem !important; }
  .ms-kpi-grid > .ms-c { min-height: 88px; padding: var(--ms-sp-4); }
}

/* The chosen row in the Sales customer queue and the F&I deal queue: a blue bar
   and tint that read in light and dark mode (dark mode used to show a near-white
   row with white text). */
:root [data-sales-customer][aria-current="true"],
:root [data-fni-deal][aria-current="true"] {
  box-shadow: inset 3px 0 0 var(--ms-blue-500, #3b82f6);
  background-color: rgb(var(--ms-blue-50-rgb, 239 246 255));
}
:root.dark body [data-sales-customer][aria-current="true"],
:root.dark body [data-fni-deal][aria-current="true"] {
  background-color: rgb(59 130 246 / 0.16);
}
