/* ============================================================================
   Contour · application chrome
   Shell only: topbar, object tabs, viewbar, view rail, configure rail,
   popovers, panels, modals, palette. View internals live in css/views.css.
   No literal colours / sizes — tokens only.
   ========================================================================== */

/* ---------------------------------------------------------------- base --- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: var(--focus-ring-w) solid var(--focus-ring);
  outline-offset: 1px;
  border-radius: var(--radius-sm);
}

h1, h2, h3, h4, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-3) 45%, transparent);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--text-2) 55%, transparent); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ----------------------------------------------------------- utilities --- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.tnum { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: var(--sp-2); }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }
.caps {
  font-size: var(--fs-xs); line-height: var(--lh-xs); font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-2);
}
.bootfail { padding: var(--sp-8); font-size: var(--fs-md); color: var(--text-2); }

.icon { display: inline-flex; flex: none; width: 16px; height: 16px; }
.icon svg { width: 100%; height: 100%; display: block; }
.icon-20 { width: 20px; height: 20px; }

/* colour dot — --c supplied inline from the object/option colour */
.dot {
  flex: none; width: 8px; height: 8px; border-radius: var(--radius-pill);
  background: var(--c, var(--accent));
}
.dot.lg { width: 10px; height: 10px; }

.swatchbox {
  flex: none; width: 16px; height: 16px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--c, var(--accent)) var(--tint-chip), var(--surface));
  border: var(--border-w) solid color-mix(in srgb, var(--c, var(--accent)) 45%, transparent);
}

/* ------------------------------------------------------------ controls --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 var(--sp-3);
  background: var(--surface); color: var(--text);
  border: var(--border); border-radius: var(--radius);
  font-size: var(--fs-base); font-weight: var(--fw-medium);
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--active); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent); color: var(--on-accent); border-color: transparent;
  height: var(--control-h-lg);
}
.btn.primary:hover { background: var(--accent-hover); }

.btn.ghost { background: transparent; border-color: transparent; font-weight: var(--fw-regular); }
.btn.ghost:hover { background: var(--hover); }

.btn.subtle { background: var(--sunken); border-color: transparent; }
.btn.subtle:hover { background: var(--active); }

.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }

.btn.sm { height: var(--control-h-sm); padding: 0 var(--sp-2); font-size: var(--fs-sm); }
.btn.icon { width: var(--control-h); padding: 0; }
.btn.icon.sm { width: var(--control-h-sm); }
.btn.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.btn[aria-expanded="true"] { background: var(--active); }

.input, .select, .textarea {
  width: 100%; height: var(--control-h); padding: 0 var(--sp-2);
  background: var(--surface); color: var(--text);
  border: var(--border); border-radius: var(--radius);
  font-size: var(--fs-base);
}
.textarea { height: auto; min-height: 64px; padding: var(--sp-2); resize: vertical; line-height: var(--lh-base); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 var(--focus-ring-w) color-mix(in srgb, var(--accent) 28%, transparent);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input.sm, .select.sm { height: var(--control-h-sm); font-size: var(--fs-sm); }
.select { appearance: none; padding-right: var(--sp-6); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

.searchbox { position: relative; display: flex; align-items: center; }
.searchbox .icon { position: absolute; left: var(--sp-2); color: var(--text-3); pointer-events: none; }
.searchbox .input { padding-left: var(--sp-8); }

.label {
  display: block; font-size: var(--fs-sm); line-height: var(--lh-sm);
  font-weight: var(--fw-medium); color: var(--text-2); margin-bottom: var(--sp-1);
}

.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; cursor: pointer; }

.seg { display: inline-flex; flex: none; padding: 2px; gap: 2px; background: var(--sunken); border-radius: var(--radius); }
.seg > button {
  height: 26px; padding: 0 var(--sp-2); border: 0; background: transparent;
  border-radius: var(--radius-sm); color: var(--text-2); white-space: nowrap;
  font-size: var(--fs-sm); font-weight: var(--fw-medium); cursor: pointer;
}
.seg > button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

.chip {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  height: 20px; padding: 0 var(--sp-2); max-width: 180px;
  border-radius: var(--radius-pill); font-size: var(--fs-sm); line-height: 1;
  background: color-mix(in srgb, var(--c, var(--text-3)) var(--tint-chip), var(--surface));
  color: color-mix(in srgb, var(--c, var(--text-2)) 55%, var(--text));
}

.count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px;
  height: 18px; padding: 0 5px; border-radius: var(--radius-pill);
  background: var(--sunken); color: var(--text-2);
  font-size: var(--fs-xs); font-variant-numeric: tabular-nums;
}

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border: var(--border-soft); border-bottom-width: 2px; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-2);
  font-family: var(--font-sans); font-size: var(--fs-xs); line-height: 1;
}

.banner {
  display: flex; gap: var(--sp-2); align-items: flex-start;
  padding: var(--sp-2) var(--sp-3); border-radius: var(--radius);
  background: var(--info-soft); color: var(--text);
  border: var(--border-w) solid var(--info-line); font-size: var(--fs-sm);
}
.banner.warn { background: var(--warning-soft); border-color: var(--warning-line); }
.banner.bad  { background: var(--danger-soft);  border-color: var(--danger-line); }

.divider { height: 1px; background: var(--line-2); border: 0; margin: var(--sp-2) 0; }
.vrule { width: 1px; height: 20px; background: var(--line-2); flex: none; }

/* ---------------------------------------------------------- app shell --- */
.app {
  display: grid;
  grid-template-rows: var(--topbar-h) var(--viewbar-h) 1fr;
  height: 100vh; overflow: hidden;
  background: var(--canvas);
}
.workarea {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) 0;
  min-height: 0;
  transition: grid-template-columns var(--dur-panel) var(--ease);
}
.app[data-rail="closed"] .workarea { grid-template-columns: 0 minmax(0, 1fr) 0; }
.app[data-config="open"] .workarea { grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--config-w); }
.app[data-rail="closed"][data-config="open"] .workarea { grid-template-columns: 0 minmax(0, 1fr) var(--config-w); }

/* ------------------------------------------------------------- topbar --- */
.topbar {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0 var(--sp-2) 0 var(--sp-3);
  background: var(--surface); border-bottom: var(--border);
  min-width: 0;
}

.ws-switch {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 var(--sp-2);
  border: 0; border-radius: var(--radius); background: transparent;
  font-weight: var(--fw-semibold); cursor: pointer; max-width: 220px;
}
.ws-switch:hover { background: var(--hover); }
.ws-mark {
  display: grid; place-items: center; flex: none; width: 22px; height: 22px;
  border-radius: var(--radius); background: var(--accent); color: var(--on-accent);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold);
}

.tabs {
  display: flex; align-items: stretch; gap: 2px; height: 100%;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none; min-width: 0; flex: 1 1 auto;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  height: 100%; padding: 0 var(--sp-3); max-width: 200px;
  border: 0; border-bottom: 2px solid transparent; background: transparent;
  color: var(--text-2); font-size: var(--fs-base); font-weight: var(--fw-medium);
  cursor: pointer; white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.tab:hover { background: var(--hover); color: var(--text); }
.tab[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--c, var(--accent));
  background: color-mix(in srgb, var(--c, var(--accent)) var(--tint-weak), transparent);
}
.tab .tab-caret { opacity: 0; color: var(--text-3); }
.tab[aria-current="page"] .tab-caret, .tab:hover .tab-caret { opacity: 1; }

.tab-add {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  height: var(--control-h); padding: 0 var(--sp-2); margin-left: var(--sp-1); flex: none;
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--text-2); font-size: var(--fs-base); cursor: pointer;
}
.tab-add:hover { background: var(--hover); color: var(--text); }

.topbar-right { display: flex; align-items: center; gap: var(--sp-1); flex: none; }

.topsearch {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  height: var(--control-h); width: 200px; padding: 0 var(--sp-2);
  border: var(--border); border-radius: var(--radius);
  background: var(--canvas); color: var(--text-2);
  font-size: var(--fs-base); cursor: pointer; text-align: left;
}
.topsearch:hover { background: var(--hover); }
.topsearch .kbd { margin-left: auto; }

.avatar {
  display: grid; place-items: center; width: 26px; height: 26px; flex: none;
  border: 0; border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--accent) var(--tint-strong), var(--surface));
  color: var(--text); font-size: var(--fs-xs); font-weight: var(--fw-semibold); cursor: pointer;
}

/* ------------------------------------------------------------ viewbar --- */
.viewbar {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0 var(--sp-2); min-width: 0;
  background: var(--surface); border-bottom: var(--border);
  /* last-resort safety net: if this bar ever exceeds its width, it scrolls.
     It used to be `visible`, which meant the overflow was simply painted past
     the viewport edge with nothing able to reach it. */
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.viewbar::-webkit-scrollbar { display: none; }

/* min-width:0 makes this the item that gives way when the bar runs out of
   room. It truncates and keeps a title; a toolbar button cannot do either. */
.view-name {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-width: 0;
  height: var(--control-h-sm); padding: 0 var(--sp-2); max-width: 320px;
  border: 0; border-radius: var(--radius); background: transparent;
  font-weight: var(--fw-semibold); cursor: pointer;
}
.view-name:hover { background: var(--hover); }

/* the layout, at the view identity, as its own control: one click reaches the
   switcher that used to cost a menu, a submenu entry and a modal */
.view-layout {
  display: inline-flex; align-items: center; gap: var(--sp-1); flex: none;
  height: var(--control-h-sm); padding: 0 var(--sp-2);
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--text-2); font-size: var(--fs-base); cursor: pointer; white-space: nowrap;
}
.view-layout:hover { background: var(--hover); color: var(--text); }
.view-layout[aria-expanded="true"] { background: var(--active); color: var(--text); }
.view-layout .icon { color: var(--text-2); }
.view-layout:hover .icon, .view-layout[aria-expanded="true"] .icon { color: var(--accent); }
.view-layout-label { font-weight: var(--fw-medium); }
/* the record count is a fixed, short string: squeezing it to 0x19 (measured)
   told the operator nothing. It never shrinks. */
.vb-count { flex: none; }

/* flex:none is the fix for the collapsing toolbar. As a shrinkable item with
   min-width:0 this box absorbed the whole squeeze — it measured 0x26 at 375px
   while laying its six buttons out at x 206..430, i.e. clipped to nothing and
   reachable by neither pointer nor scrollbar. It never shrinks now; the view
   name and the record count, which truncate and carry a title, give way first. */
.tools { display: flex; align-items: center; gap: 2px; flex: none; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tools::-webkit-scrollbar { display: none; }

.tool {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  height: var(--control-h-sm); padding: 0 var(--sp-2);
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--text-2); font-size: var(--fs-base); cursor: pointer; white-space: nowrap;
}
.tool:hover { background: var(--hover); color: var(--text); }
.tool[aria-expanded="true"] { background: var(--active); color: var(--text); }
/* the label is normal-size text, so the tint is darkened toward --text to hold
   4.5:1 while keeping the hue that identifies the control */
.tool.on {
  background: color-mix(in srgb, var(--tool-c, var(--accent)) var(--tint-weak), transparent);
  color: color-mix(in srgb, var(--tool-c, var(--accent)) 55%, var(--text));
}
.tool.on .icon { color: var(--tool-c, var(--accent)); }
.tool .count { background: color-mix(in srgb, var(--tool-c, var(--accent)) var(--tint-chip), transparent); color: inherit; }

/* ---------------------------------------------------------- view rail --- */
.viewrail {
  grid-column: 1; grid-row: 1; position: relative;   /* stable containing block at every width */
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  background: var(--surface); border-right: var(--border);
  z-index: var(--z-rail);
}
.app[data-rail="closed"] .viewrail { border-right: 0; }

.rail-head { padding: var(--sp-2); display: flex; flex-direction: column; gap: var(--sp-2); }
.rail-create {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%;
  height: var(--control-h); padding: 0 var(--sp-2);
  border: var(--border); border-radius: var(--radius); background: var(--surface);
  color: var(--text); font-weight: var(--fw-medium); cursor: pointer; text-align: left;
}
.rail-create:hover { background: var(--hover); }

.rail-list { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--sp-2) var(--sp-3); }
.rail-sec { padding: var(--sp-3) var(--sp-2) var(--sp-1); }

.rail-item {
  display: flex; align-items: center; width: 100%;
  padding-right: var(--sp-1); border-radius: var(--radius);
  color: var(--text);
}
.rail-item:hover { background: var(--hover); }
.rail-item[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
.rail-item[aria-current="true"] .rail-open { font-weight: var(--fw-medium); }

.rail-open {
  display: flex; align-items: center; gap: var(--sp-2); flex: 1 1 auto; min-width: 0;
  min-height: var(--control-h); padding: 0 var(--sp-2);
  border: 0; border-radius: var(--radius); background: transparent;
  color: inherit; font-size: var(--fs-base); text-align: left; cursor: pointer;
}
.rail-open .icon { color: var(--text-3); }
.rail-item[aria-current="true"] .rail-open .icon { color: var(--accent); }

.rail-more {
  flex: none; display: grid; place-items: center;
  width: var(--control-h-sm); height: var(--control-h-sm);
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--text-2); cursor: pointer; opacity: 0;
}
.rail-item:hover .rail-more, .rail-more:focus-visible, .rail-more[aria-expanded="true"] { opacity: 1; }
.rail-more:hover { background: var(--active); }
.rail-default { color: var(--text-3); }

.rail-foot { padding: var(--sp-2); border-top: var(--border-soft); }

/* ------------------------------------------------------------- canvas --- */
/* explicit tracks: an overlaid (position:fixed) rail must not pull the canvas
   into column 1 — grid auto-placement would otherwise reflow every region */
.canvas {
  grid-column: 2; grid-row: 1;
  position: relative; min-width: 0; min-height: 0;
  display: flex; flex-direction: column; background: var(--canvas);
}
.viewhost { flex: 1 1 auto; min-height: 0; min-width: 0; position: relative; overflow: auto; }

/* --------------------------------------------------------- empty state --- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); height: 100%; min-height: 200px;
  padding: var(--sp-8); text-align: center;
}
.empty-mark {
  display: grid; place-items: center; width: 44px; height: 44px;
  border-radius: var(--radius-lg); background: var(--sunken); color: var(--text-3);
}
.empty-title { font-size: var(--fs-lg); line-height: var(--lh-lg); font-weight: var(--fw-semibold); }
.empty-body { max-width: 460px; color: var(--text-2); font-size: var(--fs-md); line-height: var(--lh-md); }
.empty-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }
.empty.inline { height: auto; padding: var(--sp-6) var(--sp-4); }

/* ----------------------------------------------------- configure rail --- */
/* position:relative at every width — the <=1200px rule below re-positions this
   to fixed, and a docked surface must not lose its containing block (and
   escape to the viewport) just because the window crossed a breakpoint. */
.configrail {
  grid-column: 3; grid-row: 1; position: relative;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  background: var(--surface); border-left: var(--border);
}
.app[data-config="closed"] .configrail { border-left: 0; }

.cfg-head { display: flex; align-items: flex-start; gap: var(--sp-2); padding: var(--sp-3) var(--sp-3) var(--sp-2); border-bottom: var(--border-soft); }
.cfg-crumb { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1); font-size: var(--fs-sm); color: var(--text-2); }
.cfg-crumb b { color: var(--text); font-weight: var(--fw-semibold); }
.cfg-crumb .sep { color: var(--text-3); }
.cfg-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }

.cfg-body { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-6); }
.cfg-section { display: flex; flex-direction: column; gap: var(--sp-2); }
.cfg-section > .caps { display: flex; align-items: center; gap: var(--sp-2); }
.cfg-row { display: flex; align-items: center; gap: var(--sp-2); justify-content: space-between; }
.cfg-row > .grow { min-width: 0; }
.cfg-sub { font-size: var(--fs-sm); color: var(--text-2); }
.cfg-foot { padding: var(--sp-2) var(--sp-3); border-top: var(--border-soft); display: flex; gap: var(--sp-2); align-items: center; }

.cfg-card {
  border: var(--border-soft); border-radius: var(--radius); padding: var(--sp-2);
  background: var(--canvas); display: flex; flex-direction: column; gap: var(--sp-2);
}
.cfg-slot { display: flex; flex-direction: column; gap: var(--sp-2); }

/* --------------------------------------------------- overlays / layer --- */
.layer { position: fixed; inset: 0; pointer-events: none; z-index: var(--z-popover); }
.layer > * { pointer-events: auto; }

.backdrop { position: fixed; inset: 0; background: transparent; }
.backdrop.scrim { background: var(--scrim); }

.popover {
  position: fixed; min-width: 200px; max-width: min(440px, calc(100vw - 24px));
  max-height: min(70vh, 620px); overflow: auto;
  background: var(--raised); border: var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  animation: pop var(--dur-panel) var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.panel { display: flex; flex-direction: column; min-width: 0; }
.panel-head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); border-bottom: var(--border-soft);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-2);
}
.panel-body { padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.panel-body.tight { padding: var(--sp-2); }
.panel-foot {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); border-top: var(--border-soft); background: var(--canvas);
}
.panel-hint { font-size: var(--fs-sm); color: var(--text-2); }

/* menus */
.menu { padding: var(--sp-1); display: flex; flex-direction: column; min-width: 200px; }
.menu-label { padding: var(--sp-2) var(--sp-2) var(--sp-1); }
.menu-item {
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: var(--control-h); padding: 0 var(--sp-2);
  border: 0; border-radius: var(--radius); background: transparent;
  color: var(--text); font-size: var(--fs-base); text-align: left; cursor: pointer; width: 100%;
}
.menu-item:hover:not([disabled]), .menu-item.sel { background: var(--hover); }
.menu-item[disabled] { color: var(--text-3); cursor: not-allowed; }
.menu-item .icon { color: var(--text-3); }
.menu-item .kbd { margin-left: auto; }
.menu-item .menu-note { margin-left: auto; font-size: var(--fs-sm); color: var(--text-3); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-item[aria-checked="true"] { font-weight: var(--fw-medium); }
.menu-sep { height: 1px; margin: var(--sp-1) 0; background: var(--line-2); }
.menu-scroll { max-height: 280px; overflow-y: auto; }

/* modal */
.modal-wrap { position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center; padding: 10vh var(--sp-4) var(--sp-4); pointer-events: none; }
.modal {
  pointer-events: auto; width: min(640px, 100%); max-height: 78vh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--raised); border: var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modalin var(--dur-panel) var(--ease);
}
@keyframes modalin { from { opacity: 0; transform: translateY(-8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal.wide { width: min(760px, 100%); }
.modal.narrow { width: min(460px, 100%); }
/* the wrapper openModal() is handed: it must be the flex column, not a block,
   or the height cap on .modal never reaches the scrollable body inside it */
.modal-shell { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.modal-head { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: var(--border-soft); }
.modal-title { font-size: var(--fs-lg); line-height: var(--lh-lg); font-weight: var(--fw-semibold); }
/* same reason as .pal-list: without min-height:0 the body wins over the
   modal's max-height and overflow:hidden eats the bottom of it silently. */
.modal-body { padding: var(--sp-4); min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: var(--sp-4); }
.modal-foot { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: var(--border-soft); background: var(--canvas); }

/* --------------------------------------------------------- layout tiles --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-2); }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-1);
  padding: var(--sp-3); text-align: left; cursor: pointer;
  border: var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
}
.tile:hover:not([disabled]) { background: var(--hover); border-color: var(--accent-line); }
.tile[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.tile[disabled] { cursor: not-allowed; background: var(--canvas); color: var(--text-3); }
.tile .icon { color: var(--accent); }
.tile[disabled] .icon { color: var(--text-3); }
.tile-name { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; font-weight: var(--fw-medium); }
.tile-reason { font-size: var(--fs-sm); color: var(--text-2); }
.tile-fix { font-size: var(--fs-sm); color: var(--accent); }
/* a layout the design names but this build does not ship: listed, never
   silently dropped, and the tile says so rather than the console saying 404 */
.tile-flag {
  flex: none; padding: 1px var(--sp-2); border-radius: var(--radius-pill);
  border: var(--border-soft); background: var(--sunken); color: var(--text-2);
  font-size: var(--fs-xs); line-height: var(--lh-xs); font-weight: var(--fw-medium);
}
.tile-absent { border-style: dashed; }

/* ------------------------------------------------------ filter builder --- */
.fb { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.fb-group {
  display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0;
  padding: var(--sp-2); border: var(--border-soft); border-radius: var(--radius); background: var(--canvas);
}
.fb-group.root { padding: 0; border: 0; background: transparent; }
.fb-line { display: flex; align-items: center; gap: var(--sp-1); min-width: 0; }
.fb-join { flex: none; width: 62px; }
.fb-join .select { padding-right: var(--sp-4); background-position: right 8px center, right 4px center; }
.fb-join-static { flex: none; width: 62px; font-size: var(--fs-sm); color: var(--text-2); padding-left: var(--sp-1); }
.fb-field { flex: 1 1 130px; min-width: 90px; }
.fb-cmp { flex: 1 1 110px; min-width: 90px; }
.fb-val { flex: 1 1 130px; min-width: 90px; }
.fb-actions { display: flex; gap: var(--sp-2); }

/* ------------------------------------------------- field / sort / colour --- */
.rowlist { display: flex; flex-direction: column; gap: var(--sp-1); max-height: 320px; overflow-y: auto; }
.listrow {
  display: flex; align-items: center; gap: var(--sp-2); min-height: var(--control-h);
  padding: 0 var(--sp-1); border-radius: var(--radius);
}
.listrow:hover { background: var(--hover); }
.listrow .type { font-size: var(--fs-sm); color: var(--text-3); }
.listrow .drag { color: var(--text-3); cursor: grab; }
.listrow.title-field { color: var(--text-2); }

.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--sp-1); }
.swatch {
  width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); cursor: pointer;
  border: var(--border-w) solid transparent; background: var(--c, var(--accent));
}
.swatch[aria-pressed="true"] { outline: var(--focus-ring-w) solid var(--text); outline-offset: 2px; }

.rule-card {
  display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-2); border: var(--border-soft); border-radius: var(--radius); background: var(--canvas);
}

/* ------------------------------------------------------------- palette --- */
.palette {
  pointer-events: auto; width: min(640px, 100%); max-height: 70vh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--raised); border: var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); animation: modalin var(--dur-panel) var(--ease);
}
.palette.search { width: min(760px, 100%); }
.pal-head { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: var(--border-soft); }
.pal-head .icon { color: var(--text-3); }
.pal-input { flex: 1 1 auto; border: 0; outline: none; background: transparent; font-size: var(--fs-lg); line-height: var(--lh-lg); }
.pal-input::placeholder { color: var(--text-3); }
.pal-scope { flex: none; }
/* min-height:0 is load-bearing. A flex item defaults to min-height:auto, so
   without it this list refuses to shrink below its content, grows past the
   palette's max-height and gets clipped by .palette{overflow:hidden} with no
   scroller anywhere — 2154px of results inside a 700px box, keyboard-only. */
.pal-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-1); }
.pal-section { padding: var(--sp-3) var(--sp-2) var(--sp-1); }
.pal-item {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%;
  min-height: var(--control-h-lg); padding: 0 var(--sp-2);
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text);
  text-align: left; cursor: pointer;
}
.pal-item[aria-selected="true"] { background: var(--accent-soft); }
.pal-item[disabled] { color: var(--text-3); cursor: not-allowed; }
.pal-item .pal-sub { color: var(--text-2); font-size: var(--fs-sm); }
.pal-item .pal-right { margin-left: auto; display: flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-sm); color: var(--text-3); }
.pal-foot {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4);
  border-top: var(--border-soft); background: var(--canvas); font-size: var(--fs-sm); color: var(--text-2);
}
.pal-foot .row { gap: var(--sp-1); }

/* ---------------------------------------------------- record composer --- */
/* js/compose.js — one panel, worn by the shell modal, the calendar draft, the list
   popover and the inline cards on board and gallery. The surface supplies placement;
   these are the parts every wearer shares. */
/* flex:1 so a wearer that caps its own height (the modal, the calendar draft) passes that
   cap down to .cmp-body, which is the part that scrolls. */
.cmp-root { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; min-height: 0; }
.cmp-body { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; min-height: 0; overflow: auto; }
.cmp-lead { margin: 0; }
.cmp-foot { display: flex; align-items: center; gap: var(--sp-2); }
/* A popover scrolls as a whole, so the submit would slide out of reach on a panel with
   several controls on it — which is exactly the panel worth submitting. */
.popover .cmp-foot { position: sticky; bottom: 0; z-index: 1; }
.cmp-root .banner { margin: 0; }
.cmp-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.cmp-row {
  display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0;
  padding: var(--sp-2); border-radius: var(--radius);
  border: var(--border-w) solid var(--warning-line); background: var(--warning-soft);
}
/* satisfied: still editable, no longer shouting */
.cmp-row.ok { border-color: var(--line-2); background: var(--canvas); }
.cmp-head { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.cmp-name { font-weight: var(--fw-medium); }
.cmp-tick { color: var(--success); }
.cmp-why { font-size: var(--fs-sm); color: var(--text-2); }
.cmp-files { display: flex; flex-direction: column; gap: var(--sp-2); }
.cmp-files .row { flex-wrap: wrap; }

/* ------------------------------------------------------------- archive --- */
.arch-sec { padding: 0 0 var(--sp-1); }
.arch-list { display: flex; flex-direction: column; gap: var(--sp-1); }
.arch-row {
  display: flex; align-items: center; gap: var(--sp-2); min-width: 0;
  min-height: var(--control-h-lg); padding: var(--sp-1) var(--sp-2);
  border: var(--border-soft); border-radius: var(--radius); background: var(--canvas);
}
.arch-row > .icon, .arch-row > .dot, .arch-row > .swatchbox { flex: none; }
.arch-row .arch-note { flex: none; white-space: nowrap; }
.arch-row .btn { flex: none; }

/* -------------------------------------------------------- record fallback --- */
.rec-grid { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: var(--sp-2) var(--sp-3); align-items: baseline; }
.rec-key { font-size: var(--fs-sm); color: var(--text-2); }
.rec-val { min-width: 0; overflow-wrap: anywhere; }

/* --------------------------------------------------------- responsive --- */


/* ---- narrow: nothing is dropped, everything gets a smaller shape ---------
   The viewbar carries 10 controls whose labelled min-content is ~700px. Below
   720 the labels go (the button keeps title + aria-label, so it is still named
   to pointer and screen reader); below 600 even the icon-only row does not fit
   on one line, so the six view controls wrap onto a second line of their own
   and --viewbar-h grows to match. No control is hidden without a route to it:
   the two topbar buttons that do disappear (keyboard help, theme toggle) are
   both items in the account menu, which stays. */
