/* ============================================================================
   Drawing Templates — Settings ▸ Preferences (src/drawing-standard.js)
   ----------------------------------------------------------------------------
   Our product, so tokens throughout. Two surfaces:

     card      Preferences' Drawing Templates TableCard, plus its publish modal
     ds-ed     the full-sheet layout editor, a full-screen layer over it

   Region colours carry meaning and are used nowhere else on the page:
     red   keep-out — nothing Drafter places may overlap it
     blue    placement — general notes and the revision table start here and grow
     violet  view — where the isometric goes; the other views take what's left
   ========================================================================== */

/* The card is Preferences' own TableCard + notes-table. What's ours keeps it calm: the files fold to
   one line, cells read as text until touched, Default is a pill on the name, rare actions in ⋯. */
.ds-tpl-same { color: var(--fg-subtle); }
/* Auto vs Custom: a fact, not a status — so plain text, coloured only when it's yours. */
.ds-layout.is-custom { font-size: var(--fs-sm); color: #1C7ED6; font-weight: var(--fw-medium); white-space: nowrap; }

/* ── Where the templates come from: one quiet line, Change to open ── */
.ds-files { margin: 0 20px 12px; border: 1px solid var(--gray-200); border-radius: var(--r-md); background: var(--gray-50); }
.ds-files-line { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; font-size: var(--fs-dense); color: var(--fg-muted); }
.ds-files-line > .icon { flex: none; color: var(--gray-500); }
.ds-files-cad { flex: none; font-weight: var(--fw-medium); color: var(--fg); }
.ds-files-cad::after { content: "·"; margin-left: 8px; color: var(--gray-400); }
.ds-files-src { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-link { flex: none; padding: 0; border: 0; background: none; color: var(--orange-600); font: inherit; font-weight: var(--fw-medium); cursor: pointer; }
.ds-link:hover { color: var(--orange-700); text-decoration: underline; }
.ds-files-body {
  display: grid;
  /* The CAD (and SOLIDWORKS' drawing template) on their own row; the two files side by side. */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 24px;
  /* One container: the body shares the header's grey, with no rule between them. */
  padding: 4px 12px 16px;
}
.ds-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ds-field-wide { grid-column: 1 / -1; max-width: calc(50% - 12px); }
.ds-field-full { grid-column: 1 / -1; }
.ds-inpart { flex-direction: row; align-items: flex-start; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--gray-100); cursor: pointer; }
.ds-inpart-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ds-inpart .toggle { flex: none; margin-top: 2px; }
/* The files added so far: plain rows, no box or rules; × shows on hover. */
.ds-dirs { list-style: none; margin: 0; padding: 0; }
.ds-dir { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 4px 0 6px; border-radius: var(--r-sm); font-size: var(--fs-dense); }
.ds-dir:hover { background: var(--gray-100); }
.ds-dir > .icon { flex: none; color: var(--gray-500); }
.ds-dir > .btn { opacity: 0; }
.ds-dir:hover > .btn, .ds-dir > .btn:focus-visible { opacity: 1; }
.ds-dir-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: var(--fs-sm); }
.ds-dir-name { font-family: inherit; font-size: var(--fs-dense); }
.ds-dir-meta { flex: none; font-size: var(--fs-sm); color: var(--fg-muted); }
.ds-dir.is-empty .ds-dir-meta { color: var(--warning); }
@media (max-width: 760px) {
  .ds-files-body { grid-template-columns: minmax(0, 1fr); }
  .ds-field-wide { max-width: none; }
}
.ds-field-label { font-size: var(--fs-dense); font-weight: var(--fw-medium); color: var(--fg); }
.ds-field-row { display: flex; gap: 8px; min-width: 0; }
.ds-path { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: var(--fs-sm); }
.ds-path-plain { font-family: inherit; }
.ds-select { width: 100%; }
.ds-field-row > .ds-select { flex: 1; min-width: 0; width: auto; }
.ds-field-row > .btn { flex: none; }
.ds-field-help { font-size: var(--fs-sm); color: var(--fg-muted); }
.ds-field-help.is-warn { color: var(--warning); }

/* ── The table: text until touched ── */
.ds-tt td { vertical-align: middle; }
.ds-tt th { white-space: nowrap; }
/* The name field hugs its text, so the Default pill sits right after the name. */
.ds-name .ds-ghost-input { flex: 0 1 auto; width: auto; field-sizing: content; min-width: 6ch; max-width: 100%; }
.ds-ghost {
  width: 100%;
  min-width: 0;
  height: 30px;
  margin: -5px 0 -5px -8px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  font: inherit;
  color: var(--fg);
  text-overflow: ellipsis;
}
.ds-ghost:hover { border-color: var(--gray-300); background: var(--white); }
.ds-ghost:focus { outline: none; border-color: var(--orange-500); background: var(--white); box-shadow: 0 0 0 3px var(--orange-100, rgba(255, 137, 51, 0.18)); }
.ds-ghost-select { appearance: none; -webkit-appearance: none; padding-right: 24px; cursor: pointer; }
.ds-ghost-select:hover, .ds-ghost-select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236B7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.ds-ghost-select.is-same { color: var(--fg-subtle); }
.ds-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ds-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-default {
  flex: none;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: var(--gray-100);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--gray-700);
}
.ds-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 8px; }
.ds-tt-foot { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; padding: 8px 12px 14px; border-top: 1px solid var(--gray-100); }
.ds-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: var(--fs-dense);
  color: var(--gray-700);
  cursor: pointer;
}
.ds-add:hover { background: var(--gray-100); color: var(--fg); }

/* ── Browse: what the add-in has reported, not this computer's disk ── */
.ds-browse { width: min(520px, calc(100vw - 32px)); }
.ds-modal .ds-browse-seen { display: flex; align-items: center; gap: 6px; margin: 0 0 var(--s-3); font-size: var(--fs-sm); color: var(--fg-muted); }
.ds-browse-path { padding: 6px 10px; border: 1px solid var(--gray-200); border-bottom: 0; border-radius: var(--r-md) var(--r-md) 0 0; background: var(--gray-50); font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--gray-700); }
.ds-browse-list { display: flex; flex-direction: column; max-height: 280px; overflow-y: auto; border: 1px solid var(--gray-200); border-radius: 0 0 var(--r-md) var(--r-md); }
.ds-browse-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-bottom: 1px solid var(--gray-100);
  background: var(--white);
  text-align: left;
  font-size: var(--fs-dense);
  color: var(--fg);
  cursor: pointer;
}
.ds-browse-item:last-child { border-bottom: 0; }
.ds-browse-item:hover { background: var(--gray-50); }
.ds-browse-item.is-on { background: var(--orange-50); box-shadow: inset 2px 0 0 var(--orange-500); }
.ds-browse-item > .icon { flex: none; color: var(--gray-500); }
.ds-browse-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-browse-meta { flex: none; font-size: var(--fs-sm); color: var(--fg-muted); }

/* ── Modals (Browse) ── */
.ds-modal-layer { position: fixed; inset: 0; z-index: var(--z-modal); display: grid; place-items: center; background: var(--scrim); }
.ds-modal { width: min(480px, calc(100vw - 32px)); padding: var(--s-6); border-radius: var(--r-lg); background: var(--white); box-shadow: var(--shadow-3); }
.ds-modal h3 { margin: 0 0 var(--s-2); font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.ds-modal p { margin: 0 0 var(--s-3); font-size: var(--fs-body); color: var(--gray-700); line-height: var(--lh-body); }
.ds-modal ul { margin: 0; padding: var(--s-3) var(--s-3) var(--s-3) 30px; border-radius: var(--r-md); background: var(--gray-50); font-size: var(--fs-dense); color: var(--gray-700); display: flex; flex-direction: column; gap: 4px; }
.ds-modal-foot { display: flex; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-5); }

/* ============================================================================
   LAYOUT EDITOR (ds-ed)
   ========================================================================== */
.ds-ed {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  background: var(--white);
  font-family: var(--font-sans);
}
.ds-ed-head {
  flex: none;
  height: 60px;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: 0 var(--s-4) 0 var(--s-2);
  border-bottom: 1px solid var(--gray-200);
}
.ds-ed-back {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--gray-700);
  cursor: pointer;
}
.ds-ed-back:hover { background: var(--gray-100); }
.ds-ed-title { display: flex; flex-direction: column; min-width: 0; }
.ds-ed-name { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-ed-sub { font-size: var(--fs-sm); color: var(--fg-muted); white-space: nowrap; }
.ds-ed-seg { flex: none; }
.ds-ed-grow { flex: 1; }

.ds-ed-body { flex: 1; min-height: 0; display: flex; }

/* Left list */
.ds-ed-list {
  flex: 0 0 232px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: var(--s-4) var(--s-3);
  border-right: 1px solid var(--gray-200);
  background: var(--gray-50);
}
.ds-list-group + .ds-list-group { margin-top: var(--s-5); }
.ds-list-label { padding: 0 var(--s-2) 6px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: 0.04em; text-transform: uppercase; color: var(--fg-subtle); }
.ds-list-item {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 34px;
  padding: 6px var(--s-2);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  font-size: var(--fs-dense);
  color: var(--fg);
  text-align: left;
  cursor: pointer;
}
.ds-list-item:hover, .ds-list-item.is-hover { background: var(--white); border-color: var(--gray-200); }
.ds-list-item.is-on { background: var(--white); border-color: var(--orange-400); box-shadow: var(--shadow-1); }
.ds-list-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-list-rename {
  flex: 1;
  min-width: 0;
  height: 22px;
  margin: -2px 0;
  padding: 0 4px;
  border: 1px solid var(--orange-400);
  border-radius: var(--r-sm);
  font: inherit;
  color: var(--fg);
  outline: none;
}
/* Only keep-outs the admin added can go; the bin shows on hover so the list stays calm. */
.ds-list-del {
  flex: none;
  width: 24px;
  height: 24px;
  margin: -4px -4px -4px 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-subtle);
  cursor: pointer;
  visibility: hidden;
}
.ds-list-item:hover .ds-list-del, .ds-list-item.is-on .ds-list-del, .ds-list-del:focus-visible { visibility: visible; }
.ds-list-del:hover { background: var(--gray-100); color: var(--danger, #E03131); }
/* A quiet text action, like Reset below — the list is the content, not the button. */
.ds-list-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  padding: 6px var(--s-2);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--gray-700);
  font-size: var(--fs-dense);
  cursor: pointer;
}
.ds-list-add:hover { color: var(--fg); background: var(--gray-100); }
/* A standard small default button, pinned to the bottom of the list. */
.ds-list-reset { margin-top: auto; align-self: flex-start; gap: 6px; }

.ds-swatch { flex: none; width: 14px; height: 14px; border-radius: 3px; border: 1.5px solid; }
.ds-swatch-keepout { border-color: #E03131; background: repeating-linear-gradient(45deg, rgba(224, 49, 49, 0.28) 0 2px, rgba(224, 49, 49, 0.06) 2px 5px); }
.ds-swatch-place { border-color: #1C7ED6; background: rgba(28, 126, 214, 0.12); border-style: dashed; }
.ds-swatch-view { border-color: #7048E8; background: rgba(112, 72, 232, 0.10); border-style: dashed; }

/* Canvas */
.ds-ed-canvas {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-3);
  background-color: var(--bg-2);
  background-image: radial-gradient(var(--gray-300) 1px, transparent 1px);
  background-size: 18px 18px;
  overflow: hidden;
}
.ds-ed-svg { width: 100%; height: 100%; display: block; user-select: none; touch-action: none; }
/* Region lines are hairlines on screen (non-scaling), like the sheet's own line-work; colour says
   what kind it is. Selection is NOT a heavier line in that colour: it's the canvas's orange halo. */
.ds-region-box { cursor: move; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ds-region-keepout .ds-region-box { stroke: #E03131; }
.ds-region-place .ds-region-box { fill: rgba(28, 126, 214, 0.06); stroke: #1C7ED6; stroke-dasharray: 5 3; }
.ds-region-view .ds-region-box { fill: rgba(112, 72, 232, 0.05); stroke: #7048E8; stroke-dasharray: 5 3; }
.ds-halo { fill: none; stroke: var(--orange-300); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.ds-halo.is-on { stroke: var(--orange-500); }
.ds-region-tag { pointer-events: none; }
.ds-region-tag-keepout rect { fill: #E03131; }
.ds-region-tag-place rect { fill: #1C7ED6; }
.ds-region-tag-view rect { fill: #7048E8; }
.ds-region-tag text { fill: #FFFFFF; font-size: 11px; font-weight: 500; font-family: var(--font-sans, Roboto, sans-serif); }
.ds-handle { fill: #FFFFFF; stroke: var(--orange-500); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ds-handle:hover { fill: var(--orange-50); }
.ds-handle-nw, .ds-handle-se { cursor: nwse-resize; }
.ds-handle-ne, .ds-handle-sw { cursor: nesw-resize; }

/* The sample is a preview, never a target: clicks go through to the regions under it. */

/* ── The editor's three steps (Sheet · Title block · Layout) ── */
.ds-steps { flex: none; display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r-md); background: var(--gray-100); }
.ds-step { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 var(--s-3); border: 0; border-radius: calc(var(--r-md) - 2px); background: transparent; font: inherit; font-size: var(--fs-dense); color: var(--gray-700); cursor: pointer; }
.ds-step:hover { color: var(--fg); }
.ds-step.is-on { background: var(--white); color: var(--fg); box-shadow: var(--shadow-1); font-weight: var(--fw-medium); }
.ds-step-num { width: 18px; height: 18px; display: inline-grid; place-items: center; border-radius: 50%; background: var(--gray-200); font-size: 11px; font-weight: var(--fw-semibold); color: var(--gray-700); }
.ds-step.is-on .ds-step-num { background: var(--orange-500); color: var(--white); }
.ds-step-next { margin-top: auto; align-self: stretch; }
.ds-hint { padding: 6px var(--s-2) 0; font-size: var(--fs-xs); line-height: var(--lh-snug); color: var(--fg-muted); }
.ds-ed-list .ds-select { width: 100%; }
/* Step 1: where the template came from. */
.ds-sheet-src { display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-2); font-size: var(--fs-dense); color: var(--fg); min-width: 0; }
.ds-sheet-src-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--fw-medium); }
.ds-sheet-src-sub { padding: 2px var(--s-2) 0 32px; font-size: var(--fs-xs); color: var(--fg-muted); }
/* Outlines of what Drafter read, lit from the list. */
.ds-found { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; pointer-events: none; }
.ds-found-keepout { stroke: #E03131; }
.ds-found-place { stroke: #1C7ED6; }
.ds-found-view { stroke: #7048E8; }
.ds-found.is-hover { stroke-width: 3; stroke-dasharray: none; }
/* Keep-outs: the corner a block grows from, and the sample part. */
.ds-anchor { fill: none; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.ds-anchor-place { stroke: #1C7ED6; }
.ds-anchor-view { stroke: #7048E8; }
/* A block that fills: the edge it's pinned to, and the arrow (a button) the way it grows. */
.ds-pin { fill: none; stroke: #1C7ED6; stroke-width: 3; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.ds-grow { cursor: pointer; }
.ds-grow circle { fill: #FFFFFF; stroke: #1C7ED6; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ds-grow path { fill: none; stroke: #1C7ED6; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.ds-grow:hover circle { fill: #1C7ED6; }
.ds-grow:hover path { stroke: #FFFFFF; }
/* Under the selected block in the list: which way it grows. */
.ds-grow-field { padding: 6px 0 var(--s-2) 0; }
.ds-grow-seg { display: flex; width: 100%; }
.ds-grow-seg .seg-item { flex: 1; height: 28px; padding: 0 var(--s-2); }
.ds-preview-toggle { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-5); padding: 6px var(--s-2); font-size: var(--fs-dense); color: var(--fg); cursor: pointer; }
.ds-preview-toggle input { position: absolute; opacity: 0; pointer-events: none; }
/* ── The card: where each template came from, and an upload in progress ── */
.ds-src { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.ds-src-tag { flex: none; padding: 1px 6px; border-radius: var(--r-sm); background: var(--gray-100); font-size: 11px; color: var(--gray-700); }
.ds-src-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-reading { align-self: center; font-size: var(--fs-sm); color: var(--fg-muted); }
.ds-reading.is-error { color: var(--danger, #E03131); }

/* ── Drafter's drawing editor, with a standard on: its Size menu (src/drawing-views.js) ── */
.dv-std-menu-label { padding: 6px var(--s-2) 4px; }
/* `width: 0; min-width: 100%` so the note wraps to the menu instead of widening it. */
.dv-std-menu-foot {
  width: 0;
  min-width: calc(100% + var(--s-2));
  box-sizing: border-box;
  margin: var(--s-1) calc(var(--s-1) * -1) calc(var(--s-1) * -1);
  padding: var(--s-2);
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  color: var(--fg-muted);
}
/* Template names in the Size menu read as words, not codes: sans, not the scale ladder's mono. */
.dv-pick-item-name, .dv-pick-current-name { font-family: var(--font-sans); font-weight: var(--fw-medium); }
