/* Scalebar studio surfaces and controls */
:root {
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
  --r-sm: 5px; --r: 7px; --r-lg: 11px;
  --control-speed: 120ms;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --on-accent: #fff;
  --sel: #2563eb;           /* selection + handles on the paper: same in both themes */
  --snap: #0f9f6e;          /* snap reticle on the paper (green, distinct from selection blue) */
  --snap-halo: rgba(255, 255, 255, .9);
  --rev1: #d42020; --rev2: #1f4fd6;
  --drawer-h: 216px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
:root, :root[data-theme="light"] {
  color-scheme: light;
  --app: #f4f6f8; --panel: #fff; --panel-2: #f4f6f8; --raised: #fff;
  --mat: #eaeff4; --well: #e5e7eb; --inspector: #fff;
  --field: #fff; --track: #f1f5f9;
  --line: #dce2ea; --line-2: #c9d1dc;
  --hover: rgba(15, 23, 42, .045); --press: rgba(15, 23, 42, .075);
  --text: #0f172a; --text-2: #334155; --muted: #475569; --faint: #637389;
  --accent-text: #1d4ed8; --accent-soft: rgba(29, 78, 216, .08); --accent-line: rgba(29, 78, 216, .36);
  --focus-ring: rgba(29, 78, 216, .16); --grid: rgba(29, 78, 216, .10);
  --danger: #a42535; --danger-soft: rgba(164, 37, 53, .07); --danger-line: rgba(164, 37, 53, .28);
  --ok: #18794e; --ok-soft: rgba(24, 121, 78, .09); --signal: #159467;
  --neutral-soft: rgba(15, 23, 42, .055); --zebra: #f8fafc;
  --highlight: rgba(255, 255, 255, .82); --scrim: rgba(30, 41, 59, .31);
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-inset: inset 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-pop: var(--shadow-1), 0 12px 32px rgba(15, 23, 42, .12);
  --shadow-modal: var(--shadow-1), 0 24px 60px rgba(15, 23, 42, .22);
  --paper-shadow: rgba(15, 23, 42, .12); --split-divider: #9aa0aa;
  --tip-bg: #161c26; --tip-fg: #f3f4f6; --tip-kbd: rgba(255, 255, 255, .66);
  --hit-bg: #fff3c4; --hit-fg: #7a5b00;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --app: #0e1117; --panel: #151a23; --panel-2: #161b24; --raised: #1c2330;
  --mat: #0e1117; --well: #14161a; --inspector: #1c1f26;
  --field: #111721; --track: #161b24;
  --line: rgba(255, 255, 255, .09); --line-2: rgba(193, 211, 239, .23);
  --hover: rgba(174, 195, 230, .085); --press: rgba(174, 195, 230, .14);
  --text: #e6edf3; --text-2: #c5d0df; --muted: #a9b7c9; --faint: #92a0b4;
  --accent-text: #a6bfff; --accent-soft: rgba(98, 145, 255, .16); --accent-line: rgba(115, 155, 255, .58);
  --focus-ring: rgba(103, 148, 255, .24); --grid: rgba(103, 148, 255, .16);
  --danger: #ff98a4; --danger-soft: rgba(255, 126, 146, .10); --danger-line: rgba(255, 126, 146, .35);
  --ok: #67d8a1; --ok-soft: rgba(76, 195, 138, .13); --signal: #55d69a;
  --neutral-soft: rgba(255, 255, 255, .075); --zebra: #181e29;
  --highlight: rgba(219, 231, 255, .075); --scrim: rgba(4, 7, 12, .64);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .32);
  --shadow-inset: inset 0 1px 2px rgba(0, 0, 0, .36);
  --shadow-pop: var(--shadow-1), 0 12px 32px rgba(0, 0, 0, .44);
  --shadow-modal: var(--shadow-1), 0 24px 60px rgba(0, 0, 0, .62);
  --paper-shadow: rgba(0, 0, 0, .55); --split-divider: #3a3f4a;
  --tip-bg: #e6edf3; --tip-fg: #0f172a; --tip-kbd: #475569;
  --hit-bg: rgba(255, 210, 60, .16); --hit-fg: #f1cf6b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--app); color: var(--text); font: 13px/1.4 var(--sans); overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.grow { flex: 1; }
kbd { font: 10.5px/1 var(--mono); color: var(--faint); }
::selection { background: var(--accent-soft); }

#app {
  display: grid; height: 100vh; width: 100vw;
  grid-template-columns: 232px 48px minmax(0, 1fr) 264px;
  grid-template-rows: 48px minmax(0, 1fr) auto 24px;
  grid-template-areas: "top top top top" "side rail stage props" "side list list props" "status status status status";
  transition: grid-template-columns .18s var(--ease);
}
#app.props-off { grid-template-columns: 232px 48px minmax(0, 1fr) 0; }
#app.props-off .props { visibility: hidden; }

/* ---------- controls ---------- */
button { background: none; border: 1px solid transparent; border-radius: var(--r); height: 28px; padding: 0 10px; cursor: pointer; white-space: nowrap; color: var(--text-2); transition: background-color var(--control-speed), border-color var(--control-speed), color var(--control-speed), box-shadow var(--control-speed), transform var(--control-speed); }
button:hover:not(:disabled) { color: var(--text); }
button:disabled { opacity: .38; cursor: default; }
button.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
button.ghost { border-color: var(--line-2); background: var(--panel); color: var(--text); box-shadow: var(--shadow-1); }
button.ghost:hover:not(:disabled, .on, .active, .live) { background: var(--panel); border-color: var(--accent-line); }
button.ghost.on, button.ghost.active { color: var(--accent-text); border-color: var(--accent-line); background: var(--accent-soft); box-shadow: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 650; box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255, 255, 255, .24); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
button.primary:active:not(:disabled) { transform: translateY(1px); box-shadow: inset 0 1px 3px rgba(15, 23, 42, .26); }
:where(button, input, select, textarea, a):focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
button.wide { width: 100%; }
.icon-btn { width: 28px; padding: 0; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent-text); background: var(--accent-soft); }
.icon-btn svg, svg.ico, .zoom svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; flex: none; }
button svg.ico { margin-right: 6px; margin-left: -2px; }
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 7px; background: var(--track); box-shadow: var(--shadow-inset); flex: none; }
.seg button { height: 24px; border-radius: 5px; padding: 0 9px; font-size: 12px; color: var(--muted); border: 0; }
.seg button:hover:not(:disabled) { color: var(--text); }
.seg button.on { background: var(--raised); color: var(--accent-text); box-shadow: 0 0 0 1px var(--line), var(--shadow-1); font-weight: 650; }
.seg button svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.4; vertical-align: -2px; }
#sheetView button { padding: 0 5px; height: 22px; }
.seg.small button { height: 20px; padding: 0 7px; font-size: 11px; }
select, input { height: 28px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--field); padding: 0 8px; min-width: 0; }
input::placeholder, textarea::placeholder { color: var(--faint); }
.vsep { width: 1px; height: 18px; background: var(--line-2); flex: none; }

/* ---------- top bar (48px) ---------- */
.topbar { grid-area: top; position: relative; z-index: 6; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow-1); min-width: 0; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 0 1 auto; }
.logo { width: 24px; height: 24px; flex: none; display: block; border-radius: 5px; }
:root[data-theme="dark"] .logo { box-shadow: 0 0 0 1px rgba(255, 255, 255, .22); }
.brand-name { font-size: 15px; font-weight: 720; letter-spacing: -.035em; white-space: nowrap; flex: none; }
.doc-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 185px; padding-left: 9px; border-left: 1px solid var(--line); line-height: 16px; }
.history { display: flex; gap: 2px; flex: none; padding: 2px; border-radius: 8px; background: var(--track); box-shadow: var(--shadow-inset); }
.history .icon-btn { width: 26px; height: 26px; }
.scale { display: flex; align-items: center; gap: 6px; flex: none; padding-inline-start: 8px; border-inline-start: 1px solid var(--line); }
.scale-lbl { color: var(--muted); font-size: 12.5px; }
.scale-pick, .pick { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px 0 10px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--field); cursor: pointer; box-shadow: var(--shadow-1); }
.scale-pick:hover, .pick:hover { background: var(--panel-2); }
.scale-pick:focus-within, .pick:focus-within { outline: 2px solid var(--accent-line); outline-offset: 1px; }
.scale-val { font-size: 12px; white-space: nowrap; color: var(--text); }
.scale-pick .chev, .pick .chev { width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.scale-pick select, .pick select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.unit-select { width: 56px; font-size: 12px; }
#calibrateBtn, #snapBtn { display: inline-flex; align-items: center; }
/* v4.4: guests in a live session cannot change sheet scale (host-only); the pick + Calibrate stay visible with a tooltip */
.scale-pick.locked, #calibrateBtn.locked { opacity: .55; cursor: not-allowed; box-shadow: none; }
.scale-pick.locked:hover { background: var(--field); }
.scale-pick.locked select { pointer-events: none; }
#snapBtn:not(.on) .ico { opacity: .6; }
.zoom { display: flex; align-items: center; height: 30px; padding: 0 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--track); box-shadow: var(--shadow-inset); flex: none; }
.zoom button { height: 24px; border: 0; }
.zoom .icon { width: 26px; padding: 0; border-radius: 999px; color: var(--muted); display: grid; place-items: center; }
.zoom .icon:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.zoom .readout { font-size: 12px; min-width: 54px; padding: 0 6px; border-radius: 999px; color: var(--text); }
.zoom .readout:hover { background: var(--panel); }
.file-actions { display: flex; gap: 5px; align-items: center; flex: none; }
.toolbar-group { display: flex; gap: 4px; align-items: center; flex: none; }
.toolbar-group + .toolbar-group { padding-inline-start: 5px; border-inline-start: 1px solid var(--line); }
.toolbar-group:not(.toolbar-session) .ghost:not(.on) { border-color: transparent; background: transparent; box-shadow: none; }
.toolbar-group:not(.toolbar-session) .ghost:hover:not(:disabled):not(.on) { background: var(--hover); }
.toolbar-session { gap: 6px; }
#compareBtn { display: inline-flex; align-items: center; }
#compareBtn.on { color: var(--accent-text); border-color: var(--accent-line); background: var(--accent-soft); box-shadow: none; }
#themeBtn .sun { display: none; }
:root[data-theme="dark"] #themeBtn .sun { display: block; }
:root[data-theme="dark"] #themeBtn .moon { display: none; }
#exportPdfBtn { padding: 0 10px; }
/* v9: Export PDF split button. The main half is the 1-click editable export; the chevron opens Editable / Flattened. */
.split-btn { display: inline-flex; align-items: center; flex: none; }
.split-btn #exportPdfBtn { border-start-end-radius: 0; border-end-end-radius: 0; }
.split-btn .split-chev { width: 22px; padding: 0; display: inline-grid; place-items: center; border-start-start-radius: 0; border-end-start-radius: 0; border-inline-start: 1px solid rgba(255, 255, 255, .28); }
.split-btn .split-chev svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.export-menu { position: fixed; z-index: 45; width: 268px; padding: 6px; display: grid; gap: 2px; background: var(--raised); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow-pop), inset 0 1px var(--highlight); animation: modal-in-pop var(--control-speed) var(--ease); }
.export-menu[hidden] { display: none; }
.export-menu .menu-item { height: auto; min-height: 44px; padding: 6px 10px; display: grid; justify-items: start; gap: 1px; white-space: normal; border-radius: 8px; }
.export-menu .mi-main { font-weight: 650; }
.export-menu .mi-sub { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.export-menu .menu-item:hover .mi-sub { color: inherit; }

/* ---------- tooltip (one floating element, positioned by main.ts) ---------- */
.uitip { position: fixed; z-index: 100; pointer-events: none; display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; background: var(--tip-bg); color: var(--tip-fg); font: 12px/1.2 var(--sans); white-space: nowrap; box-shadow: 0 4px 14px rgba(0, 0, 0, .18); animation: tip-in .1s var(--ease); }
.uitip kbd { color: var(--tip-kbd); font-size: 11px; }
@keyframes tip-in { from { opacity: 0; transform: translateY(2px); } }

/* ---------- sidebar ---------- */
.sidebar { grid-area: side; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--panel-2); min-height: 0; }
.panel-head { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); box-shadow: inset 0 1px var(--highlight); font-weight: 650; flex: none; min-width: 0; font-size: 12.5px; }
.side-head { padding: 0 8px; gap: 4px; }
.tabs { display: flex; gap: 1px; padding: 2px; border-radius: 8px; background: var(--track); box-shadow: var(--shadow-inset); }
.tab { height: 25px; padding: 0 8px; font-weight: 600; font-size: 12.5px; color: var(--muted); border-radius: 6px; border: 0; }
.tab:hover:not(:disabled) { color: var(--text); background: var(--hover); }
.tab .mono { font-weight: 400; font-size: 11px; margin-left: 3px; color: var(--faint); }
.tab.active { color: var(--accent-text); background: var(--raised); box-shadow: 0 0 0 1px var(--line), var(--shadow-1); }
.sheet-list, .layer-list { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; scrollbar-width: thin; }
.sheet { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: baseline; column-gap: 6px; row-gap: 1px; width: 100%; height: auto; margin-bottom: 3px; padding: 7px 8px; border: 1px solid transparent; border-radius: var(--r); text-align: left; color: var(--text); }
.sheet:hover:not(:disabled) { background: var(--panel); border-color: var(--line); }
.sheet.active, .sheet.active:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent-line); box-shadow: var(--shadow-1); }
.sheet.active .num { color: var(--accent-text); }
.sheet .num { font: 11px var(--mono); color: var(--faint); }
.sheet .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.sheet .sub { grid-column: 2; font: 11px var(--mono); color: var(--faint); }
.sheet .badge { font: 10.5px var(--mono); color: var(--muted); min-width: 18px; text-align: center; padding: 1px 5px; border-radius: 999px; background: var(--neutral-soft); }
.sheet .badge:empty { display: none; }
.sheet .hits { font: 10.5px var(--mono); color: var(--hit-fg); background: var(--hit-bg); border-radius: 999px; padding: 1px 6px; }
.sheet-list.thumbs { padding: 8px; display: grid; gap: 8px; align-content: start; }
.sheet.thumb { display: block; padding: 6px; margin: 0; border: 1px solid var(--line); background: var(--panel); }
.sheet.thumb:hover:not(:disabled) { background: var(--panel); border-color: var(--line-2); }
.sheet.thumb.active, .sheet.thumb.active:hover:not(:disabled) { border-color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent-line), var(--shadow-1); background: var(--panel); }
.sheet.thumb canvas { display: block; width: 100%; background: #fff; border-radius: 3px; box-shadow: 0 0 0 1px rgba(15, 23, 42, .08); }
.sheet.thumb .cap { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 4px; align-items: baseline; margin-top: 6px; }
.layer-head { padding: 4px 6px 10px; font-size: 12px; color: var(--muted); display: grid; gap: 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.layer-head .row { display: flex; gap: 6px; align-items: center; }
.layer-head button { height: 24px; font-size: 11.5px; padding: 0 8px; }
.layer { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 4px 6px; font-size: 12px; cursor: pointer; border-radius: var(--r-sm); }
.layer:hover { background: var(--hover); }
.layer input { width: 13px; height: 13px; margin: 0; accent-color: var(--accent); }
.layer .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .c { font: 11px var(--mono); color: var(--faint); }
.layer.unused .n { color: var(--faint); }
.layer.locked { cursor: default; }
.layer-note { padding: 10px 6px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.sidebar-foot { height: 30px; display: flex; align-items: center; gap: 4px; padding: 0 12px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--faint); flex: none; }
.sidebar-foot kbd { padding: 2px 4px; border-radius: 4px; background: var(--neutral-soft); color: var(--muted); }
.sidebar-foot span { margin-left: 4px; }

/* ---------- docked tool rail (48px, outside the canvas) ---------- */
.rail { grid-area: rail; position: relative; z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; background: var(--panel); border-right: 1px solid var(--line); overflow: hidden auto; scrollbar-width: none; }
.rail button { position: relative; width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border-radius: 8px; color: var(--text-2); flex: none; }
.rail button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.rail button:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.rail button.active, .rail button.active:hover { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-line); box-shadow: var(--shadow-1), inset 0 1px var(--highlight); }
.rail button.active::before { position: absolute; left: -6px; top: 8px; bottom: 8px; width: 2px; content: ""; border-radius: 2px; background: var(--accent-text); }
.rail .sep { width: 20px; height: 1px; background: var(--line-2); margin: 6px 0; flex: none; }
.no-doc .rail button { opacity: .35; pointer-events: none; }
.no-doc .scale { opacity: .45; pointer-events: none; }

/* ---------- stage (drafting-table well) ---------- */
.stage { grid-area: stage; position: relative; overflow: hidden; background: var(--mat); touch-action: none; user-select: none; min-width: 0; }
#view, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { overflow: visible; }
.stage[data-tool="pan"], .stage.panning { cursor: grab; }
.stage.panning.dragging { cursor: grabbing; }
.stage[data-tool="select"] { cursor: default; }
.stage[data-tool="cloud"], .stage[data-tool="callout"], .stage[data-tool="length"], .stage[data-tool="area"], .stage[data-tool="count"], .stage[data-tool="calibrate"],
.stage[data-tool="perimeter"], .stage[data-tool="arrow"], .stage[data-tool="rect"], .stage[data-tool="highlight"] { cursor: crosshair; }
.stage[data-tool="text"] { cursor: text; }
#screen .hdl { fill: #fff; stroke: var(--sel); stroke-width: 1.5; cursor: crosshair; }
#screen .hdl:hover { fill: var(--sel); }
#screen .hdl.knee { fill: #dbe6fd; }
/* Snap to Content reticle: square = endpoint, diamond = intersection / midpoint */
#screen .snap-ret { fill: none; stroke: var(--snap); stroke-width: 1.5; pointer-events: none; }
#screen .snap-ret.halo { stroke: var(--snap-halo); stroke-width: 3.5; }
#screen .snap-dot { fill: var(--snap); pointer-events: none; }
#world .hit { fill: #ffd21f; fill-opacity: .38; }
#world .hit.cur { fill: #ff8a00; fill-opacity: .45; stroke: #c25e00; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#world .mk { cursor: inherit; }
.stage[data-tool="select"] #world .mk { cursor: move; }
#world text { font-family: Helvetica, Arial, sans-serif; }

/* floating surfaces on the well */
.float { background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); }
.toolopts { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 2; display: flex; align-items: center; gap: 10px; padding: 0 12px; height: 34px; background: var(--raised); border-radius: 999px; box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); max-width: calc(100% - 24px); font-size: 12px; white-space: nowrap; color: var(--text-2); }
.toolopts:empty { display: none; }
.toolopts .k { color: var(--muted); }
.toolopts .k + .k::before { content: "·"; margin-right: 10px; color: var(--faint); }
.toolopts input { height: 24px; font-size: 12px; border-radius: 999px; padding: 0 10px; }
.toolopts select, .toolopts button { height: 24px; font-size: 12px; }
.toolopts .total { font-family: var(--mono); color: var(--text); font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--neutral-soft); }

.searchbar { position: absolute; top: 12px; right: 12px; z-index: 3; display: flex; align-items: center; gap: 2px; height: 38px; padding: 0 5px 0 12px; background: var(--raised); border-radius: var(--r-lg); box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); }
.searchbar > .ico { color: var(--muted); }
.searchbar input { width: 200px; height: 28px; border: 0; padding: 0 8px; outline: none; background: transparent; }
.searchbar input:focus-visible { outline: none; }
.searchbar .search-count { font-size: 11px; color: var(--muted); min-width: 96px; text-align: right; padding-right: 8px; white-space: nowrap; }
.searchbar .vsep { margin: 0 4px 0 0; }
.searchbar .icon-btn { height: 28px; width: 28px; }
#app.cmp-on .searchbar { top: 62px; }

.comparebar { position: absolute; top: 12px; left: 0; right: 0; margin: 0 auto; width: max-content; z-index: 3; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 8px; min-height: 40px; padding: 4px 8px 4px 12px; background: var(--raised); border-radius: var(--r-lg); box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); font-size: 12px; max-width: calc(100% - 24px); box-sizing: border-box; white-space: nowrap; }
/* v4.3: no control is ever squeezed or clipped; if the bar cannot fit one row it wraps (last resort) */
.comparebar > *, .nudge > * { flex-shrink: 0; }
.cmp-ico { color: var(--accent-text); }
.cmp-pair { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.cmp-pair .pick { height: 26px; padding: 0 6px 0 9px; box-shadow: none; }
.cmp-pair .pick .mono { font-size: 11.5px; color: var(--text); white-space: nowrap; }
.nudge { display: flex; flex-wrap: nowrap; align-items: center; gap: 1px; }
.nudge .icon-btn { width: 24px; height: 24px; }
.nudge .icon-btn svg { width: 14px; height: 14px; }
.nudge .seg { margin-left: 4px; }
.nudge .cmp-auto { height: 26px; margin-left: 6px; padding: 0 9px; font-size: 12px; box-shadow: none; display: inline-flex; align-items: center; }
.nudge .cmp-auto:disabled { opacity: .55; }
.cmp-off { display: inline-flex; flex-direction: column; align-items: flex-end; justify-content: center; font-size: 11px; line-height: 1.2; color: var(--muted); min-width: 64px; margin: 0 4px 0 8px; text-align: right; }
.cmp-off.two { font-size: 10.5px; }
.cmp-off.two span + span { color: var(--text-2); }
#cmpReset { margin-left: 2px; }
.comparebar > button.ghost { height: 26px; font-size: 12px; padding: 0 10px; box-shadow: none; }
.cmp-legend { position: absolute; left: 12px; bottom: 12px; z-index: 3; display: flex; gap: 14px; align-items: center; height: 32px; padding: 0 12px; background: var(--raised); border-radius: var(--r-lg); box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); font-size: 12px; color: var(--text-2); white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; }
.cmp-legend i { display: inline-block; width: 9px; height: 9px; margin-right: 7px; vertical-align: -.5px; border-radius: 2px; }
.cmp-label { position: absolute; top: 64px; z-index: 2; padding: 3px 8px; font: 500 11.5px var(--sans); background: var(--text); color: var(--panel); border-radius: 5px; pointer-events: none; white-space: nowrap; }
.cmp-label.rev1 { background: var(--rev1); color: #fff; }
.cmp-label.rev2 { background: var(--rev2); color: #fff; }
.wipe { position: absolute; top: 0; bottom: 0; width: 0; z-index: 2; }
.wipe-line { position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: var(--accent); box-shadow: 0 0 0 1px rgba(255, 255, 255, .6); pointer-events: none; }
.wipe-grip { position: absolute; top: 50%; left: -16px; width: 32px; height: 32px; margin-top: -16px; padding: 0; border-radius: 50%; background: var(--panel); border: 1.5px solid var(--accent); color: var(--accent-text); display: grid; place-items: center; cursor: ew-resize; touch-action: none; box-shadow: var(--shadow-pop); }
.wipe-grip svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.popover { position: absolute; top: 12px; right: 12px; z-index: 4; width: 284px; padding: 14px; background: var(--raised); border-radius: var(--r-lg); box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); display: grid; gap: 8px; }
.popover p { margin: 0 0 4px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.pop-title { font-weight: 600; }
.readout-tip { position: absolute; pointer-events: none; padding: 3px 7px; background: var(--tip-bg); color: var(--tip-fg); border-radius: 5px; font-size: 12px; white-space: nowrap; transform: translate(14px, 14px); box-shadow: 0 4px 14px rgba(0, 0, 0, .18); }
.editor { position: absolute; resize: none; border: 1px solid var(--sel); border-radius: 0; background: #fff; padding: 0; overflow: hidden; font-family: Helvetica, Arial, sans-serif; line-height: 1.25; outline: none; }

.calib { position: absolute; width: 308px; background: var(--raised); border-radius: var(--r-lg); padding: 14px; display: grid; gap: 10px; box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); z-index: 4; }
.calib-title { font-weight: 600; }
.calib-row { display: grid; grid-template-columns: 116px minmax(0, 1fr); align-items: center; gap: 8px; font-size: 12.5px; }
.calib-err { color: var(--danger); font-size: 12px; }
.calib-err:empty { display: none; }
.calib-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 2px; }

.empty { position: absolute; inset: 0; display: none; place-items: center; overflow: auto; padding: 20px; background: radial-gradient(ellipse at 50% 38%, var(--panel), transparent 75%), var(--mat); touch-action: pan-y; }
.no-doc .empty { display: grid; }
.empty::before { position: absolute; inset: 0; content: ""; pointer-events: none; background: linear-gradient(to right, var(--grid) 1px, transparent 1px) center / 24px 24px, linear-gradient(to bottom, var(--grid) 1px, transparent 1px) center / 24px 24px; mask-image: radial-gradient(ellipse, #000 12%, transparent 80%); }
.empty-card { position: relative; width: min(436px, 100%); padding: 24px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--raised); box-shadow: var(--shadow-pop), inset 0 1px var(--highlight); text-align: center; }
.empty-mark { display: block; width: 76px; height: 58px; margin: 0 auto 14px; padding: 9px; fill: none; stroke: var(--accent-text); stroke-width: 1.25; border: 1px dashed var(--accent-line); border-radius: 10px; background: var(--accent-soft); }
.empty-title { margin: 0 0 8px; font-size: clamp(20px, 3vw, 26px); line-height: 1.16; font-weight: 720; letter-spacing: -.035em; }
.empty-card p { margin: 0 auto 19px; max-width: 32ch; color: var(--muted); line-height: 1.5; }
.empty-actions { display: flex; justify-content: center; gap: 7px; flex-wrap: wrap; }
.empty-actions button { height: 36px; }
.empty-actions .empty-compare { border-color: transparent; background: transparent; box-shadow: none; color: var(--accent-text); }
.empty-shortcuts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 14px; margin-top: 18px; padding-top: 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.empty-shortcuts span { display: inline-flex; align-items: center; gap: 5px; }
.empty-shortcuts kbd { padding: 3px 5px; border: 1px solid var(--line); border-radius: 4px; background: var(--track); color: var(--text-2); box-shadow: var(--shadow-1); }
.drop { position: absolute; inset: 10px; border: 1.5px dashed var(--accent); border-radius: var(--r-lg); background: var(--accent-soft); display: grid; place-items: center; color: var(--accent-text); font-weight: 600; pointer-events: none; z-index: 10; }

/* ---------- inspector (right) ---------- */
.props { grid-area: props; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--inspector); min-height: 0; min-width: 0; overflow: hidden; }
.props > * { min-width: 264px; }
#propsKind { display: inline-flex; align-items: center; gap: 6px; font: 400 11.5px var(--sans); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.kind-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.props-body { flex: 1; overflow-y: auto; padding: 0 0 12px; scrollbar-width: thin; animation: fade-in .16s var(--ease); }
.ins-sec { padding: 13px 14px; border-bottom: 1px solid var(--line); display: grid; gap: 9px; }
.ins-sec:last-child { border-bottom: 0; }
.ins-h { font-size: 12px; font-weight: 700; color: var(--text); }
.ins-line { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); }
.ins-line .v { font: 11px var(--mono); color: var(--text-2); }
.ins-ctl { display: grid; gap: 6px; }
.ins-readout { padding: 14px; border-bottom: 1px solid var(--line); background: var(--panel); box-shadow: inset 0 1px var(--highlight); }
.ro-lbl { font-size: 11.5px; color: var(--muted); }
.prop-meas { font: 600 26px/1.15 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin-top: 4px; color: var(--text); }
.ro-cap { font-size: 11.5px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field { display: grid; gap: 5px; }
.field .lbl { font-size: 11.5px; color: var(--muted); }
.field input, .field textarea { width: 100%; font-size: 12.5px; }
.field textarea { height: 56px; resize: vertical; border: 1px solid var(--line-2); border-radius: var(--r); padding: 6px 8px; background: var(--field); line-height: 1.4; }
.status-pills { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.status-pills button { height: 26px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--panel); font-size: 12px; display: flex; align-items: center; gap: 7px; padding: 0 10px; color: var(--text-2); }
.status-pills button:hover:not(:disabled) { background: var(--panel-2); border-color: var(--accent-line); }
.status-pills button.on { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-text); font-weight: 550; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot.s-open { background: #8a919c; } .dot.s-accepted { background: var(--ok); } .dot.s-rejected { background: var(--danger); } .dot.s-back-checked { background: var(--accent); }
.swatches { display: flex; gap: 8px; align-items: center; }
.swatch-btn { width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); position: relative; }
.swatch-btn.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 3.5px var(--text); }
/* v4.3: "original artwork colours" swatch for symbols (white with a diagonal rule) */
.swatch-btn.sym-orig { background: linear-gradient(135deg, #fff 44%, #8a8a86 44% 56%, #fff 56%); }
:root[data-theme="dark"] .swatch-btn:not(.on) { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22); }
.widths { display: grid; grid-template-columns: repeat(6, 1fr); padding: 2px; gap: 2px; border-radius: 7px; background: var(--track); box-shadow: var(--shadow-inset); }
.widths button { height: 24px; border-radius: 5px; padding: 0; border: 0; display: grid; place-items: center; color: var(--muted); }
.widths button span { display: block; width: 16px; background: currentColor; border-radius: 1px; }
.widths button.on { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(15, 23, 42, .08); }
:root[data-theme="dark"] .widths button.on { background: var(--raised); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; padding: 0; border: 0; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(var(--accent), var(--accent)) 0 / var(--fill, 50%) 100% no-repeat, var(--press); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: #fff; border: 1px solid rgba(15, 23, 42, .2); box-shadow: 0 1px 3px rgba(15, 23, 42, .2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--press); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 1px solid rgba(15, 23, 42, .2); }
.stepper { display: inline-flex; align-items: center; height: 28px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--field); overflow: hidden; }
.stepper button { width: 26px; height: 26px; padding: 0; border: 0; border-radius: 0; color: var(--muted); display: grid; place-items: center; }
.stepper button:hover:not(:disabled) { background: var(--hover); }
.stepper button svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.stepper input { width: 48px; height: 26px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 0; text-align: center; padding: 0 2px; font: 12px var(--mono); background: transparent; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.font-line { display: flex; align-items: center; justify-content: space-between; }
.font-line .lbl { font-size: 11.5px; color: var(--muted); }
.meta { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 4px 8px; font-size: 11.5px; }
.meta span:nth-child(odd) { color: var(--muted); }
.meta span:nth-child(even) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 11px var(--mono); color: var(--text-2); padding-top: 1px; }
.prop-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 12px 14px 4px; }
.prop-actions button { height: 28px; font-size: 12.5px; }
.prop-actions .danger { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); box-shadow: none; }
.prop-actions .danger:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }
/* sheet overview (nothing selected) */
.ov-sheet { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: baseline; }
.ov-num { font: 11px var(--mono); color: var(--accent-text); padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); }
.ov-title { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-grid { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 6px 8px; font-size: 12px; }
.ov-grid span:nth-child(odd) { color: var(--muted); }
.ov-grid span:nth-child(even) { font-family: var(--mono); font-size: 11.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-scale { font: 600 15px var(--mono); color: var(--text); letter-spacing: -.01em; }
.ov-note { font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.ov-actions { display: flex; gap: 6px; }
.ov-actions button { flex: 1; display: inline-flex; justify-content: center; align-items: center; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 11.5px; }
.keys div { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; }
.keys kbd, .ov-actions kbd { font-size: 10.5px; color: var(--text-2); background: var(--neutral-soft); border-radius: 4px; padding: 2px 5px; flex: none; }
.ov-actions kbd { margin-left: 8px; }

/* ---------- markups drawer ---------- */
.markups { grid-area: list; position: relative; display: flex; flex-direction: column; height: 36px; border-top: 1px solid var(--line); background: var(--panel); min-height: 0; min-width: 0; }
#app.drawer-open .markups { height: var(--drawer-h); }
.drawer-grip { position: absolute; left: 0; right: 0; top: -4px; height: 8px; cursor: ns-resize; z-index: 3; }
.drawer-grip::after { content: ""; position: absolute; left: 50%; top: 2px; width: 32px; height: 3px; margin-left: -16px; border-radius: 2px; background: var(--line-2); opacity: 0; transition: opacity .12s; }
.markups:hover .drawer-grip::after, .drawer-grip.dragging::after { opacity: 1; }
.drawer-head { height: 35px; padding: 0 6px 0 8px; gap: 8px; border-bottom: 0; font-weight: 400; }
#app.drawer-open .drawer-head { border-bottom: 1px solid var(--line); }
.drawer-title { display: inline-flex; align-items: center; gap: 7px; height: 26px; padding: 0 8px; font-weight: 600; font-size: 12.5px; color: var(--text); border: 0; flex: none; }
.drawer-title:hover:not(:disabled) { background: var(--hover); }
.drawer-title .count { font-weight: 400; font-size: 11px; color: var(--muted); padding: 1px 6px; border-radius: 999px; background: var(--neutral-soft); }
.summary { display: flex; gap: 6px; min-width: 0; overflow: hidden; align-items: center; }
.summary.fade { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
.chip { font: 11.5px var(--mono); padding: 3px 8px; border-radius: 999px; background: var(--neutral-soft); white-space: nowrap; color: var(--text); }
.chip b { font-family: var(--sans); font-weight: 500; color: var(--muted); margin-right: 6px; font-size: 11.5px; }
.chip .muted { color: var(--faint); }
.author { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; flex: none; }
.author input { width: 124px; height: 26px; color: var(--text); font-size: 12px; }
#app:not(.drawer-open) .author { display: none; }
.drawer-head button.ghost { height: 26px; font-size: 12px; flex: none; }
#drawerToggle { flex: none; }
#drawerToggle svg { transition: transform .18s var(--ease); }
#app.drawer-open #drawerToggle svg { transform: rotate(180deg); }
.table-wrap { flex: 1; overflow: auto; min-height: 0; position: relative; scrollbar-width: thin; }
#app:not(.drawer-open) .table-wrap { display: none; }
#app.drawer-open .table-wrap { animation: fade-in .16s var(--ease); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { position: sticky; top: 0; z-index: 1; background: var(--panel-2); text-align: left; font-weight: 650; color: var(--muted); font-size: 11.5px; height: 28px; padding: 0 12px; box-shadow: inset 0 -1px var(--line-2); }
td { height: 30px; padding: 0 12px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
tbody tr { cursor: pointer; }
tbody tr:nth-child(even) td { background: var(--zebra); }
tbody tr:hover td { background: var(--hover); }
tbody tr.sel td { background: var(--accent-soft); }
tbody tr.sel td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
td.meas { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
td .swatch { display: inline-block; width: 8px; height: 8px; margin-right: 9px; border-radius: 2px; vertical-align: 0; }
td.mono { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
td .muted { color: var(--faint); }
.st { display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 0 8px 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 500; }
.st.s-open { background: var(--neutral-soft); color: var(--text-2); }
.st.s-accepted { background: var(--ok-soft); color: var(--ok); }
.st.s-rejected { background: var(--danger-soft); color: var(--danger); }
.st.s-back-checked { background: var(--accent-soft); color: var(--accent-text); }
.st .dot { width: 6px; height: 6px; }
.table-empty { padding: 16px 14px; color: var(--muted); font-size: 12.5px; }

/* ---------- status bar ---------- */
.statusbar { grid-area: status; display: flex; align-items: center; gap: 16px; padding: 0 12px; border-top: 1px solid var(--line); background: var(--panel-2); font-size: 11px; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; }
#memStatus { color: var(--faint); }
#renderStatus.busy::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: 1px; animation: pulse-dot 1s ease-in-out infinite alternate; }
@keyframes pulse-dot { to { opacity: .35; } }

@media (max-width: 1360px) {
  .scale-lbl, .brand-name { display: none; }
  .doc-name { border-left: 0; padding-left: 0; max-width: 160px; }
  #sampleBtn { display: none; }
  #app { grid-template-columns: 208px 48px minmax(0, 1fr) 248px; }
  #app.props-off { grid-template-columns: 208px 48px minmax(0, 1fr) 0; }
  .props > * { min-width: 248px; }
  .side-head .tab .mono, .cmp-off { display: none; }
  /* v4.3: the picker keeps its "Rev 2 sheet" label / tip; the readout moves into the Reset tooltip */
  .comparebar > .cmp-ico, .cmp-pair > span { display: none; }
}
@media (max-width: 1100px) {
  #app, #app.props-off { grid-template-columns: 180px 44px minmax(0, 1fr) 0; }
  .props, #propsToggle { display: none; }
  .doc-name, #calibrateBtn svg { display: none; }
  .cmp-pair, .author { display: none !important; }
}

/* ---------- benchmark mode (?bench): stage only, so the viewport matches the old 1600x1000 harness ---------- */
#app.bench { grid-template-columns: 0 0 minmax(0, 1fr) 0; grid-template-rows: 0 minmax(0, 1fr) 0 0; transition: none; }
#app.bench .topbar, #app.bench .sidebar, #app.bench .markups, #app.bench .statusbar, #app.bench .toolopts, #app.bench .props, #app.bench .rail { display: none; }

/* ---------- v3.1: stamp tool, Tool Chest, list filter / sort, recovery bar, autosave status ---------- */
.stage[data-tool="stamp"] { cursor: copy; }
.toolopts .stamp-pick { height: 24px; padding: 0 6px 0 8px; box-shadow: none; border-radius: 999px; gap: 6px; }
.toolopts .stamp-pick span { font: 600 11px var(--mono); color: var(--text); white-space: nowrap; }
.stamp-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.preset-tag { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 2px 0 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-weight: 550; }
.preset-tag i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.toolopts .preset-tag button { width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; color: inherit; }
.toolopts .preset-tag button:hover { background: var(--accent-soft); }
.preset-tag svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.toolopts .preset-tag + .k::before { content: none; }

/* sidebar tabs: three now, counts only on the active one so the header never overflows */
.side-head { gap: 2px; padding: 0 6px; }
.tabs { gap: 1px; }
.tab { padding: 0 6px; font-size: 12px; }
.tab:not(.active) .mono { display: none; }
#sheetView button { padding: 0 4px; }
@media (max-width: 1360px) { .side-head { padding: 0 4px; } .tab { padding: 0 5px; } #sheetView button { padding: 0 2px; } }

.chest-list { flex: 1; overflow-y: auto; padding: 4px 6px 10px; min-height: 0; scrollbar-width: thin; }
.chest-sec { display: flex; align-items: center; gap: 6px; padding: 10px 6px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.chest-sec .mono { font-weight: 400; font-size: 11px; color: var(--faint); }
.chest-item { position: relative; display: flex; align-items: center; border: 1px solid transparent; border-radius: var(--r); transition: background-color var(--control-speed), border-color var(--control-speed), box-shadow var(--control-speed); }
.chest-item:hover { border-color: var(--line); background: var(--panel); box-shadow: var(--shadow-1); }
.chest-item.on { border-color: var(--accent-line); background: var(--accent-soft); box-shadow: var(--shadow-1); }
.chest-use { flex: 1; min-width: 0; height: auto; display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; gap: 8px; padding: 6px 6px; border: 0; text-align: left; color: var(--text); }
.chest-use:hover:not(:disabled) { background: none; }
.chest-ico { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; background: var(--panel); box-shadow: 0 0 0 1px var(--line), var(--shadow-inset); }
:root[data-theme="dark"] .chest-ico { background: #23262e; }
.chest-ico svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.chest-txt { display: grid; min-width: 0; }
.chest-txt .n { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chest-txt .d { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chest-item.on .chest-txt .n { color: var(--accent-text); font-weight: 550; }
.chest-del { width: 24px; height: 24px; margin-right: 4px; opacity: 0; flex: none; }
.chest-item:hover .chest-del, .chest-del:focus-visible { opacity: 1; }
.chest-del svg { width: 13px; height: 13px; }
.chest-import { display: flex; gap: 6px; padding: 6px 6px 2px; }
.chest-import button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; font-size: 12px; }
.chest-sec .chest-src { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chest-sec .chest-del-set { margin-left: auto; width: 22px; height: 22px; opacity: .7; }
.chest-sec .chest-del-set:hover { opacity: 1; }
.chest-sec .chest-del-set svg { width: 12px; height: 12px; }
.chest-note { padding: 6px 8px 8px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* inspector: stamp fields + Save to Chest */
.field select { width: 100%; font-size: 12.5px; }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 8px; }
.field input.invalid { border-color: var(--danger); }
.prop-actions { grid-template-columns: 1fr 1fr; }
.prop-actions .chest-save { grid-column: 1 / -1; display: inline-flex; align-items: center; justify-content: center; }
.prop-actions .chest-save.done { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }

/* markups drawer: status + text filter, sortable headers */
.list-filter { display: flex; align-items: center; gap: 6px; flex: none; }
#app:not(.drawer-open) .list-filter { display: none; }
.status-pick { height: 26px; padding: 0 6px 0 9px; box-shadow: none; }
.status-pick .mono { font-family: var(--sans); font-size: 12px; color: var(--text); white-space: nowrap; }
.status-pick.on { border-color: var(--accent-line); background: var(--accent-soft); }
.status-pick.on .mono { color: var(--accent-text); }
.list-q { position: relative; display: flex; align-items: center; }
.list-q svg { position: absolute; left: 8px; width: 13px; height: 13px; color: var(--faint); pointer-events: none; }
.list-q input { width: 128px; height: 26px; padding: 0 8px 0 26px; font-size: 12px; }
.list-q input::-webkit-search-cancel-button { cursor: pointer; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
th[data-sort]::after { content: ""; display: inline-block; width: 0; height: 0; margin-left: 6px; vertical-align: 2px; border: 3.5px solid transparent; opacity: 0; }
th[data-sort]:hover::after { opacity: .35; border-top-color: currentColor; border-bottom-width: 0; }
th.sorted { color: var(--text); }
th.sorted[data-dir="asc"]::after { opacity: 1; border-bottom-color: currentColor; border-top-width: 0; vertical-align: 2px; }
th.sorted[data-dir="desc"]::after { opacity: 1; border-top-color: currentColor; border-bottom-width: 0; }
.drawer-head button.ghost { padding: 0 9px; }
.author input { width: 104px; }

/* crash recovery: a quiet bar at the top of the canvas */
.recoverbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4; display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 6px 0 12px; background: var(--raised); border-radius: var(--r-lg); box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); font-size: 12.5px; white-space: nowrap; max-width: calc(100% - 24px); animation: tip-in .16s var(--ease); }
.recoverbar > .ico { color: var(--accent-text); }
.rec-text { display: grid; min-width: 0; line-height: 1.25; }
.rec-text #recoverText { font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.rec-sub { font-size: 11px; color: var(--muted); }
.rec-sub:empty { display: none; }
.recoverbar button { height: 28px; }

/* status bar: autosave indicator */
.save-status { display: inline-flex; align-items: center; gap: 6px; }
.save-status:empty { display: none; }
.save-status.saved::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.save-status.saving::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.save-status.paused, .save-status.error { color: var(--danger); }
#app.bench .recoverbar { display: none; }
@media (max-width: 1100px) { .side-head { padding: 0 3px; gap: 1px; } .tab { padding: 0 4px; font-size: 11.5px; } }
th { white-space: nowrap; }

/* ---------- v4: Live Review Sessions (share / join dialogs, presence, live cursors, author lock, threaded replies) ---------- */
#shareBtn { display: inline-flex; align-items: center; }
#shareBtn.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 38%, transparent); background: var(--ok-soft); box-shadow: none; }
#shareBtn.live::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 3px var(--ok-soft); margin-left: 7px; }
.presence { display: flex; align-items: center; gap: 8px; margin-right: 2px; }
.presence.retrying { opacity: .55; }
.avatars { display: flex; align-items: center; }
.avatar { --c: var(--muted); width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; background: var(--c); color: #fff; font: 600 10px/1 var(--sans); letter-spacing: .02em; box-shadow: 0 0 0 2px var(--panel); }
.avatars .avatar + .avatar { margin-left: -6px; }
.avatar.more { background: var(--neutral-soft); color: var(--text-2); }
.avatar.xs { width: 20px; height: 20px; font-size: 9px; box-shadow: none; }
.presence-count { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.presence-count.done { color: var(--muted); }
@media (max-width: 1500px) {
  .presence-count { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

/* live cursors: one absolutely positioned pointer + name tag per reviewer, moved with transforms (no layout) */
.cursors { position: absolute; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.rcursor { --c: #1d4ed8; position: absolute; left: 0; top: 0; display: flex; align-items: flex-start; transition: transform 70ms linear; will-change: transform; }
.rcursor svg { width: 16px; height: 16px; fill: var(--c); stroke: #fff; stroke-width: 1.1; stroke-linejoin: round; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .25)); }
.rc-name { margin: 12px 0 0 -2px; padding: 2px 7px; border-radius: 4px; background: var(--c); color: #fff; font: 550 11px/16px var(--sans); white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }

/* dialogs */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); backdrop-filter: blur(6px); animation: fade-in var(--control-speed) var(--ease); }
.modal { position: fixed; z-index: 41; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(456px, calc(100% - 28px)); max-height: calc(100% - 32px); overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; background: var(--raised); border: 1px solid var(--line-2); border-radius: 15px; box-shadow: var(--shadow-modal), inset 0 1px var(--highlight); animation: dialog-in var(--control-speed) var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translate(-50%, calc(-50% + 5px)); } }
@keyframes modal-in { from { opacity: 0; transform: translate(-50%, 4px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes fade-in { from { opacity: 0; } }
.modal-form { --dialog-pad: 22px; display: grid; gap: 14px; min-width: 0; padding: 0 var(--dialog-pad) 20px; }
.modal-head { display: flex; align-items: center; gap: 8px; min-height: 70px; margin-inline: calc(-1 * var(--dialog-pad)); padding: 14px var(--dialog-pad); border-bottom: 1px solid var(--line); background: var(--panel); box-shadow: inset 0 1px var(--highlight); }
.modal-title { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 19px; line-height: 1.2; font-weight: 700; letter-spacing: -.025em; }
.modal-title::before { content: ""; width: 28px; height: 28px; flex: none; border-radius: 6px; background: url("./favicon.svg") center / contain no-repeat; box-shadow: 0 0 0 1px var(--line-2); }
.modal-x { margin-left: auto; flex: none; background: var(--track); border-color: var(--line); }
.modal-p { margin: 0; font-size: 13px; color: var(--text-2); line-height: 1.55; overflow-wrap: anywhere; }
.modal-p.small { font-size: 12px; color: var(--muted); }
.modal-p b { color: var(--text); font-weight: 600; }
.modal-note { display: flex; align-items: flex-start; gap: 8px; padding: 10px 11px; border: 1px solid var(--line); border-radius: var(--r); background: var(--track); font-size: 12px; color: var(--text-2); line-height: 1.5; overflow-wrap: anywhere; }
.modal-note .ico { margin-top: 1px; color: var(--muted); }
.modal-err { padding: 9px 11px; border: 1px solid var(--danger-line); border-radius: var(--r); background: var(--danger-soft); color: var(--danger); font-size: 12.5px; line-height: 1.45; overflow-wrap: anywhere; }
.modal-err:empty { display: none; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; margin-top: 2px; }
.modal-form > .modal-actions { margin: 2px calc(-1 * var(--dialog-pad)) -20px; padding: 13px var(--dialog-pad); border-top: 1px solid var(--line); background: var(--panel); }
.modal-actions button.sm { height: 36px; padding-inline: 12px; }
.modal-actions.left { justify-content: flex-start; flex-wrap: wrap; }
.modal-actions .danger { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); box-shadow: none; }
.modal-sec { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.modal-sec .lbl, .rev-head .lbl { font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.modal .field input { height: 40px; border: 1px solid var(--line-2); border-radius: var(--r); padding: 0 11px; background: var(--field); box-shadow: var(--shadow-inset); font-size: 13px; transition: border-color var(--control-speed); }
.modal .field .lbl { font-size: 12.5px; font-weight: 650; color: var(--text); }
.modal .field input:focus { outline: none; border-color: var(--accent-text); box-shadow: var(--shadow-inset), 0 0 0 3px var(--focus-ring); }
.ghost-link { font-size: 12px; font-weight: 600; color: var(--accent-text); text-decoration: none; }
.ghost-link:hover { color: var(--text); text-decoration: underline; }
.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; min-width: 0; font-size: 12px !important; color: var(--text); }
.copy-row button { height: 40px; min-width: 64px; }
.copy-row button.done { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.live-chip { display: inline-flex; align-items: center; gap: 6px; height: 21px; padding: 0 8px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); font: 650 11px/1 var(--sans); white-space: nowrap; }
.live-chip::before, .ms-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 3px var(--ok-soft); }
.live-chip.done::before, .ms-status.done::before { background: var(--faint); box-shadow: none; }
.live-chip.done { background: var(--neutral-soft); color: var(--muted); }
.rev-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: -4px; }
.rev-count { font-size: 11px; color: var(--muted); }
.rev-list { display: grid; gap: 3px; max-height: 180px; overflow-y: auto; padding: 4px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.rev { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 7px; border-radius: var(--r); font-size: 12.5px; }
.rev:hover { background: var(--hover); }
.rev .avatar { box-shadow: none; }
.rev.off { color: var(--muted); }
.rev-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rev .tag { height: 18px; padding: 0 6px; border-radius: 4px; background: var(--neutral-soft); color: var(--muted); font-size: 10.5px; line-height: 18px; }
.rev-state { font-size: 11px; font-weight: 600; color: var(--ok); }

.rev.off .rev-state { color: var(--muted); }
.modal[data-kind="session"] { width: min(516px, calc(100% - 28px)); }

.toast { position: fixed; z-index: 60; left: 50%; bottom: 40px; transform: translateX(-50%); max-width: min(560px, calc(100vw - 32px)); padding: 8px 12px; border-radius: var(--r); background: var(--tip-bg); color: var(--tip-fg); font-size: 12.5px; line-height: 1.4; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); animation: modal-in .14s var(--ease); transition: opacity .18s; }
.toast.out { opacity: 0; }

/* author lock + threaded replies in the inspector */
.lock-badge { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 3px 8px; margin: 12px 14px 0; padding: 9px 10px; border: 1px solid var(--accent-line); border-radius: var(--r); background: var(--accent-soft); color: var(--text); font-size: 12px; font-weight: 650; overflow-wrap: anywhere; }
.lock-badge .ico { width: 14px; height: 14px; color: var(--accent-text); }
.lock-badge .lock-sub { grid-column: 2; font-weight: 400; font-size: 11.5px; color: var(--muted); }
.props-body :disabled { cursor: not-allowed; }
.replies-h { display: flex; align-items: center; gap: 6px; }
.reply-n { font-weight: 400; font-size: 11px; color: var(--faint); }
.reply-list { display: grid; gap: 10px; max-height: 240px; overflow-y: auto; }
.reply { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.reply-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; font-size: 11.5px; }
.reply-meta b { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-meta .mono { font-size: 10.5px; color: var(--faint); white-space: nowrap; }
.reply-text { margin-top: 3px; font-size: 12.5px; color: var(--text-2); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.reply-empty { font-size: 12px; color: var(--faint); }
.reply-box { display: flex; align-items: flex-end; gap: 6px; }
.reply-box textarea { flex: 1; min-width: 0; height: 30px; min-height: 30px; resize: none; border: 1px solid var(--line-2); border-radius: var(--r); padding: 6px 8px; background: var(--field); font-size: 12.5px; line-height: 1.4; }
.reply-box button { height: 30px; flex: none; }
.reply-badge { display: inline-flex; align-items: center; gap: 3px; margin-right: 7px; padding: 0 5px; height: 17px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font: 600 10.5px/17px var(--mono); vertical-align: 1px; }
.reply-badge svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
#markupRows td .cmt { overflow: hidden; text-overflow: ellipsis; }
td.auth { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lock-ico { width: 12px; height: 12px; margin-right: 4px; vertical-align: -1px; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linejoin: round; }
#app.session-done .rail button:not([data-tool="select"]):not([data-tool="pan"]) { opacity: .38; }
.reply-box textarea { overflow-y: hidden; }
.props-body input:disabled, .props-body textarea:disabled, .props-body select:disabled { opacity: .62; background: var(--panel-2); }
.props-body .swatch-btn:disabled, .props-body .widths button:disabled { opacity: .45; }

/* v4.2: imported symbol artwork in the Tool Chest list (draws its own colours on white paper) */
.chest-ico svg.sym-ico { width: 22px; height: 22px; stroke: none; fill: none; background: #fff; border-radius: 4px; }

/* v6 accounts: top-bar Sign in / account pill, account popover, sign-in dialog, My Sessions */
.account { display: flex; align-items: center; flex: none; }
.account-pill { height: 30px; padding: 0 6px 0 4px; display: inline-flex; align-items: center; gap: 4px; border-color: var(--line-2); border-radius: 999px; background: var(--panel); box-shadow: var(--shadow-1); }
.account-pill:hover:not(:disabled), .account-pill[aria-expanded="true"] { background: var(--panel-2); }
.account-pill .chev { width: 12px; height: 12px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.acct-avatar { --c: #1d4ed8; }
.account-pop { position: fixed; z-index: 45; top: 48px; right: 12px; width: min(268px, calc(100vw - 24px)); padding: 7px; display: grid; gap: 3px; background: var(--raised); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow-pop), inset 0 1px var(--highlight); animation: modal-in-pop var(--control-speed) var(--ease); }
@keyframes modal-in-pop { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.acct-head { display: flex; align-items: flex-start; gap: 10px; min-width: 0; padding: 8px 9px 6px; }
.acct-head .avatar { width: 36px; height: 36px; font-size: 12px; box-shadow: 0 0 0 3px var(--accent-soft); }
.acct-id { min-width: 0; display: grid; justify-items: start; gap: 2px; }
.acct-name { max-width: 100%; font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-email { max-width: 100%; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-plan { height: 20px; margin-top: 4px; padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font: 650 11px/20px var(--sans); }
.acct-sep { height: 1px; background: var(--line); margin: 3px -7px; }
.menu-item { display: flex; align-items: center; width: 100%; height: 34px; padding: 0 9px; font-size: 12.5px; color: var(--text); text-align: left; }
.menu-item:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-text); }
.menu-item svg.ico { margin-right: 8px; color: var(--muted); }
.auth-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 4px; gap: 3px; border: 1px solid var(--line); border-radius: 11px; }
.auth-tabs button { height: 34px; padding: 0 6px; border-radius: 8px; font-size: 12.5px; }
.auth-fine { flex: 1 0 auto; }
#authReason { padding: 9px 11px; border: 1px solid var(--accent-line); border-radius: var(--r); background: var(--accent-soft); }
.modal .field input.invalid { border-color: var(--danger); }
.modal.wide { width: min(626px, calc(100% - 28px)); }
.ms-count { padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 11.5px; }
.ms-count:empty { display: none; }
.ms-list { display: grid; gap: 8px; max-height: 50vh; overflow-y: auto; padding: 2px; margin: -2px; scrollbar-width: thin; }
.ms-row { display: flex; align-items: center; gap: 12px; min-height: 65px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); box-shadow: var(--shadow-1); transition: border-color var(--control-speed), box-shadow var(--control-speed); }
.ms-row:hover { border-color: var(--accent-line); box-shadow: 0 2px 6px var(--focus-ring); }
.ms-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.ms-file { font-size: 13.5px; font-weight: 650; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 7px; font-size: 11px; color: var(--muted); }
.ms-meta > span:nth-child(n + 3)::before { content: "\00b7"; margin-right: 7px; color: var(--faint); }
.ms-status { display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); font: 650 11px/1 var(--sans); }
.ms-status.done { background: var(--neutral-soft); color: var(--muted); }
.ms-actions { display: flex; gap: 6px; flex: none; }
.ms-actions button { height: 34px; }
.ms-actions button.done { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.ms-empty { padding: 14px 12px; border: 1px dashed var(--line-2); border-radius: var(--r); background: var(--panel); font-size: 12.5px; line-height: 1.5; color: var(--text-2); }
.ms-empty b { color: var(--text); font-weight: 600; }
@media (max-width: 560px) { .ms-row { flex-wrap: wrap; } .ms-actions { width: 100%; justify-content: flex-end; } }

@media (max-width: 880px) {
  #app, #app.props-off { grid-template-rows: auto minmax(0, 1fr) auto 24px; }
  .topbar { flex-wrap: wrap; min-height: 48px; gap: 5px; padding: 5px 8px; }
  .file-actions { flex: 0 1 auto; flex-wrap: wrap; min-width: 0; }
  .drawer-head { gap: 4px; padding-inline: 4px; }
  .list-q input { width: 104px; }
  .summary { display: none; }
}
@media (max-width: 620px) {
  #app, #app.props-off { grid-template-columns: 126px 39px minmax(0, 1fr) 0; }
  .side-head { flex-wrap: wrap; align-content: center; height: 58px; }
  .side-head > .grow { display: none; }
  .empty { padding: 10px; }
  .empty-card { padding: 14px 9px; }
  .empty-actions, .empty-shortcuts { gap: 6px; }
  .empty-actions button { max-width: 100%; white-space: normal; }
  .markups { height: auto; }
  .drawer-head { flex-wrap: wrap; align-content: center; height: auto; min-height: 35px; padding-block: 4px; }
  .comparebar > .vsep { display: none; }
  #cmpModes, .comparebar .nudge { flex-wrap: wrap; justify-content: center; max-width: 100%; }
  .toolopts { white-space: normal; height: auto; min-height: 34px; flex-wrap: wrap; }
  .searchbar { max-width: calc(100% - 16px); right: 8px; padding-left: 6px; }
  .searchbar .search-count { min-width: 0; padding-right: 2px; }
  .searchbar .icon-btn { width: 22px; flex: none; }
}
@media (max-width: 420px) {
  .modal-form { --dialog-pad: 15px; }
  .modal-head { min-height: 58px; }
  .modal-title { font-size: 17px; }
  .auth-fine:empty { display: none; }
  .auth-fine { flex-basis: 100%; }
  .ms-actions { justify-content: flex-start; flex-wrap: wrap; }
  .statusbar { gap: 6px; padding-inline: 6px; font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* ---------------------------------------------------------------- v7 Visual Search / Auto-Count */
#vsBtn.on { color: var(--accent-text); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-line); }
#vsBtn svg circle { fill: currentColor; stroke: none; }
.vs-banner svg circle { fill: currentColor; stroke: none; }
.stage.vs-on, .stage.vs-on #world .mk { cursor: crosshair; }
.stage.vs-on.panning { cursor: grab; }
/* on-paper marks: the paper is white in both themes, so these stay fixed colours */
#screen .vs-layer { pointer-events: none; }
#screen .vsm { pointer-events: all; cursor: pointer; }
#screen .vs-box { fill: rgba(37, 99, 235, .07); stroke: var(--sel); stroke-width: 1.5; }
#screen .vsm:hover .vs-box { stroke-width: 2.5; fill: rgba(37, 99, 235, .14); }
#screen .vsm.off .vs-box { fill: rgba(255, 255, 255, .55); stroke: #8a94a6; stroke-dasharray: 3 2.5; }
#screen .vsm.off:hover .vs-box { stroke: var(--sel); }
#screen .vs-tag rect { fill: var(--sel); }
#screen .vs-tag text { fill: #fff; font: 600 9.5px/1 var(--mono); }
#screen .vs-src { fill: none; stroke: var(--snap); stroke-width: 2; stroke-dasharray: 5 3; }
#screen .vs-marquee { fill: rgba(37, 99, 235, .08); stroke: var(--sel); stroke-width: 1.5; stroke-dasharray: 6 4; }
.vs-banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 16px 0 12px; background: var(--raised); border-radius: 999px; box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); font-size: 12.5px; color: var(--text-2); white-space: nowrap; max-width: calc(100% - 24px); pointer-events: none; animation: tip-in .16s var(--ease); }
.vs-banner .ico { color: var(--accent-text); flex: none; }
.vs-banner .vs-dot { color: var(--faint); }
.vs-banner kbd { display: inline-block; padding: 2px 5px; margin-right: 2px; border-radius: 4px; background: var(--neutral-soft); color: var(--text-2); }
.vs-panel { position: absolute; top: 12px; right: 12px; z-index: 5; width: 288px; max-height: calc(100% - 24px); overflow: auto; padding: 12px 14px 14px; display: grid; gap: 12px; background: var(--raised); border-radius: var(--r-lg); box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); font-size: 12.5px; color: var(--text-2); animation: tip-in .16s var(--ease); }
.searchbar:not([hidden]) ~ .vs-panel { top: 62px; }
.vs-head { display: flex; align-items: flex-start; gap: 8px; }
.vs-titles { display: grid; gap: 1px; flex: 1; min-width: 0; }
.vs-title { font-weight: 650; font-size: 13px; color: var(--text); }
.vs-sub { font-size: 11.5px; color: var(--muted); }
.vs-head .icon-btn { width: 26px; height: 26px; margin: -3px -7px 0 0; }
.vs-hero { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: center; }
.vs-thumb { width: 64px; height: 64px; border-radius: var(--r); background: #fff; box-shadow: inset 0 0 0 1px var(--line-2), var(--shadow-1); overflow: hidden; }
.vs-thumb canvas { width: 64px; height: 64px; display: block; }
.vs-stat { display: grid; gap: 6px; min-width: 0; }
.vs-badge { justify-self: start; display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent-line); font-size: 12px; font-weight: 650; white-space: nowrap; }
.vs-meta { font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.vs-err { padding: 8px 10px; border-radius: var(--r); background: var(--danger-soft); box-shadow: inset 0 0 0 1px var(--danger-line); color: var(--danger); font-size: 12px; line-height: 1.45; }
.vs-ctl { display: grid; gap: 6px; }
.vs-line { display: flex; justify-content: space-between; align-items: baseline; }
.vs-line .mono { color: var(--text); font-weight: 650; }
.vs-scale { display: flex; justify-content: space-between; gap: 6px; font-size: 10.5px; color: var(--faint); }
.vs-check { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text-2); }
.vs-check input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.vs-ctl .swatches { margin-top: 4px; }
.vs-hint { font-size: 11.5px; color: var(--faint); }
.vs-actions { display: flex; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.vs-actions .primary { min-width: 120px; }

/* ---------- v8: Page Tools strip (Sheets sidebar) + document tabs (only with 2+ documents open) ---------- */
.page-tools { display: flex; align-items: center; gap: 2px; height: 38px; padding: 0 8px; border-bottom: 1px solid var(--line); background: var(--panel-2); flex: none; min-width: 0; }
#app.no-doc .page-tools { display: none; }
.pt-btn { width: 28px; height: 28px; padding: 0; display: inline-grid; place-items: center; flex: none; color: var(--muted); border: 1px solid transparent; border-radius: var(--r-sm); }
.pt-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.pt-btn:hover:not([aria-disabled="true"]) { color: var(--text); background: var(--raised); border-color: var(--line); box-shadow: var(--shadow-1), inset 0 1px var(--highlight); }
.pt-btn:active:not([aria-disabled="true"]) { background: var(--press); box-shadow: none; transform: translateY(1px); }
.pt-btn[aria-disabled="true"] { opacity: .38; cursor: default; }
.pt-sep { flex: 1; }
.pt-danger:hover:not([aria-disabled="true"]) { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-line); box-shadow: none; }
@media (max-width: 1100px) { .page-tools { padding: 0 4px; gap: 0; } .pt-btn { width: 27px; } }
@media (max-width: 620px) { .pt-btn { width: 23px; } .page-tools { padding: 0 2px; } }

#app.multi-doc {
  grid-template-rows: 48px 32px minmax(0, 1fr) auto 24px;
  grid-template-areas: "top top top top" "side rail tabs props" "side rail stage props" "side list list props" "status status status status";
}
.doc-tabs { grid-area: tabs; position: relative; z-index: 4; display: flex; align-items: stretch; min-width: 0; height: 32px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.dt-list { display: flex; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.dt { position: relative; display: flex; align-items: center; flex: 0 1 auto; min-width: 72px; max-width: 248px; border-right: 1px solid var(--line); transition: background-color var(--control-speed); }
.dt:hover { background: var(--hover); }
.dt-main { display: flex; align-items: center; gap: 6px; min-width: 0; height: 31px; padding: 0 2px 0 12px; border: 0; border-radius: 0; background: none; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.dt-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt-count { flex: none; padding: 1px 6px; border-radius: 999px; background: var(--neutral-soft); color: var(--faint); font-size: 10.5px; font-weight: 400; }
.dt-dirty { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent-text); }
.dt-close { flex: none; width: 22px; height: 22px; margin: 0 5px 0 2px; padding: 0; display: inline-grid; place-items: center; color: var(--faint); border-radius: 5px; opacity: 0; }
.dt-close svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.dt:hover .dt-close, .dt.active .dt-close, .dt-close:focus-visible { opacity: 1; }
.dt-close:hover:not([aria-disabled="true"]) { color: var(--text); background: var(--press); }
.dt.active { background: var(--mat); }
.dt.active .dt-main { color: var(--text); }
.dt.active .dt-count { background: var(--accent-soft); color: var(--accent-text); }
.dt.active::after { position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; content: ""; border-radius: 2px; background: var(--accent); }
.dt-add { flex: none; width: 26px; height: 26px; margin: 3px 6px; }
.dt-add svg { width: 14px; height: 14px; }
.dt-main[aria-disabled="true"], .dt-close[aria-disabled="true"], .dt-add[aria-disabled="true"] { opacity: .38; cursor: default; }
@media (max-width: 880px) { #app.multi-doc { grid-template-rows: auto 32px minmax(0, 1fr) auto 24px; } }

/* ---------- v9.1 touch, iPad and stylus (Apple Pencil / Surface Pen) ---------- */
/* invisible touch-sized hit target under each selection handle (drawn for touch / pen / coarse devices only) */
#screen .hdl-hit { fill: transparent; stroke: none; cursor: crosshair; }
.stage { -webkit-touch-callout: none; -webkit-user-select: none; overscroll-behavior: contain; }
@media (pointer: coarse) {
  .rail { gap: 4px; }
  .rail button { width: 42px; height: 42px; }
  .rail button svg { width: 20px; height: 20px; }
  .topbar button { min-height: 36px; min-width: 36px; }
  .zoom button { height: 32px; min-width: 32px; }
  .seg button { height: 30px; }
  #screen .hdl { stroke-width: 2; }
}

/* v9.2: PDF sheet links (Auto-Link or links already in the file): subtle box, the sheet stays readable */
#world .pdf-link { fill: rgba(37, 99, 235, .07); stroke: rgba(37, 99, 235, .55); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.stage.over-link, .stage.over-link #world .mk { cursor: pointer; }
.link-back { position: absolute; top: 12px; left: 12px; z-index: 3; display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 12px 0 8px; border-radius: var(--r-lg); background: var(--raised); color: var(--text); font-size: 12.5px; font-weight: 600; box-shadow: 0 0 0 1px var(--line), var(--shadow-pop); }
.link-back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.link-back:hover { background: var(--panel); }
/* v9.2: Slip-Sheet dialog */
.slip-sec { display: grid; gap: 6px; }
.slip-sec .lbl { font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.slip-list { list-style: none; margin: 0; padding: 4px; max-height: 196px; overflow: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: var(--r); background: var(--track); scrollbar-width: thin; }
.slip-row { display: flex; align-items: center; gap: 8px; min-height: 28px; padding: 3px 8px; border-radius: var(--r-sm); font-size: 12.5px; color: var(--text); }
.slip-row + .slip-row { border-top: 1px solid var(--line); }
.slip-row .mono { overflow-wrap: anywhere; }
.slip-row .slip-src { margin-left: auto; flex: none; font-size: 11px; color: var(--muted); }
.slip-row label { display: flex; align-items: center; gap: 8px; width: 100%; cursor: pointer; }
.slip-empty { padding: 6px 8px; font-size: 12px; color: var(--muted); }
.slip-opts { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.slip-opt { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; color: var(--text); cursor: pointer; }
.slip-opt input[type="checkbox"] { margin-top: 2px; flex: none; }
.slip-opt .sub { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.slip-opt select { height: 28px; margin-top: 6px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--field); color: var(--text); font-size: 12.5px; padding: 0 6px; }
.slip-opt select:disabled { opacity: .5; }
