/* Plans & drawings: gallery cards and the full-screen canvas editor. Tokens only. */

/* ---------- gallery ---------- */
.dw-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.dw-group + .dw-group { margin-top: var(--s2); }
.dw-group-head a { color: inherit; text-decoration: none; }
.dw-group-head a:hover { text-decoration: underline; }
.dw-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; text-decoration: none; color: inherit; }
.dw-thumb {
  position: relative; aspect-ratio: 3 / 2; background-color: var(--paper); border-bottom: 1px solid var(--border);
  display: grid; place-items: center; overflow: hidden;
}
.dw-thumb.paper-grid, .dw-thumb.paper-iso {
  background-image: linear-gradient(var(--paper-line) 1px, transparent 1px), linear-gradient(90deg, var(--paper-line) 1px, transparent 1px);
  background-size: 16px 16px;
}
.dw-thumb.paper-dots { background-image: radial-gradient(var(--paper-line) 1.2px, transparent 1.4px); background-size: 14px 14px; }
.dw-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dw-thumb-empty { color: var(--text-muted); opacity: .6; }
.dw-flag {
  position: absolute; left: 8px; top: 8px; display: inline-flex; gap: 4px; align-items: center; padding: 2px 8px;
  border-radius: var(--r-pill); background: var(--surface); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; box-shadow: var(--shadow-card);
}
.dw-meta { padding: var(--s3) var(--s4) var(--s4); }
.dw-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dw-meta .meta { font-size: var(--fs-xs); }
.dw-new {
  cursor: pointer; border: 1.5px dashed var(--border-input); background: transparent; box-shadow: none; min-height: 200px;
  align-items: center; justify-content: center; gap: 6px; padding: var(--s4); font: inherit; color: var(--text);
}
.dw-new:hover { background: var(--surface); border-color: var(--accent); }
.dw-new-ico { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-fill); color: var(--on-accent); margin-bottom: 4px; }
.dw-empty-actions { justify-content: center; }

/* plan sets in the gallery: one stacked card per set, opening up to its sheets */
.dw-set {
  box-shadow: var(--shadow-card), 6px 6px 0 -1px var(--surface), 6px 6px 0 0 var(--border), 11px 11px 0 -1px var(--surface), 11px 11px 0 0 var(--border);
  overflow: visible; margin: 0 11px 11px 0;
}
.dw-set.open { border-color: var(--accent-fill); }
.dw-set-open { display: flex; flex-direction: column; text-decoration: none; color: inherit; border-radius: var(--r-lg) var(--r-lg) 0 0; overflow: hidden; }
.dw-set-open:hover .dw-name { text-decoration: underline; }
.dw-set-actions { display: flex; align-items: center; gap: var(--s1); padding: 0 var(--s2) var(--s2); }
.dw-set-actions .btn { height: 44px; }
.dw-set-actions .btn.icon { width: 44px; }
.dw-set-sheets {
  grid-column: 1 / -1; display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  padding: var(--s3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.dw-sheet .dw-meta { padding: var(--s2) var(--s3) var(--s3); }
.dw-menu-row { width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent; font: inherit; color: inherit; text-align: left; min-height: 56px; }
.dw-menu-row .title, .dw-menu-row .meta { display: block; }
.dw-menu-row.danger, .dw-menu-row.danger .title { color: var(--danger); }

/* ---------- editor shell ---------- */
body.canvas-open .wheel-fab, body.canvas-open .wheel, body.canvas-open .wheel-scrim, body.canvas-open .rail { display: none !important; }
.cv { position: absolute; inset: 0; overflow: hidden; background: var(--paper); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.cv-canvas { position: absolute; inset: 0; display: block; touch-action: none; cursor: crosshair; }
.cv[data-tool="hand"] .cv-canvas, .cv.space .cv-canvas { cursor: grab; }
.cv.panning .cv-canvas { cursor: grabbing; }
.cv[data-tool="select"] .cv-canvas { cursor: default; }
.cv[data-tool="text"] .cv-canvas { cursor: text; }
.cv[data-tool="eraser"] .cv-canvas { cursor: none; }
.cv[data-tool="place"] .cv-canvas { cursor: copy; }

.cv-bar {
  position: absolute; z-index: 2; display: flex; align-items: center; gap: 2px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-pill); box-shadow: var(--shadow-float);
}
.cv-top-left { left: var(--s3); top: var(--s3); max-width: calc(50vw - 24px); }
.cv-top-right { right: var(--s3); top: var(--s3); }
.cv-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; flex: none; }
.cv-sep.h { width: 22px; height: 1px; margin: 4px 0; }
.cv-btn {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; background: transparent; color: var(--text);
  display: grid; place-items: center; cursor: pointer; transition: background var(--t-fast), color var(--t-fast);
}
.cv-btn:hover { background: var(--surface-2); }
.cv-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.cv-btn[aria-pressed="true"] { background: var(--accent-fill); color: var(--on-accent); }
.cv-btn.danger { color: var(--danger); }
.cv-title {
  border: 0; background: transparent; font-weight: 650; font-size: var(--fs-sm); color: var(--text); cursor: pointer;
  padding: 0 14px 0 4px; height: 40px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; border-radius: var(--r-pill);
}
.cv-title:hover { background: var(--surface-2); }

/* context bar: selection, wire, measure, placing */
.cv-ctx { left: 50%; top: 68px; transform: translateX(-50%); padding: 4px 6px 4px 14px; max-width: calc(100vw - 24px); overflow-x: auto; scrollbar-width: none; }
.cv-ctx[hidden] { display: none; }
.cv-ctx canvas { flex: none; margin-left: -6px; }
.cv-ctx-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); white-space: nowrap; padding-right: 6px; }
.cv-chip {
  height: 32px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--surface);
  font-weight: 600; font-size: var(--fs-xs); cursor: pointer; white-space: nowrap; color: var(--text); flex: none; margin-left: 2px;
}
.cv-chip.on { background: var(--text); color: var(--surface); border-color: transparent; }

/* shapes pill, above the wheel */
.cv-shapes { flex-direction: column; left: var(--s3); bottom: calc(var(--wheel) + var(--s5)); border-radius: var(--r-lg); }

/* the tool wheel */
.cv-wheel {
  position: absolute; z-index: 3; left: var(--s3); bottom: var(--s3); width: var(--wheel); height: var(--wheel); border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-pop);
}
.cv-wheel::before { content: ""; position: absolute; inset: 26%; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); }
.cv-wheel-tool {
  position: absolute; width: 38px; height: 38px; margin: -19px 0 0 -19px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--text-muted); cursor: pointer; transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.cv-wheel-tool:hover { background: var(--surface-2); color: var(--text); }
.cv-wheel-tool[aria-pressed="true"] { background: var(--accent-fill); color: var(--on-accent); transform: scale(1.08); }
.cv-wheel-center {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; transform: translate(-50%, -50%); border-radius: 50%;
  border: 0; background: transparent; cursor: pointer; display: grid; place-items: center;
}
.cv-ring {
  position: absolute; inset: 4px; border-radius: 50%;
  background: conic-gradient(var(--accent-fill) calc(var(--op, 100) * 1%), var(--border) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
}
.cv-dot { border-radius: 50%; box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 2.5px var(--border-input); transition: width var(--t-fast), height var(--t-fast); }
.cv-dot.eraser { background: transparent; box-shadow: 0 0 0 1.5px var(--text-muted); border: 1px dashed var(--text-muted); }
.cv-wheel-label {
  position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font-size: 9px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-muted); pointer-events: none;
}

/* brush popover */
.cv-pop {
  position: absolute; z-index: 4; left: calc(var(--wheel) + var(--s5)); bottom: var(--s3); width: 280px; padding: var(--s4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column; gap: var(--s3); animation: fade var(--t-base) var(--ease);
}
.cv-pop[hidden] { display: none; }
.cv-pop-title { font-weight: 650; }
.cv-range { display: grid; grid-template-columns: 60px 1fr 44px; gap: 8px; align-items: center; font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); }
.cv-range output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.cv-range input[type=range], .cv-layer-op { accent-color: var(--accent-fill); width: 100%; }
.cv-swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cv-swatch {
  aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--border-input); cursor: pointer; padding: 0; position: relative;
}
.cv-swatch.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent-fill); }
.cv-swatch.custom { background: conic-gradient(#c62f2f, #f5b301, #1d7044, #1f5fb8, #7a3fb0, #c62f2f); overflow: hidden; display: block; }
.cv-swatch.custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }

/* zoom pill */
.cv-zoom { right: var(--s3); bottom: var(--s3); }
.cv-zoom .cv-btn { width: 34px; height: 34px; }
.cv-zoom-label { border: 0; background: transparent; min-width: 52px; height: 34px; font-weight: 650; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; cursor: pointer; color: var(--text); border-radius: var(--r-pill); }
.cv-zoom-label:hover { background: var(--surface-2); }

/* plan set: sheet bar (bottom centre on tablets, above the zoom pill on phones); toasts sit above it */
body.canvas-open .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
.cv-sheetbar { left: 50%; bottom: var(--s3); transform: translateX(-50%); }
.cv-sheetbar[hidden] { display: none; }
.cv-sheetbar .cv-btn { width: 44px; height: 44px; }
.cv-sheet-label {
  display: inline-flex; align-items: center; gap: 6px; height: 44px; min-width: 104px; max-width: 240px; padding: 0 12px;
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text); font: inherit; font-size: var(--fs-sm); cursor: pointer;
}
.cv-sheet-label:hover { background: var(--surface-2); }
.cv-sheet-label strong { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cv-sheet-pos { font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; flex: none; }
.cv-sheet-list .cv-sheet-row { width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent; font: inherit; color: inherit; text-align: left; min-height: 64px; }
.cv-sheet-row.on { background: var(--accent-soft); }
.cv-sheet-text .title, .cv-sheet-text .meta { display: block; }
.cv-sheet-thumb {
  width: 72px; height: 48px; flex: none; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--paper);
  display: grid; place-items: center; overflow: hidden; color: var(--text-muted);
}
.cv-sheet-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* plan set import: full-screen page picker */
.sheet.cv-full { left: calc(var(--s3) + env(safe-area-inset-left)); width: auto; }
.pp { display: flex; flex-direction: column; gap: var(--s4); }
.pp-bar {
  position: sticky; top: calc(-1 * var(--s5)); z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2);
  margin: calc(-1 * var(--s5)) calc(-1 * var(--s5)) 0; padding: var(--s3) var(--s5); background: var(--surface); border-bottom: 1px solid var(--border);
}
.pp-bar .btn.sm { height: 40px; }
.pp-count { font-variant-numeric: tabular-nums; }
.pp-range { display: flex; gap: var(--s2); flex: 1 1 280px; max-width: 420px; }
.pp-range .input { flex: 1; min-width: 0; min-height: 40px; }
.pp-error { flex-basis: 100%; color: var(--danger); font-size: var(--fs-sm); font-weight: 600; }
.pp-error[hidden] { display: none; }
.pp-job { max-width: 420px; }
.pp-grid { display: grid; gap: var(--s4) var(--s3); grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.pp-tile { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pp-page {
  position: relative; aspect-ratio: 4 / 3; padding: var(--s2); border: 2px solid var(--border); border-radius: var(--r-md);
  background: var(--paper); cursor: pointer; display: grid; place-items: center; overflow: hidden; color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.pp-page[aria-pressed="true"] { border-color: var(--accent-fill); box-shadow: 0 0 0 2px var(--accent-soft); }
.pp-thumb { width: 100%; height: 100%; display: grid; place-items: center; min-height: 0; }
.pp-thumb canvas { max-width: 100%; max-height: 100%; display: block; box-shadow: var(--shadow-card); }
.pp-thumb.failed::after { content: "No preview"; font-size: var(--fs-xs); color: var(--text-muted); }
.pp-num { font-size: var(--fs-lg); font-weight: 650; color: var(--text-muted); opacity: .6; }
.pp-tile.off .pp-thumb { opacity: .4; }
.pp-tick {
  position: absolute; right: 6px; top: 6px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-fill); color: var(--on-accent); box-shadow: var(--shadow-card);
}
.pp-tile.off .pp-tick { background: var(--surface); color: transparent; box-shadow: inset 0 0 0 2px var(--border-input); }
.pp-cap { display: flex; align-items: center; gap: var(--s1); min-height: 44px; }
.pp-label { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: var(--lh-xs); }
.pp-label span { font-weight: 650; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pp-only {
  flex: none; height: 40px; padding: 0 var(--s3); border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: var(--fs-xs); font-weight: 600; cursor: pointer;
}
.pp-only:hover { border-color: var(--accent); }
.pp-progress-msg { margin: 0; font-weight: 650; }
.pp-progress-note { margin: 0; font-size: var(--fs-sm); }
.pp-failed { margin: 0; padding-left: var(--s5); font-size: var(--fs-sm); }
.pp-dialog-msg { margin: 0; }
.pp-choice .sheet-foot .btn { height: 44px; }

/* sheets */
.cv-symbol-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: var(--s2); }
.cv-symbol {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: var(--s3) var(--s2); border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--paper); cursor: pointer; font-size: var(--fs-xs); font-weight: 600; text-align: center; color: var(--text);
}
.cv-symbol:hover { border-color: var(--accent); }
.cv-symbol.on { border-color: var(--accent-fill); box-shadow: 0 0 0 2px var(--accent-soft); }
.cv-layers .list-row { gap: 2px; padding: 6px 8px; }
.cv-layer.active { background: var(--accent-soft); }
.cv-layer .cv-btn { width: 34px; height: 34px; }
.cv-layer-name { border: 0; background: transparent; text-align: left; display: flex; flex-direction: column; cursor: pointer; padding: 4px 8px; min-width: 0; color: var(--text); }
.cv-layer-name .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-layer-op { width: 72px !important; flex: none; }

/* rooms: sheet fields that only apply to some room types */
.sheet .field[hidden] { display: none; }

/* rooms: "add door, window…" picker */
.cv-feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--s2); }
.cv-feature {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: var(--s3); min-height: 56px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--paper); cursor: pointer; text-align: left; color: var(--text); font: inherit; font-size: var(--fs-sm);
}
.cv-feature:hover { border-color: var(--accent); }
.cv-feature small { font-size: var(--fs-xs); }

/* code check: findings panel (side panel on tablets, bottom sheet on phones) */
.cv-findings {
  position: absolute; z-index: 3; right: var(--s3); top: 68px; bottom: 64px; width: 330px; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); overflow: hidden;
  animation: fade var(--t-base) var(--ease);
}
.cv-findings[hidden] { display: none; }
.cv-findings-head { display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s3) var(--s2) var(--s2) var(--s4); }
.cv-findings-head .cv-btn { width: 34px; height: 34px; }
.cv-findings-book { font-size: var(--fs-xs); color: var(--text-muted); }
.cv-findings-bar { display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s3) var(--s2) var(--s4); flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.cv-findings-sum { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; min-width: 0; }
.cv-findings-live { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); cursor: pointer; }
.cv-findings-live input { accent-color: var(--accent-fill); width: 18px; height: 18px; }
.cv-sev { font-size: var(--fs-xs); font-weight: 650; padding: 2px 8px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--text-muted); }
.cv-sev.error { background: var(--danger-soft); color: var(--danger); }
.cv-sev.warning { background: var(--warning-soft); color: var(--warning); }
.cv-sev.info { background: var(--info-soft); color: var(--info); }
.cv-sev.ok { background: var(--success-soft); color: var(--success); }
.cv-findings-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--s1) 0; }
.cv-finding {
  display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s3) var(--s3) var(--s4); cursor: pointer;
  border-left: 3px solid transparent; min-height: 48px;
}
.cv-finding:hover { background: var(--surface-2); }
.cv-finding.on { background: var(--accent-soft); border-left-color: var(--accent-fill); }
.cv-finding-n {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700;
  color: var(--surface); background: var(--text-muted);
}
.cv-finding-n.error { background: var(--danger); }
.cv-finding-n.warning { background: var(--warning); }
.cv-finding-n.info { background: var(--info); }
.cv-finding-msg { font-size: var(--fs-sm); line-height: var(--lh-sm); }
.cv-finding-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; font-size: var(--fs-xs); color: var(--text-muted); }
.cv-rule { font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }
.cv-verify { font-weight: 700; letter-spacing: .04em; padding: 0 6px; border-radius: var(--r-pill); background: var(--warning-soft); color: var(--warning); }
.cv-finding .cv-chip { align-self: center; }
.cv-findings-foot { padding: var(--s2) var(--s4) var(--s3); font-size: var(--fs-xs); color: var(--text-muted); border-top: 1px solid var(--border); }

/* compact layout for phones */
@media (max-width: 760px) {
  .cv { --wheel: 140px; }
  .wide-only { display: none !important; }
  .cv-top-left { max-width: calc(100vw - 212px); }
  .cv-title { max-width: 140px; padding-right: 8px; }
  .cv-btn { width: 38px; height: 38px; }
  .cv-ctx { top: 64px; }
  .cv-wheel-tool { width: 34px; height: 34px; margin: -17px 0 0 -17px; }
  .cv-shapes { bottom: calc(var(--wheel) + var(--s4)); }
  .cv-shapes .cv-btn { width: 36px; height: 36px; }
  .cv-pop { left: var(--s3); right: var(--s3); width: auto; bottom: calc(var(--wheel) + var(--s5)); }
  .cv-zoom .cv-sep, .cv-zoom .cv-btn:first-child { display: none; }
  .cv-layer-op { display: none; }
  .cv-findings { left: var(--s2); right: var(--s2); top: auto; bottom: var(--s2); width: auto; max-height: 42vh; z-index: 5; }
  .cv-sheetbar { left: auto; right: var(--s3); bottom: 64px; transform: none; }
  body.canvas-open .toasts { bottom: calc(128px + env(safe-area-inset-bottom)); }
  .cv-sheet-label { min-width: 0; max-width: 132px; }
  .sheet.cv-full { top: env(safe-area-inset-top); left: 0; max-height: none; border-radius: 0; }
  .pp-grid { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); }
}
@media (max-width: 760px) and (orientation: landscape) { .cv-findings { max-height: 60vh; } }
@media print { .cv-findings { display: none !important; } }
@media (max-width: 380px) { .cv-zoom .cv-btn:nth-of-type(2) { display: none; } }
@media print { .cv-bar, .cv-wheel, .cv-pop { display: none !important; } }
.cv-layer .cv-btn[aria-pressed] { background: transparent; color: var(--text); }
.cv-layer .cv-btn[aria-label^="Unlock"] { color: var(--accent); }
