/* ============================================
   THE SYSTEM, MADE VISIBLE
   Inspect mode, brand re-theming, the ⌘K menu, and the /system page.
   Site components re-theme with the active brand; the inspector's own chrome
   does not — a measuring tool keeps one colour, whatever it measures.
   ============================================ */

/* ---------- Header tools (injected by system.js) ---------- */
.ds-tools { display: flex; align-items: center; gap: 4px; }
.ds-tool {
  height: 36px;
  min-width: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-inline: 9px;
  color: var(--ink);
  transition: background-color var(--motion-duration-base) var(--ease), color var(--motion-duration-base) var(--ease);
}
.ds-tool:hover { background: var(--bg-soft); }
.ds-tool svg { width: 18px; height: 18px; flex: none; }
.ds-tool[aria-pressed="true"] { background: #0a6dd4; color: #fff; }
.ds-tool kbd {
  font-family: var(--font);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
}
/* Icon buttons (Inspect, theme) are 36px with 9px side padding, 4px apart,
   so icon-to-icon is 22px. The search field is the one bordered control;
   9px extra margin keeps its edge 22px from the next icon too. */
.ds-tools .theme-toggle { width: auto; min-width: 36px; padding-inline: 9px; border-radius: 999px; }

.ds-tool--cmdk {
  justify-content: flex-start;
  gap: 8px;
  min-width: 168px;
  margin-right: 9px;
  padding-inline: 12px 6px;
  border: 1px solid var(--field-line);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--ink-dim);
  font-size: var(--text-sm);
  transition: border-color var(--motion-duration-base) var(--ease), background-color var(--motion-duration-base) var(--ease);
}
.ds-tool--cmdk:hover { background: var(--bg); border-color: var(--ink); }
.ds-tool--cmdk svg { width: 16px; height: 16px; }
.ds-tool--cmdk .ds-tool__label { margin-right: auto; }
.ds-tool--cmdk kbd {
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--bg-soft);
  color: var(--ink-dim);
  font-size: var(--text-xs);
  line-height: 1.2;
}
@media (max-width: 880px) {
  /* Phones and small tablets: same field, no key hint (often no keyboard). */
  .ds-tool--cmdk { min-width: 0; padding-inline: 12px 14px; }
  .ds-tool kbd { display: none; }
}

/* ---------- Brand re-theme ----------
   For the length of a brand swap every colour and corner eases on the slow
   duration, then the class comes off and components get their own timings
   back. */
html.is-rebranding *,
html.is-rebranding *::before,
html.is-rebranding *::after {
  transition-property: background-color, color, border-color, border-radius, outline-color, fill, stroke, opacity, transform !important;
  transition-duration: var(--motion-duration-slow) !important;
  transition-timing-function: var(--motion-ease-settle) !important;
}

.brand-chip {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 14px;
  border-radius: 999px;
  background: #1d1d1f;
  color: #f5f5f7;
  font-size: var(--text-sm);
  line-height: 1.3;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 12px);
  transition: opacity var(--motion-duration-calm) var(--ease), transform var(--motion-duration-calm) var(--ease), visibility 0s linear var(--motion-duration-calm);
}
.brand-chip.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition-delay: 0s;
}
.brand-chip__swatches { display: flex; flex: none; }
.brand-chip__swatches span {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #1d1d1f;
  margin-left: -5px;
}
.brand-chip__swatches span:first-child { margin-left: 0; }
.brand-chip__text { min-width: 0; }
.brand-chip__text strong { font-weight: 600; }
.brand-chip__text span { color: #a1a1a6; }
.brand-chip__reset {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  background: #3a3a3c;
  color: #f5f5f7;
  font-size: var(--text-xs);
  font-weight: 500;
}
.brand-chip__reset:hover { background: #48484a; }
.brand-chip__reset[hidden] { display: none; }
@media (max-width: 560px) {
  .brand-chip__text span { display: none; }
}

/* ---------- Inspect mode ---------- */
.inspect-layer { position: fixed; inset: 0; z-index: 400; pointer-events: none; }
.inspect-layer[hidden] { display: none; }
.inspect-margin,
.inspect-pad,
.inspect-box { position: fixed; top: 0; left: 0; box-sizing: border-box; }
.inspect-margin { border-style: solid; border-color: rgba(255, 159, 67, 0.28); }
.inspect-pad { border-style: solid; border-color: rgba(52, 199, 89, 0.24); }
.inspect-box { border: 1.5px solid #0a6dd4; }
.inspect-label {
  position: fixed;
  top: 0;
  left: 0;
  padding: 3px 7px;
  border-radius: 4px;
  background: #0a6dd4;
  color: #fff;
  font: 500 var(--text-xs)/1.3 var(--font);
  white-space: nowrap;
}
.inspect-label span { opacity: 0.75; margin-left: 6px; font-variant-numeric: tabular-nums; }

html.is-inspecting [data-ds-name] { outline: 1px dashed rgba(10, 109, 212, 0.5); outline-offset: -1px; }
html.is-inspecting [data-ds-name].is-ds-pinned { outline: 2px solid #0a6dd4; }
/* The card's full-bleed link overlay would swallow every hover on the card. */
html.is-inspecting .card__title a::after { display: none; }
html.is-inspecting body { cursor: crosshair; }

.inspect-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 500;
  width: 340px;
  max-height: min(70vh, 640px);
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: #1e1e1e;
  color: #e6e6e6;
  font: 400 var(--text-xs)/1.45 var(--font);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.06);
  cursor: default;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--motion-duration-calm) var(--ease), transform var(--motion-duration-calm) var(--ease);
}
.inspect-panel.is-open { opacity: 1; transform: none; }
.inspect-panel[hidden] { display: none; }
.inspect-panel__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 10px 14px;
  border-bottom: 1px solid #2c2c2c;
}
.inspect-panel__title { font-size: var(--text-xs); font-weight: 600; color: #fff; margin-right: auto; }
.inspect-panel__title span { font-weight: 400; color: #8e8e93; margin-left: 6px; }
.inspect-panel__close {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: #a1a1a6;
}
.inspect-panel__close:hover { background: #2c2c2c; color: #fff; }
.inspect-panel__close svg { width: 14px; height: 14px; }
.inspect-panel__body { overflow-y: auto; padding: 4px 14px 12px; overscroll-behavior: contain; }
.inspect-panel__empty { padding: 14px 0 6px; color: #a1a1a6; }
.inspect-panel__empty kbd,
.inspect-panel__foot kbd {
  font: 500 var(--text-xs)/1 var(--font);
  padding: 2px 5px;
  border-radius: 4px;
  background: #2c2c2c;
  color: #e6e6e6;
}
.inspect-panel__name { font-size: var(--text-base); font-weight: 600; color: #fff; padding-top: 12px; letter-spacing: -0.01em; }
.inspect-panel__size { color: #8e8e93; font-variant-numeric: tabular-nums; margin-top: 2px; }
.inspect-group { margin-top: 14px; }
.inspect-group__label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: #8e8e93;
  margin-bottom: 6px;
}
.inspect-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  padding-block: 4px;
  align-items: start;
}
.inspect-row__key { color: #8e8e93; }
.inspect-row__val { min-width: 0; color: #e6e6e6; overflow-wrap: anywhere; }
.inspect-row__val code { font-size: var(--text-xs); color: #e6e6e6; }
.inspect-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; }
.inspect-chain__tok { font-family: var(--mono); font-size: var(--text-xs); color: #7cc4ff; }
.inspect-chain__arrow { color: #8e8e93; }
.inspect-chain__hex { font-family: var(--mono); font-size: var(--text-xs); color: #e6e6e6; }
.inspect-sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  vertical-align: -2px;
  margin-right: 4px;
}
.inspect-note { color: #8e8e93; }
.inspect-warn { color: #ffb340; }
.inspect-ok { color: #63d471; }

.inspect-themes { margin-top: 14px; padding-top: 12px; border-top: 1px solid #2c2c2c; }
.inspect-themes__row { display: flex; flex-wrap: wrap; gap: 4px; }
.inspect-themes__btn {
  padding: 5px 9px;
  border-radius: 999px;
  background: #2c2c2c;
  color: #e6e6e6;
  font-size: var(--text-xs);
  font-weight: 500;
}
.inspect-themes__btn:hover { background: #3a3a3c; }
.inspect-themes__btn[aria-pressed="true"] { background: #0a6dd4; color: #fff; }
.inspect-panel__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #2c2c2c;
  color: #8e8e93;
  font-size: var(--text-xs);
}
.inspect-panel__foot a { color: #7cc4ff; font-weight: 500; }
.inspect-panel__foot a:hover { text-decoration: underline; }
@media (max-width: 560px) {
  .inspect-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 46vh;
  }
}

/* ---------- Toast ---------- */
.ds-toast {
  position: fixed;
  left: 50%;
  top: calc(var(--nav-h) + 12px);
  z-index: 700;
  padding: 8px 14px;
  border-radius: 999px;
  background: #1d1d1f;
  color: #f5f5f7;
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translate(-50%, -6px);
  pointer-events: none;
  transition: opacity var(--motion-duration-calm) var(--ease), transform var(--motion-duration-calm) var(--ease);
}
.ds-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Command menu ---------- */
.cmdk { position: fixed; inset: 0; z-index: 600; }
.cmdk[hidden] { display: none; }
.cmdk__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  transition: opacity var(--motion-duration-calm) var(--ease);
}
.cmdk__panel {
  position: relative;
  width: min(600px, calc(100vw - 32px));
  margin: min(14vh, 120px) auto 0;
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28), 0 0 0 1px var(--line);
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition: opacity var(--motion-duration-calm) var(--ease), transform var(--motion-duration-calm) var(--ease);
}
.cmdk.is-open .cmdk__backdrop { opacity: 1; }
.cmdk.is-open .cmdk__panel { opacity: 1; transform: none; }
.cmdk__field { display: flex; align-items: center; gap: 10px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.cmdk__field svg { width: 18px; height: 18px; color: var(--ink-dim); flex: none; }
.cmdk__input {
  flex: 1;
  min-width: 0;
  height: 56px;
  border: 0;
  outline: none;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: var(--text-md);
}
.cmdk__input::placeholder { color: var(--ink-dim); }
.cmdk__list { max-height: min(56vh, 420px); overflow-y: auto; padding: 6px; overscroll-behavior: contain; }
.cmdk__group {
  padding: 12px 12px 6px;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ink-dim);
}
.cmdk__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  cursor: pointer;
}
.cmdk__item[aria-selected="true"] { background: var(--bg-soft); }
.cmdk__icon { width: 18px; height: 18px; flex: none; color: var(--ink-dim); display: grid; place-items: center; }
.cmdk__icon svg { width: 18px; height: 18px; }
.cmdk__swatch { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.cmdk__label { flex: 1; min-width: 0; }
.cmdk__hint { font-size: var(--text-sm); color: var(--ink-dim); }
.cmdk__empty { padding: 28px 12px; text-align: center; color: var(--ink-dim); font-size: var(--text-base); }
.cmdk__foot {
  display: flex;
  gap: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  font-size: var(--text-xs);
  color: var(--ink-dim);
}
.cmdk__foot kbd {
  font: 500 var(--text-xs)/1 var(--font);
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--bg-soft);
  color: var(--ink);
  margin-right: 4px;
}
@media (max-width: 560px) {
  .cmdk__panel { margin-top: 12px; }
  .cmdk__foot { display: none; }
}

/* ---------- /system page ---------- */
.sys { padding-bottom: clamp(64px, 9vw, 112px); }
.sys-section { padding-top: clamp(48px, 7vw, 72px); }
.sys-section > .section__title { margin-bottom: 8px; }
.sys-lede { max-width: var(--measure); color: var(--ink-dim); margin-bottom: 24px; }
.sys-lede kbd {
  font: 500 var(--text-sm)/1 var(--font);
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  color: var(--ink);
}

.sys-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.sys-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ink-dim);
  padding: 0 12px 10px 0;
  border-bottom: 1px solid var(--line);
}
.sys-table td { padding: 12px 12px 12px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.sys-table code { font-size: var(--text-sm); }
.sys-table td:last-child { color: var(--ink-dim); }
.sys-val { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: var(--text-sm); white-space: nowrap; }
.sys-sw {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 14%, transparent);
  flex: none;
}
.sys-ref { color: var(--ink-dim); font-family: var(--mono); font-size: var(--text-xs); }
@media (max-width: 760px) {
  .sys-table thead { display: none; }
  .sys-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding-block: 12px; border-bottom: 1px solid var(--line); }
  .sys-table td { padding: 0; border: 0; }
  .sys-table td:first-child, .sys-table td:last-child { grid-column: 1 / -1; }
}

.sys-brands { display: grid; gap: 16px; }
.sys-brand {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.sys-brand__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sys-brand__name { font-size: var(--text-md); font-weight: 600; letter-spacing: -0.01em; }
.sys-brand__source { font-size: var(--text-sm); color: var(--ink-dim); margin-top: 2px; }
.sys-brand__swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.sys-chip { display: grid; gap: 8px; }
.sys-chip__sw { height: 52px; border-radius: var(--radius-sm); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 12%, transparent); }
.sys-chip__name { font-family: var(--mono); font-size: var(--text-xs); line-height: 1.3; }
.sys-chip__hex { font-family: var(--mono); font-size: var(--text-xs); color: var(--ink-dim); }
.sys-brand details { margin-top: 16px; }
.sys-brand summary { cursor: pointer; font-size: var(--text-sm); font-weight: 500; color: var(--ink-dim); }
.sys-brand summary:hover { color: var(--ink); }
.sys-brand details .sys-table { margin-top: 12px; }

.sys-radius { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px; }
.sys-radius__item { display: grid; gap: 8px; font-size: var(--text-sm); }
.sys-radius__shape { height: 80px; background: var(--bg-soft); border: 1px solid var(--line); }
.sys-radius__item code { font-size: var(--text-xs); }
.sys-radius__item span { color: var(--ink-dim); font-family: var(--mono); font-size: var(--text-xs); }

.sys-motion { display: grid; gap: 10px; }
.sys-motion__row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.sys-motion__row code { font-size: var(--text-sm); }
.sys-motion__row small { display: block; color: var(--ink-dim); font-size: var(--text-sm); }
.sys-motion__track { position: relative; height: 28px; border-radius: 999px; background: var(--bg-soft); }
.sys-motion__dot {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink);
  transition-property: left;
  transition-timing-function: var(--motion-ease-settle);
}
.sys-motion.is-played .sys-motion__dot { left: calc(100% - 24px); }
.sys-motion__play { margin-top: 16px; }
@media (max-width: 760px) {
  .sys-motion__row { grid-template-columns: 1fr; gap: 8px; }
}

.sys-components { display: flex; flex-wrap: wrap; gap: 8px; }
.sys-components li {
  font-size: var(--text-sm);
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
}
.sys-files { border-top: 1px solid var(--line); }
.sys-files li { display: grid; grid-template-columns: 160px 1fr; gap: 16px; padding-block: 14px; border-bottom: 1px solid var(--line); font-size: var(--text-base); }
.sys-files a { color: var(--link); font-family: var(--mono); font-size: var(--text-sm); }
.sys-files a:hover { text-decoration: underline; text-underline-offset: 3px; }
.sys-files span { color: var(--ink-dim); }
@media (max-width: 760px) {
  .sys-files li { grid-template-columns: 1fr; gap: 4px; }
}

.sys .page-hero { max-width: var(--measure); padding-bottom: 0; }
