/* ---------------------------------------------------------------------------
   Outsource China — storefront shell

   The masthead, the corridor strip, the command palette and the footer: the
   chrome around every storefront page. All of it sits on command plates
   (--plate-*), which stay dark in both themes. Loaded by layouts/app.php only;
   the .brand lockup and the theme switch live in app.css because the admin
   and auth layouts use them too.
--------------------------------------------------------------------------- */

/* --- Masthead -------------------------------------------------------------- */

/* In-page links (#inspection, #cbam) land below the sticky bar, not under it. */
html { scroll-padding-top: calc(var(--mast-h) + 16px); }

/* Only the bar sticks; the corridor strip is its sibling and scrolls away. */
.mast {
  position: sticky; top: 0; z-index: var(--z-mast);
  height: var(--mast-h);
  background: var(--plate-0); color: var(--plate-text);
  border-bottom: 1px solid var(--plate-line);
}
.mast a { color: inherit; text-decoration: none; }
.mast__inner { height: 100%; display: flex; align-items: center; gap: var(--s-4); }

/* Brand lockup — the footer uses it too */
.mast__brand { display: flex; align-items: center; gap: 10px; flex: none; color: var(--plate-text); text-decoration: none; }
.mast__brand:hover { color: var(--plate-text); text-decoration: none; }
.mast__mark {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  border-radius: var(--radius); border: 1px solid var(--plate-line-strong);
  background: linear-gradient(160deg, var(--plate-3), var(--plate-1));
  font: 800 13px/1 var(--font); letter-spacing: -.02em; color: var(--brand-on-dark);
}
.mast__name { display: flex; flex-direction: column; font-weight: 700; font-size: 15px; line-height: 1.15; letter-spacing: -.01em; white-space: nowrap; }
.mast__name small {
  font: 600 10px/1.3 var(--mono); text-transform: uppercase;
  letter-spacing: var(--track-label); color: var(--plate-text-muted);
}

/* Command trigger, and the plain search form it replaces when scripts run */
.cmd {
  flex: 1 1 auto; min-width: 0; max-width: 560px; height: 36px; margin: 0;
  display: flex; align-items: center; gap: var(--s-2);
  padding: 0 var(--s-2) 0 var(--s-3);
  background: var(--plate-2); color: var(--plate-text-muted);
  border: 1px solid var(--plate-line-strong); border-radius: var(--radius);
  font: inherit; font-size: 13.5px; text-align: left;
}
.cmd[hidden] { display: none; }
.cmd--trigger { cursor: pointer; }
.cmd:hover { border-color: var(--plate-text-muted); }
.cmd:focus-within, .cmd--trigger:focus-visible { outline: none; box-shadow: var(--ring-plate); }
.cmd__icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.cmd input[type="search"] {
  flex: 1; min-width: 0; width: auto; height: 100%; border: 0; padding: 0; border-radius: 0;
  background: transparent; color: var(--plate-text); box-shadow: none; font-size: 13.5px;
}
.cmd input[type="search"]:focus { outline: none; box-shadow: none; }
.cmd input::placeholder, .cmd__placeholder { color: var(--plate-text-muted); }
.cmd__placeholder { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd__key {
  flex: none; padding: 2px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--plate-line-strong); background: var(--plate-1);
  font: 600 var(--fs-xs)/1.4 var(--mono); color: var(--plate-text-muted);
}

/* Intelligent Trading Solutions — the masthead's link to the simulation hub.
   A terminal badge: mono code, a cyan pulse. The pulse marks a capability,
   it reports no status, and it stops under reduced motion. */
.mast .its {
  display: inline-flex; align-items: center; gap: 8px; flex: none; margin-left: auto;
  height: 32px; padding: 0 12px 0 10px;
  border: 1px solid rgba(90, 215, 239, .38); border-radius: var(--radius-sm);
  background: linear-gradient(90deg, rgba(90, 215, 239, .14), rgba(90, 215, 239, .04));
  color: var(--plate-text); white-space: nowrap;
  font: 600 12px/1 var(--font);
  transition: border-color .15s, background .15s;
}
.mast .its:hover, .mast .its.is-active { border-color: var(--signal-on-plate); background: rgba(90, 215, 239, .2); color: var(--plate-text); }
.its:focus-visible { box-shadow: var(--ring-plate); }
.its__pulse { position: relative; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--signal-on-plate); }
.its__pulse::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 1.5px solid var(--signal-on-plate); opacity: 0;
  animation: its-pulse 2.4s ease-out infinite;
}
.its__code {
  padding: 2px 5px; border-radius: 2px; background: var(--signal-on-plate); color: var(--plate-0);
  font: 800 10px/1.2 var(--mono); letter-spacing: .06em;
}
@keyframes its-pulse { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(1.9); opacity: 0; } }

/* Phones reach the hub from the corridor strip instead. */
.corridor .corridor__link--its { display: none; color: var(--signal-on-plate); }

/* China desk status — still used by the projects intake bar. */
.desk {
  display: flex; align-items: center; gap: var(--s-2); margin: 0 0 0 auto; flex: none;
  font: 600 var(--fs-xs)/1.2 var(--mono); text-transform: uppercase;
  letter-spacing: var(--track-label); color: var(--plate-text-muted); white-space: nowrap;
}
.desk__label { color: var(--plate-text); }
.desk__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--plate-text-muted); flex: none; }
.desk.is-open .desk__dot   { background: var(--ok-on-plate); box-shadow: 0 0 0 3px rgba(86, 217, 154, .18); }
.desk.is-closed .desk__dot { background: var(--caution-on-plate); }

/* Workspace tools */
.mast__tools { display: flex; align-items: center; gap: var(--s-1); flex: none; }
.mtool {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px;
  border: 1px solid transparent; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; color: var(--plate-text); cursor: pointer; white-space: nowrap;
}
.mtool:hover, .mtool.is-active, .mtool-menu[open] > .mtool {
  background: var(--plate-hover); border-color: var(--plate-line); color: var(--plate-text);
}
.mtool__glyph { color: var(--brand-on-dark); }
.mtool__avatar {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--plate-3); font-size: 11px; font-weight: 800;
}
.mtool__badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: var(--radius-pill);
  background: var(--signal-on-plate); color: var(--plate-0);
  font-size: 11px; line-height: 18px; text-align: center;
}
.mtool__badge[hidden] { display: none; }

.mtool-menu { position: relative; }
.mtool-menu > summary { list-style: none; }
.mtool-menu > summary::-webkit-details-marker { display: none; }
.mtool-menu > summary::marker { content: ""; }
.mtool-menu__pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: var(--z-pop);
  min-width: 250px; padding: var(--s-2);
  background: var(--surface-raised); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.mtool-menu__who { margin: 0 0 var(--s-2); padding: var(--s-2) var(--s-3) var(--s-3); border-bottom: 1px solid var(--border); font-weight: 700; }
.mtool-menu__who small { display: block; font-weight: 400; font-size: 12px; color: var(--text-muted); }
.mast .mtool-menu__pop a,
.mtool-menu__pop button {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  width: 100%; padding: 8px var(--s-3); border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text); font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.mast .mtool-menu__pop a:hover,
.mtool-menu__pop button:hover { background: var(--surface-hover); color: var(--text); }
.mtool-menu__pop b { font-size: 11px; color: var(--signal); }
.mtool-menu__pop b[hidden] { display: none; }
.mtool-menu__pop form { margin: var(--s-1) 0 0; padding-top: var(--s-1); border-top: 1px solid var(--border); }
.mtool-menu__pop button { color: var(--danger); font-weight: 600; }

/* Trade brief — the one amber control in the bar */
.mast .briefbtn {
  display: inline-flex; align-items: stretch; height: 36px; margin-left: var(--s-2);
  border-radius: var(--radius); overflow: hidden;
  background: var(--brand); color: var(--brand-contrast); font-weight: 700;
}
.mast .briefbtn:hover, .mast .briefbtn.is-active { background: var(--brand-hover); color: var(--brand-contrast); }
.briefbtn:focus-visible { box-shadow: var(--ring-plate); }
.briefbtn__count {
  display: grid; place-items: center; min-width: 34px; padding: 0 8px;
  background: rgba(0, 0, 0, .12); font-size: 13px;
}
.briefbtn__text { display: flex; flex-direction: column; justify-content: center; padding: 0 12px; font-size: 13px; line-height: 1.1; white-space: nowrap; }
.briefbtn__text small { font-size: 10.5px; font-weight: 600; opacity: .75; }

/* --- Corridor strip -------------------------------------------------------- */

.corridor {
  position: relative; z-index: calc(var(--z-mast) - 1);
  height: var(--corridor-h);
  background: var(--plate-1); color: var(--plate-text-muted);
  border-bottom: 1px solid var(--plate-line);
}
.corridor a { text-decoration: none; }
.corridor__inner { height: 100%; display: flex; align-items: center; gap: var(--s-1); }
.corridor__menu { position: relative; flex: none; }
.corridor__menu > summary,
.corridor__link {
  display: flex; align-items: center; gap: 7px; height: 30px; padding: 0 10px;
  border-radius: var(--radius-sm); list-style: none; cursor: pointer; white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--plate-text-muted);
}
.corridor__menu > summary::-webkit-details-marker { display: none; }
.corridor__menu > summary::marker { content: ""; }
.corridor__menu > summary::after {
  content: ""; width: 5px; height: 5px; margin-top: -3px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg); transition: transform .15s;
}
.corridor__menu[open] > summary::after { transform: rotate(-135deg); margin-top: 3px; }
.corridor__menu > summary:hover, .corridor__menu[open] > summary,
.corridor__link:hover, .corridor__link[aria-current="page"] { color: var(--plate-text); background: var(--plate-hover); }
.corridor__rule { width: 1px; height: 18px; margin: 0 var(--s-2); background: var(--plate-line-strong); flex: none; }
.corridor .corridor__cta { margin-left: auto; font-size: 13px; font-weight: 700; color: var(--brand-on-dark); white-space: nowrap; }
.corridor .corridor__cta:hover { color: var(--plate-text); }

/* Mega-panel: glass on a plate, opaque where blur is not available */
.mega {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: var(--z-pop);
  width: min(760px, calc(100vw - 32px)); padding: var(--s-4);
  background: var(--glass-bg-strong);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop), var(--glass-highlight);
  animation: shell-fade .12s ease-out;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .mega { background: var(--plate-1); }
}
.mega--narrow { width: min(480px, calc(100vw - 32px)); }
.mega__head { margin: 0 0 var(--s-3); color: var(--plate-text-muted); }
.mega__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; margin: 0; padding: 0; list-style: none; }
.mega__list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.mega li a {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: baseline; gap: var(--s-3);
  padding: 9px var(--s-3); border-radius: var(--radius-sm); color: var(--plate-text);
}
.mega__grid li a { grid-template-columns: minmax(0, 1fr) auto; }
.mega li a:hover, .mega li a[aria-current="page"] { background: var(--plate-hover); color: var(--plate-text); }
.mega li a[aria-current="page"] { box-shadow: inset 2px 0 0 var(--signal-on-plate); }
.mega__code { min-width: 52px; font-size: 12px; font-weight: 700; color: var(--signal-on-plate); }
.mega__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mega__count { font-size: 11px; color: var(--plate-text-muted); white-space: nowrap; }
.mega .mega__foot {
  display: block; margin-top: var(--s-3); padding-top: var(--s-3);
  border-top: 1px solid var(--plate-line); color: var(--brand-on-dark); font-weight: 600; font-size: 13px;
}
.mega .mega__foot:hover { color: var(--plate-text); }

/* --- Command palette ------------------------------------------------------- */

.cmdk {
  width: min(680px, calc(100vw - 32px)); max-height: min(560px, calc(100vh - 120px));
  margin: 12vh auto auto; padding: 0;
  background: var(--glass-bg-strong); color: var(--plate-text);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop), var(--glass-highlight);
}
.cmdk[open] { display: flex; flex-direction: column; animation: shell-rise .16s ease-out; }
.cmdk::backdrop { background: rgba(4, 8, 14, .55); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .cmdk { background: var(--plate-1); }
}

.cmdk__bar { display: flex; align-items: center; gap: var(--s-3); margin: 0; padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--plate-line); color: var(--plate-text-muted); }
.cmdk__bar input[type="search"] {
  flex: 1; min-width: 0; height: 36px; border: 0; padding: 0; border-radius: 0;
  background: transparent; color: var(--plate-text); font-size: 16px; box-shadow: none;
}
.cmdk__bar input[type="search"]:focus { outline: none; box-shadow: none; }
.cmdk__bar input::placeholder { color: var(--plate-text-muted); }

.cmdk__list { flex: 1; overflow-y: auto; padding: var(--s-2); overscroll-behavior: contain; }
.cmdk__group + .cmdk__group { margin-top: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--plate-line); }
.cmdk__label { margin: var(--s-1) var(--s-3) var(--s-2); color: var(--plate-text-muted); }
.cmdk .cmdk__opt {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--s-3);
  padding: 8px var(--s-3); border-radius: var(--radius); color: var(--plate-text); text-decoration: none;
}
.cmdk .cmdk__opt--img { grid-template-columns: auto minmax(0, 1fr) auto; }
.cmdk .cmdk__opt[aria-selected="true"] { background: var(--plate-3); box-shadow: inset 2px 0 0 var(--signal-on-plate); }
.cmdk__opt img { width: 32px; height: 32px; object-fit: contain; border-radius: var(--radius-sm); background: var(--photo-plate); }
.cmdk__name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk__hint { max-width: 38ch; overflow: hidden; text-overflow: ellipsis; font: 500 var(--fs-xs)/1.2 var(--mono); color: var(--plate-text-muted); white-space: nowrap; }
.cmdk__empty { margin: 0; padding: var(--s-5) var(--s-4); color: var(--plate-text-muted); text-align: center; }
.cmdk__empty a { color: var(--brand-on-dark); }
.cmdk__foot {
  display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); padding: var(--s-2) var(--s-4);
  border-top: 1px solid var(--plate-line); font-size: var(--fs-xs); color: var(--plate-text-muted);
}
.cmdk__foot kbd {
  margin-right: 2px; padding: 0 4px; border: 1px solid var(--plate-line-strong);
  border-radius: var(--radius-sm); font-family: var(--mono);
}
.cmdk__note { margin-left: auto; }

@keyframes shell-fade { from { opacity: 0; } }
@keyframes shell-rise { from { opacity: 0; transform: translateY(8px); } }

/* --- Footer ---------------------------------------------------------------- */

.foot { background: var(--plate-0); color: var(--plate-text-muted); font-size: 13px; padding: 0 0 var(--s-5); }
.foot a { color: var(--plate-text-muted); }
.foot a:hover { color: var(--plate-text); }
.foot .label-mono { color: var(--plate-text-muted); }
.foot .btn--brand { color: var(--brand-contrast); }

.foot__assure {
  display: grid; grid-template-columns: repeat(4, 1fr);
  margin: 0; padding: 0; list-style: none;
  border-bottom: 1px solid var(--plate-line);
}
.foot__assure li { padding: var(--s-5) var(--s-5) var(--s-5) 0; }
.foot__assure li + li { padding-left: var(--s-5); border-left: 1px solid var(--plate-line); }
.foot__assure .label-mono { color: var(--signal-on-plate); }
.foot__assure p { margin: var(--s-2) 0 0; color: var(--plate-text); max-width: 34ch; }

.foot__main { display: grid; grid-template-columns: 1.6fr repeat(4, 1fr); gap: var(--s-6); padding: var(--s-7) 0 var(--s-6); }
.foot__brand p { max-width: 42ch; margin: var(--s-4) 0; }
.foot__col h2 { margin: 0 0 var(--s-3); }
.foot__col ul { display: grid; gap: var(--s-2); margin: 0; padding: 0; list-style: none; }

.foot__touch { display: flex; flex-wrap: wrap; gap: var(--s-6); margin: 0; padding: var(--s-4) 0; border-top: 1px solid var(--plate-line); }
.foot__touch dd { margin: var(--s-1) 0 0; color: var(--plate-text); }

.foot__bar { display: flex; justify-content: space-between; gap: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--plate-line); font-size: 12px; }
.foot__bar p { margin: 0; }
.foot__terms { letter-spacing: .04em; white-space: nowrap; }

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

@media (max-width: 1240px) {
  .its__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

@media (max-width: 1100px) {
  .mtool--wide .mtool__text { display: none; }
  .mast__name small { display: none; }
  .foot__assure { grid-template-columns: 1fr 1fr; }
  .foot__assure li:nth-child(3) { padding-left: 0; border-left: 0; }
  .foot__assure li:nth-child(n + 3) { border-top: 1px solid var(--plate-line); }
  .foot__main { grid-template-columns: repeat(4, 1fr); }
  .foot__brand { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .mast .its { display: none; }
  .mast__tools { margin-left: auto; }
  .corridor .corridor__link--its { display: flex; }
  .cmd__key, .cmd__placeholder { display: none; }
  .cmd--trigger { flex: none; width: 36px; padding: 0; justify-content: center; }
}

/* Phones: the bar keeps the mark, search, theme, account and the brief; the
   strip scrolls sideways, and a menu opens as a sheet under the bar. */
@media (max-width: 760px) {
  .mast__inner { gap: var(--s-2); padding: 0 12px; }
  .mast__name, .mtool--wide { display: none; }
  .mast__tools { margin-left: auto; }
  .cmd { flex: 1; }
  .cmd--trigger { flex: none; }
  .theme-switch button { padding: 4px 6px; }
  .briefbtn__text { display: none; }
  .mast .briefbtn { margin-left: 0; }
  .corridor__inner { overflow-x: auto; scrollbar-width: none; padding: 0 8px; }
  .corridor__inner::-webkit-scrollbar { display: none; }
  .corridor .corridor__cta { margin-left: var(--s-2); }
  .mega, .mega--narrow {
    position: fixed; left: 12px; right: 12px; width: auto;
    top: calc(var(--mast-h) + var(--corridor-h) + 4px);
    max-height: calc(100vh - var(--mast-h) - var(--corridor-h) - 20px); overflow-y: auto;
  }
  .mega__grid { grid-template-columns: 1fr; }
  .cmdk { margin-top: 8vh; }
  .cmdk__note { display: none; }
  .foot__assure { grid-template-columns: 1fr; }
  .foot__assure li, .foot__assure li + li { padding: var(--s-4) 0; border-left: 0; }
  .foot__assure li + li { border-top: 1px solid var(--plate-line); }
  .foot__main { grid-template-columns: 1fr 1fr; gap: var(--s-5); }
  .foot__bar { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .mega, .cmdk[open], .its__pulse::after { animation: none; }
  .corridor__menu > summary::after { transition: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .mega, .cmdk { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--plate-1); }
}

@media print {
  .mast, .corridor, .cmdk, .foot { display: none; }
}
