/* meshworks.css — the one token/overlay layer on Pico (UI plan §2 D5, §3).
 *
 * Pico stays the base; this file extends it via CSS custom properties and a few
 * component classes (app shell, tables, chips, density). No utility framework,
 * no fighting Pico specificity — additive rules and tokens only.
 */

/* --- tokens ---------------------------------------------------------------- */
:root {
  --mw-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --mw-sidebar-w: 15rem;
  --mw-rail-w: 60px;        /* collapsed sidebar: just wide enough for the square logo */
  --mw-logo-h: 50px;        /* brand logo display height (both wide + square); fixed px so it
                               doesn't shrink at higher density and stays crisp */
  --mw-header-h: 3.25rem;

  /* semantic state colors — light theme */
  --mw-ok: #2e7d32;
  --mw-warn: #b26a00;
  --mw-danger: #c62828;
  --mw-info: #1565c0;
}

/* semantic state colors — dark theme (verify contrast here first, §3) */
[data-theme="dark"] {
  --mw-ok: #66bb6a;
  --mw-warn: #ffb74d;
  --mw-danger: #ef5350;
  --mw-info: #64b5f6;
}

/* Pin the type scale — never viewport-scaled (UI plan §3.8). Pico's responsive
 * breakpoint font-scaling changes the root font-size on wide monitors, inflating
 * the whole UI; we pin --pico-font-size and set html font-size explicitly per
 * density (the html[data-density] specificity beats Pico's :root media rules). */
:root {
  --pico-font-size: 100%;
}

/* Density axis: root font-size + Pico spacing/form vars + the --mw tokens.
 * Default (:root) mirrors compact, matching the pref default. */
:root,
html[data-density="compact"] {
  font-size: 14px;

  --pico-spacing: 0.75rem;
  --pico-typography-spacing-vertical: 0.8rem;
  --pico-form-element-spacing-vertical: 0.4rem;
  --pico-form-element-spacing-horizontal: 0.6rem;

  --mw-row-py: 0.25rem;
  --mw-cell-px: 0.5rem;
  --mw-font-table: 0.85rem;
  --mw-input-h: 2rem;
}

html[data-density="comfortable"] {
  font-size: 16px;

  --pico-spacing: 1rem;
  --pico-typography-spacing-vertical: 1rem;
  --pico-form-element-spacing-vertical: 0.55rem;
  --pico-form-element-spacing-horizontal: 0.85rem;

  --mw-row-py: 0.55rem;
  --mw-cell-px: 0.85rem;
  --mw-font-table: 1rem;
  --mw-input-h: 2.4rem;
}

html[data-density="dense"] {
  font-size: 13px;

  --pico-spacing: 0.5rem;
  --pico-typography-spacing-vertical: 0.55rem;
  --pico-form-element-spacing-vertical: 0.25rem;
  --pico-form-element-spacing-horizontal: 0.45rem;

  --mw-row-py: 0.1rem;
  --mw-cell-px: 0.35rem;
  --mw-font-table: 0.78rem;
  --mw-input-h: 1.7rem;
}

/* Modest in-app heading scale — no large display type anywhere (UI plan §3.9). */
.mw-content h1 { font-size: 1.4rem; }
.mw-content h2 { font-size: 1.15rem; }
.mw-content h3 { font-size: 1.1rem; }
.mw-content h4 { font-size: 1rem; }
.mw-content h5,
.mw-content h6 { font-size: 0.95rem; }
.mw-content hgroup > :first-child { font-size: 1.4rem; }

/* --- app shell (P1) -------------------------------------------------------- */
body.mw-app {
  margin: 0;
}

.mw-layout {
  display: grid;
  grid-template-columns: var(--mw-sidebar-w) 1fr;
  min-height: 100vh;
}

/* collapse the persistent nav to reclaim horizontal room (checkbox toggle, no JS).
   Collapses to a narrow rail — not zero — so the square logo mark stays pinned to
   the window's top-left; the wordmark + nav go with the menu. */
#mw-nav-toggle:checked ~ .mw-layout {
  grid-template-columns: var(--mw-rail-w) 1fr;
}
#mw-nav-toggle:checked ~ .mw-layout .mw-nav { display: none; }
#mw-nav-toggle:checked ~ .mw-layout .mw-sidebar { padding-inline: 0.3rem; }
#mw-nav-toggle:checked ~ .mw-layout .mw-brand { padding-inline: 0; justify-items: center; }
#mw-nav-toggle:checked ~ .mw-layout .mw-logo-wide { display: none; }
#mw-nav-toggle:checked ~ .mw-layout .mw-logo-mark { display: block; }

.mw-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--pico-muted-border-color);
  background: var(--pico-card-background-color);
  padding: 0.75rem 0.5rem;
}

.mw-brand {
  display: grid;
  padding: 0.4rem 0.5rem 0.75rem;
  white-space: nowrap;
}
.mw-brand a {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
/* Logo swaps with the nav state; height is fixed so the swap never shifts the
   layout vertically. Wide fills the expanded sidebar; the square mark shows only
   in the collapsed rail (rule above). */
.mw-logo {
  height: var(--mw-logo-h);
  width: auto;
  max-width: 100%;
  display: block;
}
.mw-logo-mark { display: none; }

.mw-nav details {
  margin: 0;
  border: 0;
  padding: 0;
}
.mw-nav summary {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--pico-muted-color);
  padding: 0.4rem 0.5rem 0.2rem;
}
.mw-nav ul {
  list-style: none;
  margin: 0 0 0.4rem;
  padding: 0;
}
.mw-nav li a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.32rem 0.55rem;
  border-radius: 0.35rem;
  text-decoration: none;
  color: var(--pico-color);
  white-space: nowrap;
}
.mw-nav li a:hover {
  background: var(--pico-secondary-focus, rgba(127, 127, 127, 0.15));
}

.mw-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.mw-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--mw-header-h);
  padding: 0 1rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
  background: var(--pico-background-color);
}
.mw-search {
  flex: 1;
  margin: 0;
  max-width: 32rem;
}
.mw-search input {
  margin: 0;
  height: 2.2rem;
}
.mw-header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}
.mw-header-right form { margin: 0; }
.mw-header-right .mw-user {
  font-size: 0.8rem;
  color: var(--pico-muted-color);
  white-space: nowrap;
}

/* compact header buttons so the slim header stays slim at every density */
.mw-iconbtn,
.mw-header-right button,
.mw-header-right [role="button"] {
  padding: 0.3rem 0.55rem;
  margin: 0;
  font-size: 0.8rem;
  line-height: 1;
  min-height: 0;
}
.mw-iconbtn {
  cursor: pointer;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 0.35rem;
  background: transparent;
  user-select: none;
}

.mw-content {
  flex: 1;
  padding: 1rem 1.25rem 2.5rem;
  width: 100%;
}

/* login / settings are the only narrow, centered surfaces (§3) */
body.mw-auth .mw-sidebar,
body.mw-auth .mw-header { display: none; }
body.mw-auth .mw-layout { grid-template-columns: 1fr; }
body.mw-auth .mw-content { max-width: 26rem; margin: 3rem auto; }

/* --- tables (§3) ----------------------------------------------------------- */
.mw-content table td,
.mw-content table th {
  padding-top: var(--mw-row-py);
  padding-bottom: var(--mw-row-py);
  padding-inline: var(--mw-cell-px);
  font-size: var(--mw-font-table);
}

.mw-content table thead th {
  position: sticky;
  top: var(--mw-header-h);
  z-index: 1;
  background: var(--pico-card-background-color);
  white-space: nowrap;
}

.mw-content tbody tr:hover {
  background: var(--pico-secondary-focus, rgba(127, 127, 127, 0.12));
}

/* data-identity columns: monospace with tabular figures (§3) */
.mono {
  font-family: var(--mw-mono);
  font-variant-numeric: tabular-nums;
}
/* right-aligned numerics */
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* sortable header links */
th a.mw-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  text-decoration: none;
  color: inherit;
}
th a.mw-sort:hover { text-decoration: underline; }
.mw-sortdir { color: var(--mw-info); font-size: 0.8em; }

/* row-action cluster, fixed to the rightmost cell */
td.mw-actions {
  white-space: nowrap;
  text-align: right;
}
td.mw-actions a,
td.mw-actions button {
  padding: 0.15rem 0.5rem;
  font-size: 0.78rem;
  margin: 0 0 0 0.15rem;
}

.mw-tablesearch {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.6rem;
  max-width: 40rem;
}
.mw-tablesearch input[type="search"] { margin: 0; flex: 1; min-width: 10rem; }
.mw-tablesearch button,
.mw-tablesearch a { margin: 0; width: auto; }
.mw-export { margin-left: auto; }   /* push Export CSV to the right of the row */

.mw-empty {
  color: var(--pico-muted-color);
}

/* --- pagination controls (shared pager macro) ------------------------------ */
.mw-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 0.6rem;
  font-size: 0.82rem;
  color: var(--pico-muted-color);
}
.mw-pager-nav { margin-left: auto; display: inline-flex; align-items: center; gap: 0.4rem; }
.mw-pager-sizes { display: inline-flex; align-items: center; gap: 0.3rem; }
.mw-pager-page { white-space: nowrap; }
.mw-pager-cur { color: var(--pico-color); }
/* compact link-buttons in the pager (override the intrinsic button sizing) */
.mw-pager-btn {
  width: auto;
  margin: 0;
  padding: 0.1rem 0.5rem;
  font-size: 0.8rem;
  line-height: 1.4;
}
.mw-pager-off { opacity: 0.45; pointer-events: none; }

/* --- multi-row select + bulk actions (bulkselect.js) ----------------------- */
.mw-bulkbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  min-height: 1.6rem;
}
.mw-bulkbar button { margin: 0; width: auto; }
th.mw-check,
td.mw-check {
  width: 1.6rem;
  text-align: center;
  padding-inline: 0.25rem;
}
.mw-check input { margin: 0; vertical-align: middle; }

/* --- CSS-only tabs (P3 detail; no JS) -------------------------------------
   Radios come first in source; the tablist and panels are later siblings so the
   ~ combinator can show the checked panel. Id-specific rules below (only the BOM
   import screen is tabbed today — generalize when a second tabbed screen lands). */
.mw-tab-radio {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);          /* visually hidden but focusable (keyboard tabs) */
  white-space: nowrap;
}
/* Tabs as a segmented pill control: every tab reads as a distinct clickable
   chip (full-contrast label + border), and the active one is a solid fill — so
   an inactive tab like "Positions" is obvious, not faint grey text. */
.mw-tabs {
  display: flex;
  justify-content: flex-start;   /* cluster tabs left (override Pico nav's space-between) */
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.mw-tabs label {
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  color: var(--pico-color);
  font-weight: 500;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 0.4rem;
  background: var(--pico-card-background-color);
}
.mw-tabs label:hover {
  border-color: var(--mw-info);
  background: var(--pico-secondary-focus, rgba(127, 127, 127, 0.12));
}
.mw-tabpanel { display: none; }

#import-tab-group:checked ~ .mw-tabpanel-group,
#import-tab-all:checked ~ .mw-tabpanel-all { display: block; }
#import-tab-group:checked ~ .mw-tabs label[for="import-tab-group"],
#import-tab-all:checked ~ .mw-tabs label[for="import-tab-all"] {
  /* text color tracks the page background so the fill reads in both themes */
  color: var(--pico-background-color);
  background: var(--mw-info);
  border-color: var(--mw-info);
  font-weight: 600;
}
#import-tab-group:focus-visible ~ .mw-tabs label[for="import-tab-group"],
#import-tab-all:focus-visible ~ .mw-tabs label[for="import-tab-all"] {
  outline: 2px solid var(--mw-info);
  outline-offset: 2px;
}

/* row of collapsed "+ Add" panels at the top of a tab, plus the board-state
   summary + Release button pushed to the right */
.mw-tab-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

/* 4-segment state summary; fills the remaining width so Release lands far right */
.mw-import-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  flex: 1;
  gap: 0.4rem;
}
.mw-import-summary .chip { font-size: 0.78rem; }
.mw-import-summary .mw-release { margin: 0 0 0 auto; }   /* pin Release to the far right */
.mw-import-summary .mw-release button { margin: 0; }

/* --- BOM grouping master-detail (0A8-6) ------------------------------------ */
/* Two stacked full-width panes: groups (capped, scrolls) over the focused
   group's instances (fills the rest). Top/bottom keeps both grids full width. */
.mw-masterdetail {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.75rem;
}
.mw-md-groups .mw-md-panebody { max-height: 38vh; overflow: auto; }
.mw-md-groups.collapsed .mw-md-panebody { display: none; }
/* BOTH master-detail panes scroll in their OWN container, so their sticky header
   sticks to the container top (0), not below the global page header (the default
   rule) — otherwise it floats mid-pane and the first data row hides behind it. */
.mw-md-groups .mw-md-panebody thead th, .mw-md-instances .mw-md-panebody thead th { top: 0; z-index: 2; }
.mw-md-panehead {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.3rem;
}
.mw-md-panehead > strong { font-size: 0.95rem; }
.mw-md-panehead button { margin: 0; width: auto; }
.mw-collapse { padding: 0.1rem 0.5rem; }
.mw-md-groups.collapsed .mw-collapse { transform: rotate(-90deg); }
.mw-md-groups table, .mw-md-instances table { margin: 0; }
.mw-md-instances .mw-md-empty { padding: 1rem 0.25rem; }

/* focused group row: a clear left accent + tint (both themes) */
.mw-md-groups tr[data-group-row] { cursor: pointer; }
.mw-md-groups tr[data-group-row].focused > td {
  background: color-mix(in srgb, var(--mw-info) 14%, transparent);
}
.mw-md-groups tr[data-group-row].focused > td:first-child {
  box-shadow: inset 3px 0 0 0 var(--mw-info);
}

/* differing raw_fields column/cell emphasis in the instance grid */
.mw-md-instances th.mw-diff { color: var(--mw-warn); }
.mw-md-instances td.mw-diff {
  background: color-mix(in srgb, var(--mw-warn) 12%, transparent);
  box-shadow: inset 2px 0 0 0 color-mix(in srgb, var(--mw-warn) 55%, transparent);
}

/* resolved-part cell: a link-like affordance that opens the part in a new tab */
.mw-partlink {
  color: var(--mw-info);
  text-decoration: none;
  cursor: pointer;
}
.mw-partlink:hover { text-decoration: underline; }

/* per-row group actions: keep buttons compact and on one line */
.mw-md-rowactions { white-space: nowrap; }
.mw-md-rowactions button, .mw-md-rowactions summary { margin: 0 0.15rem 0 0; width: auto; padding: 0.15rem 0.5rem; font-size: 0.8rem; }
.mw-splitkeys { list-style: none; margin: 0.25rem 0 0; padding: 0; }
.mw-splitkeys button { display: block; width: 100%; text-align: left; }
.mw-split-preview { list-style: none; margin: 0.5rem 0; padding: 0; }
.mw-split-preview li { display: flex; align-items: center; gap: 0.5rem; padding: 0.15rem 0; }
.mw-split-confirm { margin-top: 0.5rem; }

/* --- status chips (§3): label + semantic color, text always present -------- */
.chip {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border: 1px solid transparent;
  border-radius: 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.chip-ok { color: var(--mw-ok); border-color: var(--mw-ok); }
.chip-warn { color: var(--mw-warn); border-color: var(--mw-warn); }
.chip-danger { color: var(--mw-danger); border-color: var(--mw-danger); }
.chip-info { color: var(--mw-info); border-color: var(--mw-info); }
.chip-muted { color: var(--pico-muted-color); border-color: var(--pico-muted-border-color); }

/* --- forms (§3): density-driven control height ----------------------------- */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  min-height: var(--mw-input-h);
}
.mw-content form .grid { align-items: start; }

/* forms are width-capped even in the full-width region (§3.11); the search
   box keeps its own narrower cap. */
.mw-content form:not(.mw-tablesearch):not(.mw-search) {
  max-width: 52rem;
}

/* buttons are intrinsic width and inline (§3.10) — override Pico's full-width
   submit default globally. */
button,
input[type="submit"],
input[type="reset"],
input[type="button"],
a[role="button"],
[role="button"] {
  width: auto;
  display: inline-block;
}

/* form action rows: the submit button group aligns right (§3.10). */
.mw-content form > button,
.mw-content form > input[type="submit"] {
  display: block;
  width: fit-content;
  margin-left: auto;
}

/* ...but buttons inside a row-action cell stay inline and horizontal, matching
   the part table (whose actions aren't wrapped in forms). */
td.mw-actions form {
  display: inline-flex;
  gap: 0.25rem;
  margin: 0;
}
td.mw-actions form > button,
td.mw-actions form > input[type="submit"] {
  display: inline-block;
  width: auto;
  margin-left: 0.15rem;
}
td.mw-actions form input:not([type="submit"]) {
  width: 9rem;
  margin: 0;
}

/* the ONE exception: /login's submit is full width (§3.10). */
body.mw-auth .mw-content form button,
body.mw-auth .mw-content form input[type="submit"] {
  display: block;
  width: 100%;
  margin-left: 0;
}

/* --- list page header + collapsed create panel (P2, §3.12) ----------------- */
.mw-pagehead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}
.mw-pagehead h1 { margin: 0; margin-right: auto; }

/* compact BOM-import header: breadcrumb + title + board summary in one row so the
   grid gets more vertical room (0A8-6 density pass) */
.mw-import-head { align-items: center; margin-bottom: 0.4rem; }
.mw-import-titles { display: flex; flex-direction: column; gap: 0.05rem; margin-right: auto; }
.mw-import-titles .mw-crumb { font-size: 0.78rem; }
.mw-import-head h1 { font-size: 1.2rem; }
.mw-import-head .mw-subtle { font-weight: 400; font-size: 0.85rem; color: var(--pico-muted-color); }
.mw-import-audit { font-size: 0.85rem; white-space: nowrap; }
.mw-tabpanel-group .mw-tab-actions { margin-bottom: 0.5rem; }
.mw-tabpanel-group .mw-masterdetail { gap: 0.5rem; }
.mw-add > summary {
  width: auto;
  margin: 0;
  cursor: pointer;
}
/* when the create panel is open, drop it to its own full-width row */
.mw-add[open] { flex-basis: 100%; }
.mw-add[open] > summary { margin-bottom: 0.6rem; }

/* --- home quick-nav (P1, §3.13): icon + label on one line, no wrapping ----- */
.mw-quickgroup { margin-bottom: 1.25rem; }
.mw-quickgroup h3 { margin-bottom: 0.5rem; }
.mw-quicknav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.mw-quicklink {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 13rem;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 0.4rem;
  text-decoration: none;
  color: var(--pico-color);
  white-space: nowrap;      /* never wrap the label mid-word */
  overflow-wrap: normal;
  word-break: keep-all;
}
.mw-quicklink:hover {
  background: var(--pico-secondary-focus, rgba(127, 127, 127, 0.12));
}

/* --- dialog primitive (0A7-1) ---------------------------------------------
   Native <dialog> chrome is Pico's; these are the only additions. Pico's
   default (class-ful) build ships the scroll-lock + open/close animation via
   the .modal-is-* utilities the island toggles — so we add just two things:
   a destructive-button token (Pico has no danger variant) and a defensive
   scroll-lock line in case a classless build is ever swapped in (harmless when
   Pico already locks it). */
button[data-variant="danger"] {
  --pico-background-color: var(--mw-danger);
  --pico-border-color: var(--mw-danger);
  --pico-color: #fff;
}
button[data-variant="danger"]:is(:hover, :focus, :active) {
  --pico-background-color: color-mix(in srgb, var(--mw-danger) 82%, #000);
  --pico-border-color: color-mix(in srgb, var(--mw-danger) 82%, #000);
}

html.modal-is-open { overflow: hidden; }

/* "?" help affordance next to a field label (components/forms.html help_icon).
   The popup itself is Pico's [data-tooltip]; this styles just the marker. */
.mw-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  margin-left: 0.3rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  color: var(--pico-muted-color);
  cursor: help;
  user-select: none;
  vertical-align: middle;
}
.mw-help:hover,
.mw-help:focus {
  color: var(--pico-color);
  border-color: var(--mw-info);
  outline: none;
}

/* inline field-level validation message under a dialog input (0A7-2) */
.mw-fielderror {
  display: block;
  margin-top: 0.15rem;
  color: var(--mw-danger);
}

/* footer buttons stay inline & right-aligned; override the global form-submit
   rule that would otherwise stack the dialog's Save/Cancel and left-hang them. */
dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
dialog footer button {
  display: inline-block;
  width: auto;
  margin: 0;
}

/* --- quality floor: visible keyboard focus everywhere (§3) ----------------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[role="button"]:focus-visible,
label.mw-iconbtn:focus-visible {
  outline: 2px solid var(--mw-info);
  outline-offset: 2px;
}

/* --- toast region (moved out of the base template's inline style) ---------- */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  max-width: 24rem;
}
.toast { position: relative; margin: 0 0 0.5rem; padding: 0.55rem 1.9rem 0.55rem 0.85rem; }
.toast.success { border-inline-start: 4px solid var(--mw-ok); }
.toast.warn { border-inline-start: 4px solid var(--mw-warn); }
.toast.error { border-inline-start: 4px solid var(--mw-danger); }
/* dismiss affordance (injected by armToasts); toasts also auto-expire after 5s */
.mw-toast-close {
  position: absolute;
  top: 0.15rem;
  right: 0.3rem;
  width: auto;
  min-height: 0;
  margin: 0;
  padding: 0 0.3rem;
  background: transparent;
  border: 0;
  color: inherit;
  opacity: 0.6;
  font-size: 1.1rem;
  line-height: 1.2;
  cursor: pointer;
}
.mw-toast-close:hover { opacity: 1; }

.nav-icon { width: 1em; height: 1em; vertical-align: -0.15em; margin-inline-end: 0.35em; }

/* 0A8-2 resolve picker (in the 0A7 dialog). Functional, not polished: a search
   box over a scrollable results list; each result is the describe() label with a
   quieter MPN line beneath. */
.mw-picker { display: flex; flex-direction: column; gap: 0.5rem; min-width: min(90vw, 32rem); }
.mw-picker-refs { margin: 0; font-size: 0.8rem; opacity: 0.7; }
.mw-picker-note { margin: 0; font-size: 0.8rem; color: var(--mw-info); opacity: 0.9; }
.mw-picker-filters { display: flex; gap: 0.5rem; align-items: flex-start; }
.mw-picker-filters input[type="search"] { flex: 1 1 auto; margin: 0; }
.mw-picker-filters select { flex: 0 0 auto; width: auto; margin: 0; }
.mw-picker-filters select[multiple] { min-width: 12rem; font-size: 0.85rem; }
.mw-picker-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.mw-picker-list li { padding: 0.15rem 0; }
.mw-picker-pick { width: 100%; text-align: left; }
.mw-picker-mpns { display: block; opacity: 0.7; font-family: var(--mw-mono); }

/* --- visual refresh --------------------------------------------------------
   A small semantic layer over Pico: clearer hierarchy, consistent surfaces,
   and breakpoints that let today's desktop shell evolve toward touch layouts. */
:root {
  --mw-accent: #2563eb;
  --mw-accent-hover: #1d4ed8;
  --mw-surface-raised: #ffffff;
  --mw-surface-subtle: #f6f8fb;
  --mw-border: #dfe4ec;
  --mw-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 4px rgba(15, 23, 42, 0.04);
  --mw-shadow-md: 0 10px 30px rgba(15, 23, 42, 0.09);
  --pico-primary: var(--mw-accent);
  --pico-primary-background: var(--mw-accent);
  --pico-primary-border: var(--mw-accent);
  --pico-primary-hover-background: var(--mw-accent-hover);
  --pico-primary-hover-border: var(--mw-accent-hover);
  --pico-border-radius: 0.55rem;
}

[data-theme="dark"] {
  --mw-accent: #60a5fa;
  --mw-accent-hover: #93c5fd;
  --mw-surface-raised: #18212f;
  --mw-surface-subtle: #111925;
  --mw-border: #2b3748;
  --mw-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --mw-shadow-md: 0 14px 36px rgba(0, 0, 0, 0.28);
}

.mw-sidebar {
  border-right-color: var(--mw-border);
  background: var(--mw-surface-subtle);
  padding: 0.9rem 0.65rem;
}
.mw-nav summary { padding: 0.65rem 0.65rem 0.25rem; font-weight: 700; }
.mw-nav li a { padding: 0.52rem 0.65rem; border-radius: 0.5rem; }
.mw-nav li a:hover { background: color-mix(in srgb, var(--mw-accent) 9%, transparent); color: var(--mw-accent); }
.mw-nav li a.active {
  background: color-mix(in srgb, var(--mw-accent) 14%, transparent);
  color: var(--mw-accent);
  font-weight: 650;
  box-shadow: inset 3px 0 0 var(--mw-accent);
}

.mw-header {
  border-bottom-color: var(--mw-border);
  background: color-mix(in srgb, var(--pico-background-color) 92%, transparent);
  backdrop-filter: blur(12px);
}
.mw-search input { background: var(--mw-surface-subtle); border-color: transparent; box-shadow: inset 0 0 0 1px var(--mw-border); }
.mw-search input:focus { background: var(--mw-surface-raised); border-color: var(--mw-accent); }
.mw-iconbtn svg, .mw-header-control svg { width: 1rem; height: 1rem; margin: 0; vertical-align: middle; }
.mw-header-control { display: inline-flex !important; align-items: center; gap: 0.35rem; }
.mw-content { padding: 1.5rem clamp(1rem, 2.2vw, 2.25rem) 3rem; }

.mw-content table {
  border: 1px solid var(--mw-border);
  border-radius: 0.65rem;
  box-shadow: var(--mw-shadow-sm);
  overflow: clip;  /* clip, not hidden: clips rounded corners WITHOUT making the table a scroll container (else the sticky thead's top:header-h pushes it down over the first row) */
}
.mw-content table thead th { background: var(--mw-surface-subtle); }
.mw-content table tbody tr:last-child td { border-bottom: 0; }
.mw-content article { border: 1px solid var(--mw-border); background: var(--mw-surface-raised); box-shadow: var(--mw-shadow-sm); }

.mw-pagehead { margin-bottom: 1rem; min-height: 2.5rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--mw-border); }
button, a[role="button"], [role="button"] { font-weight: 650; box-shadow: none; }
button.outline, a[role="button"].outline { background: transparent; }
input, select, textarea { border-color: var(--mw-border); box-shadow: none; }
input:focus, select:focus, textarea:focus { border-color: var(--mw-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mw-accent) 16%, transparent); }

.mw-homehead { margin-bottom: 1.75rem; }
.mw-homehead h1 { margin: 0 0 0.25rem; font-size: 1.65rem; }
.mw-homehead p:last-child { margin: 0; color: var(--pico-muted-color); }
.mw-eyebrow { margin: 0 0 0.2rem; color: var(--mw-accent); font-size: 0.72rem; font-weight: 750; letter-spacing: 0.1em; text-transform: uppercase; }
.mw-quickgroup h2 { margin-bottom: 0.65rem; font-size: 0.78rem; color: var(--pico-muted-color); text-transform: uppercase; letter-spacing: 0.08em; }
.mw-quicknav { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.7rem; }
.mw-quicklink {
  display: flex;
  min-width: 0;
  padding: 0.8rem;
  border-color: var(--mw-border);
  border-radius: 0.65rem;
  background: var(--mw-surface-raised);
  box-shadow: var(--mw-shadow-sm);
}
.mw-quicklink:hover { border-color: color-mix(in srgb, var(--mw-accent) 55%, var(--mw-border)); background: var(--mw-surface-raised); color: var(--mw-accent); transform: translateY(-1px); box-shadow: var(--mw-shadow-md); }
.mw-quickicon { display: grid; place-items: center; width: 2rem; height: 2rem; flex: 0 0 2rem; border-radius: 0.5rem; color: var(--mw-accent); background: color-mix(in srgb, var(--mw-accent) 12%, transparent); }
.mw-quickicon svg { width: 1rem; height: 1rem; }
.mw-quickarrow { width: 0.9rem; height: 0.9rem; margin-left: auto; color: var(--pico-muted-color); }

@media (max-width: 980px) {
  :root { --mw-sidebar-w: 13.5rem; }
  .mw-header-control span { display: none; }
  .mw-header-control { padding-inline: 0.55rem !important; }
  .mw-content { padding-inline: 1rem; }
}

@media (max-width: 720px) {
  .mw-layout { grid-template-columns: var(--mw-rail-w) minmax(0, 1fr); }
  .mw-sidebar { padding-inline: 0.3rem; }
  .mw-nav, .mw-logo-wide { display: none; }
  .mw-logo-mark { display: block; }
  .mw-brand { padding-inline: 0; justify-items: center; }
  .mw-search { max-width: none; }
  .mw-search input { min-width: 6rem; }
  .mw-header { padding-inline: 0.65rem; gap: 0.4rem; }
  .mw-quicknav { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: no-preference) {
  .mw-quicklink { transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease; }
}

/* Resource pages share one heading and table rhythm, including legacy Parts. */
[data-resource-head] { align-items: flex-end; }
[data-resource-head] > div { margin-right: auto; }
[data-resource-head] h1 { margin: 0; }
.mw-workflow-head { align-items: flex-end; }
.mw-workflow-head > div:first-child { margin-right: auto; }
.mw-workflow-head h1 { margin: 0.1rem 0 0; }
.mw-pageactions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.45rem; }
.mw-pageactions > * { margin: 0; }
.mw-pageintro { margin: 0.2rem 0 0; color: var(--pico-muted-color); font-size: 0.86rem; }
.mw-resource-grid { min-width: 0; }
.mw-resource-grid .mw-tablesearch { max-width: none; }
.mw-resource-grid .mw-bulkbar:has(button:only-child) { min-height: 0; }
.mw-resource-grid td.mw-actions { width: 1%; }
.mw-resource-locations tbody td:first-of-type:not(.mw-check) { font-weight: 650; }
.mw-resource-locations tbody td:nth-child(3),
.mw-resource-locations tbody td:nth-child(4) { color: var(--pico-muted-color); }

/* BOM import detail is a workspace: toolbar, bounded master pane, focused pane. */
.mw-import-head { padding-bottom: 0.9rem; margin-bottom: 0.75rem; }
.mw-import-titles { gap: 0; }
.mw-import-titles h1 { margin: 0; font-size: 1.35rem; }
.mw-import-meta { margin: 0.15rem 0 0; color: var(--pico-muted-color); font-size: 0.82rem; }
.mw-import-tabs { padding-bottom: 0.75rem; border-bottom: 1px solid var(--mw-border); }
.mw-import-toolbar {
  padding: 0.65rem;
  border: 1px solid var(--mw-border);
  border-radius: 0.65rem;
  background: var(--mw-surface-subtle);
}
.mw-import-summary { gap: 0.5rem; }
.mw-import-summary .mw-release button { min-width: 9rem; }
.mw-masterdetail { gap: 0.85rem; }
.mw-pane-resizer { display: none; }
.mw-md-groups,
.mw-md-instances {
  min-width: 0;
  border: 1px solid var(--mw-border);
  border-radius: 0.7rem;
  background: var(--mw-surface-raised);
  box-shadow: var(--mw-shadow-sm);
  overflow: hidden;
}
.mw-md-panehead {
  min-height: 3rem;
  margin: 0;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--mw-border);
  background: var(--mw-surface-subtle);
}
.mw-pane-label { margin-right: 0.15rem; color: var(--pico-muted-color); font-size: 0.69rem; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
.mw-row-height { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0 0 0 auto; color: var(--pico-muted-color); font-size: 0.72rem; white-space: nowrap; }
.mw-row-height select { width: 3.2rem; min-height: 1.8rem; height: 1.8rem; margin: 0; padding-block: 0; }
.mw-md-groups .mw-md-panebody { max-height: 32rem; }
.mw-md-instances > .mw-bulkbar { min-height: 2.8rem; margin: 0; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--mw-border); }
.mw-md-instances .mw-md-panebody { max-height: 22rem; overflow: auto; }
.mw-md-groups table,
.mw-md-instances table { border: 0; border-radius: 0; box-shadow: none; }
.mw-md-groups .mw-md-panebody,
.mw-md-instances .mw-md-panebody { min-width: 0; overflow: auto; scrollbar-gutter: stable; }
.mw-md-groups .mw-md-panebody { overflow-x: scroll; }
.mw-md-groups #groups-rows { width: max-content; min-width: 100%; }
.mw-md-groups table[data-resizable="true"],
.mw-md-instances table[data-resizable="true"] { width: max-content; min-width: 100%; table-layout: auto; }
.mw-md-groups tbody tr { height: 2.65rem; }
.mw-md-groups[data-row-lines] tbody tr, .mw-md-instances[data-row-lines] tbody tr { height: calc(var(--mw-row-py) * 2 + 1.35em * var(--mw-row-lines, 1)); }
.mw-md-groups:not([data-row-lines="1"]) :is(.mw-group-refs,.mw-group-value,.mw-group-footprint,.mw-group-part) { white-space: normal; overflow-wrap: anywhere; }
.mw-md-groups tbody td { vertical-align: middle; }
.mw-group-refs { max-width: 14rem; }
.mw-group-footprint { max-width: 20rem; }
.mw-group-part { max-width: 18rem; }
.mw-group-refs,
.mw-group-footprint,
.mw-group-part { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mw-group-value { white-space: nowrap; }
.mw-md-rowactions { display: flex; align-items: center; gap: 0.2rem; }
.mw-md-rowactions button, .mw-md-rowactions summary { margin: 0; }

@media (min-width: 1280px) {
  .mw-masterdetail { grid-template-columns: minmax(22rem, var(--mw-master-pane, 60%)) 0.7rem minmax(20rem, 1fr); grid-template-rows: minmax(28rem, calc(100vh - 20rem)); gap: 0; align-items: stretch; }
  .mw-pane-resizer { display: block; position: relative; cursor: col-resize; touch-action: none; outline: 0; }
  .mw-pane-resizer::after { content: ""; position: absolute; inset-block: 0.5rem; left: calc(50% - 1px); width: 2px; border-radius: 2px; background: var(--mw-border); }
  .mw-pane-resizer:hover::after, .mw-pane-resizer:focus-visible::after { width: 3px; background: var(--mw-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mw-accent) 12%, transparent); }
  .mw-md-groups .mw-md-panebody,
  .mw-md-instances .mw-md-panebody { max-height: none; height: calc(100% - 3rem); }
  .mw-md-groups, .mw-md-instances { display: flex; flex-direction: column; }
  .mw-md-groups .mw-md-panebody, .mw-md-instances .mw-md-panebody { flex: 1; min-height: 0; height: auto; }
}

@media (max-width: 820px) {
  .mw-import-head { align-items: flex-start; }
  .mw-import-head .mw-import-audit { order: 3; }
  .mw-import-summary .mw-release { flex-basis: 100%; margin-left: 0; }
  .mw-group-refs { max-width: 9rem; }
}

/* Shared section rhythm for workflow pages and Inventory. */
.mw-section { margin-bottom: 2rem; }
.mw-sectionhead { display: flex; align-items: flex-end; gap: 1rem; margin-bottom: 0.75rem; }
.mw-sectionhead > div { margin-right: auto; }
.mw-sectionhead h2 { margin: 0; font-size: 1.05rem; }
.mw-sectionhead p { margin: 0.15rem 0 0; color: var(--pico-muted-color); font-size: 0.82rem; }
.mw-action-grid { display: grid; grid-template-columns: repeat(3, minmax(14rem, 1fr)); gap: 0.75rem; }
.mw-action-card { border: 1px solid var(--mw-border); border-radius: 0.7rem; background: var(--mw-surface-raised); box-shadow: var(--mw-shadow-sm); }
.mw-action-card > summary { display: flex; align-items: center; gap: 0.65rem; min-height: 4rem; padding: 0.75rem; list-style: none; cursor: pointer; }
.mw-action-card > summary::-webkit-details-marker { display: none; }
.mw-action-card > summary > span:nth-child(2) { display: grid; gap: 0.1rem; }
.mw-action-card summary small { color: var(--pico-muted-color); font-weight: 400; }
.mw-action-icon { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; flex: 0 0 auto; border-radius: 0.55rem; color: var(--mw-accent); background: color-mix(in srgb, var(--mw-accent) 12%, transparent); }
.mw-action-icon svg, .mw-chevron { width: 1rem; height: 1rem; }
.mw-chevron { margin-left: auto; transition: transform 140ms ease; }
.mw-action-card[open] .mw-chevron { transform: rotate(180deg); }
.mw-action-card form { padding: 0 0.75rem 0.75rem; }

/* All data tables expose the same resize affordance. Double-click resets a
   column; keyboard users can focus the divider and use left/right arrows. */
.mw-content table[data-resizable="true"] { table-layout: fixed; min-width: 100%; }
.mw-content table[data-resizable="true"] th { position: sticky; }  /* sticky, not relative: `relative` kept the shared `top:header-h` but lost sticky, shoving the header down over row 1; sticky still anchors .mw-col-resizer */
.mw-col-resizer { position: absolute; z-index: 4; top: 15%; right: -4px; width: 9px; height: 70%; cursor: col-resize; touch-action: none; }
.mw-col-resizer::after { content: ""; position: absolute; left: 4px; top: 0; width: 1px; height: 100%; background: var(--mw-border); }
.mw-col-resizer:hover::after, .mw-col-resizer:focus-visible::after { width: 2px; background: var(--mw-accent); }
html.mw-resizing, html.mw-resizing * { cursor: col-resize !important; user-select: none !important; }

/* Older workflow templates still use a leading back-link followed by a title.
   Normalize their spacing without changing their specialized interactions. */
.mw-content > p:first-child:has(> a:first-child:last-child) { margin: 0 0 0.25rem; font-size: 0.8rem; }
.mw-content > p:first-child:has(> a:first-child:last-child) + h1 { margin: 0 0 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--mw-border); }

@media (max-width: 980px) { .mw-action-grid { grid-template-columns: 1fr; } }
/* Digi-Key MPN import dialog (0C.1) — functional cues on shared danger/warn tokens. */
.mpn-import-error{color:var(--mw-danger);font-weight:600}.mpn-import-warn{color:var(--mw-warn)}.mpn-import-note{font-size:.85rem;opacity:.85}.mpn-import-deltas{border-left:3px solid var(--mw-warn);padding:.5rem .75rem}.mpn-import-error,.mpn-import-warn,.mpn-import-note,.mpn-import-deltas{margin:.5rem 0}.mpn-import-readonly .grid>div{font-size:.9rem}

/* 0C-2C · create-part suggestions (a chip row under an input) + the unplaced table */
.mw-suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 0.15rem 0 0.35rem; }
.mw-suggest .mw-accept, .mw-suggest .mw-forget { margin: 0; padding: 0.1rem 0.5rem; font-size: var(--mw-font-table); }
.mw-suggest-src { color: var(--pico-muted-color); }
.mw-unplaced td { vertical-align: top; }
.mw-unplaced select { margin-bottom: 0.25rem; }
.mw-unplaced .mw-inline { display: block; font-size: var(--mw-font-table); }

/* order-history grid: sort/pager controls are buttons (they carry hx-vals), styled as the link sorts */
.mw-sortbtn { background: none; border: 0; padding: 0; margin: 0; width: auto; color: inherit; font: inherit; cursor: pointer; text-align: inherit; }
.mw-sortbtn:hover, .mw-sortbtn:focus { text-decoration: underline; box-shadow: none; }
/* one row: the shared .mw-tablesearch caps at 40rem, which wrapped this form
   into three rows — the worklist params get the full width and compact inputs */
.mw-worklist-params { max-width: none; align-items: end; gap: 0.5rem 0.75rem; }
.mw-worklist-params label { margin: 0; white-space: nowrap; font-size: var(--mw-font-table); }
.mw-worklist-params input[type="date"], .mw-worklist-params input[type="number"] {
  margin: 0; width: auto; height: var(--mw-input-h); padding-block: 0;
}
.mw-worklist-params input[type="date"] { width: 10rem; }
.mw-worklist-params input[type="number"] { width: 5.5rem; }
.mw-worklist-params label.mw-inline { display: flex; align-items: center; gap: 0.3rem; height: var(--mw-input-h); }
.mw-worklist-params label.mw-inline input { margin: 0; }
.mw-worklist-params input[type="search"] { min-width: 12rem; height: var(--mw-input-h); padding-block: 0; }
.mw-worklist-params button, .mw-worklist-params a[role="button"] { height: var(--mw-input-h); padding-block: 0; line-height: 1; }
.mw-pager button.mw-pager-btn { width: auto; margin: 0; padding: 0.1rem 0.5rem; }

/* detail page: entity fields beside a related read-only panel; compact price ladder */
.mw-detail-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 64rem) { .mw-detail-cols { grid-template-columns: minmax(0, 1fr); } }
.mw-detail-cols > div > table, .mw-detail-cols .mw-related table { margin-bottom: 0; }
.mw-pricebreaks { width: auto; margin: 0; font-size: var(--mw-font-table); }
.mw-pricebreaks th, .mw-pricebreaks td { padding: 0.1rem 0.6rem; }
.mw-toast-action { margin: 0 0 0 0.4rem; padding: 0 0.5rem; height: 1.6rem; font-size: 0.85em; width: auto; display: inline-block; vertical-align: middle; }
