/* ===== Base ===== */
* { box-sizing: border-box; }

:root {
  /* OP-1 Light / TX-6 inspired palette — warm cream, warm greys, orange, near-white */
  --bg:          #ece6d6;   /* page background — warm cream */
  --surface:     #f6f1e4;   /* tabs, cards — warm off-white */
  --surface-2:   #efe9d8;   /* side panels */
  --surface-3:   #e4dcc7;   /* pills, hint blocks */
  --line:        #cfc6ae;   /* borders — warm sand */
  --line-strong: #b4aa8d;
  --ink:         #35302a;   /* main text — warm charcoal */
  --ink-soft:    #7c7160;   /* secondary — warm taupe grey (not cold) */
  --key:         #e9e1cf;   /* keycap buttons — warm light grey */
  --key-hover:   #ddd4bd;
  --dark:        #3c362e;   /* primary buttons — warm dark grey */
  --dark-hover:  #4e473a;
  --paper:       #fffef9;   /* inputs — bright near-white */
  --light:       #fbf7ec;   /* bright warm near-white accent */
  --accent:      #ff6b00;   /* Teenage Engineering orange */
  --accent-dark: #d95500;
  --ref:         #d0342c;   /* reference line red */
  --warn:        #a85b00;
  --ok:          #4a6b3a;
  --lcd-bg:      #2c2820;   /* LCD — warm near-black */
  --lcd-text:    #ffa233;   /* LCD text — amber */
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

#app { max-width: 1200px; margin: 0 auto; padding: 12px 16px 0; }

.app-header h1 { margin: 0 0 6px; font-size: 1.5rem; letter-spacing: 0.02em; }
.third-party-notices-link {
  display: inline-block;
  color: var(--ink-soft);
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.third-party-notices-link:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 3px; border-radius: 2px; }
#auth-wall .third-party-notices-link { margin-top: 16px; }
.settings-license-link {
  display: block;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.74rem;
  text-align: right;
  text-underline-offset: 2px;
}
.settings-license-link:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 3px; border-radius: 2px; }

.settings-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 6px 0 12px;
}
.settings-bar label { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--ink-soft); }

/* Discrete image-load cap. The range input supplies keyboard/screen-reader
   control; the dots make the six fixed choices visible at a glance. */
.image-cap-control {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: min(100%, 330px);
  margin: 4px 0 9px;
  color: var(--ink-soft);
  font-size: 0.75rem;
}
.image-cap-control[hidden] { display: none; }
.image-cap-heading,
.image-cap-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.image-cap-heading label { color: var(--ink); font-weight: 700; }
.image-cap-heading output { color: var(--accent-dark); margin-left: 3px; }
.image-cap-context,
.image-cap-hint { color: var(--ink-soft); font-size: 0.68rem; }
.image-cap-slider { position: relative; height: 18px; margin: 0 4px; }
.image-cap-slider input {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.image-cap-dots {
  position: absolute;
  z-index: 1;
  top: 50%;
  right: 7px;
  left: 7px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: center;
  transform: translateY(-50%);
  pointer-events: none;
}
.image-cap-dots span {
  justify-self: center;
  width: 7px;
  height: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
}
.image-cap-dots span.is-active {
  border-color: var(--accent-dark);
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--surface);
}
.image-cap-labels { color: var(--ink-soft); font-size: 0.64rem; line-height: 1; }
.image-cap-labels span { width: 16.666%; text-align: center; }
.image-cap-labels span:first-child { text-align: left; }
.image-cap-labels span:last-child { text-align: right; }

body[data-ui-layout="compact"] .image-cap-control {
  flex: 0 1 300px;
  width: min(300px, 34vw);
  margin: 0;
}
body[data-ui-layout="compact"] .image-cap-hint { display: none; }
@media (max-width: 760px) {
  body[data-ui-layout="compact"] .app-header { flex-wrap: wrap; }
  body[data-ui-layout="compact"] .image-cap-control { order: 4; flex-basis: 100%; width: 100%; }
}

/* ===== Settings menu (permanently enabled, DECISIONS #160) =====
   A single dropdown on the right of the header: Unit, Inches precision,
   Paper size and Sign out. Filled by app.js (relocates the existing paper/unit
   selects + sign-out button so all listeners keep working). Slides down on
   open, closes on outside click. When enabled, the old header .settings-bar and
   the bottom .side-settings block are hidden. */
.settings-btn-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.settings-backdrop { position: fixed; inset: 0; z-index: 1400; background: rgba(0, 0, 0, 0.48); }
.settings-backdrop[hidden] { display: none; }
@media print { .settings-backdrop { display: none !important; } }
.settings-btn-wrap.settings-open { z-index: 1401; }
.fullscreen-status { display: block; max-width: min(320px, calc(100vw - 32px)); margin-top: 4px; color: var(--ink-soft); font-size: .8rem; }
.fullscreen-status[hidden] { display: none; }
.settings-btn-wrap[hidden] { display: none; }
#browser-fullscreen,
#settings-btn {
  min-height: 34px;
  padding: 6px 10px;
  font: 600 0.9rem/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  white-space: nowrap;
}
.settings-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(384px, calc(100vw - 28px));
  min-width: 0;
  max-height: calc(100dvh - 100px);
  overflow: auto;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  padding: 14px 18px;
  transform-origin: top right;
}
.settings-menu.open {
  display: block;
  animation: slideDown 0.16s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.settings-menu label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
.settings-menu select { font: inherit; font-weight: 500; color: var(--ink); max-width: 100%; min-width: 0; }
.settings-info {
  color: var(--ink-soft);
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1.35;
  margin: 0 0 7px;
  overflow-wrap: anywhere;
}
.settings-info + .settings-info { margin-top: -2px; }
#app-version {
  margin-top: 12px;
  margin-bottom: 0;
  padding-top: 6px;
  text-align: right;
  font-size: 0.7rem;
}
body[data-settings-menu="on"] .settings-bar { display: none !important; }
body[data-settings-menu="on"] .side-settings { display: none !important; }
.settings-menu #sign-out-btn { margin-top: 5px; }
.settings-menu #privacy-settings { margin-top: 8px; }
body[data-settings-menu="on"] .settings-btn-wrap { margin-left: auto; }

.tabs { display: flex; gap: 4px; margin: 8px 0 0; }
.tabs button {
  border: 1px solid var(--line);
  border-bottom: none;
  background: var(--key);
  color: var(--ink-soft);
  border-radius: 8px 8px 0 0;
  padding: 8px 18px;
  font-weight: 600;
  cursor: pointer;
}
/* Active tab welds onto the panel below it: it shares the panel's surface and
   overlaps the panel's top border by 1px, so tab + content read as one box with
   a single outline (no separating line across the top). */
.tabs button.active {
  position: relative;
  z-index: 1;
  background: var(--surface);
  color: var(--accent-dark);
  margin-bottom: -1px;
  padding-bottom: 9px;
}
.tabs button:hover { background: var(--key-hover); color: var(--ink); }

main .tab { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 1.05rem; }
.card p { margin: 8px 0; line-height: 1.5; }

.hint { color: var(--ink-soft); font-size: 0.9rem; background: var(--light); padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row label { margin-right: 2px; }

input, select, button { font: inherit; padding: 8px 10px; border-radius: 6px; }
input, select { border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink); }
input:focus, select:focus { border-color: var(--accent); outline: 2px solid rgba(255, 107, 0, 0.25); outline-offset: 0; }
button {
  border: none;
  background: var(--dark);
  color: var(--paper);
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--dark-hover); }
button.secondary { background: var(--key); color: var(--ink); border: 1px solid var(--line); }
button.secondary:hover { background: var(--key-hover); }
button.ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); font-weight: 600; padding: 6px 10px; border-radius: 6px; }
button.ghost:hover { background: var(--key-hover); color: var(--ink); }
button.primary { background: var(--dark); color: var(--paper); padding: 10px 22px; border-radius: 8px; }

/* Crop-trim (flag): Apply/Undo crop buttons hidden until the feature is on and
   an applicable crop state exists (JS toggles their `hidden` attribute). */
.toolbar .crop-trim-only[hidden] { display: none; }
#undo-crop-btn { display: none !important; }

/* Auth wall — shown only when no valid session (see app.js boot()). */
#auth-wall {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
#auth-wall[hidden] { display: none; }
body:not([data-auth="signed-in"]) #app { visibility: hidden; }
.auth-wall-inner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px 32px;
  max-width: 380px;
  text-align: center;
}
.auth-wall-inner h2 { margin: 0 0 10px; letter-spacing: 0.02em; }
.auth-wall-inner p { color: var(--ink-soft); margin: 0 0 18px; font-size: 0.95rem; line-height: 1.5; }

.result { font-weight: 600; color: var(--ok); }
.result.warn { color: var(--warn); }
.warn-text { color: var(--warn); font-weight: 600; }

#calibration-status { font-size: 0.95rem; }
#active-cal-status { font-weight: 600; }

/* ===== Workspace: canvas column + single right menu panel ===== */
.workspace {
  display: grid;
  grid-template-columns: 1fr 220px;
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
  height: calc(100vh - 246px);
  min-height: 420px;
  overflow: hidden;
}

.canvas-column {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-panel {
  height: 100%;
  min-height: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  overflow-y: auto;
}
.panel-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

/* ===== Collapsible menu sections (accordion, one open at a time) ===== */
.menu-panel { display: flex; flex-direction: column; gap: 8px; }
.menu-section .menu-title {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--key);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.menu-section .menu-title:hover { background: var(--key-hover); }
.menu-section.open .menu-title {
  background: var(--dark);
  color: var(--paper);
  box-shadow: inset 3px 0 0 var(--accent);
}
.menu-section .menu-caret {
  font-size: 0.7rem;
  transition: transform 0.15s ease;
  color: inherit;
  opacity: 0.8;
}
.menu-section.open .menu-caret { transform: rotate(180deg); }
.menu-body { display: none; margin-top: 8px; }
.menu-section.open .menu-body { display: block; }

/* ===== Status strip (summary values, above the workspace) ===== */
.status-strip {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow: hidden;
  margin-bottom: 10px;
}
.status-strip .status-pill {
  background: #f6e7cd;
  border-color: #e6d0a3;
  color: #7a5f33;
}

/* ===== Vertical toolbar (side panel) ===== */
.toolbar.vertical { display: flex; flex-direction: column; gap: 6px; }
.toolbar button { background: var(--key); color: var(--ink); border: 1px solid var(--line); text-align: left; }
.toolbar button:hover { background: var(--key-hover); }
.toolbar button.active { background: var(--dark); color: var(--paper); box-shadow: inset 3px 0 0 var(--accent); }
.toolbar button.ref-tool.active { background: var(--ref); }
.toolbar button[data-tool="tape"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
}
.toolbar button[data-tool="tape"]:hover { background: var(--accent-dark); }
.toolbar button[data-tool="tape"].active {
  background: var(--dark);
  color: var(--paper);
  box-shadow: inset 3px 0 0 var(--accent);
}
.toolbar button.ref-tool {
  background: #f6e2d8;
  color: #a0441f;
  border-color: #e8bda6;
}
.toolbar button.ref-tool:hover { background: #f0d4c4; }
.toolbar .sep { width: 100%; height: 1px; background: var(--line); margin: 2px 0; }

.zoom-tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 12px;
}
.zoom-tools button { background: var(--key); color: var(--ink); border: 1px solid var(--line); padding: 8px 0; text-align: center; }
.zoom-tools button:hover { background: var(--key-hover); }

/* ===== Reference length panel (side panel) ===== */
.side-panel .ref-panel { margin-top: 12px; margin-bottom: 0; padding: 12px; border-color: var(--line); background: var(--light); }
.side-panel .ref-panel label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.side-panel .ref-panel input:not(.ftin-ft):not(.ftin-in) { width: 100%; }
.ref-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.side-panel .ref-panel .hint { font-size: 0.8rem; margin: 10px 0 0; }

/* ===== Canvas column ===== */
.canvas-head {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}
/* Two logical control groups below/above the canvas, each in its own box:
   measure (tape) vs print (grid, orientation, sheet count). */
.foot-section {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 8px 12px;
  min-width: 0;
}
.print-section { flex: 1 1 auto; }
.measure-section { flex: 0 0 auto; }
.history-section {
  flex: 0 0 auto;
  margin-left: auto;
  gap: 2px;
  padding: 2px;
}
#tab-image .history-button {
  display: inline-flex;
  flex: 0 0 auto;
  flex-direction: row;
  gap: 3px;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 0;
  min-height: 30px;
  height: 30px;
  padding: 0 4px;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
}
#tab-image .history-button .v2-tool-icon {
  display: grid;
  place-items: center;
  min-height: 0;
  font-size: 0;
  line-height: 1;
}
#tab-image .history-button .v2-tool-icon svg { width: 16px; height: 16px; }
#tab-image .history-button .v2-tool-label { font-size: inherit; font-weight: 600; line-height: 1; }
#tab-image .history-button:disabled,
#tab-image .history-button:disabled:hover {
  background: #ddd;
  color: #777;
  border-color: #bbb;
  cursor: not-allowed;
  opacity: 1;
  box-shadow: none;
}
.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--light);
}
.status-pill {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.lcd-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 0 0 auto;
}
.lcd-label {
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}
.lcd-readout {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--lcd-text);
  background: var(--lcd-bg);
  border: 1px solid #1e1b15;
  border-radius: 6px;
  padding: 3px 10px 5px;
  min-height: 26px;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lcd-readout.lcd-sheets {
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-width: 54px; /* holds two 2-digit numbers, e.g. 12x12 */
}
/* The tape readout is the flagship measure display: oversized and FIXED so it
   never resizes with content — it must fit up to "≈ 99′ 11 63/64″" (2-digit
   feet, 2-digit inches, 63/64ths) without changing its footprint. */
.lcd-readout.tape-readout {
  width: 320px;
  max-width: 320px;
  font-size: 20px;
  letter-spacing: 0.06em;
  padding: 7px 14px 9px;
  min-height: 38px;
}
.sheets-group {
  margin-left: auto;
}
.canvas-warn {
  flex: 1 1 100%;
  line-height: 1.35;
}
.print-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.print-bar button {
  white-space: nowrap;
  background: var(--accent);
  color: #fff;
}
.print-bar button:hover { background: var(--accent-dark); }
.print-bar button.is-printing,
.print-bar button.is-printing:hover {
  background: var(--accent-dark);
  cursor: wait;
  opacity: 0.78;
}
.canvas-warn.print-progress {
  color: var(--ink-soft);
}
/* Sliding grid-print switch (matching the app's flat palette) */
.print-grid-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  white-space: nowrap;
  color: var(--ink-soft);
}
.print-grid-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.print-grid-switch .pg-track {
  position: relative;
  width: 40px;
  height: 20px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  flex: none;
  transition: background 0.15s;
}
.print-grid-switch .pg-thumb {
  position: absolute;
  top: 50%;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transform: translateY(-50%);
  transition: left 0.15s;
}
.print-grid-switch input:checked + .pg-track {
  background: var(--accent);
  border-color: var(--accent-dark);
}
.print-grid-switch input:checked + .pg-track .pg-thumb { left: 22px; }
.print-grid-switch input:focus-visible + .pg-track { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Three-position print orientation: Auto / Landscape (H) / Portrait (V) */
.orient-seg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.orient-title {
  font-size: 0.7rem;
  color: var(--ink-soft);
}
.orient-opts {
  display: inline-flex;
  gap: 4px;
}
.orient-seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.orient-opt span {
  display: inline-block;
  padding: 3px 9px;
  font-size: 0.78rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  line-height: 1.3;
  transition: background 0.15s, color 0.15s;
}
.orient-opt input:checked + span {
  background: var(--dark);
  color: var(--paper);
  border-color: var(--dark);
}
.orient-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.foot-section button[data-tool="tape"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
}
.foot-section button[data-tool="tape"]:hover { background: var(--accent-dark); }
.foot-section button[data-tool="tape"].active {
  background: var(--dark);
  color: var(--paper);
  box-shadow: inset 3px 0 0 var(--accent);
}
#img-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}
#img-canvas.pan-tool, #img-canvas.is-pan-active { cursor: grab; }
#img-canvas.pan-tool:active, #img-canvas.is-pan-active:active { cursor: grabbing; }
#img-canvas.crop-tool { cursor: crosshair; }
#img-canvas.shape-adjust-tool { cursor: grab; }
#img-canvas.shape-adjust-tool:active { cursor: grabbing; }

.img-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
/* "Scaling info" dropdown: one button replaces the always-visible
   reference-line / scale / calibration pills. It opens a small panel under
   the button and closes on re-click, outside click, or Escape. */
.si-wrap { position: relative; }
.si-toggle { white-space: nowrap; }
.si-caret { font-size: 0.7rem; }
.si-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 240px;
  padding: 10px 12px;
  border: 1px solid var(--line, rgba(0, 0, 0, 0.14));
  border-radius: 8px;
  background: var(--paper, #fff);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}
.si-panel[hidden] { display: none; }
.si-item {
  font-size: 0.8rem;
  color: var(--ink, #222);
  font-weight: 600;
}

/* Live pipeline progress — a permanent 220px dock INSIDE the actions row,
   pushed to the right edge (`margin-left: auto`), so it shares the buttons'
   line and never costs the workspace a full row. The bar goes idle (empty),
   running (fills), waiting (shimmer), done (green 100%). */
.progress-dock[hidden] { display: none; } /* feature flag off */
.progress-dock {
  margin-left: auto;
  width: 220px;
  padding: 6px 10px;
  border: 1px solid var(--line, rgba(0, 0, 0, 0.14));
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.04);
}
.progress-dock[data-state="idle"] {
  border-style: dashed;
  border-color: var(--line, rgba(0, 0, 0, 0.1));
  background: transparent;
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 0.78rem;
}
.progress-label {
  font-weight: 600;
  color: var(--ink-soft, #555);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.progress-pct {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft, #555);
}
.progress-track {
  height: 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.12);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: var(--accent, #2d7ff9);
  transition: width 150ms linear;
}
.progress-dock[data-state="done"] .progress-fill { background: #2e9e5b; }
.progress-dock[data-state="idle"] .progress-fill,
.progress-dock[data-state="waiting"] .progress-fill { transition: none; }
.progress-dock[data-state="waiting"] .progress-track {
  background-color: rgba(0, 0, 0, 0.12);
  background-image: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  background-size: 40px 100%;
  animation: progress-shimmer 0.9s linear infinite;
}
@keyframes progress-shimmer {
  from { background-position: -40px 0; }
  to { background-position: 40px 0; }
}
.file-btn {
  background: var(--dark);
  color: var(--paper);
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
.file-btn:hover { background: var(--dark-hover); }

.switch-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.switch-label input {
  width: auto;
  padding: 0;
  accent-color: var(--accent);
}
.switch-label input:disabled { cursor: not-allowed; }
.switch-label:has(input:disabled) { color: #9a8f76; cursor: not-allowed; }

.experimental-badge {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-dark);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 1px 7px;
  line-height: 1.4;
  white-space: nowrap;
}

.tool-hint {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(46, 43, 36, 0.85);
  color: var(--paper);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  pointer-events: none;
}
body[data-image-loaded="false"] .tool-hint { display: none; }

/* ===== Edges & outline panel (right side) ===== */
.edges-panel { border-color: var(--line); background: var(--surface-2); }
.edges-panel .hint { background: var(--surface-3); }
.v2-appearance-feedback { display: grid; gap: 7px; margin: 0 0 10px; }
.v2-appearance-feedback > .status-pill { display: block; text-align: center; }
.v2-appearance-actions { display: flex; gap: 6px; }
.v2-appearance-actions button { flex: 1 1 0; min-width: 0; padding-inline: 7px; }
#v2-appearance-status[data-state="pending"] { border-color: #bd8a24; color: #714d00; }
#v2-appearance-status[data-state="failed"] { border-color: #b84a3a; color: #8a2419; }
#v2-appearance-guidance { margin-top: 0; }
#v2-appearance-guidance[data-kind="size"],
#v2-appearance-guidance[data-kind="overload"] { border-left: 3px solid #bd8a24; padding-left: 7px; }
#v2-appearance-guidance[data-kind="network"],
#v2-appearance-guidance[data-kind="processing"],
#v2-appearance-guidance[data-kind="unknown"] { border-left: 3px solid #b84a3a; padding-left: 7px; }

.edge-row { margin: 11px 0; }
.edge-row > label,
.edge-group-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.edge-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin-bottom: 5px;
}
.edge-label-row label { margin-bottom: 0; }
.edge-label-row input[type="range"] {
  flex: 1;
  min-width: 70px;
  max-width: 110px;
  margin: 0 4px;
}
.sens-val {
  font-weight: 600;
  font-size: 12px;
  min-width: 12px;
  text-align: center;
}
.edge-row select { width: 100%; }
/* Bound native inputs so label + value fit the 220px side panel; the
   Swap button then wraps onto its own line instead of overflowing off-screen. */
.side-panel .edge-row input[type="number"],
.side-panel .edge-row input[inputmode="decimal"] { width: 74px; min-width: 0; }
/* Other length fields (reference line, calibration measurements) take
   fractional inch entries too — keep them compact instead of the ~177px
   native text-input width. */
input[inputmode="decimal"] { width: 90px; min-width: 0; }

/* Feet+inches entry: [ft] [in] [fraction ▾]. Compact enough for the 198px
   side-panel rows; the inches box also accepts typed mixed fractions. */
.ftin-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
}
/* The group is toggled via the `hidden` property, but `display: inline-flex`
   above would otherwise win over the UA's [hidden] rule and keep the whole
   ft/in (or in) triplet rendered next to the single mm/cm field. */
.ftin-group[hidden] { display: none; }
.ftin-group input[type="text"] { padding: 3px 4px; }
.ftin-group .ftin-ft { width: 34px; min-width: 0; }
.ftin-group .ftin-in { width: 46px; min-width: 0; }
.ftin-group .ftin-sep {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-soft);
  line-height: 1;
}
.ftin-group select.ftin-frac {
  width: auto;
  max-width: 64px;
  min-width: 0;
  padding: 1px 2px;
  font-size: 0.78rem;
  color: var(--ink);
}
.side-panel .edge-row .ftin-group .ftin-ft {
  width: 30px;
  min-width: 0;
}
.side-panel .edge-row .ftin-group .ftin-in {
  width: 42px;
  min-width: 0;
}
.side-panel .edge-row .ftin-group select.ftin-frac { max-width: 60px; }
.edge-row .status-pill { display: block; text-align: center; margin-top: 7px; }
.edge-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.edge-btns button { flex: 1 1 auto; }
.edge-note { font-size: 11px; color: var(--ink-soft); margin: 6px 0 0; }

.edge-row input[type="range"] {
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
}
.edge-row input[type="range"]:disabled {
  accent-color: #b9ae93;
  cursor: not-allowed;
}
.edge-row select:disabled,
.edge-row button:disabled {
  background: var(--surface-3);
  color: #9a8f76;
  cursor: not-allowed;
}
#edge-bg-status { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.edges-panel button.pick-active,
.auto-transform-panel button.pick-active {
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 107, 0, 0.35);
}
.edges-panel button.pick-active:hover,
.auto-transform-panel button.pick-active:hover { background: var(--accent-dark); }

.hint.compact { font-size: 0.8rem; margin: 14px 0 0; }

/* Printer setup uses the workspace's warm surfaces and orange actions. */
#printer-calibration-dialog { width: min(780px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); box-sizing: border-box; overflow: auto; border: 1px solid var(--line); border-radius: 16px; padding: 24px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 80px #0004; }
#printer-calibration-dialog::backdrop { background: #10151088; }
.calibration-dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.calibration-dialog-heading h2 { margin: 0; }
#tab-calibration { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
#tab-calibration .card { margin: 0; padding: 16px; }
#tab-calibration .card:nth-child(n+3) { grid-column: 1 / -1; }
#tab-calibration h2 { font-size: 1.05rem; }
.calibration-step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--key); margin-right: 6px; }
.calibration-visual { display: block; width: 160px; height: 90px; margin: 12px auto; text-align: center; font-size: 48px; color: var(--ink-soft); }
#tab-calibration .row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
#tab-calibration .row input { min-width: 0; max-width: 100%; }
.calibration-advanced summary { cursor: pointer; font-weight: 600; }
#printer-calibration-dialog p { font-size: .85rem; line-height: 1.45; }
#printer-calibration-dialog .calibration-dialog-heading .hint { padding: 0; border: 0; background: none; }
#tab-calibration .card { align-self: start; }
#tab-calibration .calibration-visual { height: 66px; margin: 8px auto; }
#tab-calibration button { margin: 4px 0; }
#tab-calibration #active-cal-status { margin: 0; }
#printer-calibration-dialog > button { margin-top: 16px; }
body[data-ui-layout="compact"] #settings-menu .image-cap-control { width: 100%; margin: 8px 0; }
@media (max-width: 600px) { #tab-calibration { grid-template-columns: 1fr; } #printer-calibration-dialog { padding: 16px; } }
@media print { #printer-calibration-dialog { display: none !important; } }

/* ===== Calibration print pattern (screen preview) ===== */
#cal-square {
  display: block;
  position: relative;
  width: 100mm;
  height: 100mm;
  box-sizing: content-box;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
#cal-square::after { content: ""; position: absolute; inset: -0.25mm; border: 0.5mm solid #000; box-sizing: border-box; }
.cal-sheet-heading { font-family: Arial, sans-serif; color: #000; margin-bottom: 10mm; }
.cal-sheet-heading .cal-sheet-brand { font-size: 12pt; font-weight: bold; margin: 0 0 2mm; }
.cal-sheet-heading h1 { font-size: 18pt; margin: 0 0 3mm; }
.cal-sheet-heading p { font-size: 10pt; margin: 0; }
.cal-sheet-pattern { position: relative; margin: 0 0 24mm; }
#cal-sheet-directions { position: absolute; top: 0; left: 0; overflow: visible; color: #000; }
.cal-sheet-instructions { font: 10pt/1.5 Arial, sans-serif; color: #000; margin: 0 0 3mm; }
#print-calibration .cal-ruler { display: none; }

.cal-ruler {
  display: block;
  margin-top: 5mm;
}

/* ===== Print output (hidden on screen) ===== */
.print-only { display: none; }

/* ===== Narrow screens: stack panels ===== */
@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  .canvas-wrap {
    flex: none;
    height: clamp(320px, 55vh, 520px);
    min-height: 0;
  }
  .side-panel { overflow: visible; }
  .status-strip { flex-wrap: wrap; }
}

@media (max-width: 600px) {
  #tab-image .history-section { margin-left: auto; }
}

/* ===== Compact workspace layout (feature flag `compact-layout`, DECISIONS #130) =====
   Applied via document.body.dataset.uiLayout = 'compact' (app.js). One-row
   header, paper/unit in the side panel, one combined actions row, and an
   always-visible bottom bar for the tape + print under the canvas. */
body[data-ui-layout="compact"] #app {
  max-width: 1600px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 8px 14px 8px;
}
body[data-ui-layout="compact"] .app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: none;
}
body[data-ui-layout="compact"] .app-header h1 { margin: 0; font-size: 1.2rem; }
body[data-ui-layout="compact"] .tabs { margin: 0 16px 0 0; }
body[data-ui-layout="compact"] .tabs button { padding: 6px 14px; }
body[data-ui-layout="compact"] .tabs button.active { padding-bottom: 7px; }
body[data-ui-layout="compact"] #sign-out-btn { margin-left: auto; }
body[data-ui-layout="compact"] main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body[data-ui-layout="compact"] .tab:not([hidden]) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 14px 10px;
}
body[data-ui-layout="compact"] #tab-calibration { overflow-y: auto; }

/* One combined actions row (Load/Remove + the status pills) */
body[data-ui-layout="compact"] .actions-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: none;
  margin-bottom: 10px;
}
body[data-ui-layout="compact"] .actions-bar .img-actions { display: contents; }
body[data-ui-layout="compact"] .actions-bar .status-strip { display: contents; margin: 0; }
body[data-ui-layout="compact"] .img-actions { margin-bottom: 0; }
/* Everything else on the line sits LEFT of the bar: the dock is always the
   LAST flex item so it butts against the right edge (above the side panel). */
body[data-ui-layout="compact"] .actions-bar .si-wrap { order: 9; }
body[data-ui-layout="compact"] .actions-bar .progress-dock { order: 10; margin-left: auto; }

/* Workspace fills the remaining height instead of a fixed calc() */
body[data-ui-layout="compact"] .workspace {
  height: auto;
  flex: 1;
  min-height: 0;
}

/* Bottom bar: measure + print sections (each its own bordered .foot-section),
   always visible under the canvas */
body[data-ui-layout="compact"] .canvas-column { gap: 6px; }
body[data-ui-layout="compact"] .canvas-head {
  flex: none;
  align-items: stretch;
}

/* Settings (Paper/Unit) pinned to the bottom of the side panel */
.side-settings {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.side-settings-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.side-settings-row { display: flex; flex-direction: column; gap: 8px; }
.side-settings-row label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.side-settings-row select { flex: 1; min-width: 0; padding: 6px 8px; }

/* Narrow screens (compact): relax the fixed viewport so content can flow */
@media (max-width: 980px) {
  body[data-ui-layout="compact"] #app { height: auto; overflow: visible; }
  body[data-ui-layout="compact"] main { overflow: visible; }
}

/* ===== Tiled print: each .print-tile lands on its own page ===== */
#print-svg { display: block; margin: 0; }
#print-tiles { margin: 0; padding: 0; }
#print-tiles .print-tile {
  display: block;
  margin: 0;
}
#print-tiles .print-tile + .print-tile {
  break-before: page;
  page-break-before: always;
}

@media print {
  @page { margin: 0; }

  html, body {
    margin: 0;
    padding: 0;
    background: #fff;
  }

  #app { display: none !important; }

  body[data-print="calibration"] #print-calibration,
  body[data-print="drawing"] #print-drawing {
    display: block;
    position: absolute;
    top: 10mm;
    left: 10mm;
    margin: 0;
    padding: 0;
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Tiled prints: tiles are exact page-sized mm SVGs, so drop the 10mm offset
     (the 15mm printable margin is inside each tile) and hide the empty
     single-page container. */
  body[data-tiled="true"] #print-drawing {
    top: 0;
    left: 0;
  }
  body[data-tiled="true"] #print-svg {
    display: none;
  }
}

/* ===== /mobile companion page ===== */
body[data-page="mobile"] {
  background: var(--bg);
  padding: 0;
}
.mob-app {
  max-width: 420px;
  margin: 0 auto;
  padding: 40px 20px;
  text-align: center;
}
.mob-app h1 { font-size: 1.5rem; margin: 0 0 6px; }
.mob-sub { color: var(--ink-soft); margin: 0 0 26px; font-size: 0.95rem; line-height: 1.5; }
.mob-actions { display: flex; gap: 12px; justify-content: center; margin-bottom: 18px; }
.mob-actions button { flex: 1; min-height: 88px; font-size: 1.05rem; margin: 0; }
.mob-status { font-size: 1rem; }
.mob-status:empty { visibility: hidden; }
.mob-preview {
  max-width: 100%;
  max-height: 320px;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* ===== "New image arrived — open?" toast (desktop) ===== */
.inbox-toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 1200;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 12px 16px;
  max-width: min(340px, calc(100vw - 36px));
  display: flex;
  align-items: center;
  gap: 12px;
}
.inbox-toast[hidden] { display: none; }
.inbox-toast-text { font-size: 0.92rem; line-height: 1.35; }
.inbox-toast-actions { display: flex; flex-direction: column; gap: 6px; }
.inbox-toast-actions button { padding: 6px 14px; font-size: 0.85rem; margin: 0; white-space: nowrap; }

/* Print errors use a fixed feedback surface so they never add a row to the
   canvas-head flex layout. */
.print-feedback {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 1250;
  max-width: min(520px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  font-size: 0.9rem;
  line-height: 1.35;
  text-align: center;
}
.print-feedback.warn { border-color: var(--accent); color: var(--accent-dark); }
.print-feedback[hidden] { display: none; }

/* ===== Image (new) tab — UI preview ===== */
.pv-tab {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 6px 14px;
  border: 1px dashed var(--accent);
  border-radius: 8px;
  color: var(--accent-dark, #b05000);
  background: #fef7f0;
  cursor: pointer;
  vertical-align: bottom;
}
.pv-tab.active,
.pv-tab:hover { background: var(--dark); color: var(--paper); border-style: solid; }
.pv-tab + .pv-tab { margin-left: 6px; }

.pv-banner {
  background: #fff7e6;
  border: 1px solid #e6c888;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: #6b4c11;
  margin-bottom: 10px;
}

.pv-stage {
  position: relative;
  min-height: 320px;
  height: 100%;
  background:
    repeating-conic-gradient(var(--line) 0% 25%, transparent 0% 50%) 0 0 / 20px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.pv-stage-note {
  font-size: 0.82rem;
  color: var(--ink-soft, #888);
  pointer-events: none;
}

/* Floating zoom pill (top-right corner of canvas) */
.pv-zoom {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 0;
  background: var(--surface, #fff);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
  z-index: 5;
}
.pv-zoom button {
  background: transparent;
  border: none;
  border-left: 1px solid var(--line);
  padding: 6px 12px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 32px;
  text-align: center;
}
.pv-zoom button:first-child { border-left: none; }
.pv-zoom button:hover { background: var(--key-hover, #eee); }

/* Compact icon toolbar (preview only) */
.pv-tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.pv-tools-more {
  grid-template-columns: repeat(2, 1fr);
  margin-top: 6px;
}
.pv-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  background: var(--key, #f5f5f5);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 1.35rem;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}
.pv-tool svg { display: block; }
.pv-tool:hover { background: var(--key-hover, #eaeaea); }
.pv-tool.active {
  background: var(--dark, #333);
  color: var(--paper, #fff);
  box-shadow: inset 3px 0 0 var(--accent, #d06000);
}
.pv-tool.pv-ref-btn {
  width: 100%;
  margin-top: 6px;
  min-height: 40px;
  font-size: 0.92rem;
  font-weight: 600;
  gap: 6px;
  background: #f6e2d8;
  color: #a0441f;
  border-color: #e8bda6;
}
.pv-tool.pv-ref-btn:hover { background: #f0d4c4; }
.pv-tool.pv-ref-btn.active {
  background: var(--ref, #c63d14);
  color: #fff;
  border-color: var(--ref, #c63d14);
}

/* Floating zoom toolbox over the canvas (top-right, like map software) */
.pv-zoom-float {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.pv-zoom-float .pv-tool {
  min-height: 30px;
  height: 30px;
  min-width: 32px;
  padding: 0 4px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 6px;
}
.pv-zoom-float #zoom-reset-img {
  min-width: 0;
  padding: 0 9px;
  font-size: 0.78rem;
  font-weight: 600;
}
.pv-one { font-size: 0.8rem; margin: 8px 0 0; color: var(--ink-soft, #666); }

/* (i) info popups */
.pv-i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--ink-soft, #999);
  font-size: 0.7rem;
  font-style: italic;
  line-height: 1;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  vertical-align: middle;
  margin-left: 4px;
}
.pv-i:hover { background: var(--key-hover, #eee); }
.pv-pop {
  position: absolute;
  z-index: 10;
  background: var(--dark, #333);
  color: var(--paper, #fff);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.4;
  max-width: 260px;
  min-width: 230px;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.20);
  white-space: normal;
}

/* Segmented appearance control (Photo / Edges) */
.pv-seg {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}
.pv-seg-opt {
  flex: 1;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 0;
  cursor: pointer;
  border-right: 1px solid var(--line);
  background: var(--key, #f5f5f5);
  color: var(--ink);
}
.pv-seg-opt:last-child { border-right: none; }
.pv-seg-opt:has(input:checked) {
  background: var(--dark, #333);
  color: var(--paper, #fff);
}
.pv-seg-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.pv-exp-tag {
  display: inline-block;
  font-size: 0.62rem;
  background: #f0d4c4;
  color: #a0441f;
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 2px;
  vertical-align: middle;
  font-weight: 700;
}
.pv-seg-opt:has(input:checked) .pv-exp-tag { background: #d88; color: #fff; }

.pv-chk {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.pv-chk-inline { margin-bottom: 0; align-self: stretch; }
.pv-chk-inline input {
  width: 16px;
  height: 16px;
  accent-color: var(--dark, #333);
}
.pv-photo-row { margin-top: 6px; }
.pv-off { opacity: 0.40; pointer-events: none; }
.pv-layer-block { padding: 0; margin: 0; }

.pv-pair { gap: 6px; }
.pv-pair button { flex: 1; min-width: 0; }
.pv-pair-big button {
  padding: 5px 0;
  min-height: 36px;
  font-size: 1.15rem;
  line-height: 1;
}
.pv-pair-big button:last-child { font-size: 0.85rem; }

.pv-groupline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.pv-groupline .edge-group-label { margin-bottom: 0; }
.pv-groupline .edge-group-label .pv-pop { top: 22px; left: 0; }
.pv-sides {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 4px;
}
.pv-side-lines {
  flex: 1;
  min-width: 0;
}
.pv-side-lines .edge-label-row { margin-bottom: 3px; }
.pv-side-lines .edge-label-row:last-child { margin-bottom: 0; }
/* Keep the mm/cm field and its unit label on one line: the swap button makes
   this column ~40px narrower than a normal row, so let the input absorb the
   slack instead of wrapping the unit onto a third line. */
.pv-side-lines .edge-label-row input[inputmode="decimal"] {
  flex: 1 1 0;
  width: auto;
  min-width: 34px;
}
/* The ft+in / in triplet is wider than the column; shave the feet box and the
   fraction list so it stays on one line without clipping. */
.pv-side-lines .edge-label-row .ftin-group .ftin-ft { width: 26px; }
.pv-side-lines .edge-label-row .ftin-group select.ftin-frac {
  max-width: 48px;
  min-width: 0;
}
.pv-sides .pv-swap-btn {
  flex: 0 0 auto;
  align-self: center;
  padding: 4px 9px;
  font-size: 1.25rem;
  line-height: 1.2;
}
.pv-sens { margin-top: 10px; }

.pv-workspace .edge-label-row {
  margin-bottom: 3px;
}
.pv-workspace .edge-row { margin: 9px 0; }
.pv-workspace .edge-group-label { margin-bottom: 4px; }

.pv-opacity-row { margin-top: 6px; }
.pv-pop[hidden] { display: none; }

/* ===== V2 task-based Image inspector ===== */
#tab-image .workspace { grid-template-columns: minmax(0, 1fr) 310px; }
#tab-image .v2-task-panel {
  padding: 0;
  gap: 0;
  overflow: hidden;
  background: var(--surface-2);
}
.v2-task-panel > [hidden],
.v2-workflow-pane[hidden],
.v2-image-empty[hidden],
.v2-quick-tools[hidden],
.v2-background-tools[hidden] { display: none !important; }

/* Compact stages and floating tools preserve canvas height. */
.v2-workflow-status { display: block; font-size: 0.74rem; color: var(--ink-soft); overflow-wrap: anywhere; }
.v2-printer-review { display: flex; align-items: center; gap: 10px; margin: 6px 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.v2-printer-warning { flex: 1 1 auto; min-width: 0; margin: 0; padding: 1px 0 1px 7px; border-left: 2px solid var(--warn); color: var(--ink); font-size: .72rem; line-height: 1.25; }
.v2-printer-warning.is-verified { border-color: var(--ok, #3b7850); }
.v2-printer-review > #v2-printer-setup-from-review { flex: 0 0 auto; min-height: 32px; margin: 0; padding: 5px 9px; font-size: .72rem; white-space: nowrap; }
.v2-printer-setup-entry, .v2-printer-setup-return { margin: 6px 6px 0 0; }
.v2-printer-setup-entry { display: block; }
#v2-next-step { display: flex; align-items: center; gap: 8px; margin: 0; padding: 0; border: 0; background: transparent; min-width: 0; }
#v2-next-step .v2-next-step-title { margin: 0; font-size: 0.74rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#v2-next-step .v2-next-step-copy { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#v2-next-step .v2-next-step-button { flex: none; max-width: 65%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#v2-next-step .v2-next-step-button[hidden] { display: none !important; }
#tab-image .v2-quick-tools { position: absolute; flex-wrap: wrap; margin: 0; max-width: calc(100% - 194px); }
#v2-tool-return[hidden] { display: none; }
#v2-tool-return { margin-left: 5px; background: #e4f0e3; color: #254f2c; border-color: #719578; }
#v2-tool-return:hover { background: #d2e5d0; }
#v2-rotate-controls { margin: 8px 0 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
#v2-rotate-controls .edge-row { flex-wrap: wrap; }
#v2-rotate-controls input[type="range"] { min-width: 80px; max-width: 100%; }
#v2-workflow-pane-review .print-section.v2-review-print-section { display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; gap: 7px; margin: 12px 0; }
#v2-workflow-pane-review .v2-review-print-section .print-bar { display: block; min-width: 0; }
#v2-workflow-pane-review .v2-review-print-section .print-bar > button { box-sizing: border-box; width: 100%; min-height: 44px; padding: 9px 12px; font-size: .92rem; font-weight: 700; }
#v2-workflow-pane-review .v2-print-controls { display: grid; gap: 6px; min-width: 0; }
#v2-workflow-pane-review .v2-print-control-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; min-width: 0; }
#v2-workflow-pane-review .v2-print-control-card { display: flex; flex-direction: column; align-items: stretch; justify-content: space-between; gap: 5px; min-width: 0; min-height: 52px; padding: 5px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); }
#v2-workflow-pane-review .v2-print-control-title { display: block; overflow: hidden; color: var(--ink-soft); font-size: .68rem; font-weight: 700; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
#v2-workflow-pane-review .v2-print-grid-card { min-height: 0; flex-direction: row; align-items: center; justify-content: space-between; gap: 6px; padding: 4px 7px; }
#v2-workflow-pane-review .v2-print-grid-card .v2-print-control-title { flex: 1 1 auto; min-width: 0; }
#v2-workflow-pane-review .v2-review-print-section .print-grid-switch { display: flex; flex: 0 0 auto; justify-content: flex-end; gap: 4px; margin: 0; font-size: .68rem; }
#v2-workflow-pane-review .v2-review-print-section .print-grid-switch .pg-track { width: 34px; height: 18px; }
#v2-workflow-pane-review .v2-review-print-section .print-grid-switch .pg-thumb { width: 14px; height: 14px; }
#v2-workflow-pane-review .v2-review-print-section .print-grid-switch input:checked + .pg-track .pg-thumb { left: 18px; }
#v2-workflow-pane-review .v2-review-print-section .sheets-group { display: flex; align-items: stretch; flex: 1 1 auto; min-width: 0; margin: 0; }
#v2-workflow-pane-review .v2-review-print-section .sheets-group { flex-direction: row; align-items: center; gap: 5px; }
#v2-workflow-pane-review .v2-review-print-section .sheets-group .lcd-label { display: block; flex: 0 0 auto; color: var(--ink-soft); font-size: .68rem; font-weight: 700; text-transform: none; }
#v2-workflow-pane-review .v2-review-print-section .sheets-group .lcd-readout { box-sizing: border-box; flex: 1 1 auto; width: auto; min-width: 0; padding: 2px 3px; text-align: center; font-size: 1rem; font-weight: 700; }
#v2-workflow-pane-review .v2-print-orientation-card { min-height: 0; flex-direction: row; align-items: center; justify-content: space-between; padding: 4px 7px; }
#v2-workflow-pane-review .v2-print-orientation-card .orient-seg { display: flex; flex: 1 1 auto; flex-direction: row; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; white-space: normal; }
#v2-workflow-pane-review .v2-print-orientation-card .orient-title { font-size: .68rem; font-weight: 700; line-height: 1.15; }
#v2-workflow-pane-review .v2-print-orientation-card .orient-opts { display: flex; flex: 1 1 auto; justify-content: stretch; gap: 4px; min-width: 0; }
#v2-workflow-pane-review .v2-print-orientation-card .orient-opt { flex: 1 1 0; min-width: 0; }
#v2-workflow-pane-review .v2-print-orientation-card .orient-opt span { display: block; padding: 5px 4px; font-size: .67rem; text-align: center; white-space: nowrap; }
#v2-workflow-pane-review .v2-review-status { margin: 2px 0; color: var(--ink-soft); font-size: .76rem; line-height: 1.4; }
#v2-workflow-pane-review .v2-review-print-section .v2-review-status:empty { display: none; }
#v2-workflow-pane-review .v2-review-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
#v2-workflow-pane-review .v2-review-summary[hidden] { display: none; }
#v2-workflow-pane-review .v2-review-summary-row { margin: 0; font-size: .74rem; line-height: 1.4; overflow-wrap: anywhere; }
#v2-workflow-pane-review .v2-review-summary-row strong { color: var(--ink); }
#v2-workflow-pane-review .v2-review-help { margin: 7px 9px 9px; color: var(--ink-soft); font-size: .71rem; line-height: 1.4; }
#v2-workflow-pane-review .v2-review-export-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
#v2-workflow-pane-review .v2-review-export-actions > button { box-sizing: border-box; width: 100%; min-width: 0; min-height: 42px; padding: 6px; font-size: .72rem; white-space: normal; }
#v2-workflow-pane-review .v2-print-preview-details,
#v2-workflow-pane-review .v2-print-details { min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
#v2-workflow-pane-review .v2-print-preview-details > summary,
#v2-workflow-pane-review .v2-print-details > summary { padding: 8px 10px; color: var(--ink); font-size: .76rem; font-weight: 700; cursor: pointer; }
#v2-workflow-pane-review .v2-print-preview-details[open] > summary,
#v2-workflow-pane-review .v2-print-details[open] > summary { border-bottom: 1px solid var(--line); }
#v2-workflow-pane-review .v2-print-details > .v2-review-summary { margin: 8px; }
#v2-workflow-pane-review .v2-print-details > .v2-review-help { margin-top: 8px; }
#v2-workflow-pane-review #v2-review-export-status { margin: 0; }
#v2-workflow-pane-review .v2-print-preview { max-height: 252px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #eef0ec; padding: 7px; }
#v2-workflow-pane-review .v2-print-preview-pages { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); align-items: start; gap: 7px; }
#v2-workflow-pane-review .v2-print-preview-sheet { min-width: 0; display: grid; justify-items: center; gap: 3px; }
#v2-workflow-pane-review .v2-print-preview-caption { color: var(--ink-soft); font-size: .66rem; }
#v2-workflow-pane-review .v2-print-preview-paper { position: relative; width: min(100%, 190px); overflow: hidden; background: white; box-shadow: 0 1px 4px #0002; }
#v2-workflow-pane-review .v2-print-preview-paper > svg { display: block; max-width: none; max-height: none; }
#v2-workflow-pane-review .v2-print-preview-artwork { position: absolute; }
#v2-workflow-pane-review .v2-print-preview-tile { width: 100%; height: 100%; object-fit: fill; }
#v2-workflow-pane-review .v2-print-preview[hidden] { display: none; }
.v2-calibration-prompt { width: min(440px, calc(100vw - 34px)); border: 1px solid var(--line); border-radius: 12px; padding: 18px; color: var(--ink); background: var(--surface); box-shadow: 0 12px 40px #0004; }
.v2-calibration-prompt::backdrop { background: #10151088; }
.v2-calibration-prompt h2 { margin: 0 0 9px; font-size: 1.08rem; }
.v2-calibration-prompt p { margin: 0; font-size: .88rem; line-height: 1.5; }
.v2-calibration-prompt-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.v2-calibration-prompt-actions button { min-height: 40px; }
#v2-print-scale-prompt .v2-calibration-prompt-actions { flex-wrap: nowrap; justify-content: flex-start; gap: 8px; }
#v2-print-scale-prompt .v2-calibration-prompt-actions button { flex: 0 1 auto; min-width: 0; min-height: 38px; padding: 7px 9px; font-size: .8rem; white-space: nowrap; }
@media (max-width: 680px) {
  #v2-workflow-pane-review .v2-review-summary { grid-template-columns: minmax(0, 1fr); }
  #v2-workflow-pane-review .v2-print-preview-pages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 360px) {
  #v2-workflow-pane-review .v2-print-control-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  #v2-workflow-pane-review .v2-print-control-card { padding: 4px; }
  #v2-workflow-pane-review .v2-print-orientation-card .orient-seg { gap: 3px; }
  #v2-workflow-pane-review .v2-print-orientation-card .orient-opt span { padding: 4px 2px; font-size: .58rem; }
}
#v2-workflow-pane-review > button { margin-top: 12px; white-space: normal; }
.v2-pane-intro, .v2-completion { display: none; }
#v2-navigation-draft, #v2-late-rotation { display: block; }
#v2-navigation-draft[hidden], #v2-late-rotation[hidden] { display: none; }
.v2-scale-chooser { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.v2-scale-chooser > strong { font-size: 0.8rem; }
.v2-scale-routes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.v2-scale-routes.v2-guided-reference { grid-template-columns: minmax(0, 1fr); gap: 8px; }
.v2-reference-choice { border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.v2-reference-choice strong { display: block; font-size: 0.75rem; line-height: 1.4; }
.v2-reference-choice p { margin: 5px 0 8px; font-size: 0.69rem; line-height: 1.4; color: var(--ink-soft); }
.v2-reference-choice .v2-scale-route { width: 100%; }
.v2-scale-route { min-width: 0; min-height: 40px; text-align: center; padding: 4px; font-size: 0.72rem; }
.v2-scale-help { margin: 0; min-height: 2.7em; font-size: 0.69rem; line-height: 1.35; color: var(--ink-soft); }
.v2-distance-controls[hidden] { display: none !important; }
.v2-workflow-pane:has(.v2-distance-controls:not([hidden])) > :is(.v2-draw-hint, [data-menu="size"]) { display: none; }
.v2-distance-controls .ref-panel { margin: 0; padding: 8px; background: var(--surface); }
.v2-distance-controls .ref-panel > input { box-sizing: border-box; max-width: 100%; width: 100%; }
.v2-distance-controls .ref-panel label { font-size: .8rem; }
.v2-distance-controls .ref-panel .hint { font-size: .72rem; line-height: 1.35; }
.v2-distance-controls > .v2-scale-warning { position: static; width: auto; margin: 6px 0 0; box-shadow: none; }
.v2-scale-route[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 3px 0 var(--accent); }
.v2-compact-reference .v2-scale-routes[hidden], .v2-selected-reference[hidden] { display: none; }
.v2-compact-reference .v2-guided-reference { gap: 5px; }
.v2-compact-reference .v2-reference-choice { padding: 0; border: 0; }
.v2-compact-reference .v2-scale-route { min-height: 36px; text-align: left; padding: 6px 9px; font-size: .78rem; }
.v2-selected-reference { display: flex; align-items: center; justify-content: space-between; gap: 5px; }
.v2-selected-reference strong { font-size: .78rem; }
.v2-selected-reference button { flex: none; padding: 5px 7px; font-size: .72rem; }
.v2-compact-reference { gap: 6px; margin-bottom: 6px; }
.v2-compact-reference .v2-scale-help { min-height: 0; font-size: .74rem; line-height: 1.3; }
.v2-compact-reference .v2-reference-guide { order: 10; }
.v2-compact-reference .v2-reference-guide p { margin: 7px 9px; font-size: .76rem; line-height: 1.35; }
.v2-compact-reference .v2-prepare-surface { gap: 6px; }
.v2-compact-reference .v2-manual-size > summary { padding: 6px 9px; }
.v2-compact-reference .v2-manual-size .edge-row { padding: 5px 9px; margin: 0; }
.v2-compact-reference .v2-manual-size .pv-groupline { display: none; }
.v2-compact-reference .v2-retained-area { padding: 0; border: 1px solid var(--line); border-radius: 6px; }
.v2-compact-reference .v2-retained-area > summary { padding: 6px 9px; font-size: .76rem; cursor: pointer; }
.v2-compact-reference .v2-retained-area > :not(summary) { margin: 7px 9px; }
.v2-compact-reference .v2-advanced > summary { padding-top: 6px; padding-bottom: 6px; }
.v2-compact-reference .v2-advanced { margin: 0; }
.v2-compact-reference .v2-manual-size .pv-side-lines { gap: 3px; }
.v2-compact-reference .v2-manual-size .edge-label-row { margin: 0; }
.v2-compact-reference .v2-prepare-actions button { min-height: 36px; line-height: 1.15; }
@media (min-width: 681px) and (max-height: 650px) {
  .v2-compact-reference .v2-prepare-top { display: none; }
  .v2-compact-reference .v2-prepare-surface { gap: 5px; }
  .v2-compact-reference .v2-manual-size input { padding-top: 5px; padding-bottom: 5px; }
  .v2-compact-reference .v2-manual-size .edge-row { padding-top: 3px; padding-bottom: 3px; }
}
.v2-perspective[hidden], .v2-detection-details[hidden], .v2-known-sheet[hidden], #at-detect[hidden] { display: none !important; }
#tab-image .canvas-head > .progress-dock { flex: 0 1 220px; width: 220px; min-width: 100px; margin: 0 0 0 auto; padding: 5px 8px; }
#tab-image .canvas-head .measure-section { min-width: 0; flex: 1 1 300px; }
#tab-image .canvas-head .measure-section .lcd-group { flex: 1 1 100px; min-width: 0; }
#tab-image .canvas-head .measure-section .tape-readout { width: 100%; max-width: 100%; }
#tape-btn-img { flex: none; white-space: nowrap; }
#tape-btn-img:disabled,
#tape-btn-img:disabled:hover {
  background: #ddd;
  color: #777;
  border-color: #bbb;
  cursor: not-allowed;
  box-shadow: none;
  opacity: 1;
}
#undo-crop-btn:disabled { background: #ddd; color: #777; border-color: #bbb; cursor: wait; }
.v2-tape-warning { max-width: min(420px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 10px; padding: 20px; color: var(--ink); background: var(--surface); }
.v2-tape-warning::backdrop { background: rgba(0, 0, 0, .35); }
.v2-tape-warning p { line-height: 1.4; }
.v2-tape-preference { display: flex; gap: 6px; align-items: center; margin: 14px 0; }
.v2-tape-warning .v2-path-actions button { font-size: 0.8rem; }
#tab-image .canvas-column { min-width: 0; }
/* Compact guidance owns the top-right cell. Progress lives below the canvas. */
body[data-ui-layout="compact"] #tab-image .actions-bar {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) minmax(120px, 160px) minmax(200px, 300px);
  gap: 8px;
}
body[data-ui-layout="compact"] #tab-image .actions-bar .file-btn { grid-column: 1; grid-row: 1; min-width: 0; }
body[data-ui-layout="compact"] #tab-image .actions-bar #img-save { grid-column: 2; grid-row: 1; min-width: 0; }
body[data-ui-layout="compact"] #tab-image .actions-bar #img-status { grid-column: 3; grid-row: 1; width: auto; min-width: 0; max-width: min(34vw, 360px); }
body[data-ui-layout="compact"] #tab-image .actions-bar .si-wrap { grid-column: 4; grid-row: 1; min-width: 0; }
body[data-ui-layout="compact"] #tab-image .actions-bar .si-toggle { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body[data-ui-layout="compact"] #tab-image .actions-bar #v2-next-step {
  grid-column: 5; grid-row: 1;
}
@media (max-width: 760px) {
  body[data-ui-layout="compact"] #tab-image .actions-bar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(100px, 1fr); }
  body[data-ui-layout="compact"] #tab-image .actions-bar #v2-next-step { grid-column: 1 / -1; grid-row: 3; }
  body[data-ui-layout="compact"] #tab-image .actions-bar #img-status { grid-column: 1 / 3; grid-row: 2; }
  body[data-ui-layout="compact"] #tab-image .actions-bar .si-wrap { grid-column: 3; grid-row: 2; }
  body[data-ui-layout="compact"] #tab-image .actions-bar .file-btn,
  body[data-ui-layout="compact"] #tab-image .actions-bar #img-save,
  body[data-ui-layout="compact"] #tab-image .actions-bar .si-toggle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-inline: 6px; max-width: 100%; }
}
@media (max-width: 980px) {
  #tab-image .workspace { grid-template-columns: minmax(0, 1fr); }
  #tab-image .v2-task-panel { min-height: 0; overflow: visible; }
  #tab-image .v2-workflow-pane { max-height: none; overflow: visible; }
  #tab-image .canvas-wrap { min-height: 280px; }
  #tab-image .v2-draw-palette, #tab-image .v2-crop-palette { top: 132px; }
}

.v2-workflow-nav {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  padding: 4px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.v2-workflow-tab {
  min-width: 0;
  padding: 8px 2px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.15;
  cursor: pointer;
}
.v2-workflow-tab:hover { background: var(--key-hover); color: var(--ink); }
.v2-workflow-tab.active {
  background: var(--dark);
  border-color: var(--dark);
  color: var(--paper);
  box-shadow: inset 0 -3px 0 var(--accent);
}
.v2-tab-status {
  display: none;
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1;
  text-transform: none;
  white-space: nowrap;
}
.v2-workflow-tab.active .v2-tab-status { color: var(--paper); opacity: 0.82; }
.v2-workflow-pane {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  scrollbar-gutter: stable;
}
.v2-pane-intro {
  padding-bottom: 9px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.v2-pane-title { margin: 0 0 4px; font-size: 1rem; line-height: 1.2; }
.v2-pane-copy { margin: 0; color: var(--ink-soft); font-size: 0.78rem; line-height: 1.35; }
.v2-prepare-surface { display: flex; flex-direction: column; gap: 10px; }
.v2-prepare-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.v2-prepare-top strong,
.v2-prepare-orientation > strong { font-size: 0.78rem; }
.v2-prepare-state {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
}
.v2-prepare-state.ready { background: #eef3dc; color: #536d20; }
.v2-prepare-state.applied { background: #e8f0e8; color: #315c39; }
.v2-prepare-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.v2-prepare-actions button[hidden] { display: none !important; }
.v2-prepare-actions button { min-height: 36px; padding: 5px 7px; font-size: 0.72rem; }
.v2-compact-clear { min-width: 48px; }
.v2-known-sheet { display: grid; gap: 4px; color: var(--ink-soft); font-size: 0.72rem; font-weight: 700; }
.v2-known-sheet-select { width: 100%; min-height: 36px; }
.v2-prepare-orientation { display: grid; gap: 6px; }
.v2-orientation-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.v2-orientation-button { min-height: 46px; padding: 4px 3px; font-size: 0.67rem; }
.v2-fine-rotation { margin-top: 2px; }
.v2-retained-area { padding: 8px 10px; }
.v2-retained-area p { margin: 4px 0 7px; }
.v2-manual-size[hidden],
.v2-crop-card[hidden] { display: none !important; }
.v2-prepare-advanced > .edge-row { padding: 7px 9px; }
.v2-prepare-advanced > button { margin: 7px 9px 0; }
.v2-prepare-advanced #tf-status { margin: 7px 9px 9px; }
.v2-prepare-status { margin: 0; }
.v2-active-tool { max-width: 145px; color: var(--ink-soft); font-size: .68rem; line-height: 1.2; }
.v2-prepare-apply { flex: none; margin: 0 9px 9px; padding: 8px 0 0; border-top: 1px solid var(--line); }
.v2-prepare-apply[hidden] { display: none !important; }
.v2-prepare-apply button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; width: 100%; min-height: 52px; padding: 6px 8px; line-height: 1.15; }
.v2-prepare-apply-title { font-size: .86rem; font-weight: 700; }
.v2-prepare-apply-copy { color: inherit; font-size: .67rem; font-weight: 500; opacity: .86; }
.v2-next-step {
  margin: 0 0 12px;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #fff4e8;
}
.v2-next-step[hidden] { display: none !important; }
.v2-next-step-title { display: block; margin-bottom: 3px; font-size: 0.82rem; }
.v2-next-step-copy { margin: 0 0 8px; color: var(--ink-soft); font-size: 0.76rem; line-height: 1.35; }
.v2-next-step-button { min-height: 30px; padding: 4px 9px; font-size: 0.74rem; }
.v2-completion {
  margin: 8px 0 10px;
  padding: 8px 10px;
  border: 1px solid var(--key);
  border: 1px solid color-mix(in srgb, var(--key) 42%, var(--line));
  border-radius: 8px;
  background: var(--surface-2);
  background: color-mix(in srgb, var(--key) 8%, var(--surface));
}
.v2-completion[hidden] { display: none !important; }
.v2-completion-title { display: block; margin-bottom: 2px; font-size: 0.8rem; }
.v2-completion-copy { margin: 0; color: var(--ink-soft); font-size: 0.74rem; line-height: 1.35; }
#v2-crop-suggestion { display: block; }
#v2-crop-suggestion button { margin: 6px 6px 0 0; }
#v2-crop-reference-advice.warn-text { color: var(--warn, #854800); }

/* Existing section-title buttons become compact, non-collapsing subheads.
   Keeping them clickable preserves established automation entry points. */
.v2-task-panel .menu-title {
  display: block;
  width: 100%;
  margin: 7px 0 5px;
  padding: 0;
  border: 0;
  background: transparent !important;
  box-shadow: none !important;
  color: var(--ink-soft) !important;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
  cursor: default;
}
.v2-task-panel .menu-caret { display: none; }
.v2-task-panel .menu-section { margin: 0; padding: 0; background: transparent; border: 0; }
.v2-task-panel .menu-body { display: block !important; margin-top: 0; }
.v2-task-panel .menu-section + .menu-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }

.v2-image-empty {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 24px;
  text-align: center;
}
.v2-empty-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin-bottom: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--accent-dark);
  background: var(--surface);
  font-size: 1.8rem;
  font-weight: 700;
}
.v2-image-empty h2 { margin: 0 0 8px; font-size: 1.05rem; }
.v2-image-empty p { margin: 0 0 14px; color: var(--ink-soft); font-size: 0.84rem; line-height: 1.45; }
.v2-image-empty .v2-empty-load { min-width: 150px; }
.v2-image-empty .v2-empty-note { margin-top: 12px; margin-bottom: 0; font-size: 0.72rem; }

.v2-step-label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 13px 0 5px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
}
.v2-step-number {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #fff;
  background: var(--accent-dark);
  font-size: 0.7rem;
}
.v2-advanced {
  margin: 9px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.32);
}
.v2-advanced > summary {
  padding: 8px 9px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.v2-advanced[open] > summary { border-bottom: 1px solid var(--line); color: var(--ink); }
.v2-advanced > .edge-row,
.v2-advanced > .menu-body { padding-left: 9px; padding-right: 9px; }
.v2-advanced-label {
  padding: 7px 9px 2px;
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 700;
}
.v2-top-advanced { margin-top: 8px; }
.v2-stretch { margin-top: 12px; }

.v2-prepare-action {
  position: sticky;
  bottom: -12px;
  z-index: 3;
  margin: 10px -12px -2px;
  padding: 9px 12px 10px;
  border-top: 1px solid var(--line);
  background: linear-gradient(to bottom, rgba(246, 241, 228, 0.92), var(--surface-2) 30%);
}
.v2-prepare-action button { width: 100%; min-height: 38px; }

.v2-crop-card {
  margin: 10px 0 12px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.34);
}
.v2-crop-card { margin-top: 8px; }
.v2-crop-title { display: block; margin-bottom: 4px; font-size: 0.82rem; }
.v2-crop-copy { margin: 0 0 8px; color: var(--ink-soft); font-size: 0.76rem; line-height: 1.35; }
.v2-crop-action { margin-bottom: 8px; }
.v2-crop-action [data-tool="crop"] { width: 100%; min-height: 36px; }
.v2-crop-action [data-tool="crop"][hidden] { display: none !important; }
.v2-crop-card .crop-trim-btns { margin-top: 0; }
.v2-crop-card .crop-trim-btns button { min-height: 32px; }

.v2-background-tools {
  margin: 10px 0;
  padding: 0;
}
.v2-background-tools > summary { padding: 7px 9px; font-size: 0.76rem; }
.v2-background-tools[open] > summary { border-bottom: 1px solid var(--line); }
.v2-background-tools > .edge-row { padding-left: 9px; padding-right: 9px; }

.v2-task-panel .pv-tools { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.v2-task-panel .pv-tool:not(.pv-ref-btn) {
  min-height: 64px;
  padding: 7px 4px;
  flex-direction: column;
  gap: 5px;
}
.v2-tool-icon { display: grid; place-items: center; min-height: 30px; font-size: 1.55rem; line-height: 1; }
.v2-tool-icon svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.v2-tool-label { font-size: 0.74rem; font-weight: 700; line-height: 1.1; }
.v2-task-panel .pv-ref-btn { min-height: 38px; padding: 5px 8px; }
.v2-path-controls {
  margin: 8px 0 4px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(246, 241, 228, 0.78);
}
.v2-path-controls p { margin: 0 0 7px; font-size: 0.73rem; line-height: 1.3; color: var(--ink-soft); }
.v2-path-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.v2-path-actions button { min-height: 30px; padding: 4px 7px; font-size: 0.7rem; }

.v2-quick-tools {
  position: absolute;
  z-index: 5;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(3px);
}
.v2-quick-tools button { min-height: 30px; padding: 4px 8px; font-size: 0.72rem; white-space: nowrap; }
.v2-quick-tools button.active { background: var(--dark); color: var(--paper); border-color: var(--dark); }

/* Image annotation controls live on the canvas only when the user asks. This
   keeps the task inspector compact while preserving a short path to marks. */
.v2-draw-palette,
.v2-crop-palette,
.v2-scale-warning,
.v2-geometry-warning {
  position: absolute;
  left: 8px;
  z-index: 8;
  width: min(310px, calc(100% - 16px));
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.2);
}
.v2-draw-palette {
  top: 48px;
  max-height: calc(100% - 60px);
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.97);
}
.v2-crop-palette {
  position: static;
  left: auto;
  z-index: auto;
  box-sizing: border-box;
  width: 100%;
  margin: 4px 0 6px;
  padding: 0;
  max-height: none;
  overflow: visible;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}
.v2-draw-palette[hidden],
.v2-crop-palette[hidden],
.v2-scale-warning[hidden],
.v2-geometry-warning[hidden],
.v2-crop-card[hidden] { display: none !important; }
.v2-draw-palette-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.v2-palette-close { min-height: 28px; padding: 3px 8px; font-size: 0.72rem; }
.v2-draw-palette .menu-body { display: block !important; padding: 8px 10px 10px; }
.v2-draw-palette[data-mode="scale"] .menu-body > .pv-tools,
.v2-draw-palette[data-mode="scale"] .menu-body > .pv-tools-more,
.v2-draw-palette[data-mode="scale"] #v2-adjust-line { display: none; }
.v2-adjust-line { width: 100%; margin-top: 8px; min-height: 34px; }
.v2-draw-palette[data-mode="scale"] .menu-body { padding-top: 0; }
.v2-scale-guide {
  display: none;
  margin: 8px 10px 0;
  padding: 9px 10px;
  border: 1px solid #e6c888;
  border-radius: 8px;
  background: #fff7e6;
  color: #6b4c11;
}
.v2-draw-palette[data-mode="scale"] .v2-scale-guide { display: block; }
.v2-scale-guide strong { display: block; font-size: 0.8rem; }
.v2-scale-guide p { margin: 4px 0 0; font-size: 0.74rem; line-height: 1.35; }
.v2-draw-palette .ref-panel {
  margin: 8px 0 0;
  padding: 10px;
  border-color: var(--line);
  background: var(--surface-2);
}
.v2-draw-palette .ref-panel label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
}
.v2-draw-palette .ref-panel > input:not(.ftin-ft):not(.ftin-in) {
  box-sizing: border-box;
  width: 100%;
}
.ref-unit-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}
.v2-draw-palette .ref-panel .ftin-group {
  display: flex;
  width: 100%;
  gap: 4px;
}
.v2-draw-palette .ref-panel .ftin-group .ftin-ft {
  width: 3.2em;
  min-width: 0;
}
.v2-draw-palette .ref-panel .ftin-group .ftin-in {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}
.v2-draw-palette .ref-panel .ftin-group select.ftin-frac {
  flex: 1 1 auto;
  max-width: none;
  min-width: 0;
}
.v2-draw-palette .ref-panel .hint { margin: 8px 0 0; font-size: 0.72rem; }
.v2-crop-palette .v2-crop-card { pointer-events: auto; }
.v2-crop-palette .v2-draw-palette-head { position: static; z-index: auto; padding: 0; border: 0; background: transparent; }
#tab-image .v2-crop-palette .v2-crop-card { margin: 0; padding: 6px 8px; }
#tab-image .v2-crop-palette .v2-crop-copy { margin-bottom: 5px; font-size: 0.72rem; }
#tab-image .v2-crop-palette .v2-crop-action { margin-bottom: 5px; }
#tab-image .v2-crop-palette .crop-trim-btns { gap: 4px; }
#tab-image .v2-crop-palette .crop-trim-btns button { min-height: 30px; padding: 4px 6px; font-size: 0.7rem; }
.v2-crop-palette .crop-trim-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.v2-crop-palette .crop-trim-btns button { flex: 1 1 92px; }
#tab-image .v2-canvas-subtoolbar {
  position: absolute;
  z-index: 12;
  top: 44px;
  left: 8px;
  box-sizing: border-box;
  width: min(242px, calc(100% - 16px));
  max-height: min(228px, calc(100% - 54px));
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.17);
  backdrop-filter: blur(4px);
}
#tab-image .v2-canvas-subtoolbar[hidden] { display: none !important; }
#tab-image .v2-canvas-subtoolbar .v2-draw-palette-head,
#tab-image .v2-subtoolbar-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 0.78rem;
}
#tab-image .v2-canvas-subtoolbar .v2-palette-close { min-height: 24px; padding: 2px 6px; font-size: 0.66rem; }
#tab-image .v2-crop-palette {
  position: absolute;
  left: 8px;
  width: min(242px, calc(100% - 16px));
  margin: 0;
  padding: 0;
  max-height: none;
  overflow: visible;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.17);
  background: rgba(255, 255, 255, 0.97);
}
#tab-image .v2-crop-palette .v2-crop-card {
  margin: 0;
  padding: 5px;
  border: 0;
  border-radius: 0;
  background: transparent;
}
#tab-image .v2-crop-palette .v2-crop-title { display: none; }
#tab-image .v2-crop-palette .v2-crop-copy { margin: 0 0 3px; font-size: 0.67rem; line-height: 1.2; }
#tab-image .v2-crop-palette #v2-crop-details { margin-top: 3px; font-size: 0.65rem; }
#tab-image .v2-crop-palette #v2-crop-details > summary { cursor: pointer; }
#tab-image .v2-crop-palette #v2-crop-details > p { margin: 4px 0 0; }
#tab-image .v2-crop-palette .crop-trim-btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 0; }
#tab-image .v2-crop-palette .crop-trim-btns button { min-width: 0; min-height: 32px; padding: 4px 7px; font-size: 0.73rem; }
#tab-image .v2-crop-palette .crop-trim-btns #undo-crop-btn[hidden] { display: none !important; }
#tab-image .v2-retained-area {
  margin: 3px 0 4px;
  padding: 4px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
}
#tab-image .v2-retained-area strong { display: block; font-size: 0.68rem; }
#tab-image .v2-retained-area p { margin: 1px 0 3px; color: var(--ink-soft); font-size: 0.63rem; line-height: 1.15; }
#tab-image .v2-retained-area button { min-height: 28px; padding: 3px 6px; font-size: 0.68rem; }
#tab-image .v2-retained-area button + button { margin-left: 4px; }
#tab-image .v2-rotate-palette .v2-orientation-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 6px; }
#tab-image .v2-rotate-palette .v2-orientation-button { min-height: 28px; padding: 3px 4px; font-size: 0.69rem; }
#tab-image .v2-rotate-palette .v2-fine-rotation,
#tab-image .v2-rotate-palette .v2-tilt-controls { margin: 0 6px 5px; }
#tab-image .v2-rotate-palette .v2-fine-rotation > summary,
#tab-image .v2-rotate-palette .v2-tilt-controls > summary { padding: 5px 6px; font-size: 0.7rem; }
#tab-image .v2-rotate-palette .v2-fine-rotation > .edge-row,
#tab-image .v2-rotate-palette .v2-tilt-controls > .edge-row { margin: 3px 0; padding: 0 6px; }
#tab-image .v2-rotate-palette .v2-fine-rotation input[type="range"],
#tab-image .v2-rotate-palette .v2-tilt-controls input[type="range"] { min-width: 0; width: 100%; }
#tab-image .v2-rotate-palette .v2-fine-rotation input[type="number"] { width: 4.5em; min-height: 27px; padding: 2px 4px; }
#tab-image .v2-rotate-palette .v2-tilt-controls .edge-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 6px; }
#tab-image .v2-rotate-palette .v2-tilt-controls .edge-row > input[type="range"] { grid-column: 1 / -1; }
.v2-draw-palette > .v2-scale-warning {
  position: static;
  width: auto;
  margin: 8px 10px 10px;
  padding: 9px 10px;
}
.v2-draw-hint { margin: 0 0 8px; color: var(--muted); font-size: 0.78rem; line-height: 1.3; }
.v2-scale-warning {
  top: 48px;
  z-index: 9;
  padding: 10px 11px;
  background: #fff5d8;
  color: var(--ink);
}
.v2-geometry-warning {
  top: 48px;
  z-index: 10;
  padding: 10px 11px;
  background: #fff5d8;
  color: var(--ink);
}
.v2-scale-warning-copy { margin: 0; font-size: 0.8rem; line-height: 1.35; }
.v2-scale-warning-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.v2-scale-warning-actions button { min-height: 30px; padding: 4px 8px; font-size: 0.72rem; }
#tab-image .canvas-warn:empty { display: none; }

/* Keep the two compact print controls beside one another on ordinary desktop
   widths. They may wrap only when the canvas genuinely becomes narrow. */
@media (min-width: 1280px) {
  #tab-image .canvas-head { flex-wrap: nowrap; gap: 8px; }
  #tab-image .measure-section { flex: 0 1 410px; min-width: 350px; }
  #tab-image .foot-section { flex: 1 1 auto; min-width: 0; padding: 6px 8px; }
  #tab-image .measure-section { padding: 6px 8px; }
  #tab-image .measure-section .lcd-readout.tape-readout { width: 250px; max-width: 100%; }
  #tab-image .measure-section .lcd-orient { gap: 4px; }
  #tab-image .measure-section .orient-opt span { padding: 2px 5px; font-size: 0.68rem; }
  #tab-image .foot-section .print-bar { gap: 5px; }
  #tab-image .foot-section label { font-size: 0.72rem; }
}
@media (min-width: 1200px) and (max-width: 1279px) {
  #tab-image .canvas-head { flex-wrap: nowrap; gap: 6px; }
  #tab-image .measure-section { flex: 0 1 350px; min-width: 315px; padding: 5px 6px; }
  #tab-image .foot-section { min-width: 0; padding: 5px 6px; }
  #tab-image .measure-section .lcd-readout.tape-readout { width: 205px; max-width: 100%; }
  #tab-image .measure-section .orient-opt span { padding: 2px 4px; font-size: 0.64rem; }
  #tab-image .foot-section .print-bar { gap: 4px; }
  #tab-image .foot-section label { font-size: 0.68rem; }
}

/* Keep History sized to its buttons even where the print sections expand. */
#tab-image .history-section {
  flex: 0 0 auto;
  gap: 5px;
  padding: 6px 8px;
}

/* The former empty tool pill carried no information. Scale remains visible as
   the useful status; detailed calibration stays one click away. */
#tool-status-img { display: none; }
#tab-image .status-strip { overflow: visible; }
#tab-image #img-status {
  flex: 0 1 min(34vw, 360px);
  width: min(34vw, 360px);
  max-width: min(34vw, 360px);
  min-width: 120px;
  font-size: 0.72rem;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
#tab-image .pv-i {
  width: 26px;
  height: 26px;
  margin: -5px 0 -5px 4px;
  font-size: 0.78rem;
  font-weight: 700;
}
#tab-image .orient-opt span { padding: 3px 6px; font-size: 0.72rem; }

@media (max-width: 1180px) and (min-width: 981px) {
  #tab-image .workspace { grid-template-columns: minmax(0, 1fr) 286px; gap: 10px; }
  .v2-workflow-tab { font-size: 0.7rem; padding-left: 2px; padding-right: 2px; }
  .v2-quick-tools button { padding-left: 6px; padding-right: 6px; }
}
@media (max-width: 980px) {
  #tab-image .workspace { grid-template-columns: minmax(0, 1fr); }
  #tab-image .v2-task-panel { min-height: 0; }
  .v2-workflow-pane { max-height: 640px; }
}

/* ===== Consent banner + footer ===== */
.consent-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 1000;
  background: var(--surface, #f6f1e4);
  border: 1px solid var(--line-strong, #b4aa8d);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  padding: 16px 20px;
  max-height: 70vh;
  overflow: auto;
  font-size: 0.92rem;
  color: var(--ink, #35302a);
}
.consent-banner-inner { max-width: 640px; margin: 0 auto; }
.consent-banner h2 { margin: 0 0 8px; font-size: 1.05rem; }
.consent-banner p { margin: 6px 0; line-height: 1.45; }
.consent-banner-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.consent-banner-actions button { margin: 0; }
.consent-banner[hidden] { display: none; }
.v2-corner-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.v2-corner-row label { display: flex; gap: 4px; align-items: center; }
.v2-corner-row input { width: 72px; min-width: 0; }
.v2-retained-area { margin: 10px 0; }
.v2-print-sizing-body { padding: 0 10px; }
.v2-deformation-confirm { margin: 12px 0; padding: 12px; border: 1px solid var(--line, #ccc); border-radius: 8px; }
.v2-print-sizing p, .v2-deformation-confirm p, .v2-print-sizing-review { font-size: 12px; line-height: 1.45; }
.v2-print-sizing label { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0; }
.v2-print-sizing select { max-width: 100%; min-width: 0; }
.v2-print-sizing label.v2-sizing-select-row { flex-wrap: nowrap; white-space: nowrap; }
.v2-print-sizing .v2-sizing-select-row select { flex: 1 1 0; width: 0; }
.v2-print-sizing input { width: 110px; min-width: 0; }
#tab-image .canvas-head .measure-section { container-type: inline-size; display: grid; grid-template-columns: max-content minmax(0, 250px) 112px minmax(100px, 220px); align-items: end; flex: 1 1 700px; min-width: min(100%, 700px); gap: 4px 8px; padding: 4px 8px; }
#tab-image .canvas-head > .history-section { align-self: stretch; padding: 4px 8px; }
#tab-image .canvas-head .measure-section .lcd-group { flex: 0 0 250px; width: 250px; min-width: 0; }
#tab-image .canvas-head .measure-section .tape-readout { box-sizing: border-box; width: 100%; max-width: 100%; height: 42px; min-height: 42px; line-height: 24px; }
#tape-btn-img { box-sizing: border-box; height: 42px; min-height: 42px; margin: 0; }
#measurement-size-control { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr); grid-template-rows: 12px 18px; align-content: center; column-gap: 4px; row-gap: 2px; width: 112px; height: 42px; margin: 0; font-size: .72rem; }
#measurement-size-basis { left: 50%; top: 50%; }
#measurement-size-control .measurement-basis-real { grid-column: 1; grid-row: 1; text-align: right; }
#measurement-size-control .measurement-basis-scaled { grid-column: 3; grid-row: 1; text-align: left; }
#measurement-size-control:has(input:not(:checked)) .measurement-basis-real,
#measurement-size-control:has(input:checked) .measurement-basis-scaled { color: var(--ink); font-weight: 700; }
#measurement-size-control[hidden] { display: none !important; }
#measurement-size-control .pg-track { grid-column: 2; grid-row: 2; width: 34px; height: 18px; }
#measurement-size-control .pg-thumb { width: 14px; height: 14px; }
#measurement-size-control input:checked + .pg-track .pg-thumb { left: 18px; }
.measure-distance-icon { display: none; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; }
#tab-image .measure-section > .progress-dock { grid-column: 4; grid-row: 1; position: relative; box-sizing: border-box; width: 100%; min-width: 0; height: 42px; margin: 0; padding: 0; }
#tab-image .measure-section .progress-meta { position: absolute; top: 3px; left: 8px; right: 8px; margin: 0; line-height: 12px; font-size: .72rem; }
#tab-image .measure-section .progress-track { position: absolute; top: 24px; left: 8px; right: 8px; height: 6px; }
@container (max-width: 700px) {
  #tape-btn-img { width: 36px; padding: 6px; }
  .measure-distance-label { display: none; }
  .measure-distance-icon { display: block; }
}
@media (max-width: 980px) {
  #tab-image .canvas-wrap { height: calc(clamp(320px, 55vh, 520px) + 44px); }
}
@media (max-width: 680px) {
  #tab-image .canvas-head .measure-section { grid-template-columns: 36px minmax(0, 1fr) 112px; }
  #tab-image .canvas-head .measure-section .lcd-group { grid-column: 2 / 4; grid-row: 1; width: min(250px, calc(100cqw - 44px)); }
  #measurement-size-control { grid-column: 3; grid-row: 2; height: 32px; }
  #tab-image .measure-section > .progress-dock { grid-column: 1 / 3; grid-row: 2; height: 32px; }
  #tab-image .measure-section .progress-meta { top: 1px; }
  #tab-image .measure-section .progress-track { top: 19px; }
}
@container (max-width: 450px) {
  #tab-image .canvas-head .measure-section .lcd-group { flex: 0 0 auto; width: min(250px, calc(100cqw - 44px)); }
  #tab-image .canvas-head .measure-section .tape-readout { font-size: 16px; letter-spacing: .02em; padding-left: 10px; padding-right: 10px; }
}
@container (max-width: 300px) {
  #tab-image .canvas-head .measure-section .tape-readout { font-size: 14px; padding-left: 8px; padding-right: 8px; }
}
#print-miniature-row > label:first-child { display: block; }
#print-miniature-preset { display: block; width: 100%; margin-top: 5px; }
.v2-print-sizing .ftin-group { display: flex; flex-wrap: wrap; max-width: 100%; }
.v2-print-sizing .ftin-group .ftin-ft { width: 3.2em; }
.v2-print-sizing .ftin-group .ftin-in { width: 4em; }
.v2-print-size-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#print-size-error, #geometry-error { color: #a02919; }
.v2-print-sizing [hidden], .v2-print-sizing[hidden], .v2-deformation-confirm[hidden] { display: none !important; }
.v2-retained-area p { font-size: 12px; }
.v2-prepare-surface button.pick-active { background: var(--accent); color: white; border-color: var(--accent-dark); }
.v2-prepare-surface button:disabled { background: #ddd; color: #777; border-color: #bbb; cursor: not-allowed; box-shadow: none; opacity: 1; }
#img-canvas.rectify-pick-mode { cursor: crosshair; }
#img-canvas.corner-adjust-mode { cursor: move; }
/* Amber-left tape LCD: the scale occupies a side rail, with no extra label row. */
#tab-image .canvas-head .measure-section {
  grid-template-columns: max-content minmax(0, 320px) 120px minmax(70px, 1fr);
  align-items: center;
}
#tab-image .canvas-head .measure-section .lcd-group { width: 100%; max-width: 320px; }
#tab-image .canvas-head .measure-section .tape-readout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: 58px;
  min-height: 58px;
  padding: 0;
  letter-spacing: 0;
  line-height: 1;
  text-overflow: clip;
}
#tab-image .canvas-head .measure-section .tape-readout.tape-dual {
  grid-template-columns: 62px minmax(0, 1fr);
}
.tape-readout [hidden] { display: none !important; }
.tape-readout .tape-single { display: flex; align-items: center; justify-content: safe center; padding: 0 10px; }
.tape-value { display: block; min-width: 0; overflow-x: auto; overflow-y: hidden; white-space: nowrap; font-size: 20px; line-height: 24px; font-weight: 700; scrollbar-width: thin; }
.tape-scale { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px; background: var(--accent); color: var(--lcd-bg); }
.tape-scale > span { font: 9px/1 system-ui, sans-serif; text-transform: uppercase; letter-spacing: .5px; }
.tape-scale strong { width: 100%; padding-inline: 4px; overflow: hidden; text-align: center; font-size: 14px; line-height: 18px; }
.tape-readings { display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); min-width: 0; padding: 3px 8px; gap: 2px; }
.tape-row { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: 5px; min-width: 0; }
.tape-caption { font: 10px/1 system-ui, sans-serif; text-transform: uppercase; }
.tape-row .tape-value { text-align: right; }
#tape-btn-img { position: relative; width: 132px; height: 58px; min-height: 58px; padding: 0; overflow: hidden; }
#tape-btn-img .measure-distance-icon { display: block; position: absolute; left: 3px; top: 5px; width: 128px; height: 48px; fill: currentColor; stroke: none; }
#tape-btn-img .tape-extension-short { display: none; }
#tape-btn-img .measure-distance-label { display: block; position: absolute; left: 44px; right: 5px; top: 14px; font-size: 16px; line-height: 20px; }
#measurement-size-control { width: 120px; min-width: 120px; }
@media (max-width: 680px) {
  #tape-btn-img { width: 48px; }
  #tape-btn-img .measure-distance-icon { left: 0; }
  #tape-btn-img .tape-extension { display: none; }
  #tape-btn-img .tape-extension-short { display: block; }
  #tape-btn-img .measure-distance-label { display: none; }
  #tab-image .canvas-head .measure-section { grid-template-columns: 48px minmax(0, 1fr) 120px; }
  #tab-image .canvas-head .measure-section .lcd-group { width: 100%; max-width: 320px; }
}
@container (max-width: 450px) {
  #tab-image .canvas-head .measure-section .tape-readout.tape-dual { grid-template-columns: 54px minmax(0, 1fr); }
  .tape-scale strong { font-size: 12px; }
  .tape-readings { padding-inline: 5px; }
  .tape-row { grid-template-columns: 38px minmax(0, 1fr); gap: 3px; }
}
.v2-prepare-surface #at-status { white-space: normal; border-radius: 8px; }
.v2-manual-size > p, .v2-prepare-surface > details > p { font-size: 12px; margin: 8px; }
@media (max-width: 980px) {
  .v2-prepare-apply { position: static; }
}
