﻿:root {
  --paper: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #eef3f1;
  --ink: #1d2528;
  --muted: #667174;
  --line: #d5ddda;
  --teal: #007d72;
  --blue: #2f5d7c;
  --brick: #b05c43;
  --amber: #d59a2f;
  --green: #436f4d;
  --danger: #9f3434;
  --shadow: 0 18px 46px rgba(35, 47, 51, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; color: var(--ink); background: var(--paper); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }

.app-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: minmax(230px, auto) 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.94);
  backdrop-filter: blur(14px);
}

.brand { display: inline-flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-weight: 900;
}
.brand strong { display: block; font-size: 0.98rem; }
.brand small { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 700; }

.top-nav { display: flex; justify-content: center; gap: 10px; min-width: 0; }
.top-nav a,
.lang-switch button,
.tool-buttons button,
.btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 11px;
  font-weight: 800;
}
.top-nav a:hover,
.lang-switch button:hover,
.tool-buttons button:hover,
.btn:hover { border-color: var(--ink); }

.lang-switch { display: flex; gap: 6px; }
.lang-switch button { min-width: 42px; padding: 8px 9px; }
.lang-switch .is-active,
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { color: var(--muted); }
.btn.danger { color: var(--danger); border-color: rgba(159, 52, 52, 0.28); }
.btn.danger:hover { border-color: var(--danger); }
.btn:disabled,
button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}
.btn.full-width { width: 100%; }

.studio { padding: 22px; }
.studio-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 20px;
  margin-bottom: 18px;
}
.kicker {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}
.studio-heading h1,
.viewport-toolbar h2,
.block-head h2 { margin: 0; letter-spacing: 0; }
.studio-heading h1 { font-size: 2.2rem; line-height: 1.05; }
.lead { max-width: 760px; margin: 8px 0 0; color: var(--muted); font-size: 1rem; line-height: 1.5; }

.easy-flow {
  display: grid;
  grid-template-columns: minmax(220px, 0.72fr) minmax(0, 1.8fr);
  gap: 14px;
  align-items: stretch;
  margin-bottom: 18px;
}
.easy-flow-head {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  box-shadow: var(--shadow);
}
.easy-flow-head h2 {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.22;
}
.easy-flow-head p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-weight: 750;
}
.easy-step-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(128px, 1fr));
  gap: 10px;
}
.easy-step {
  min-height: 150px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  box-shadow: var(--shadow);
}
.easy-step.is-active { border-color: rgba(0, 125, 114, 0.36); background: #f5fbf9; }
.easy-step > span {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
  font-size: 0.82rem;
}
.easy-step b { font-size: 0.88rem; }
.easy-step p {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
  font-weight: 750;
}
.easy-step .btn { width: 100%; padding-inline: 8px; }

.metric-row { display: grid; grid-template-columns: repeat(4, minmax(96px, 1fr)); gap: 8px; }
.metric-row span {
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.metric-row b { font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-row small { color: var(--muted); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; }

.studio-grid {
  display: grid;
  grid-template-columns: 324px minmax(480px, 1fr) 356px;
  gap: 16px;
  align-items: start;
}
.control-rail,
.decision-rail {
  display: grid;
  gap: 12px;
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 104px);
  overflow: auto;
  padding-right: 2px;
}
.control-block,
.result-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow);
}
.block-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.block-head span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 900;
}
.block-head h2 { font-size: 1rem; }
.block-head.compact { margin-bottom: 10px; }

label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 0.83rem; font-weight: 800; }
label span { display: block; margin-bottom: 5px; }
.file-field {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}
.file-field > span { display: block; margin-bottom: 5px; }
.file-picker {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}
.file-picker input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.file-trigger {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  white-space: nowrap;
}
.file-name {
  min-height: 42px;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 125, 114, 0.12); }
textarea { min-height: 132px; resize: vertical; line-height: 1.45; }
.mono-area {
  min-height: 72px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
}
.field-grid { display: grid; gap: 8px; }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.button-row { display: flex; gap: 8px; }
.button-row.stack { display: grid; }
.btn { width: auto; }

.material-strip { display: grid; gap: 8px; }
.plan-builder,
.floor-zone-builder,
.custom-material-builder {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.custom-material-builder h3 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink);
}
.floor-zone-builder h3 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink);
}
.plan-builder .three-cols,
.plan-builder .two-cols,
.floor-zone-builder .two-cols,
.custom-material-builder .two-cols {
  grid-template-columns: 1fr;
}
.floor-zone-list { display: grid; gap: 7px; }
.floor-zone-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}
.floor-zone-row b { display: block; font-size: 0.82rem; }
.floor-zone-row small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}
.floor-zone-row button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--danger);
  font-weight: 900;
}
.opening-list { display: grid; gap: 6px; }
.opening-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
}
.opening-row span {
  min-width: 0;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}
.opening-row button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--danger);
  font-weight: 900;
}
.material-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel-soft);
}
.swatch,
.material-preview {
  width: 46px;
  height: 38px;
  border-radius: 6px;
  border: 1px solid rgba(29, 37, 40, 0.18);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.32);
}
.material-item b { display: block; font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.material-item small { color: var(--muted); font-size: 0.72rem; font-weight: 800; }

.visual-workspace { min-width: 0; }
.viewport-toolbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: var(--panel);
}
.viewport-toolbar h2 { font-size: 1.18rem; }
.tool-buttons { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.tool-buttons button { min-width: 42px; padding: 8px 10px; }
.view-mode-tabs { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.view-mode-tabs button { border: 0; border-right: 1px solid var(--line); border-radius: 0; min-width: 62px; background: #fff; }
.view-mode-tabs button:last-child { border-right: 0; }
.view-mode-tabs button.is-active,
#togglePlanReference.is-active,
#toggleWallEdit.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.stage-unified {
  position: relative;
  min-height: calc(100vh - 214px);
  height: 720px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  background: #dfe8e6;
}
.three-mount,
.three-mount canvas { width: 100%; height: 100%; display: block; }
.plan-canvas {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: min(430px, 42%);
  aspect-ratio: 1100 / 760;
  height: auto;
  border: 1px solid rgba(29, 37, 40, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.93);
  box-shadow: 0 16px 36px rgba(29, 37, 40, 0.16);
  touch-action: none;
}
.stage-unified.view-model.plan-collapsed .plan-canvas { display: none; }
.stage-unified.view-plan .three-mount { display: none; }
.stage-unified.view-plan .plan-canvas { position: static; width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; box-shadow: none; background: #fff; }
.stage-unified.view-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 42%); gap: 1px; background: var(--line); }
.stage-unified.view-split .three-mount { min-width: 0; min-height: 100%; background: #dfe8e6; }
.stage-unified.view-split .plan-canvas { position: static; width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; box-shadow: none; background: #fff; }
.plan-canvas.is-wall-editing { cursor: crosshair; box-shadow: 0 0 0 3px rgba(0, 128, 128, 0.18), 0 16px 36px rgba(29, 37, 40, 0.16); }

.object-list,
.breakdown,
.detail-list { display: grid; gap: 8px; }
.object-row,
.cost-row,
.detail-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px;
}
.object-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: start; }
.object-row.is-selected { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(213,154,47,.16); }
.object-row b,
.detail-row b { display: block; font-size: 0.86rem; }
.object-row small,
.detail-row small { color: var(--muted); font-size: 0.74rem; font-weight: 700; line-height: 1.35; }
.object-actions { display: flex; gap: 6px; }
.object-row button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--danger);
  font-weight: 900;
}
.object-actions button:first-child {
  width: 42px;
  color: var(--teal);
}
.cost-row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.cost-row span { color: var(--muted); font-weight: 800; }
.cost-row b { white-space: nowrap; }
.cost-row.total { background: var(--ink); border-color: var(--ink); color: #fff; }
.cost-row.total span { color: rgba(255,255,255,0.78); }
.detail-code {
  display: inline-flex;
  min-width: 42px;
  justify-content: center;
  margin-right: 6px;
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--panel-soft);
  color: var(--teal);
  font-weight: 900;
}
.detail-sketch {
  width: 100%;
  height: auto;
  display: block;
  margin-bottom: 8px;
  border-radius: 6px;
}
.request-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.request-grid .full { grid-column: 1 / -1; }
.field-note { margin: -3px 0 12px; color: var(--muted); font-size: 0.76rem; line-height: 1.42; font-weight: 750; }
.request-grid .field-note { margin: -4px 0 4px; }
.reference-file-chip { display: inline-flex; max-width: 100%; gap: 6px; align-items: center; margin: 0 0 10px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-soft); color: var(--ink); font-size: 0.76rem; font-weight: 850; }
.status { min-height: 20px; margin: 8px 0 0; color: var(--green); font-size: 0.83rem; font-weight: 900; }
.empty { margin: 0; color: var(--muted); font-weight: 800; }

@media (max-width: 1320px) {
  .easy-flow { grid-template-columns: 1fr; }
  .easy-step-grid { grid-template-columns: repeat(5, minmax(118px, 1fr)); overflow-x: auto; padding-bottom: 4px; }
  .studio-grid { grid-template-columns: 300px minmax(420px, 1fr); }
  .decision-rail { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); position: static; max-height: none; overflow: visible; }
  .request-block, .result-block:nth-child(4) { grid-column: 1 / -1; }
}

@media (max-width: 940px) {
  .app-bar { grid-template-columns: 1fr auto; }
  .top-nav { grid-column: 1 / -1; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; }
  .studio { padding: 14px; }
  .studio-heading { grid-template-columns: 1fr; align-items: start; }
  .easy-step-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .metric-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .studio-grid { grid-template-columns: 1fr; }
  .control-rail, .decision-rail { position: static; max-height: none; overflow: visible; }
  .stage-unified { height: 620px; min-height: 520px; }
  .plan-canvas { width: calc(100% - 28px); }
  .stage-unified.view-split { grid-template-columns: 1fr; grid-template-rows: minmax(360px, 1fr) minmax(300px, 44%); }
}

@media (max-width: 620px) {
  .app-bar { padding: 10px 12px; gap: 10px; }
  .brand strong { font-size: 0.9rem; }
  .brand small { font-size: 0.72rem; }
  .lang-switch button { min-width: 36px; padding: 7px; }
  .studio-heading h1 { font-size: 1.7rem; }
  .easy-step-grid { grid-template-columns: 1fr; }
  .three-cols, .two-cols, .request-grid, .decision-rail { grid-template-columns: 1fr; }
  .viewport-toolbar { align-items: flex-start; }
  .stage-unified { height: 560px; }
  .metric-row { grid-template-columns: 1fr; }
}

/* Mobile overflow guard */
.studio-grid,
.control-rail,
.decision-rail,
.visual-workspace,
.control-block,
.result-block,
.viewport-toolbar,
.stage-unified,
.metric-row,
.material-item,
.object-row,
.cost-row,
.detail-row,
.opening-row { min-width: 0; }
.easy-flow,
.easy-flow-head,
.easy-step,
.floor-zone-row { min-width: 0; }
.lead,
.brand strong,
.brand small,
.top-nav a,
.material-item b,
.material-item small,
.object-row small,
.detail-row small,
.opening-row span,
.easy-step p,
.easy-step b { overflow-wrap: anywhere; }
input,
select,
textarea { min-width: 0; }
.button-row { flex-wrap: wrap; }
input[type="file"] { font-size: 0.78rem; }
.file-picker input[type="file"] { font-size: 1px; }

@media (max-width: 940px) {
  .studio-grid { grid-template-columns: minmax(0, 1fr); }
  .top-nav { flex-wrap: wrap; }
}

@media (max-width: 620px) {
  body { overflow-x: hidden; }
  .studio { padding-inline: 14px; }
  .material-item { grid-template-columns: 46px minmax(0, 1fr); }
  .material-item > small { grid-column: 2; justify-self: start; }
  .viewport-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
}


.cad-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: #f9fbfa;
}
.cad-tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.cad-tool-group.compact { justify-content: flex-end; }
.cad-opening-controls {
  display: none;
  align-items: end;
  gap: 7px;
  padding: 7px;
  border: 1px solid rgba(176, 92, 67, 0.24);
  border-radius: 7px;
  background: #fff7f2;
}
.cad-toolbar.is-opening-mode .cad-opening-controls { display: flex; }
.cad-opening-controls label {
  width: 76px;
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
}
.cad-opening-controls span {
  display: block;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cad-opening-controls input {
  min-height: 32px;
  padding: 6px 7px;
  font-size: 0.76rem;
}
.cad-tool {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 900;
}
.cad-tool:hover,
.cad-tool.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.cad-history-tool {
  margin-left: 4px;
  border-color: rgba(0, 125, 114, 0.28);
  color: var(--teal);
}
.cad-history-tool + .cad-history-tool { margin-left: 0; }
.cad-tool:disabled:hover {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}
.cad-history-tool:disabled:hover {
  border-color: rgba(0, 125, 114, 0.28);
  color: var(--teal);
}
.cad-readout {
  min-width: 150px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.76rem;
  font-weight: 900;
  text-align: right;
}
.cad-hint {
  margin: 0;
  padding: 8px 12px;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}
.plan-canvas.is-cad-wall { cursor: copy; }
.plan-canvas.is-cad-delete-vertex { cursor: not-allowed; }
.plan-canvas.is-cad-door,
.plan-canvas.is-cad-window { cursor: cell; }
.plan-canvas.grid-off { background: rgba(255, 255, 255, 0.96); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(29, 37, 40, 0.56);
}
.modal-backdrop[hidden] { display: none; }
.reference-editor-dialog {
  width: min(1180px, 100%);
  max-height: min(880px, calc(100vh - 44px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
}
.reference-editor-head,
.reference-editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.reference-editor-head h2 { margin: 0; font-size: 1.28rem; }
.reference-editor-head p:last-child { margin: 5px 0 0; color: var(--muted); font-size: 0.88rem; font-weight: 700; }
.reference-editor-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 14px;
  padding: 16px;
  background: #f9fbfa;
}
#referenceEditorCanvas {
  width: 100%;
  height: min(62vh, 620px);
  min-height: 360px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(29,37,40,.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(29,37,40,.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(29,37,40,.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(29,37,40,.035) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  touch-action: none;
}
.reference-editor-side {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 10px;
}
.reference-editor-mode-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.reference-editor-mode-tabs button {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
  cursor: pointer;
}
.reference-editor-mode-tabs button:hover,
.reference-editor-mode-tabs button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}
.reference-scale-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.reference-scale-grid label {
  display: grid;
  gap: 5px;
}
.reference-scale-grid span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}
.reference-scale-grid input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 850;
}
.reference-editor-readout {
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  font-weight: 900;
}
.reference-editor-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  background: var(--panel);
}

@media(max-width: 960px) {
  .cad-toolbar { align-items: stretch; flex-direction: column; }
  .cad-tool-group, .cad-tool-group.compact { justify-content: flex-start; }
  .cad-opening-controls { width: 100%; flex-wrap: wrap; }
  .cad-opening-controls label { width: auto; flex: 1 1 92px; }
  .cad-readout { min-width: 0; text-align: left; }
  .reference-editor-body { grid-template-columns: 1fr; }
  .reference-editor-side { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .reference-editor-side .field-note,
  .reference-editor-mode-tabs,
  .reference-scale-grid,
  .reference-editor-readout { grid-column: 1 / -1; }
  #referenceEditorCanvas { height: 52vh; min-height: 300px; }
}

@media(max-width: 620px) {
  .modal-backdrop { padding: 10px; align-items: stretch; }
  .reference-editor-dialog { max-height: calc(100vh - 20px); }
  .reference-editor-head { align-items: flex-start; flex-direction: column; }
  .reference-editor-head .btn { width: 100%; }
  .reference-editor-side { grid-template-columns: 1fr; }
  .reference-scale-grid { grid-template-columns: 1fr; }
  .reference-editor-actions .btn { width: 100%; }
}
