/* ---------------------------------------------------------------------------
   Outsource China — corridor (category) page and the specification index

   Head with counted facts; a spec-schema filter beside the specification
   index (a real table: reference, designation, parameter columns, declared
   compliance, customisation vectors); data tiles as the alternative layout;
   the compare tray and sheet; an intelligence band under the index. Builds
   on intel.css. Also loaded by search, which uses the same index.
--------------------------------------------------------------------------- */

/* --- Head ------------------------------------------------------------------ */

.cx-head {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-4) var(--s-6);
  padding: var(--s-6) 0 var(--s-5);
}
.cx-head__path { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 var(--s-3); }
.cx-head__path a { color: var(--text-subtle); }
.cx-head__path a:hover { color: var(--accent); text-decoration: none; }
.cx-head__path [aria-current] { color: var(--text-muted); }
.cx-head__title { display: flex; align-items: center; gap: var(--s-3); margin: 0; }
.cx-head__title .cat-mark { margin: 0; flex: none; }
.cx-head__lede { max-width: 72ch; margin: var(--s-3) 0 0; color: var(--text-muted); font-size: 15px; }
.cx-head__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: flex-start; justify-content: flex-end; }
.cx-head__kpi { grid-column: 1 / -1; }

/* --- Frame: filter | index, intelligence band underneath ------------------- */

.cx-frame {
  display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--s-4);
  align-items: start; scroll-margin-top: var(--sticky-top);
}

/* Spec-schema filter */
.cx-schema {
  position: sticky; top: var(--sticky-top);
  max-height: calc(100vh - var(--sticky-top) - 16px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.cx-schema__box { padding: var(--s-4); }
.cx-schema__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  margin: 0 0 var(--s-3); list-style: none; cursor: pointer;
}
.cx-schema__head::-webkit-details-marker { display: none; }
.cx-schema__head::marker { content: ""; }
.cx-schema__box:not([open]) .cx-schema__head { margin-bottom: 0; }
.cx-facet { margin: 0 0 var(--s-4); padding: 0; border: 0; min-width: 0; }
.cx-facet legend {
  display: flex; justify-content: space-between; gap: var(--s-2); width: 100%;
  margin-bottom: var(--s-2); padding: 0; font-weight: 700; font-size: 13px;
}
.cx-facet legend code { font: 500 var(--fs-xs)/1.6 var(--mono); color: var(--text-subtle); background: none; padding: 0; }
.cx-opt {
  display: flex; align-items: center; gap: var(--s-2); margin: 0 -8px; padding: 5px 8px;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 400; color: var(--text); cursor: pointer;
}
.cx-opt:hover { background: var(--surface-hover); }
.cx-opt input { width: auto; margin: 0; accent-color: var(--signal); }
.cx-opt:has(input:checked) { background: var(--signal-subtle); }
.cx-opt:has(input:checked) .cx-opt__v { font-weight: 700; }
.cx-opt__v { flex: 1; min-width: 0; }
.cx-opt__n { font-size: 11px; color: var(--text-subtle); }

/* Results head */
.cx-results { min-width: 0; }
.cx-results .gscan { margin-top: 0; }
.cx-results__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); margin: var(--s-3) 0; }
.cx-results__head > .muted { margin-right: auto; }
.cx-sort select { width: auto; }
.cx-view { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.cx-view a { padding: 6px 14px; font: 600 12px/1.4 var(--mono); color: var(--text-muted); }
.cx-view a + a { border-left: 1px solid var(--border-strong); }
.cx-view a:hover { background: var(--surface-hover); text-decoration: none; }
.cx-view a[aria-current="true"] { background: var(--plate-2); color: var(--plate-text); }
.cx-results .pager { margin-top: var(--s-4); }

/* --- Specification index — .sx --------------------------------------------- */

.sx-wrap {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  overflow: hidden;
}
.sx-tools {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: 8px var(--s-3); background: var(--plate-1); color: var(--plate-text-muted);
}
.sx-tools[hidden] { display: none; }
.sx-tools .label-mono { color: var(--plate-text-muted); }
.sx-density { display: inline-flex; border: 1px solid var(--plate-line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.sx-density button {
  padding: 3px 10px; border: 0; background: none; cursor: pointer;
  font: 600 11px/1.4 var(--mono); color: var(--plate-text-muted);
}
.sx-density button + button { border-left: 1px solid var(--plate-line-strong); }
.sx-density button[aria-pressed="true"] { background: var(--plate-3); color: var(--plate-text); }

.sx-scroll { overflow-x: auto; }
.sx { width: 100%; border-collapse: collapse; font-size: 13px; }
.sx thead th {
  position: sticky; top: 0; z-index: 1;
  padding: 8px 10px; background: var(--surface-sunken);
  border-bottom: 1px solid var(--grid-line-strong);
  text-align: left; vertical-align: bottom; white-space: nowrap;
  font: 600 var(--fs-xs)/1.2 var(--mono); text-transform: uppercase; letter-spacing: var(--track-label); color: var(--text-subtle);
}
.sx thead th + th { border-left: 1px solid var(--grid-line); }
.sx thead th button {
  display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit;
}
.sx thead th button::after { content: "↕"; opacity: .35; font-size: 10px; }
.sx thead th[aria-sort="ascending"] button::after  { content: "↑"; opacity: 1; color: var(--signal); }
.sx thead th[aria-sort="descending"] button::after { content: "↓"; opacity: 1; color: var(--signal); }
.sx thead th button:hover { color: var(--text); }
.sx__key { display: block; margin-top: 2px; padding: 0; background: none; font: 500 10px/1.2 var(--mono); text-transform: none; letter-spacing: 0; color: var(--text-subtle); opacity: .8; }

.sx tbody td, .sx tbody th {
  padding: 9px 10px; border-bottom: 1px solid var(--grid-line);
  vertical-align: middle; text-align: left; font-weight: 400;
}
.sx tbody td + td, .sx tbody th + td, .sx tbody td + th { border-left: 1px solid var(--grid-line); }
.sx tbody tr:last-child > * { border-bottom: 0; }
.sx--compact tbody td, .sx--compact tbody th { padding-top: 4px; padding-bottom: 4px; }
.sx--compact .sx__thumb { width: 24px; height: 24px; }
.sx--compact .sx__line, .sx--compact .sx__kv div:nth-child(n + 2) { display: none; }

.sx__row { transition: background .12s, opacity .2s; }
.sx__row:hover > * { background: var(--surface-hover); }
.sx__row.is-picked > * { background: var(--signal-subtle); }
.sx__row.is-picked > :first-child { box-shadow: inset 3px 0 0 var(--signal); }
.sx-wrap.is-matching .sx__row:not(.is-match) { opacity: .38; }
.sx__row.is-match > * { background: var(--signal-subtle); }
.sx__row.is-match > :first-child { box-shadow: inset 3px 0 0 var(--signal); }

/* Compare tick — only once scripts run, since it does nothing without them */
.sx__pick-h, .sx__pick { width: 1%; }
html:not(.js) .sx__pick-h, html:not(.js) .sx__pick { display: none; }
.sx__pickbox { display: grid; place-items: center; margin: 0; cursor: pointer; }
.sx__pickbox input { width: 15px; height: 15px; margin: 0; accent-color: var(--signal); }

.sx__ref { white-space: nowrap; width: 1%; }
.sx__ref .num { font-weight: 700; font-size: 12px; color: var(--signal); vertical-align: middle; }
.sx__thumb {
  display: inline-grid; place-items: center; width: 34px; height: 34px; margin-right: 8px; vertical-align: middle;
  background: var(--photo-plate); border: 1px solid var(--grid-line-strong); border-radius: var(--radius-sm); overflow: hidden;
}
.sx__thumb img { width: 100%; height: 100%; object-fit: contain; }
.sx__title { min-width: 200px; }
.sx__title a { display: block; font-weight: 600; color: var(--text); line-height: 1.3; }
.sx__title a:hover { color: var(--accent); }
.sx__line { display: block; margin-top: 2px; font-size: 10px; }
.sx__p { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sx__nil { color: var(--text-subtle); font-size: 12px; }
.sx__kv { display: grid; gap: 1px; margin: 0; font-size: 12px; white-space: normal; }
.sx__kv div { display: flex; gap: 6px; }
.sx__kv dt { color: var(--text-subtle); }
.sx__kv dd { margin: 0; font-weight: 600; }

.sx__codes { display: flex; flex-wrap: wrap; gap: 3px; margin: 0; padding: 0; list-style: none; }
.sx__codes li {
  padding: 1px 5px; border: 1px solid color-mix(in srgb, var(--cx-declared) 40%, transparent);
  border-radius: var(--radius-sm); background: var(--cx-declared-subtle);
  font: 700 10.5px/1.5 var(--mono); color: var(--cx-declared);
}

/* Customisation vectors: four fixed cells, filled = offered */
.sx__vec, .sx__vec-h { width: 1%; }
.vec { display: inline-grid; grid-template-columns: repeat(4, 18px); gap: 2px; margin: 0; padding: 0; list-style: none; }
.vec li {
  display: grid; place-items: center; height: 18px;
  border: 1px dashed var(--border-strong); border-radius: 2px;
  font: 700 10px/1 var(--mono); color: var(--text-subtle);
}
.vec li.is-on { border-style: solid; border-color: var(--success); background: var(--success-subtle); color: var(--success); }

.sx__act { width: 1%; }
.sx__act form, .stile__foot form { margin: 0; }
.sx__add {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 9px; white-space: nowrap; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
  font: 600 11.5px/1.4 var(--mono); color: var(--text);
}
.sx__add:hover { border-color: var(--brand); background: var(--brand-subtle); }
.sx__add span[aria-hidden] { color: var(--brand-hover); font-weight: 800; }

.sx-legend { margin: 0; padding: 8px var(--s-3); border-top: 1px solid var(--grid-line-strong); background: var(--surface-sunken); font-size: 10px; text-transform: none; letter-spacing: .02em; }
.sx-legend b { color: var(--text); }

/* --- Data tiles — .stile ---------------------------------------------------- */

.stiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1px; background: var(--grid-line-strong); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); overflow: hidden; }
.stile { display: grid; grid-template-rows: auto auto 1fr auto; gap: var(--s-2); padding: var(--s-3); background: var(--surface); transition: background .12s, opacity .2s; }
.stile:hover { background: var(--surface-hover); }
.stiles.is-matching .stile:not(.is-match) { opacity: .38; }
.stile.is-match { background: var(--signal-subtle); box-shadow: inset 3px 0 0 var(--signal); }
.stile__head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--s-2); }
.stile__head .sx__thumb { margin: 0; width: 40px; height: 40px; }
.stile__ref { font-weight: 700; font-size: 12px; color: var(--signal); }
.stile__line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.stile__title { margin: 0; font-size: 14px; line-height: 1.3; }
.stile__title a { color: var(--text); }
.stile__specs { display: grid; gap: 0; margin: 0; font-size: 12px; border-top: 1px solid var(--grid-line); }
.stile__specs div { display: flex; justify-content: space-between; gap: var(--s-2); padding: 4px 0; border-bottom: 1px solid var(--grid-line); }
.stile__specs dt { color: var(--text-subtle); }
.stile__specs dd { margin: 0; font-weight: 600; text-align: right; }
.stile__foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.stile__foot form { margin-left: auto; }

/* --- Compare tray and sheet -------------------------------------------------- */

.cmp-tray {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-pop);
  background: var(--plate-0); color: var(--plate-text); border-top: 1px solid var(--plate-line-strong);
  box-shadow: 0 -12px 32px rgba(0, 0, 0, .25);
}
.cmp-tray[hidden] { display: none; }
body.has-cmp-tray { padding-bottom: 60px; }
.cmp-tray__inner { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); padding-top: 10px; padding-bottom: 10px; }
.cmp-tray .label-mono { color: var(--signal-on-plate); }
.cmp-tray__refs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.cmp-tray__refs li { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; border: 1px solid var(--plate-line-strong); border-radius: var(--radius-sm); font-size: 12px; }
.cmp-tray__refs button { border: 0; background: none; color: var(--plate-text-muted); cursor: pointer; font-size: 15px; line-height: 1; }
.cmp-tray__hint { margin-right: auto; font-size: 12px; color: var(--plate-text-muted); }
.cmp-tray .btn { background: var(--plate-2); color: var(--plate-text); border-color: var(--plate-line-strong); }
.cmp-tray .cmp-tray__go { background: var(--signal-on-plate); color: var(--plate-0); border-color: var(--signal-on-plate); }
.cmp-tray .cmp-tray__go[disabled] { opacity: .45; }

.cmp {
  width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 64px); margin: auto; padding: 0;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
}
.cmp[open] { display: flex; flex-direction: column; }
.cmp::backdrop { background: rgba(4, 8, 14, .55); }
.cmp__head { display: flex; align-items: center; gap: var(--s-4); padding: 10px var(--s-4); background: var(--plate-1); color: var(--plate-text); }
.cmp__head .label-mono { margin: 0 auto 0 0; color: var(--signal-on-plate); }
.cmp__diff { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; color: var(--plate-text-muted); }
.cmp__diff input { width: auto; margin: 0; accent-color: var(--signal-on-plate); }
.cmp__close { border: 0; background: none; color: var(--plate-text); font-size: 22px; line-height: 1; cursor: pointer; }
.cmp__body { overflow: auto; }
.cmp__table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cmp__table th, .cmp__table td { padding: 8px 12px; border-bottom: 1px solid var(--grid-line); text-align: left; vertical-align: top; }
.cmp__table thead th { position: sticky; top: 0; background: var(--surface-sunken); border-bottom: 1px solid var(--grid-line-strong); font-weight: 600; }
.cmp__table thead th a { display: block; margin-top: 4px; color: var(--text); }
.cmp__table thead .label-mono { display: block; margin-top: 2px; font-size: 10px; }
.cmp__table td + td, .cmp__table th + td, .cmp__table th + th { border-left: 1px solid var(--grid-line); }
.cmp__table tbody th { width: 22%; color: var(--text-muted); font-weight: 600; }
.cmp__thumb { display: grid; place-items: center; width: 56px; height: 56px; background: var(--photo-plate); border: 1px solid var(--grid-line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.cmp__thumb img { width: 100%; height: 100%; object-fit: contain; }
.cmp__ref { display: block; margin-top: 6px; color: var(--signal); font-weight: 700; font-size: 12px; }
.cmp__table tr.is-diff td { background: var(--warning-subtle); }
.cmp__table tr.is-diff th { box-shadow: inset 3px 0 0 var(--warning); }
.cmp__table tr.cmp__sep > * { border-top: 2px solid var(--grid-line-strong); }
.cmp.is-diff-only tr.is-same { display: none; }
.cmp__foot { padding: 8px var(--s-4); border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }

/* --- Intelligence band (under the index) ------------------------------------ */

.cx-intel {
  grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--s-4); align-items: start; min-width: 0; margin-top: var(--s-2);
}
.cx-intel .ifr + .ifr { margin-top: 0; }
.cx-intel .tiles { grid-template-columns: 1fr 1fr; }
.cx-intel .tile a { font-size: 12px; font-weight: 600; }
.cx-intel .label-mono { margin: 0 0 var(--s-1); }
.cx-feed__gap { margin-top: var(--s-4) !important; }
.cx-cbam { display: flex; align-items: center; gap: var(--s-2); margin: var(--s-3) 0 0; font-size: 12.5px; color: var(--text-muted); }
.cx-cbam .tag:hover { text-decoration: none; }

/* --- Lead band (partials/category-hero.php) --------------------------------- */

.chero--lead { margin: var(--s-7) 0 var(--s-4); }
.chero--lead .chero__eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--signal-on-plate); }
.chero--lead .chero__title { font-size: 26px; }

/* --- Search page --------------------------------------------------------------- */

.sxp-head { padding: var(--s-6) 0 var(--s-4); }
.sxp-head h1 { margin: 0; }
.sxp-head p { margin: var(--s-2) 0 0; color: var(--text-muted); }
.sxp .gscan { margin-bottom: var(--s-3); }

/* --- Responsive ------------------------------------------------------------ */

@media (max-width: 900px) {
  .cx-head { grid-template-columns: 1fr; }
  .cx-head__actions { justify-content: flex-start; }
  .cx-frame { grid-template-columns: 1fr; }
  .cx-schema { position: static; max-height: none; }
  .cx-intel .tiles { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .cx-head__kpi { grid-template-columns: 1fr 1fr; }
  .cx-head__kpi .kpi__cell:nth-child(3) { border-left: 0; }
  .cx-head__kpi .kpi__cell:nth-child(n + 3) { border-top: 1px solid var(--grid-line-strong); }
  .cx-intel { grid-template-columns: 1fr; }
  .sx-tools .label-mono { display: none; }
  .stiles { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .sx__row, .stile { transition: none; }
}

@media print {
  .sx-tools, .sx__pick-h, .sx__pick, .sx__act, .cmp-tray, .cx-schema { display: none !important; }
  .cx-frame { grid-template-columns: 1fr; }
}
