/* Slabsmith Explorer — dark industrial design system.
   Locked to dark: the slab photographs carry the color, the chrome stays neutral.
   Class names are the contract app.js renders against. Do not rename .layout-*,
   .zoom-*, .slab-card, .selected, .loading, .missing.

   Two rules that look like style but are load-bearing:
   - .layout-figure must NOT declare `fill`. Figure fill comes from the inline
     SVG attribute (the contour color groups), and CSS would override it.
   - .layout-side-hit needs stroke:transparent + stroke-width:18 + pointer-events:stroke,
     or side selection in the layout viewer stops working. */

/* ---------------------------------------------------------------- fonts
   IBM Plex: drawn for engineering and industrial documentation, and its mono
   keeps digits unambiguous at 10px, which is where most of this UI lives. */
/* Urbanist is one variable file per subset, covering 100-900 -- lighter than the three
   static Plex Sans cuts it replaces. It is the UI/text face; Plex Mono still carries every
   label, number and meta line (--mono), which is the industrial signal of this tool. */
@font-face {
  font-family: "Urbanist";
  src: url("fonts/Urbanist-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Urbanist";
  src: url("fonts/Urbanist-latinext.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Plex Sans";
  src: url("fonts/IBMPlexSans-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Plex Sans";
  src: url("fonts/IBMPlexSans-Medium.woff2") format("woff2");
  font-weight: 500 550;
  font-display: swap;
}
@font-face {
  font-family: "Plex Sans";
  src: url("fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
  font-weight: 600 700;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("fonts/IBMPlexMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("fonts/IBMPlexMono-Medium.woff2") format("woff2");
  font-weight: 500 700;
  font-display: swap;
}

/* --------------------------------------------------------------- tokens */
:root {
  color-scheme: dark;

  /* graphite surfaces, cool-neutral, never pure black */
  --bg: #0b0d10;
  --surface: #101318;
  --surface-2: #161a20;
  --surface-3: #1d222a;
  --line: #262c35;
  --line-soft: #1b2027;
  --stage: #0d0f13;

  /* every step passes WCAG AA (>=4.5:1) on bg, surface, surface-2 and surface-3.
     text-3 carries labels, placeholders and mono meta, so it cannot go dimmer. */
  --text: #e7eaef;
  --text-2: #a7b0bd;
  --text-3: #828b99;

  /* one accent, everywhere or nowhere */
  --accent: #4da3ff;
  --accent-ink: #06121f;
  --accent-soft: rgba(77, 163, 255, 0.12);
  --accent-line: rgba(77, 163, 255, 0.4);

  --ok: #3fb984;
  --warn: #e0a33e;
  --danger: #f2645a;

  /* one radius scale */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --shadow: 0 22px 60px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.32);

  --sans: "Urbanist", "Plex Sans", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --mono: "Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  /* entries and exits get the strong ease-out; color and hover shifts get plain
     ease, which is what a tint change actually wants. Nothing over 300ms. */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --fast: 130ms ease;
  --base: 200ms var(--ease);
  --press: 110ms var(--ease);

}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.012em; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }

/* data is numeric: mono, tabular, always */
td, th, dd, .info-chip, .slab-card-meta, .scan-card-meta,
.pager-page, .pager-arrow, .status-chip { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
::selection { background: var(--accent-soft); }

* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--surface-3); background-clip: padding-box; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes lift-in {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- shell */
.shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.brand {
  flex: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }

input[type="search"],
input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 13px;
  transition: border-color var(--fast), background var(--fast), box-shadow var(--fast);
}
input::placeholder { color: var(--text-3); }
input:hover, select:hover { border-color: var(--surface-3); }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent-line);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); }
select {
  appearance: none;
  padding-right: 26px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

/* -------------------------------------------------------------- main nav */
.nav-toggle {
  display: none;  /* desktop shows the nav itself; the hamburger is a mobile affordance */
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  color: var(--text-2);
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.nav-toggle svg { width: 20px; height: 20px; }
.nav-toggle:hover { background: var(--surface-2); color: var(--text); }

/* Pushes everything after it (page controls, link state, session) to the right edge,
   whether or not the page has table controls. */
.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  margin-right: auto;
}
.nav-tabs { display: flex; gap: 2px; }

.nav-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  color: var(--text-2);
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.nav-tab strong { font-size: 13px; font-weight: 500; }
/* A one-word tab does not need a subtitle; the drawer, where the tabs stack, does. */
.nav-tab .object-desc { display: none; }
.nav-tab:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-tab:hover .object-icon { color: var(--text-2); }
.nav-tab.active { background: var(--accent-soft); color: var(--text); }
.nav-tab.active .object-icon { color: var(--accent); }

.nav-advanced { position: relative; flex: none; }
.nav-advanced > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  color: var(--text-2);
  border-radius: var(--r-sm);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background var(--fast), color var(--fast);
}
.nav-advanced > summary::-webkit-details-marker { display: none; }
.nav-advanced > summary svg { width: 14px; height: 14px; transition: transform var(--fast); }
.nav-advanced > summary:hover,
.nav-advanced[open] > summary { background: var(--surface-2); color: var(--text); }
.nav-advanced[open] > summary svg { transform: rotate(180deg); }

.nav-advanced-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  width: 320px;
  max-height: min(70vh, 520px);
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.object-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow-y: auto;
}
.object-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 6px 6px;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.object-group::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}
.object-group:first-child { padding-top: 2px; }

.object-item {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  color: var(--text-2);
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--fast), color var(--fast), box-shadow var(--fast);
}
/* fill:currentColor is load-bearing: the <path> has no fill attribute, so without this it
   falls back to black and the icons vanish. `color` alone does nothing to an SVG fill. */
.object-icon { width: 16px; height: 16px; color: var(--text-3); fill: currentColor; flex: none; transition: color var(--fast); }
.object-text { min-width: 0; }
.object-item strong,
.object-desc {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.object-item strong { font-size: 13px; font-weight: 500; }
.object-desc {
  margin-top: 1px;
  color: var(--text-3);
  font-size: 11px;
  line-height: 1.35;
}
.object-desc:empty { display: none; }
.object-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.object-item:hover .object-icon { color: var(--text-2); }

.object-empty {
  padding: 14px 10px;
  color: var(--text-3);
  font-size: 12px;
}
.object-item.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}
.object-item.active strong { color: var(--text); }
.object-item.active .object-desc { color: var(--text-2); }
.object-item.active .object-icon { color: var(--accent); }

/* right edge of the topbar: link state, then who is signed in */
.top-meta {
  display: flex;
  align-items: center;
  flex: none;
}

/* Account dropdown: same native <details> pattern as the Advanced menu, so it behaves
   identically on desktop and mobile -- the panel drops straight down from the avatar. */
.user-menu { position: relative; flex: none; }
.user-menu > summary {
  position: relative;
  display: grid;
  place-items: center;
  padding: 3px;
  border-radius: 999px;
  cursor: pointer;
  list-style: none;
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover .session-avatar,
.user-menu[open] > summary .session-avatar { background: var(--surface-3); color: var(--text); }
/* A dot on the avatar mirrors the SQL link, so a dropped connection shows without opening
   the menu. It carries real state, which is why it earns a status dot. */
.user-menu > summary::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 2px solid var(--surface);
  background: var(--text-3);
  transition: background var(--fast);
}
.user-menu[data-state="online"] > summary::after { background: var(--ok); }
.user-menu[data-state="offline"] > summary::after { background: var(--danger); }

.user-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  display: grid;
  gap: 10px;
  width: 240px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}
.user-id {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  color: var(--text-2);
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.menu-item svg { width: 16px; height: 16px; flex: none; }
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.user-menu form { display: block; }

.conn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 4px;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.conn i {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 999px;
  background: var(--text-3);
  transition: background var(--fast);
}
.conn[data-state="online"] i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.conn[data-state="offline"] i { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }
.conn[data-state="offline"] { color: var(--danger); }

.session-avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.session-who { flex: 1; min-width: 0; }
.session-who strong,
.session-who span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-who strong { font-size: 12px; font-weight: 500; }
.session-who span {
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  color: var(--text-3);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color var(--fast), background var(--fast), border-color var(--fast);
}
.icon-button:hover { color: var(--text); background: var(--surface-2); border-color: var(--line); }
.icon-button:active { transform: scale(0.97); }
.icon-button svg { width: 15px; height: 15px; }

/* ------------------------------------------------------------ workspace */
/* The topbar is a sibling now, not the first row here, so the scrolling region cannot be
   pinned to a row number: it is simply the child that takes the leftover height. */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* No sticky, no z-index, no backdrop-filter: the topbar is a grid row of .shell now, and the
   page scrolls inside .workspace, so nothing ever passes under it. Dropping the blur is not
   just cleanup -- backdrop-filter makes an element the containing block for its
   position: fixed descendants, which pinned the mobile drawer inside the 60px bar. */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-soft);
}
.detail-head h2 {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.eyebrow {
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.top-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.top-actions input[type="search"] { width: 280px; }
.top-actions select { width: auto; }

.view-toggle {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.view-toggle[hidden] { display: none; }
.view-toggle button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 9px;
  color: var(--text-3);
  background: none;
  border: 0;
  border-radius: var(--r-xs);
  font-size: 12px;
  cursor: pointer;
  transition: color var(--fast), background var(--fast);
}
.view-toggle button:hover { color: var(--text); }
.view-toggle button.active { background: var(--surface-3); color: var(--text); }
.view-icon { width: 14px; height: 14px; }

/* Pinned to the flexible row on purpose. The two pagers are `hidden` until there
   are rows, and a hidden element is not a grid item, so auto-placement would slide
   this section up into an `auto` row and it would collapse to the height of its
   own content (a 40px spinner in a 900px window). */
.data-region {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.table-wrap {
  height: 100%;
  overflow: auto;
  padding: 16px 20px 24px;
}
.table-wrap[hidden] { display: none; }

/* --------------------------------------------------------------- tables */
table {
  width: 100%;
  min-width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}
th, td {
  max-width: 280px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 12px;
  color: var(--text-3);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
tbody td {
  padding: 7px 12px;
  color: var(--text-2);
  border-bottom: 1px solid var(--line-soft);
  font-size: 12.5px;
  transition: background var(--fast), color var(--fast);
}
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface); color: var(--text); }
tbody tr.selected td {
  background: var(--accent-soft);
  color: var(--text);
  border-bottom-color: var(--accent-line);
}

.table-message {
  display: grid;
  align-content: center;
  min-height: 380px;
  padding: 24px;
  color: var(--text-3);
  text-align: center;
}
.muted { color: var(--text-3); font-size: 12.5px; }

.column-list { display: flex; flex-wrap: wrap; gap: 6px; }
.column-pill {
  padding: 3px 8px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
}

/* ------------------------------------------- image containers + spinners
   One stacking cell per container so the spinner, the fallback text and the
   image all land in the same box. .loading / .missing are toggled by app.js. */
.slab-card-image,
.relation-thumb,
.available-thumb,
.selection-photo,
.layout-preview {
  position: relative;
  display: grid;
  grid-template-areas: "preview";
  /* The row must be the box, not the content. Without this the single row auto-sizes to
     the image, which on a wide window is far taller than the box -- and anything using
     `place-self: end` (the zoom pill) is then aligned to the bottom of that overgrown row,
     lands outside the box, and is silently cut off by `overflow: hidden`. It looked like a
     hover bug: the pill was there at opacity 1, just clipped. minmax(0, 1fr) pins the row
     to the box and lets it shrink below the content. */
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  overflow: hidden;
  background: var(--surface-2);
}
.slab-card-image > *,
.relation-thumb > *,
.available-thumb > *,
.selection-photo > *,
.layout-preview > svg { grid-area: preview; }

.slab-card-image.loading::after,
.relation-thumb.loading::after,
.available-thumb.loading::after,
.selection-photo.loading::after,
.layout-preview.loading::after {
  content: "";
  grid-area: preview;
  place-self: center;
  z-index: 2;
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 700ms linear infinite;
}
.slab-card-image.missing::after,
.relation-thumb.missing::after,
.available-thumb.missing::after,
.selection-photo.missing::after {
  content: "No photo";
  grid-area: preview;
  place-self: center;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.missing img { display: none; }
.layout-preview.loading .layout-svg { opacity: 0.25; transition: opacity var(--base); }

/* -------------------------------------------------------- slab gallery */
.slab-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(214px, 1fr));
  gap: 14px;
}
.slab-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0;
  text-align: left;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--fast), box-shadow var(--fast), transform var(--press);
}
/* No hover lift: this grid is scanned constantly and 50 cards floating on
   pass-through is noise. The border and shadow carry the affordance. */
@media (hover: hover) and (pointer: fine) {
  .slab-card:hover { border-color: var(--surface-3); box-shadow: var(--shadow-sm); }
  .relation-card:hover { border-color: var(--surface-3); }
}
.slab-card:active { transform: scale(0.985); }
.slab-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-sm);
}

.slab-card-image {
  aspect-ratio: 4 / 3;
  border-bottom: 1px solid var(--line-soft);
}
.slab-card-image img,
.relation-thumb img,
.available-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.slab-card-body {
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 10px 12px 8px;
  min-width: 0;
}
.slab-card-body strong,
.slab-card-body > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slab-card-body strong { font-size: 13px; font-weight: 550; }
.slab-card-body > span { color: var(--text-2); font-size: 12px; }
.slab-card-body .info-chips { padding-top: 3px; }

.slab-card-meta {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  color: var(--text-3);
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 10.5px;
}
.slab-card-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scan-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.scan-card {
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 12px 14px;
  text-align: left;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--fast), background var(--fast);
}
.scan-card:hover { border-color: var(--surface-3); background: var(--surface-2); }
.scan-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.scan-card strong,
.scan-card > span,
.scan-card-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-card strong { font-size: 13px; font-weight: 550; }
.scan-card-kicker {
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.scan-card-meta {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding-top: 4px;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 11px;
}

/* --------------------------------------------------------------- pager */
.pager-nav { display: flex; justify-content: center; padding: 10px 20px; }
.pager-nav[hidden] { display: none; }
.pager-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.pager-arrow,
.pager-page {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  font-size: 12px;
  cursor: pointer;
  transition: color var(--fast), border-color var(--fast), background var(--fast);
}
.pager-arrow:hover:not(:disabled),
.pager-page:hover { color: var(--text); border-color: var(--surface-3); }
.pager-arrow:disabled { opacity: 0.35; cursor: default; }
.pager-page.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.pager-ellipsis { padding: 0 4px; color: var(--text-3); }

/* ------------------------------------------------------- loading states */
.async-loader {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 8px;
  min-height: 92px;
  padding: 24px 16px;
  color: var(--text-2);
  text-align: center;
}
/* A loader that owns a whole panel centers in that panel, not at its top edge.
   `min-height: 100%` does not work here: the panel's height comes from a stretched
   grid item, so the percentage has nothing definite to resolve against. Filling the
   positioned panel does work, and it does not depend on the parent's height at all. */
.data-region,
.detail-panel { position: relative; }
.table-wrap > .async-loader,
.table-wrap > .table-message,
.detail-panel > .async-loader {
  position: absolute;
  inset: 0;
  min-height: 0;
  margin: 0;
}
.async-loader strong { font-size: 12.5px; font-weight: 500; }
.async-loader p { color: var(--text-3); font-size: 11.5px; }
.async-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 700ms linear infinite;
}

/* Shown while a full page navigation is in flight. Opening a slab costs a round trip, and
   the browser keeps painting the old page until the new one answers -- so without this the
   click looks ignored. The 140ms delay is the point: a navigation that resolves faster than
   that never shows a flash, only a slow one does. */
.nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(2px);
  cursor: progress;
  opacity: 0;
  animation: fade-in 160ms var(--ease) 140ms forwards;
}
@media (prefers-reduced-motion: reduce) {
  .nav-overlay { animation-duration: 1ms; }
  .nav-overlay .async-spinner { animation-duration: 1600ms; }
}
.selection-photo .async-loader,
.available-thumb .async-loader,
.layout-preview .async-loader {
  grid-area: preview;
  place-self: center;
  min-height: 0;
  padding: 0;
}

/* -------------------------------------------------------------- buttons */
.button,
.ghost-button,
.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 12.5px;
  cursor: pointer;
  transition: color var(--fast), background var(--fast), border-color var(--fast), transform var(--press);
}
.button:hover,
.ghost-button:hover,
.detail-back:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--surface-3);
  text-decoration: none;
}
/* press reads as pressure, not as displacement */
.button:active,
.ghost-button:active,
.detail-back:active { transform: scale(0.97); }
.detail-back::before { content: "←"; color: var(--accent); font-size: 14px; line-height: 1; }

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.button.primary:hover {
  background: color-mix(in srgb, var(--accent) 86%, white);
  border-color: color-mix(in srgb, var(--accent) 86%, white);
  color: var(--accent-ink);
}

/* ---------------------------------------------------------- detail page */
.detail-actions { padding: 14px 20px 0; }
.detail-head { padding: 10px 20px 0; }
.detail-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px 40px;
}
.detail-panel.empty { display: grid; align-content: center; color: var(--text-3); }

.selection-grid {
  display: grid;
  grid-template-columns: minmax(0, 40%) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.selection-grid.compact { grid-template-columns: minmax(0, 260px) minmax(0, 1fr); }
.selection-grid.order-grid { grid-template-columns: minmax(0, 34%) minmax(0, 1fr); }
.selection-media { position: sticky; top: 12px; min-width: 0; }

/* Definite height, not aspect-ratio: the slab photo scales UP into the box and
   is never cropped (object-fit: contain). Slabs come in every orientation. */
.selection-photo {
  width: 100%;
  height: min(60vh, 560px);
  min-height: 200px;
  padding: 0;
  color: inherit;
  background: var(--stage);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: zoom-in;
  text-decoration: none;
}
.selection-photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}
.selection-photo.placeholder {
  align-content: center;
  gap: 4px;
  background: var(--surface);
  color: var(--text-3);
  cursor: default;
  text-align: center;
}
.selection-photo.placeholder strong { color: var(--text-2); font-size: 13px; font-weight: 500; }
.selection-photo.placeholder span { font-size: 11.5px; }
.selection-photo.placeholder .selection-zoom { display: none; }

/* zoom affordance: hidden until hover, so it never sits on top of the photo */
.selection-zoom {
  grid-area: preview;
  place-self: end center;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 12px;
  padding: 6px 11px;
  color: var(--text);
  background: rgba(11, 13, 16, 0.84);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  text-decoration: none;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--fast), transform var(--fast);
}
/* the photo is an <a>; its hover underline must not leak into the pill */
a.selection-photo:hover { text-decoration: none; }
.selection-photo:hover .selection-zoom,
.selection-photo:focus-visible .selection-zoom,
.layout-zoom:hover .selection-zoom,
.layout-zoom:focus-visible .selection-zoom {
  opacity: 1;
  transform: translateY(0);
}
.selection-zoom-icon {
  position: relative;
  width: 13px;
  height: 13px;
  flex: none;
  border: 1.5px solid currentColor;
  border-radius: 999px;
}
.selection-zoom-icon::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 6px;
  height: 1.5px;
  background: currentColor;
  transform: rotate(45deg);
}
.selection-zoom-label { font-size: 12px; line-height: 1; }

.selection-content { display: grid; gap: 18px; align-content: start; min-width: 0; }
.selection-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
  min-width: 0;
}
.selection-header h3 { margin-top: 3px; font-size: 20px; }

.status-chip {
  flex: none;
  padding: 4px 10px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.info-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.info-chip {
  display: inline-flex;
  max-width: 100%;
  padding: 3px 9px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  font-size: 11.5px;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info-chip.ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 35%, transparent);
  background: color-mix(in srgb, var(--ok) 10%, transparent);
}
.info-chip.warn {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
}
.info-chip.status { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }

/* key/value data: hairlines, no card boxes */
dt {
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
dd { margin: 0; color: var(--text); font-size: 12.5px; min-width: 0; overflow-wrap: anywhere; }

.detail-list, .summary-facts, .job-facts { display: grid; margin: 0; }
.detail-list > div,
.summary-facts > div,
.job-facts > div {
  display: grid;
  grid-template-columns: minmax(96px, 32%) minmax(0, 1fr);
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-soft);
  min-width: 0;
}
.detail-list.two-col,
.summary-facts,
.job-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
.job-detail .job-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.job-facts .wide { grid-column: 1 / -1; }
.summary-facts dd, .detail-list dd { overflow: hidden; text-overflow: ellipsis; }

.detail-disclosure {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
}
.detail-disclosure > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  list-style: none;
  cursor: pointer;
  transition: background var(--fast);
}
.detail-disclosure > summary::-webkit-details-marker { display: none; }
.detail-disclosure > summary:hover { background: var(--surface-2); }
.detail-disclosure > summary em {
  margin-left: auto;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 11px;
  font-style: normal;
}
.detail-disclosure > summary::after {
  content: "";
  width: 6px;
  height: 6px;
  flex: none;
  border-right: 1.5px solid var(--text-3);
  border-bottom: 1.5px solid var(--text-3);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform var(--base);
}
.detail-disclosure[open] > summary::after { transform: rotate(-135deg); }
.detail-disclosure > *:not(summary) { padding: 0 14px 14px; }

.section-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
}
.section-row h3 { font-size: 14px; }
.section-row span { color: var(--text-3); font-family: var(--mono); font-size: 11px; }
.section-row.compact { padding-bottom: 8px; }

.job-detail { display: grid; gap: 18px; min-width: 0; }
.job-detail-header { display: grid; gap: 14px; }

.relation-section { display: grid; gap: 4px; }
.relation-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.relation-card {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 2px;
  padding: 0 0 8px;
  text-align: left;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--fast), transform var(--press);
}
.relation-card:active { transform: scale(0.985); }
.relation-card strong,
.relation-card > span { padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relation-card strong { padding-top: 6px; font-size: 12px; font-weight: 550; }
.relation-card > span { color: var(--text-3); font-size: 11px; }
.relation-thumb { aspect-ratio: 4 / 3; }
.relation-initial { color: var(--text-3); font-size: 18px; font-weight: 600; text-transform: uppercase; }

.job-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.job-item {
  display: grid;
  gap: 3px;
  padding: 9px 12px;
  min-width: 0;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  font-size: 12.5px;
}
.job-item strong, .job-item span, .job-item em {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job-item strong { color: var(--text); }
.job-item em { color: var(--text-3); font-family: var(--mono); font-size: 11px; font-style: normal; }

.available-slabs { display: grid; gap: 10px; padding-top: 6px; }
.available-title { display: flex; align-items: baseline; gap: 10px; }
.available-title h3 { font-size: 14px; }
.available-title span { color: var(--text-3); font-family: var(--mono); font-size: 11px; }
.slab-lot { color: var(--text-3); font-family: var(--mono); font-size: 12px; }

.available-list { display: grid; gap: 8px; }
.available-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  transition: border-color var(--fast);
}
.available-row:hover { border-color: var(--surface-3); }
.available-thumb {
  aspect-ratio: 4 / 3;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  cursor: zoom-in;
}
.available-copy { display: grid; gap: 6px; min-width: 0; }
.available-copy dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px 18px;
  margin: 0;
}
.available-copy dl > div { display: grid; gap: 1px; min-width: 0; }
.available-copy dd { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.available-actions { display: grid; gap: 5px; justify-items: end; }
.available-actions button {
  height: 30px;
  padding: 0 12px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 12px;
  cursor: pointer;
  transition: color var(--fast), border-color var(--fast);
}
.available-actions button:hover { color: var(--text); border-color: var(--accent-line); }
.available-actions span { color: var(--text-3); font-family: var(--mono); font-size: 10.5px; }

.text-link {
  justify-self: start;
  padding: 0;
  color: var(--accent);
  background: none;
  border: 0;
  font-size: 13px;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.text-link:hover { text-decoration: underline; }

.mini-list { display: grid; gap: 2px; }
.mini-row, .link-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  text-align: left;
  color: var(--text-2);
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.link-row { grid-template-columns: 1fr; }
.mini-row:hover, .link-row:hover { background: var(--surface-2); color: var(--text); }
.mini-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row span:first-child { color: var(--text-3); font-family: var(--mono); font-size: 11.5px; }

.detail-block { display: grid; gap: 6px; padding-top: 4px; }
.detail-block h3 { font-size: 13px; }
.slab-summary { display: grid; gap: 4px; padding-bottom: 10px; }
.slab-summary strong { font-size: 16px; }
.deferred-section { min-height: 120px; }

/* -------------------------------------------------------- layout viewer */
.layout-section { display: grid; gap: 6px; }
.layout-grid { display: grid; gap: 14px; }
.layout-card {
  display: grid;
  gap: 14px;
  padding: 14px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
}

.layout-previews {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
/* --pane-aspect comes from the layout's own geometry (layoutPairAspect in app.js). The old
   hardcoded 16/11 belonged to no real layout: a 5.6:1 slab nest and a portrait part sheet
   were both forced into it and letterboxed. */
.layout-preview {
  aspect-ratio: var(--pane-aspect, 16 / 11);
  background: var(--stage);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
}
.layout-preview > span {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 1;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.layout-svg { display: block; width: 100%; height: 100%; }

/* One button covers BOTH panes, because both open the same paired modal. Its pill
   therefore cannot sit centered: it would land on the seam between the panes and
   read as belonging to one of them. Top-right of the pair, always visible. */
.layout-zoom {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: start end;
  padding: 8px;
  background: none;
  border: 0;
  border-radius: var(--r-md);
  cursor: zoom-in;
  transition: background var(--fast);
}
.layout-zoom:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.layout-zoom .selection-zoom {
  /* the base rule parks the pill in the `preview` grid area, which only exists
     inside a photo container; here it would land in an implicit row */
  grid-area: auto;
  position: static;
  place-self: start end;
  margin: 0;
  opacity: 0.75;
  transform: none;
}
.layout-zoom:hover .selection-zoom,
.layout-zoom:focus-visible .selection-zoom {
  opacity: 1;
  border-color: var(--accent-line);
}
.layout-zoom:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

.layout-copy { display: grid; gap: 10px; min-width: 0; }
.layout-copy > div:first-child { display: grid; gap: 2px; min-width: 0; }
.layout-copy strong { font-size: 13px; }
.layout-copy > div span { color: var(--text-3); font-size: 12px; }
.layout-copy dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px 18px;
  margin: 0;
}
.layout-copy dl > div { display: grid; gap: 1px; min-width: 0; }
.layout-copy dd { font-size: 13px; font-weight: 550; }
.layout-copy p { color: var(--text-2); font-size: 12px; }
.layout-copy em { color: var(--text-3); font-family: var(--mono); font-size: 11px; font-style: normal; }
.layout-empty { display: grid; place-items: center; min-height: 140px; color: var(--text-3); }

/* SVG primitives.
   NOTE: no `fill` on .layout-figure — the color group fill is an inline SVG
   attribute and a CSS fill would silently override every contour color. */
.layout-bg { fill: var(--stage); }
.layout-slab { fill: #1a1f26; stroke: #39424e; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.layout-slab-image { pointer-events: none; }
.layout-slab-label {
  fill: #f2f5f9;
  font-family: var(--mono);
  paint-order: stroke;
  stroke: rgba(8, 10, 13, 0.85);
  stroke-width: 4;
  stroke-linejoin: round;
  text-anchor: middle;
  pointer-events: none;
}

.layout-figure {
  opacity: 0.92;
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
  transition: opacity var(--fast), stroke var(--fast);
}
.layout-figure.is-figure-active {
  fill: var(--accent-soft);
  opacity: 1;
  stroke: var(--accent);
  stroke-width: 1.6;
}
.layout-hole { fill: none; stroke: rgba(255, 255, 255, 0.42); stroke-width: 0.55; vector-effect: non-scaling-stroke; }

/* lines sit on top of stone photography: white reads, gray does not */
.layout-line {
  fill: none;
  stroke: #ffffff;
  stroke-width: 0.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.layout-line.reserved, .layout-line.arc { stroke: #ffffff; }
.layout-line.is-side-active {
  stroke: var(--accent) !important;
  stroke-width: 1.8;
  stroke-opacity: 1;
}

.layout-seam line { fill: none; stroke: var(--danger); stroke-width: 1.35; stroke-linecap: round; }
.layout-seam text {
  fill: var(--danger);
  font-family: var(--mono);
  font-weight: 600;
  paint-order: stroke;
  stroke: rgba(8, 10, 13, 0.8);
  stroke-width: 1.6;
  stroke-linejoin: round;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
.layout-seam.is-side-active line { stroke: var(--accent); stroke-width: 1.9; }
.layout-seam.is-side-active text { fill: var(--accent); }

.layout-label {
  fill: #ffffff;
  font-family: var(--mono);
  font-weight: 600;
  paint-order: stroke;
  stroke: rgba(8, 10, 13, 0.7);
  stroke-width: 1.5;
  stroke-linejoin: round;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* invisible fat hit target — required, not decorative */
.layout-side-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 18;
  stroke-linecap: round;
  pointer-events: stroke;
  cursor: pointer;
}

/* ---------------------------------------------------------- zoom modal */
body.modal-open { overflow: hidden; }
.zoom-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 8, 10, 0.78);
  backdrop-filter: blur(4px);
  animation: fade-in 140ms var(--ease);
}
.zoom-modal[hidden] { display: none; }

.zoom-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, calc(100vw - 48px));
  height: min(860px, calc(100vh - 48px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: lift-in 180ms var(--ease);
}
.zoom-dialog.layout-pair-dialog { width: min(1560px, calc(100vw - 32px)); }
/* the pair modal has per-pane controls; the global zoom buttons would lie */
.zoom-dialog.layout-pair-dialog .zoom-controls button:not([data-zoom-action="close"]) { display: none; }

.zoom-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-soft);
}
.zoom-toolbar strong {
  font-size: 13px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zoom-controls, .zoom-pane-controls { display: flex; gap: 4px; flex: none; }
.zoom-controls button,
.zoom-controls a,
.zoom-pane-controls button,
.zoom-pane-controls a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 28px;
  padding: 0 9px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--fast), background var(--fast), border-color var(--fast), transform var(--fast);
}
.zoom-controls button:hover,
.zoom-controls a:hover,
.zoom-pane-controls button:hover,
.zoom-pane-controls a:hover {
  color: var(--text);
  background: var(--surface-3);
  border-color: var(--surface-3);
  text-decoration: none;
}
.zoom-controls button:active,
.zoom-pane-controls button:active { transform: scale(0.95); }

/* panzoom + svg-pan-zoom both need a measurable, clipped viewport */
.zoom-viewport {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 18px;
  background: var(--stage);
  cursor: grab;
  touch-action: none;
  user-select: none;
  overscroll-behavior: none;
}
.zoom-stage {
  display: grid;
  place-items: center;
  min-height: 100%;
  transform-origin: center center;
}
/* panzoom drives the transform on the image element itself; the stage must stay put */
.zoom-stage.image-panzoom,
.zoom-stage.svg-native,
.layout-pair-dialog .zoom-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  transform: none !important;
}
.layout-pair-dialog .zoom-stage { place-items: stretch; }
.layout-pair-dialog .zoom-viewport { align-items: stretch; justify-content: stretch; padding: 0; cursor: default; }

.zoom-stage.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 700ms linear infinite;
}
.zoom-stage img { display: block; max-width: none; max-height: none; pointer-events: none; }
.zoom-stage.image-panzoom .zoom-image {
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: auto;
  user-select: none;
  cursor: grab;
}
.zoom-stage.image-panzoom.is-loading .zoom-image { opacity: 0; }

/* prepareModalSvg() strips width/height attributes: CSS sizes the clone */
.zoom-stage .zoom-svg {
  display: block;
  width: min(88vw, 1600px);
  height: min(82vh, 1200px);
  max-width: none;
  max-height: none;
  background: var(--stage);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.zoom-stage.svg-native .zoom-svg { width: 100%; height: 100%; }

.zoom-layout-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--line-soft);
}
.zoom-layout-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}
.zoom-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.zoom-pane-head strong {
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.zoom-pane-viewport {
  position: relative;
  display: block;
  min-height: 0;
  overflow: hidden;
  background: var(--stage);
  cursor: grab;
  touch-action: none;
  user-select: none;
  overscroll-behavior: none;
}
.zoom-pane-stage { width: 100%; height: 100%; }
.layout-pair-dialog .zoom-pane-stage .zoom-svg {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
}

/* ------------------------------------------------------- image browser */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; font-size: 12px; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.folder-button, .image-tile {
  display: grid;
  gap: 6px;
  padding: 10px;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: color var(--fast), border-color var(--fast);
}
.folder-button:hover, .image-tile:hover { color: var(--text); border-color: var(--surface-3); text-decoration: none; }
.image-tile img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--r-xs); }
.image-tile span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------- login */
.auth-body { margin: 0; background: var(--bg); }

.auth-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  min-height: 100dvh;
}

/* left: the nesting diagram, on a plotted grid */
.auth-art {
  position: relative;
  display: grid;
  place-items: center;
  padding: 48px;
  overflow: hidden;
  border-right: 1px solid var(--line-soft);
  background-color: #0e1116;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 48px 48px;
}
.auth-art-inner { display: grid; gap: 20px; width: min(560px, 100%); }
.nest { width: 100%; height: auto; color: var(--text-3); }
.nest-slab { fill: #14181e; stroke: #4c5663; stroke-width: 1.5; }
.nest-part { fill: rgba(167, 176, 189, 0.1); stroke: #99a3b0; stroke-width: 1.2; }
.nest-part.accent { fill: var(--accent-soft); stroke: var(--accent); }
.nest-hole { fill: #0e1116; stroke: #7f8b99; stroke-width: 1; stroke-dasharray: 3 3; }
.nest-seam { stroke: var(--danger); stroke-width: 2; }
.nest-offcut { color: #7f8b99; stroke: #4c5663; stroke-width: 1; }
.nest-dim { stroke: #4c5663; stroke-width: 1; }

/* right: the form */
.auth-panel {
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 40px;
  background: var(--surface-2);
  border-left: 1px solid var(--line);
}
/* no entrance animation: the first thing a user must do here is read and type */
.auth-form {
  display: grid;
  gap: 14px;
  width: min(360px, 100%);
}
.auth-title { font-size: 24px; margin-bottom: 4px; }
.auth-error {
  padding: 9px 11px;
  color: #ffb4ae;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 38%, transparent);
  border-radius: var(--r-sm);
  font-size: 12.5px;
}
.field { display: grid; gap: 6px; }
.field label { color: var(--text-2); font-size: 12px; }
.auth-submit { justify-content: center; width: 100%; height: 38px; margin-top: 4px; }
/* ---------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .layout-copy dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-actions input[type="search"] { width: 200px; }
}

/* the diagram is context, not content: drop it before it gets cramped */
@media (max-width: 900px) {
  .auth-split { grid-template-columns: minmax(0, 1fr); }
  .auth-art { display: none; }
  .auth-panel { justify-items: center; padding: 24px; }
}

@media (max-width: 1024px) {
  .selection-grid,
  .selection-grid.compact,
  .selection-grid.order-grid { grid-template-columns: minmax(0, 1fr); }
  .selection-media { position: static; }
  .selection-photo { height: min(46vh, 420px); }
  .job-detail .job-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .zoom-layout-pair {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }
}

/* ------------------------------------------------- nav drawer (mobile) */
/* Below this width the nav will not fit beside the page controls, so it becomes a drawer.
   The hamburger is the only nav affordance left in the bar. */
@media (max-width: 900px) {
  .nav-toggle { display: grid; }

  .main-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: min(300px, 84vw);
    margin-right: 0;
    padding: 16px 12px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform var(--base);
  }
  body.nav-open .main-nav { transform: none; }

  .nav-tabs { flex-direction: column; gap: 2px; }
  .nav-tab { min-height: 44px; }
  /* Stacked, a tab has room for its subtitle again. */
  .nav-tab .object-desc { display: block; }

  /* No room to float a popover: the advanced list just opens inline in the drawer. */
  .nav-advanced { position: static; }
  .nav-advanced-panel {
    position: static;
    width: auto;
    max-height: none;
    padding: 8px 0 0;
    background: none;
    border: 0;
    box-shadow: none;
  }
  .nav-advanced-panel .object-list { max-height: 50vh; }

  .nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.55);
  }

  /* Page controls drop to their own row: they are not navigation. */
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  /* Its own row (order 3, full width), and it wraps internally: the view toggle, page-size
     select and refresh do not shrink, so together they exceeded 390 and stretched the whole
     bar, pushing the avatar off-screen. Wrapping puts the search on one line and the controls
     on the next instead of overflowing. */
  .top-actions {
    order: 3;
    flex: 1 1 100%;
    min-width: 0;
    margin-left: 0;
    flex-wrap: wrap;
  }
  .top-actions input[type="search"] { flex: 1 1 100%; width: auto; min-width: 0; }
  /* The account trigger is a single avatar now, so it needs no special mobile handling;
     the panel drops down the same as on desktop. */
  .top-meta { margin-left: auto; }
}

@media (max-width: 860px) {
  .layout-previews { grid-template-columns: minmax(0, 1fr); }
  .available-row { grid-template-columns: 96px minmax(0, 1fr); }
  .available-actions { grid-column: 1 / -1; justify-items: start; }
  .available-copy dl,
  .detail-list.two-col,
  .summary-facts,
  .job-facts,
  .job-detail .job-facts { grid-template-columns: minmax(0, 1fr); }
  .mini-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .table-wrap, .detail-panel { padding-inline: 14px; }
}

/* ----------------------------------------------------------- touch input */
/* This runs on a phone or tablet next to the slabs, so anything tappable clears the 44px
   the finger actually needs. It keys on the pointer, not the width: a small desktop window
   is still a mouse. */
@media (pointer: coarse) {
  .nav-toggle,
  .icon-button { width: 44px; height: 44px; }
  .nav-tab,
  .object-item,
  .nav-advanced > summary,
  .menu-item,
  .view-toggle button { min-height: 44px; }
  .user-menu > summary { min-width: 44px; min-height: 44px; }
  .detail-back { min-height: 44px; display: inline-flex; align-items: center; }
}

/* ------------------------------------------------------ reduced motion */
@media (prefers-reduced-motion: reduce) {
  .main-nav { transition: none; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* spinners must still read as "working" */
  .async-spinner,
  .slab-card-image.loading::after,
  .relation-thumb.loading::after,
  .available-thumb.loading::after,
  .selection-photo.loading::after,
  .layout-preview.loading::after,
  .zoom-stage.is-loading::after {
    animation: spin 1400ms linear infinite !important;
    animation-duration: 1400ms !important;
    animation-iteration-count: infinite !important;
  }
}
