/* ============================================================================
   SIXTY SIP — unified design system
   Owner-approved direction (2026-11-18), ported from the Clean Ops mockup.

   Rules enforced on every screen:
     1. Action = brand red. Status is a separate 4-level scale
        (danger / warning / info / neutral) and never used for buttons.
     2. No one-side colour rails, no coloured corner bars on cards or tables.
     3. Tables read as tables: neutral header band, hairline grid, quiet hover.
     4. Tabs are prominent pills; the active tab is a solid red pill.
     5. Stat cards share one scale: bold title, big number, note, one badge.

   This layer declares its own --ds-* tokens on purpose: the department skins
   remap --bg-elevated / --pd-soft / --radius-* per route, which would drag the
   unified chrome back into beige/green. Components here stay neutral.
   ========================================================================== */

:root {
  --ds-surface: #ffffff;
  --ds-head: #f4f6f8;
  --ds-text: #14181f;
  --ds-muted: #5b6472;
  --ds-border: rgba(15, 23, 42, 0.1);
  --ds-border-strong: rgba(15, 23, 42, 0.16);
  --ds-radius: 14px;
  --ds-radius-sm: 9px;
  --ds-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 22px rgba(15, 23, 42, 0.05);

  --ds-badge-size: 60px;
  --ds-badge-radius: 18px;
  --ds-badge-red: radial-gradient(120% 120% at 30% 0%, rgba(255, 255, 255, .24), rgba(255, 255, 255, 0) 58%), linear-gradient(180deg, #e8465a 0%, #b92333 100%);
  --ds-badge-amber: radial-gradient(120% 120% at 30% 0%, rgba(255, 255, 255, .26), rgba(255, 255, 255, 0) 58%), linear-gradient(180deg, #d08a3c 0%, #a9661a 100%);
  --ds-badge-blue: radial-gradient(120% 120% at 30% 0%, rgba(255, 255, 255, .26), rgba(255, 255, 255, 0) 58%), linear-gradient(180deg, #3d7bf0 0%, #1f47b8 100%);
  --ds-badge-green: radial-gradient(120% 120% at 30% 0%, rgba(255, 255, 255, .24), rgba(255, 255, 255, 0) 58%), linear-gradient(180deg, #2f9e6b 0%, #16754c 100%);
  --ds-badge-slate: radial-gradient(120% 120% at 30% 0%, rgba(255, 255, 255, .2), rgba(255, 255, 255, 0) 58%), linear-gradient(180deg, #49546a 0%, #2c3444 100%);
  --ds-badge-violet: radial-gradient(120% 120% at 30% 0%, rgba(255, 255, 255, .24), rgba(255, 255, 255, 0) 58%), linear-gradient(180deg, #7c66d6 0%, #5441a8 100%);
}

/* The warm workspace skin (beige) is the base of every department page.
   Neutralise it here so tables, cards and page chrome come out neutral. */
:root {
  --workspace-page: #f4f5f7;
  --workspace-surface: #ffffff;
  --workspace-subtle: #f4f6f8;
  --workspace-line: rgba(15, 23, 42, 0.1);
  --workspace-ink: #14181f;
  --workspace-secondary: #5b6472;
  --workspace-brand-soft: #fdecea;
}

:root[data-theme="dark"] {
  --ds-surface: #1a1f27;
  --ds-head: #232a35;
  --ds-text: #e9edf3;
  --ds-muted: #a6b0bd;
  --ds-border: rgba(255, 255, 255, 0.1);
  --ds-border-strong: rgba(255, 255, 255, 0.18);
  --ds-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 22px rgba(0, 0, 0, 0.28);
  --workspace-page: #0f1216;
  --workspace-surface: #1a1f27;
  --workspace-subtle: #232a35;
  --workspace-line: rgba(255, 255, 255, 0.1);
  --workspace-ink: #e9edf3;
  --workspace-secondary: #a6b0bd;
  --workspace-brand-soft: #3a1a1d;
}

/* ---------------------------------------------------------------------------
   1. Table chrome — replace the department rail + tinted header band
   ------------------------------------------------------------------------- */
body[class] #app :is(.ops-table-card, .panel, .final-detail-section)[data-table-purpose] {
  border: 1px solid var(--ds-border) !important;
  border-left: 1px solid var(--ds-border) !important;
  box-shadow: var(--ds-shadow) !important;
}

body[class] #app .table-visual-identity {
  border: 1px solid var(--ds-border) !important;
  border-top: 1px solid var(--ds-border) !important;
  border-radius: var(--ds-radius) !important;
  background: var(--ds-surface) !important;
}

html body[class] #app :is(.ac-panel, .pd-panel, .aw-panel, .ops-table-card) :is(thead, th) {
  background: var(--ds-head) !important;
  color: var(--ds-muted) !important;
  border-color: var(--ds-border) !important;
}

body[class] #app .table-purpose-label {
  border-color: var(--ds-border) !important;
  background: var(--ds-head) !important;
  color: var(--ds-muted) !important;
}

body[class] #app :is(.ac-page, .pd-page, .aw-page, .ops-page) :is(td, th) {
  border-color: var(--ds-border) !important;
}

body[class] #app tbody tr:hover td {
  background: rgba(15, 23, 42, 0.025) !important;
}

:root[data-theme="dark"] body[class] #app tbody tr:hover td {
  background: rgba(255, 255, 255, 0.035) !important;
}

/* ---------------------------------------------------------------------------
   2. Tabs — one pill set for every workspace tab strip
   ------------------------------------------------------------------------- */
body[class] :is(.workspace-status-tabs, .workspace-primary-tabs) {
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-sm);
  background: var(--ds-head);
}

body[class] :is(.workspace-primary-tabs, .workspace-status-tabs, .task-workspace-tabs) button {
  min-height: 40px !important;
  padding: 8px 14px !important;
  border: 1px solid transparent !important;
  border-radius: 8px !important;
  background: transparent !important;
  color: var(--ds-muted) !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  box-shadow: none !important;
}

body[class] :is(.workspace-primary-tabs, .workspace-status-tabs, .task-workspace-tabs) button:hover {
  background: var(--ds-surface) !important;
  color: var(--ds-text) !important;
}

body[class] :is(.workspace-primary-tabs, .workspace-status-tabs, .task-workspace-tabs) button.active,
body[class] :is(.workspace-primary-tabs, .workspace-status-tabs, .task-workspace-tabs) button[aria-selected="true"] {
  border-color: var(--primary) !important;
  background: var(--primary) !important;
  color: #fff !important;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 26%, transparent) !important;
}

body[class] :is(.workspace-primary-tabs, .workspace-status-tabs, .task-workspace-tabs) button.active :is(small, .workspace-tab-count),
body[class] :is(.workspace-primary-tabs, .workspace-status-tabs, .task-workspace-tabs) button[aria-selected="true"] :is(small, .workspace-tab-count) {
  background: rgba(255, 255, 255, .22) !important;
  color: #fff !important;
}

/* ---------------------------------------------------------------------------
   3. Stat cards — one shell, one type scale, one badge
   ------------------------------------------------------------------------- */

/* shell: icon-led families become body-left / badge-right */
body[class] :is(.ac-kpis article, .aw-kpis article, .pd-stat, .ss-stock-metric-card) {
  position: relative;
  display: flex !important;
  flex-direction: row-reverse !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 16px !important;
  min-height: 104px;
  padding: 16px 18px !important;
  border: 1px solid var(--ds-border) !important;
  border-radius: var(--ds-radius) !important;
  background: var(--ds-surface) !important;
  box-shadow: var(--ds-shadow) !important;
}

/* badge */
body[class] :is(.ac-kpis article > span:first-child:has(.ti, svg, img), .aw-kpis article > span:first-child:has(.ti, svg, img), .pd-stat-icon, .ss-stock-metric-icon:has(.ti, svg, img)) {
  width: var(--ds-badge-size) !important;
  height: var(--ds-badge-size) !important;
  border-radius: var(--ds-badge-radius) !important;
  display: grid !important;
  place-items: center !important;
  flex: none !important;
  color: #fff !important;
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3);
}

body[class] :is(.ac-kpis article > span:first-child:has(.ti, svg, img), .aw-kpis article > span:first-child:has(.ti, svg, img), .pd-stat-icon, .ss-stock-metric-icon:has(.ti, svg, img)) :is(.ti, svg) {
  font-size: 28px !important;
  width: 28px;
  height: 28px;
  color: #fff !important;
}

/* badge ramps per tone */
body[class] .ac-kpis article > span:first-child:has(.ti, svg, img),
body[class] .aw-kpis article.blue > span:first-child,
body[class] .pd-stat.pd-blue .pd-stat-icon,
body[class] .ss-stock-metric-card.tone-linked .ss-stock-metric-icon:has(.ti, svg, img) { background-image: var(--ds-badge-blue) !important; }

body[class] .ac-kpis article.tone-red > span:first-child,
body[class] .pd-stat.pd-red .pd-stat-icon { background-image: var(--ds-badge-red) !important; }

body[class] .ac-kpis article.tone-green > span:first-child,
body[class] .aw-kpis article.green > span:first-child,
body[class] .pd-stat.pd-green .pd-stat-icon { background-image: var(--ds-badge-green) !important; }

body[class] .ac-kpis article.tone-purple > span:first-child,
body[class] .aw-kpis article.purple > span:first-child,
body[class] .pd-stat.pd-purple .pd-stat-icon { background-image: var(--ds-badge-violet) !important; }

body[class] .aw-kpis article.slate > span:first-child,
body[class] .pd-stat.pd-slate .pd-stat-icon,
body[class] .ss-stock-metric-card.tone-pending .ss-stock-metric-icon:has(.ti, svg, img) { background-image: var(--ds-badge-slate) !important; }

body[class] .ac-kpis article.tone-amber > span:first-child,
body[class] .aw-kpis article.amber > span:first-child,
body[class] .pd-stat.pd-amber .pd-stat-icon { background-image: var(--ds-badge-amber) !important; }

/* type scale: title -> value -> note */
body[class] :is(.ac-kpis article small, .aw-kpis article small, .pd-stat small, .ss-stock-metric-card small,
  .flow-kpi small, .pp-stats article > span, .wh-kpi-label, .dashboard-live-kpi > span, .ss-overview-kpis article > span) {
  font-size: 15px !important;
  font-weight: 800 !important;
  line-height: 1.35 !important;
  color: var(--ds-text) !important;
  letter-spacing: -.005em;
}

body[class] :is(.ac-kpis article strong, .aw-kpis article strong, .pd-stat strong, .ss-stock-metric-card strong,
  .flow-kpi strong, .pp-stats article strong, .wh-kpi-card .wh-kpi-value, .dashboard-live-kpi > strong, .ss-overview-kpis article > strong) {
  font-size: clamp(26px, 2.1vw, 32px) !important;
  font-weight: 800 !important;
  line-height: 1.15 !important;
  font-variant-numeric: tabular-nums;
}

body[class] :is(.ac-kpis article, .aw-kpis article, .pd-stat, .ss-stock-metric-card) :is(small, strong) {
  overflow-wrap: anywhere;
}

/* icon-led cards: body column must not shrink away from the badge */
body[class] :is(.ac-kpis article, .aw-kpis article, .pd-stat, .ss-stock-metric-card) > div {
  min-width: 0;
  flex: 1 1 auto;
}

/* ---------------------------------------------------------------------------
   4. Overview work queue — the tone lives on the icon, not on a side rail
   ------------------------------------------------------------------------- */
body[data-route="overview"] .ss-work-row::before { display: none !important; }

body[data-route="overview"] .ss-work-row {
  grid-template-columns: 38px minmax(0, 1fr) 64px minmax(112px, auto) !important;
}

body[data-route="overview"] .ss-work-row > i {
  width: 36px; height: 36px; display: grid !important; place-items: center;
  border-radius: 10px; background: var(--ds-head); font-size: 18px;
}

body[data-route="overview"] .ss-work-row.tone-danger > i { color: var(--danger) !important; }
body[data-route="overview"] .ss-work-row.tone-warning > i { color: var(--warning) !important; }
body[data-route="overview"] .ss-work-row.tone-safe > i { color: var(--success, #0f7b4d) !important; }

/* ---------------------------------------------------------------------------
   5. Overview KPI strip — same card as everywhere else
   ------------------------------------------------------------------------- */
body[data-route="overview"] .ss-overview-kpis article {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  justify-content: center !important;
  gap: 6px;
  min-height: 104px;
  padding: 16px 18px !important;
  border: 1px solid var(--ds-border) !important;
  border-radius: var(--ds-radius) !important;
  background: var(--ds-surface) !important;
  box-shadow: var(--ds-shadow) !important;
}

body[data-route="overview"] .ss-overview-kpis article::before { display: none !important; }

body[data-route="overview"] .ss-overview-kpis article > span {
  font-size: 15px !important;
  font-weight: 800 !important;
  color: var(--ds-text) !important;
  letter-spacing: -.005em;
}

body[data-route="overview"] .ss-overview-kpis article > strong {
  font-size: clamp(30px, 2.4vw, 38px) !important;
  font-weight: 800 !important;
  line-height: 1.1 !important;
  color: var(--ds-text) !important;
  font-variant-numeric: tabular-nums;
}

body[data-route="overview"] .ss-overview-kpis article.is-critical > strong { color: var(--danger) !important; }

/* ---------------------------------------------------------------------------
   6. Badge ramps — cover every tone name the modules emit, so a badge can
      never fall back to a pale tint with a white icon on it.
   ------------------------------------------------------------------------- */
body[class] :is(.ac-kpis article, .aw-kpis article, .pd-stat) > :is(span:first-child, .pd-stat-icon) {
  background-image: var(--ds-badge-slate) !important;
}

body[class] :is(.ac-kpis article.tone-blue, .aw-kpis article.blue, .pd-stat.pd-blue) > :is(span:first-child, .pd-stat-icon) {
  background-image: var(--ds-badge-blue) !important;
}

body[class] :is(.ac-kpis article.tone-green, .ac-kpis article.tone-safe, .aw-kpis article.green, .aw-kpis article.safe, .pd-stat.pd-green) > :is(span:first-child, .pd-stat-icon) {
  background-image: var(--ds-badge-green) !important;
}

body[class] :is(.ac-kpis article.tone-purple, .aw-kpis article.purple, .pd-stat.pd-purple) > :is(span:first-child, .pd-stat-icon) {
  background-image: var(--ds-badge-violet) !important;
}

body[class] :is(.ac-kpis article.tone-red, .ac-kpis article.tone-danger, .aw-kpis article.red, .aw-kpis article.danger, .pd-stat.pd-red) > :is(span:first-child, .pd-stat-icon) {
  background-image: var(--ds-badge-red) !important;
}

body[class] :is(.ac-kpis article.tone-amber, .ac-kpis article.tone-warning, .aw-kpis article.amber, .aw-kpis article.warning, .pd-stat.pd-amber) > :is(span:first-child, .pd-stat-icon) {
  background-image: var(--ds-badge-amber) !important;
}

body[class] :is(.ac-kpis article.tone-slate, .ac-kpis article.tone-neutral, .ac-kpis article.tone-idle, .aw-kpis article.slate, .aw-kpis article.neutral, .pd-stat.pd-slate) > :is(span:first-child, .pd-stat-icon) {
  background-image: var(--ds-badge-slate) !important;
}

/* neutral sidebar in dark mode (the brand skin tints it brown) */
:root[data-theme="dark"] {
  --bg-sidebar: #151a21;
}

/* compact badges on narrow viewports so the text column keeps room */
@media (max-width: 1200px) {
  :root { --ds-badge-size: 52px; --ds-badge-radius: 15px; }
  body[class] :is(.ac-kpis article > span:first-child:has(.ti, svg, img), .aw-kpis article > span:first-child:has(.ti, svg, img), .pd-stat-icon, .ss-stock-metric-icon:has(.ti, svg, img)) :is(.ti, svg) {
    font-size: 24px !important;
    width: 24px;
    height: 24px;
  }
}

/* ---------------------------------------------------------------------------
   7. Page kit — the approved Clean Ops layout, reusable on any route
   ------------------------------------------------------------------------- */
.ds-page { display: block; }

.ds-page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.ds-page-head h2 {
  margin: 0; font-size: clamp(24px, 2.2vw, 28px); line-height: 1.3;
  font-weight: 800; letter-spacing: -.01em; color: var(--ds-text);
}
.ds-page-head p { margin: 6px 0 0; font-size: 13px; color: var(--ds-muted); }
.ds-page-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

.ds-kpis, .ds-kpi-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.ds-kpi {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  gap: 14px; min-height: 104px; padding: 16px 18px; text-align: left;
  border: 1px solid var(--ds-border); border-radius: var(--ds-radius);
  background: var(--ds-surface); box-shadow: var(--ds-shadow);
  font: inherit; cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ds-kpi:hover { border-color: var(--ds-border-strong); }
.ds-kpi.is-active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary), var(--ds-shadow); }
.ds-kpi-body { min-width: 0; }
.ds-kpi-label {
  display: block; font-size: 18px; font-weight: 800; line-height: 1.3;
  letter-spacing: -.01em; color: var(--ds-text);
}
.ds-kpi-value {
  display: block; margin-top: 2px; font-size: 32px; font-weight: 800;
  line-height: 1.15; color: var(--ds-text); font-variant-numeric: tabular-nums;
}
.ds-kpi-note { display: block; margin-top: 3px; font-size: 12.5px; color: var(--ds-muted); }
.ds-kpi-badge {
  width: var(--ds-badge-size); height: var(--ds-badge-size); flex: none;
  display: grid; place-items: center; border-radius: var(--ds-badge-radius);
  color: #fff; font-size: 28px; border: 1px solid rgba(255, 255, 255, .18);
  background-image: var(--ds-badge-slate);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3);
}
.ds-kpi-badge .ti { font-size: 28px; }
.ds-kpi--danger .ds-kpi-badge { background-image: var(--ds-badge-red); }
.ds-kpi--warning .ds-kpi-badge { background-image: var(--ds-badge-amber); }
.ds-kpi--info .ds-kpi-badge { background-image: var(--ds-badge-blue); }
.ds-kpi--neutral .ds-kpi-badge { background-image: var(--ds-badge-slate); }
.ds-kpi--danger.is-active .ds-kpi-value { color: var(--danger); }

/* panel + tabs + toolbar */
.ds-panel {
  border: 1px solid var(--ds-border); border-radius: var(--ds-radius);
  background: var(--ds-surface); box-shadow: var(--ds-shadow); overflow: hidden;
}
.ds-panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 15px 18px 10px; flex-wrap: wrap;
}
.ds-panel-head h3 { margin: 0; font-size: 17px; font-weight: 800; color: var(--ds-text); }
.ds-eyebrow {
  margin: 0 0 3px; font-size: 12px; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ds-muted);
}

.ds-tabs {
  display: flex; gap: 8px; padding: 0 18px 12px; overflow-x: auto;
  border-bottom: 1px solid var(--ds-border); scrollbar-width: thin;
}
.ds-tab {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px;
  padding: 8px 14px; border: 1px solid transparent; border-radius: 9px;
  background: transparent; color: var(--ds-muted);
  font: inherit; font-size: 13px; font-weight: 700; white-space: nowrap; cursor: pointer;
}
.ds-tab:hover { background: var(--ds-head); color: var(--ds-text); }
.ds-tabs .ds-tab[aria-selected="true"] {
  background: #c8102e !important; border-color: #c8102e !important; color: #fff !important;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 26%, transparent);
}
.ds-tab .ds-count {
  display: inline-grid; min-width: 21px; height: 20px; padding: 0 6px;
  place-items: center; border-radius: 999px;
  background: var(--ds-head); color: var(--ds-muted);
  font-size: 12px; font-weight: 800;
}
.ds-tabs .ds-tab[aria-selected="true"] .ds-count { background: rgba(255, 255, 255, .22); color: #fff; }
:root[data-theme="dark"] .ds-tabs .ds-tab[aria-selected="true"] { background: #e11d33 !important; border-color: #e11d33 !important; }

.ds-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 18px; border-bottom: 1px solid var(--ds-border);
}
.ds-search {
  flex: 1 1 280px; display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px;
  border: 1px solid var(--ds-border-strong); border-radius: 10px; background: var(--ds-surface);
}
.ds-search .ti { color: var(--ds-muted); font-size: 16px; }
.ds-search input {
  width: 100%; border: 0 !important; background: transparent !important; box-shadow: none !important; outline: none;
  font: inherit; font-size: 13px; color: var(--ds-text);
}
.ds-select {
  height: 40px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--ds-border-strong); background: var(--ds-surface);
  color: var(--ds-text); font: inherit; font-size: 13px;
}

/* table */
.ds-table-wrap { overflow: auto; }
.ds-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ds-table thead th {
  padding: 10px 14px; text-align: left; white-space: nowrap;
  background: var(--ds-head); color: var(--ds-muted);
  font-size: 12px; font-weight: 700; border-bottom: 1px solid var(--ds-border);
}
.ds-table tbody td { padding: 12px 14px; border-bottom: 1px solid var(--ds-border); vertical-align: middle; }
.ds-table tbody tr:last-child td { border-bottom: 0; }
.ds-table tbody tr:hover td { background: rgba(15, 23, 42, .025); }
:root[data-theme="dark"] .ds-table tbody tr:hover td { background: rgba(255, 255, 255, .035); }
.ds-table .ds-check { width: 44px; }
.ds-cell-main strong { display: block; font-size: 13.5px; font-weight: 700; color: var(--ds-text); }
.ds-cell-main small { display: block; margin-top: 2px; font-size: 12px; color: var(--ds-muted); }
.ds-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ds-num--danger { color: var(--danger); font-weight: 800; }
.ds-num small { font-size: 12px; color: var(--ds-muted); font-weight: 600; }

.ds-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.ds-chip .ti { font-size: 12px; }
.ds-chip--danger { background: var(--danger-soft); color: var(--danger); }
.ds-chip--warning { background: var(--warning-soft); color: var(--warning); }
.ds-chip--info { background: var(--info-soft); color: var(--info); }
.ds-chip--neutral { background: var(--ds-head); color: var(--ds-muted); }

/* buttons inside a table row */
.ds-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 11px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-size: 12px; font-weight: 700; white-space: nowrap; cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.ds-btn--primary { background: var(--primary); color: #fff; }
.ds-btn--primary:hover { background: var(--primary-hover); }
.ds-btn--ghost { background: transparent; border-color: var(--ds-border-strong); color: var(--ds-text); }
.ds-btn--ghost:hover { background: var(--ds-head); }
.ds-btn--icon { width: 32px; padding: 0; }
.ds-row-actions { display: flex; align-items: center; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }

.ds-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-top: 1px solid var(--ds-border);
  color: var(--ds-muted); font-size: 12px; flex-wrap: wrap;
}

.ds-bulkbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; border-bottom: 1px solid var(--ds-border);
  background: var(--primary-soft); color: var(--ds-text); font-size: 13px;
}
.ds-bulkbar .spacer { flex: 1; }

@media (max-width: 1100px) {
  .ds-kpis, .ds-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .ds-kpis, .ds-kpi-grid { grid-template-columns: 1fr; }
  .ds-kpi { min-height: 88px; padding: 14px; }
  .ds-kpi-label { font-size: 16px; }
  .ds-kpi-value { font-size: 28px; }
}

/* active tab fill — declared last and as longhands so no page skin can win */
body[class] #app .ds-tabs > .ds-tab[aria-selected="true"] {
  background-color: #c8102e !important;
  background-image: none !important;
  border-color: #c8102e !important;
  color: #ffffff !important;
}
body[class] #app .ds-tabs > .ds-tab[aria-selected="true"] .ds-count {
  background-color: rgba(255, 255, 255, 0.22) !important;
  color: #ffffff !important;
}
:root[data-theme="dark"] body[class] #app .ds-tabs > .ds-tab[aria-selected="true"] {
  background-color: #e11d33 !important;
  border-color: #e11d33 !important;
}

body[class] #app .ds-tabs > .ds-tab.is-active {
  background-color: #c8102e !important;
  background-image: none !important;
  border-color: #c8102e !important;
  color: #ffffff !important;
}
body[class] #app .ds-tabs > .ds-tab.is-active .ds-count {
  background-color: rgba(255, 255, 255, 0.22) !important;
  color: #ffffff !important;
}
:root[data-theme="dark"] body[class] #app .ds-tabs > .ds-tab.is-active {
  background-color: #e11d33 !important;
  border-color: #e11d33 !important;
}

/* tab strip built from the proven button classes */
.ds-tabs .ds-btn { height: 40px; padding: 0 16px; font-size: 13px; font-weight: 700; border-radius: 9px; }
.ds-tabs .ds-btn .ds-count {
  display: inline-grid; min-width: 21px; height: 20px; padding: 0 6px; margin-left: 2px;
  place-items: center; border-radius: 999px; background: rgba(255, 255, 255, .22);
  font-size: 12px; font-weight: 800;
}
.ds-tabs .ds-btn--ghost .ds-count { background: var(--ds-head); color: var(--ds-muted); }

.ds-tabs > .ds-btn--primary {
  background-color: #c8102e !important;
  background-image: none !important;
  border-color: #c8102e !important;
  color: #ffffff !important;
}
:root[data-theme="dark"] .ds-tabs > .ds-btn--primary {
  background-color: #e11d33 !important;
  border-color: #e11d33 !important;
}

/* materials page: size the app buttons inside the new layout */
.ds-tabs > .ri-tab-btn { min-height: 40px; height: 40px; padding: 0 16px; font-size: 13px; }
.ds-tabs > .ri-tab-btn .ds-count {
  display: inline-grid; min-width: 21px; height: 20px; padding: 0 6px; margin-left: 6px;
  place-items: center; border-radius: 999px; background: rgba(255, 255, 255, .22);
  font-size: 12px; font-weight: 800;
}
.ds-tabs > .ghost-button .ds-count { background: var(--ds-head); color: var(--ds-muted); }
.ds-row-actions .ri-row-btn { min-height: 32px; height: 32px; padding: 0 11px; font-size: 12px; border-radius: 8px; }
.ds-row-actions .ri-row-icon { width: 42px; padding: 0; }

#app .ds-search input,
#app .ds-search input:focus {
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  outline: none;
}

/* ---------------------------------------------------------------------------
   8. Remaining KPI families — same card, badge parked top-right
   ------------------------------------------------------------------------- */
body[class] :is(.flow-kpi, .pp-stats article, .dashboard-live-kpi, .wh-kpi-card, .metric) {
  position: relative !important;
  min-height: 104px;
  padding: 16px 18px !important;
  border: 1px solid var(--ds-border) !important;
  border-radius: var(--ds-radius) !important;
  background: var(--ds-surface) !important;
  box-shadow: var(--ds-shadow) !important;
}

body[class] :is(.flow-kpi-badge, .pp-stat-badge, .live-kpi-badge, .wh-kpi-icon:has(.ti, svg, img), .metric-icon:has(.ti, svg, img)) {
  position: absolute !important;
  top: 16px; right: 16px;
  width: var(--ds-badge-size) !important;
  height: var(--ds-badge-size) !important;
  border-radius: var(--ds-badge-radius) !important;
  display: grid !important;
  place-items: center !important;
  color: #fff !important;
  font-size: 28px !important;
  background-image: var(--ds-badge-slate);
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3);
}
body[class] :is(.flow-kpi-badge, .pp-stat-badge, .live-kpi-badge, .wh-kpi-icon:has(.ti, svg, img), .metric-icon:has(.ti, svg, img)) :is(.ti, i) {
  font-size: 28px !important; color: #fff !important;
}

/* tone ramps */
body[class] .flow-kpi.review-cases .flow-kpi-badge { background-image: var(--ds-badge-red); }
body[class] .flow-kpi.review-stock .flow-kpi-badge { background-image: var(--ds-badge-blue); }
body[class] .flow-kpi.review-seller .flow-kpi-badge,
body[class] .flow-kpi.review-history .flow-kpi-badge { background-image: var(--ds-badge-slate); }

body[class] .pp-stats article:nth-child(1) .pp-stat-badge { background-image: var(--ds-badge-blue); }
body[class] .pp-stats article:nth-child(2) .pp-stat-badge { background-image: var(--ds-badge-green); }
body[class] .pp-stats article:nth-child(3) .pp-stat-badge { background-image: var(--ds-badge-slate); }
body[class] .pp-stats article:nth-child(4) .pp-stat-badge { background-image: var(--ds-badge-amber); }

body[class] .dashboard-live-kpi.tone-danger .live-kpi-badge { background-image: var(--ds-badge-red); }
body[class] .dashboard-live-kpi.tone-warning .live-kpi-badge { background-image: var(--ds-badge-amber); }
body[class] .dashboard-live-kpi.tone-safe .live-kpi-badge { background-image: var(--ds-badge-green); }

body[class] .wh-kpi-card .wh-kpi-icon:has(.ti, svg, img) { background-image: var(--ds-badge-blue); }
body[class] .metric .metric-icon:has(.ti, svg, img) { background-image: var(--ds-badge-blue); }

/* keep the text clear of the badge */
body[class] :is(.flow-kpi, .pp-stats article, .dashboard-live-kpi, .wh-kpi-card, .metric) > :is(span, strong, small, p, b, div) {
  padding-right: calc(var(--ds-badge-size) + 14px);
}
body[class] .metric { padding: 14px 18px !important; min-height: 88px; }

/* production job rows: one primary action + a menu, never a stack of buttons */
.pd-row-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: nowrap; }
.pd-row-actions :is(.primary-button, .ghost-button) { min-height: 32px; height: 32px; padding: 0 10px; font-size: 12px; }
.pd-row-menu { position: relative; }
.pd-row-menu > summary {
  list-style: none; width: 32px; height: 32px; display: grid; place-items: center;
  cursor: pointer; border: 1px solid var(--ds-border-strong); border-radius: 8px;
  background: var(--ds-surface); color: var(--ds-muted);
}
.pd-row-menu > summary::-webkit-details-marker { display: none; }
.pd-row-menu[open] > summary { background: var(--ds-head); color: var(--ds-text); }
.pd-row-menu-list {
  position: absolute; right: 0; top: 38px; z-index: 30; min-width: 200px;
  display: grid; gap: 6px; padding: 8px;
  background: var(--ds-surface); border: 1px solid var(--ds-border);
  border-radius: 10px; box-shadow: var(--ds-shadow);
}
.pd-row-menu-list :is(.primary-button, .ghost-button) { width: 100%; justify-content: flex-start; }

/* headings are programmatic focus targets after navigation — never draw a ring */
#app :is(h1, h2, h3):focus,
#app :is(h1, h2, h3):focus-visible { outline: none !important; }

/* F12 — form error summary */
.ux-form-summary {
  margin: 0 0 14px; padding: 12px 14px;
  border: 1px solid var(--danger-border, rgba(180, 35, 45, .38));
  border-radius: 10px; background: var(--danger-soft, rgba(180, 35, 45, .1));
  color: var(--ds-text); font-size: 13px;
}
.ux-form-summary:focus { outline: none; }
.ux-form-summary p { margin: 0 0 6px; }
.ux-form-summary ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.ux-form-summary button {
  padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--danger-link, #9f1d2b); font: inherit; text-align: left; text-decoration: underline;
}

/* F13b — undo toast */
.ux-undo {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 1200; display: flex; align-items: center; gap: 12px;
  max-width: min(560px, calc(100vw - 32px)); padding: 12px 14px 14px;
  border: 1px solid var(--ds-border-strong); border-radius: 12px;
  background: var(--ds-surface); color: var(--ds-text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .28); font-size: 13px;
  transition: opacity .2s ease, transform .2s ease;
}
.ux-undo.is-leaving { opacity: 0; transform: translateX(-50%) translateY(6px); }
.ux-undo button {
  min-height: 32px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--primary); background: var(--primary-soft); color: var(--primary-ink, #b3131f);
  font: inherit; font-weight: 800;
}
.ux-undo-timer {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
  background: var(--primary); border-radius: 0 0 12px 12px;
  transform-origin: left; animation: ux-undo-countdown linear forwards;
}
@keyframes ux-undo-countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------------------------------------------------------------------------
   P3 F5b — one skin for every department: these rules stop the module sheets
   (production / accounting / warehouse) from re-tinting shared components.
   ------------------------------------------------------------------------- */
body[class] #app :is(.primary-button, .flow-primary) {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}
body[class] #app :is(.ghost-button, .compact-button) {
  background: var(--ds-surface) !important;
  border-color: var(--ds-border-strong) !important;
  color: var(--ds-text) !important;
}
body[class] #app .danger-button {
  background: var(--danger) !important;
  border-color: var(--danger) !important;
  color: #fff !important;
}
body[class] #app :is(.ac-panel, .pd-panel, .aw-panel, .panel) > header {
  background: var(--ds-head) !important;
  color: var(--ds-text) !important;
}
body[class] #app :is(.ac-page, .pd-page, .aw-page, .wh-page, .flow-page) :is(thead, th) {
  background: var(--ds-head) !important;
  color: var(--ds-muted) !important;
  border-color: var(--ds-border) !important;
}
body[class] #app :is(.ac-page, .pd-page, .aw-page, .wh-page, .flow-page) td {
  border-color: var(--ds-border) !important;
}
body[class] #app :is(.ac-tag, .aw-tag, .pd-badge, .flow-badge, .badge) {
  border-color: transparent !important;
}

/* P3 — sortable headers + pagination */
.ds-sort {
  padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 700; color: inherit;
}
.ds-sort::after { content: "↕"; margin-left: 4px; opacity: .45; font-size: 11px; }
th[aria-sort="ascending"] .ds-sort::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"] .ds-sort::after { content: "↓"; opacity: 1; }
.ds-pager { display: inline-flex; align-items: center; gap: 8px; }
.ds-pager .ds-btn[disabled] { opacity: .45; cursor: default; }

/* typography floor — pages that still ship sub-12px labels */
body[data-route="backup-recovery"] #app :is(button, label, span, small, p, dt, dd, option) {
  font-size: max(12px, 1em);
}

/* dark-mode contrast: shortfall numbers need a lighter red on the dark surface */
:root[data-theme="dark"] .ds-num--danger { color: #ff8f97; }

/* P3 dark contrast: danger-toned text and danger buttons */
:root[data-theme="dark"] { --workspace-error: #ff9aa2; --danger-link: #ff9aa2; }
:root[data-theme="dark"] :is(.pd-job-readiness.is-blocked, .pd-job-readiness.is-blocked strong) { color: #ff9aa2 !important; }
:root[data-theme="dark"] .pd-tabs > span { color: #ff9aa2 !important; }
:root[data-theme="dark"] .danger-button { background: #8f1724 !important; border-color: #8f1724 !important; color: #fff !important; }

/* P3 dark contrast: warehouse-record surfaces were hardcoded white */
:root[data-theme="dark"] .wr-box {
  background: var(--ds-surface) !important;
  border-color: var(--ds-border) !important;
  color: var(--ds-text) !important;
}
:root[data-theme="dark"] .wr-box :is(input, select, textarea) {
  background: var(--ds-head) !important;
  color: var(--ds-text) !important;
  border-color: var(--ds-border-strong) !important;
}
:root[data-theme="dark"] .pd-tabs [aria-current="true"] :is(span, small) { color: #ff9aa2 !important; }

/* P3 dark contrast: transient messages (toast/dialog errors) used light surfaces */
:root[data-theme="dark"] :is(.toast, .ux-undo, [role="alert"], .ri-error, .ac-modal-error, .error-state-panel) {
  background: var(--ds-surface) !important;
  color: var(--ds-text) !important;
  border-color: var(--ds-border) !important;
}

/* P3 dark contrast: department work rows must stay light-on-dark */
:root[data-theme="dark"] .ss-work-row { background: var(--ds-surface) !important; }
:root[data-theme="dark"] .ss-work-row :is(strong, small, span) { color: var(--ds-text) !important; }

/* P4 axe: #live-data-status used warning ink at 4.49 on warning-soft */
:root { --warning: #a04a06; }

/* P4 axe: live-data status pill — force readable warning ink */
#live-data-status { color: #8a3f05 !important; }

/* P4 axe: remaining contrast fixes */
#customer-message-selected-count { color: #c4121f !important; }
.ds-tabs [aria-selected="true"] .ds-count { background: rgba(0, 0, 0, .3) !important; color: #fff !important; }
.ds-tabs .primary-button .ds-count { background: rgba(0, 0, 0, .3) !important; color: #fff !important; }
