/* STEP Viewer plugin styles (design doc §8).
   Uses Obsidian CSS variables so the viewer matches the active theme. */

.step-viewer-content {
  padding: 0;
  height: 100%;
}

.step-viewer-host {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--background-primary);
}

.step-viewer-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* --- Toolbar overlay --- */
/* Right-side rail: view cube, roll arrows and toolbar stacked top-right. */
.step-viewer-rail {
  position: absolute;
  top: var(--size-4-2);
  right: var(--size-4-2);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--size-4-2);
  z-index: 10;
}

.step-viewer-viewcube {
  width: 96px;
  height: 96px;
  cursor: pointer;
}

.step-viewer-roll {
  display: flex;
  gap: var(--size-2-1);
  padding: var(--size-2-1);
  border-radius: var(--radius-m);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
}

.step-viewer-toolbar {
  display: flex;
  flex-direction: column;
  gap: var(--size-2-1);
  padding: var(--size-2-1);
  border-radius: var(--radius-m);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
}


.step-viewer-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
}

.step-viewer-btn:hover {
  color: var(--text-normal);
  background-color: var(--background-modifier-hover);
}

.step-viewer-btn.is-active {
  color: var(--text-accent);
  background-color: var(--background-modifier-active-hover);
}

/* --- Measurement / annotate cursor --- */
.step-viewer-host.is-measuring .step-viewer-canvas,
.step-viewer-host.is-annotating .step-viewer-canvas {
  cursor: crosshair;
}

/* --- Immersive (walk / fly) mode: centre crosshair + controls hint --- */
.step-viewer-host.is-immersive .step-viewer-canvas {
  cursor: none;
}
.step-viewer-host.is-immersive::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 20;
}
.step-viewer-host.is-immersive::before {
  content: "WASD move · Q/E down/up · Shift faster · mouse look · Esc exit";
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-on-accent, #fff);
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
}

/* --- Projected HTML labels (measurement numbers + annotations) --- */
.step-viewer-labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.step-viewer-labels > * {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

/* Labels whose anchor is behind the camera / outside the depth range. The
   two-class selector outweighs the per-label display rules (e.g. annotations
   use display:flex) without needing !important. */
.step-viewer-labels > .step-viewer-label-offscreen {
  display: none;
}

.step-viewer-mlabel {
  padding: 1px 6px;
  border-radius: var(--radius-s);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
  font-size: var(--font-ui-smaller);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.step-viewer-annot {
  display: flex;
  align-items: flex-start;
  gap: var(--size-2-1);
  max-width: 200px;
  padding: var(--size-2-1) var(--size-2-2);
  border-radius: var(--radius-s);
  border: 1px solid var(--background-modifier-border);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
  pointer-events: auto;
}

.step-viewer-annot-body {
  display: flex;
  flex-direction: column;
  gap: var(--size-2-1);
  min-width: 0;
}

.step-viewer-annot-tools {
  display: flex;
  align-items: center;
  gap: var(--size-2-1);
  padding-bottom: var(--size-2-1);
  border-bottom: 1px solid var(--background-modifier-border);
}

.step-viewer-annot-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.step-viewer-annot-tool:hover {
  color: var(--text-normal);
  background-color: var(--background-modifier-hover);
}

.step-viewer-annot-tool.is-active {
  color: var(--text-on-accent);
  background-color: var(--interactive-accent);
}

.step-viewer-annot-tool svg {
  width: 15px;
  height: 15px;
}

/* Delete button sits at the far right of the tools row. */
.step-viewer-annot-del {
  margin-left: auto;
}

/* Colour swatch button + palette popover. */
.step-viewer-annot-swatch {
  border: 1px solid var(--background-modifier-border);
}

.step-viewer-annot-swatch:hover {
  background-color: inherit; /* keep the swatch colour on hover */
}

.step-viewer-annot-palette {
  display: flex;
  gap: var(--size-2-1);
  padding: var(--size-2-1) 0;
}

.step-viewer-annot-palette-swatch {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-s);
  cursor: pointer;
}

.step-viewer-annot-palette-swatch:hover {
  outline: 2px solid var(--interactive-accent);
  outline-offset: 1px;
}

/* Custom-colour picker sitting alongside the preset swatches. */
.step-viewer-annot-palette-custom {
  width: 22px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-s);
  cursor: pointer;
  background: none;
}

.step-viewer-annot-palette-custom::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.step-viewer-annot-palette-custom::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

/* Leader arrowhead (points at the anchor). */
.step-viewer-leader-arrow {
  fill: var(--text-muted);
}

.step-viewer-annot-text {
  min-width: 60px;
  font-size: var(--font-ui-smaller);
  color: var(--text-normal);
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}

.step-viewer-annot-text:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
}

.step-viewer-annot-del {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  padding: 0;
  line-height: 1;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.step-viewer-annot-del:hover {
  color: var(--text-error);
  background-color: var(--background-modifier-hover);
}

.step-viewer-annot.is-hidden {
  display: none;
}

.step-viewer-annot.is-flash {
  outline: 2px solid var(--interactive-accent);
  outline-offset: 1px;
}

/* Collapsed marker used in hover-only mode. */
.step-viewer-annot-dot {
  display: none;
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background-color: #ffc531;
  box-shadow: 0 0 0 2px var(--background-primary);
}

/* Hover-only: collapse to just the dot; expand the note on hover. */
.step-viewer-annot.is-hover-only {
  padding: 0;
  border-color: transparent;
  background-color: transparent;
  box-shadow: none;
}

.step-viewer-annot.is-hover-only .step-viewer-annot-dot {
  display: block;
}

.step-viewer-annot.is-hover-only .step-viewer-annot-body {
  display: none;
}

.step-viewer-annot.is-hover-only:hover {
  padding: var(--size-2-1) var(--size-2-2);
  border-color: var(--background-modifier-border);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
}

.step-viewer-annot.is-hover-only:hover .step-viewer-annot-dot {
  display: none;
}

.step-viewer-annot.is-hover-only:hover .step-viewer-annot-body {
  display: flex;
}

/* Leader mode: the toolbar strip doubles as a drag handle. */
.step-viewer-annot.is-leader .step-viewer-annot-tools {
  cursor: move;
}

.step-viewer-annot.is-dragging {
  opacity: 0.85;
  user-select: none;
}

/* Leader connector lines (drawn behind the labels). */
.step-viewer-leaders {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.step-viewer-leader-line {
  stroke: var(--text-muted);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
  opacity: 0.85;
}

/* Leader line hidden while its label is off-screen or pinned on the anchor. */
.step-viewer-leader-line.is-hidden {
  display: none;
}

/* Pinned (persistent) measurement labels. */
.step-viewer-mpinned {
  display: flex;
  align-items: center;
  gap: var(--size-2-1);
  padding: 1px var(--size-2-1) 1px var(--size-2-2);
  border-radius: var(--radius-s);
  border: 1px solid var(--background-modifier-border);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
  font-size: var(--font-ui-smaller);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: auto;
}

.step-viewer-mpinned-text {
  color: #ff5500;
}

.step-viewer-mpinned-del {
  width: 16px;
  height: 16px;
  padding: 0;
  line-height: 1;
  border: none;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.step-viewer-mpinned-del:hover {
  color: var(--text-error);
  background-color: var(--background-modifier-hover);
}

.step-viewer-mpinned.is-hidden {
  display: none;
}

.step-viewer-mpinned.is-flash {
  outline: 2px solid var(--interactive-accent);
  outline-offset: 1px;
}

/* --- Annotations list panel --- */
.step-viewer-annots {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: 45vh;
  width: 240px;
  border-radius: var(--radius-m);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
  overflow: hidden;
}

/* --- Measurements section in the annotations list --- */
.step-viewer-annots-subhead {
  padding: var(--size-2-2) var(--size-4-2) var(--size-2-1);
  font-size: var(--font-ui-smaller);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-top: 1px solid var(--background-modifier-border);
}

.step-viewer-annots-mdot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-top: 2px;
  background: none;
  color: var(--text-muted);
}

.step-viewer-annots-mdot svg {
  width: 14px;
  height: 14px;
}

/* --- Resize grip (structure tree + annotations panels) --- */
.step-viewer-resize-grip {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 2;
  /* A subtle diagonal-corner glyph drawn with a gradient of two hairlines. */
  background-image: linear-gradient(
    135deg,
    transparent 0 45%,
    var(--background-modifier-border) 45% 55%,
    transparent 55% 70%,
    var(--background-modifier-border) 70% 80%,
    transparent 80%
  );
  opacity: 0.7;
}

.step-viewer-resize-grip:hover {
  opacity: 1;
}

.step-viewer-tree.is-resizing,
.step-viewer-annots.is-resizing {
  user-select: none;
}

.step-viewer-annots-header {
  display: flex;
  align-items: center;
  gap: var(--size-2-2);
  padding: var(--size-2-1) var(--size-2-2) var(--size-2-1) var(--size-4-2);
  border-bottom: 1px solid var(--background-modifier-border);
}

.step-viewer-annots-header .step-viewer-tree-title {
  margin-right: auto;
}

.step-viewer-annots-opacity {
  width: 70px;
}

.step-viewer-annots-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: var(--size-2-1) 0;
}

.step-viewer-annots-empty {
  padding: var(--size-2-2) var(--size-4-2);
  font-size: var(--font-ui-smaller);
  color: var(--text-muted);
}

.step-viewer-annots-row {
  display: flex;
  align-items: flex-start;
  gap: var(--size-2-1);
  padding: var(--size-2-1) var(--size-2-2) var(--size-2-1) var(--size-4-2);
}

.step-viewer-annots-row:hover {
  background-color: var(--background-modifier-hover);
}

.step-viewer-annots-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.step-viewer-annots-text {
  font-size: var(--font-ui-small);
  color: var(--text-normal);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-viewer-annots-part {
  font-size: var(--font-ui-smaller);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-viewer-annots-del {
  flex: 0 0 auto;
}

/* --- Note embeds --- */
.step-viewer-embed-host {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius-m);
  border: 1px solid var(--background-modifier-border);
  background-color: var(--background-primary);
}

.step-viewer-embed-placeholder {
  gap: var(--size-2-2);
}

.step-viewer-measure-readout {
  position: absolute;
  left: var(--size-4-2);
  bottom: var(--size-4-2);
  display: flex;
  align-items: center;
  gap: var(--size-2-2);
  padding: var(--size-2-2) var(--size-4-2);
  border-radius: var(--radius-m);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
  color: var(--text-normal);
  font-size: var(--font-ui-small);
  font-variant-numeric: tabular-nums;
  z-index: 10;
  pointer-events: none;
}

/* The readout is click-through, but the "pin" button must accept clicks. */
.step-viewer-measure-keep {
  flex: 0 0 auto;
  pointer-events: auto;
}

/* --- Measurement-type strip (under the toolbar while measuring) --- */
.step-viewer-measure-modes {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--size-2-1);
  max-width: 190px;
  padding: var(--size-2-1);
  border-radius: var(--radius-m);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
}

.step-viewer-mode-btn {
  min-width: 26px;
  height: 26px;
  font-size: var(--font-ui-medium);
  line-height: 1;
}

/* --- Floating view controls (section, explode) at bottom-centre --- */
.step-viewer-viewctls {
  position: absolute;
  bottom: var(--size-4-2);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--size-2-2);
  z-index: 10;
  pointer-events: none;
}

.step-viewer-viewctl {
  display: flex;
  align-items: center;
  gap: var(--size-2-2);
  padding: var(--size-2-1) var(--size-4-2);
  border-radius: var(--radius-m);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
  pointer-events: auto;
}

.step-viewer-viewctl-title {
  font-size: var(--font-ui-smaller);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.step-viewer-viewctl-axes {
  display: flex;
  gap: var(--size-2-1);
}

.step-viewer-viewctl-axis,
.step-viewer-viewctl-flip {
  min-width: 26px;
  height: 24px;
  padding: 0 var(--size-2-2);
  font-size: var(--font-ui-smaller);
}

.step-viewer-viewctl-slider {
  width: 150px;
}

.step-viewer-viewctl-hint {
  font-size: var(--font-ui-smaller);
  color: var(--text-muted);
}

/* --- Annotation extras: colour swatch, link, markdown --- */
.step-viewer-annot-dot {
  background-color: var(--annot-color, #ffc531);
}

.step-viewer-annot-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--background-modifier-border);
}

.step-viewer-annot-link {
  display: block;
  font-size: var(--font-ui-smaller);
  color: var(--text-accent);
  cursor: pointer;
  pointer-events: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.step-viewer-annot-linkrow {
  display: flex;
}

.step-viewer-annot-linkrow input {
  width: 100%;
  font-size: var(--font-ui-smaller);
}

.step-viewer-annot-render {
  font-size: var(--font-ui-smaller);
  color: var(--text-normal);
  pointer-events: auto;
  cursor: text;
  max-width: 200px;
  word-break: break-word;
}

.step-viewer-annot-render > *:first-child {
  margin-top: 0;
}

.step-viewer-annot-render > *:last-child {
  margin-bottom: 0;
}

/* --- Annotations panel: category filter + row dots --- */
.step-viewer-annots-filter {
  display: flex;
  align-items: center;
  gap: var(--size-2-1);
  padding: var(--size-2-1) var(--size-4-2);
  border-bottom: 1px solid var(--background-modifier-border);
}

.step-viewer-annots-chip {
  min-width: 22px;
  height: 20px;
  padding: 0 var(--size-2-1);
  font-size: var(--font-ui-smaller);
  border-radius: var(--radius-s);
  border: 1px solid var(--background-modifier-border);
  cursor: pointer;
  opacity: 0.5;
}

.step-viewer-annots-chip.is-active {
  opacity: 1;
  outline: 2px solid var(--interactive-accent);
  outline-offset: 1px;
}

.step-viewer-annots-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  margin-top: 3px;
  padding: 0;
  border: 1px solid var(--background-modifier-border);
  border-radius: 50%;
  cursor: pointer;
}

button.step-viewer-annots-dot:hover {
  outline: 2px solid var(--interactive-accent);
  outline-offset: 1px;
}

/* Measurement rows use the dot slot for a ruler glyph, not a colour button. */
.step-viewer-annots-mdot {
  cursor: default;
  border: none;
}

button.step-viewer-annots-mdot:hover {
  outline: none;
}

/* Colour-picker popover opened from a list row's dot. */
.step-viewer-annots-pop {
  position: fixed;
  z-index: 100;
  display: flex;
  gap: var(--size-2-1);
  padding: var(--size-2-1);
  border-radius: var(--radius-s);
  border: 1px solid var(--background-modifier-border);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-m);
}

/* --- Part info panel (hover) --- */
.step-viewer-info {
  position: absolute;
  right: var(--size-4-2);
  bottom: var(--size-4-2);
  max-width: 260px;
  padding: var(--size-2-2) var(--size-4-2);
  border-radius: var(--radius-m);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
  z-index: 10;
  pointer-events: none;
}

.step-viewer-info-name {
  font-size: var(--font-ui-small);
  font-weight: var(--font-semibold);
  color: var(--text-normal);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-viewer-info-meta {
  font-size: var(--font-ui-smaller);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.step-viewer-info-path {
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-viewer-info-mat {
  display: flex;
  align-items: center;
  gap: var(--size-2-1);
  color: var(--text-normal);
}

.step-viewer-info-swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid var(--background-modifier-border);
}

/* --- Left rail: stacked side panels (tree, annotations) --- */
.step-viewer-left {
  position: absolute;
  top: var(--size-4-2);
  left: var(--size-4-2);
  display: flex;
  flex-direction: column;
  gap: var(--size-4-2);
  max-height: calc(100% - var(--size-4-4));
  z-index: 10;
}

/* --- Structure tree panel --- */
.step-viewer-tree {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: 45vh;
  width: 240px;
  border-radius: var(--radius-m);
  background-color: var(--background-secondary);
  box-shadow: var(--shadow-s);
  overflow: hidden;
}

.step-viewer-tree-header {
  display: flex;
  align-items: center;
  gap: var(--size-2-2);
  padding: var(--size-2-1) var(--size-2-2) var(--size-2-1) var(--size-4-2);
  border-bottom: 1px solid var(--background-modifier-border);
}

.step-viewer-tree-count {
  font-size: var(--font-ui-smaller);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.step-viewer-tree-actions {
  display: flex;
  align-items: center;
  gap: var(--size-2-1);
  margin-left: auto;
}

.step-viewer-tree-actions .step-viewer-btn {
  width: 24px;
  height: 24px;
}

.step-viewer-tree-filter {
  margin: var(--size-2-1) var(--size-2-2);
  padding: var(--size-2-1) var(--size-2-2);
  font-size: var(--font-ui-smaller);
}

.step-viewer-tree-row.is-filtered-out {
  display: none;
}

.step-viewer-tree-title {
  font-size: var(--font-ui-smaller);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.step-viewer-tree-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: var(--size-2-1) 0;
}

.step-viewer-tree-row {
  display: flex;
  align-items: center;
  gap: var(--size-2-1);
  padding: 1px var(--size-4-2) 1px 0;
  font-size: var(--font-ui-small);
  white-space: nowrap;
}

.step-viewer-tree-row.is-active {
  background-color: var(--background-modifier-active-hover);
  border-radius: var(--radius-s);
}

.step-viewer-tree-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: var(--text-muted);
  cursor: pointer;
}

.step-viewer-tree-caret:empty {
  cursor: default;
}

.step-viewer-tree-check {
  flex: 0 0 auto;
  margin: 0;
}

.step-viewer-tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  color: var(--text-normal);
}

.step-viewer-tree-label:hover {
  color: var(--text-accent);
}

/* --- Overlays (loading / empty / error) --- */
.step-viewer-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--size-4-2);
  padding: var(--size-4-4);
  text-align: center;
  pointer-events: none;
}

/* Overlays are click-through, but interactive controls inside them (e.g. the
   mobile "Open anyway" button) must still receive taps. */
.step-viewer-overlay button {
  pointer-events: auto;
}

.step-viewer-message {
  color: var(--text-normal);
  font-size: var(--font-ui-medium);
}

.step-viewer-message-sub {
  color: var(--text-muted);
  font-size: var(--font-ui-smaller);
  max-width: 40ch;
}

.step-viewer-error .step-viewer-message {
  color: var(--text-error);
}

/* --- Loading spinner --- */
.step-viewer-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--background-modifier-border);
  border-top-color: var(--interactive-accent);
  border-radius: 50%;
  animation: step-viewer-spin 0.8s linear infinite;
}

@keyframes step-viewer-spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Mobile layout ---------------------------------------------------------
   Scoped to Obsidian's body.is-mobile so the desktop layout is untouched.
   Shrinks the fixed-size overlays and enlarges tap targets so the viewer is
   usable on a narrow touchscreen. */
body.is-mobile .step-viewer-viewcube {
  width: 64px;
  height: 64px;
}

/* Fixed-width side panels must never exceed the viewport on a narrow screen. */
body.is-mobile .step-viewer-tree,
body.is-mobile .step-viewer-annots {
  width: min(240px, calc(100vw - var(--size-4-8)));
}

/* Comfortable tap targets for the toolbar / roll / view-cube buttons. */
body.is-mobile .step-viewer-btn {
  min-width: 40px;
  min-height: 40px;
}

/* Keep the corner readouts within the viewport width. */
body.is-mobile .step-viewer-info,
body.is-mobile .step-viewer-measure-readout {
  max-width: calc(100vw - var(--size-4-8));
}


/* STEP Viewer web shell.
   1. Obsidian's CSS variables (the viewer's styles.css is written against them)
   2. Obsidian base widgets the viewer relies on (clickable-icon, mod-cta, menu, notice)
   3. The app shell (header, empty state, settings, modals) */

/* ---------- 1. Theme variables ---------- */
:root, body.theme-light {
  color-scheme: light;
  --background-primary: #ffffff;
  --background-secondary: #f6f6f7;
  --background-modifier-border: #e0e0e2;
  --background-modifier-hover: rgba(0, 0, 0, 0.06);
  --background-modifier-active-hover: rgba(242, 200, 0, 0.28);
  --text-normal: #1f2328;
  --text-muted: #5f6368;
  --text-faint: #9a9ea6;
  --text-accent: #9a7f00;
  --text-on-accent: #111111;
  --text-error: #d73a49;
  --interactive-accent: #f2c800;
  --interactive-accent-hover: #e0b800;
  --icon-color: #5f6368;
  --icon-color-hover: #1f2328;
  --shadow-s: 0 1px 2px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-m: 0 4px 16px rgba(0, 0, 0, 0.16);
  --sv-scrim: rgba(0, 0, 0, 0.35);
  --sv-brand: #b89900;
}
body.theme-dark {
  color-scheme: dark;
  --background-primary: #1e1e1e;
  --background-secondary: #262626;
  --background-modifier-border: #3a3a3a;
  --background-modifier-hover: rgba(255, 255, 255, 0.08);
  --background-modifier-active-hover: rgba(255, 214, 0, 0.2);
  --text-normal: #dadada;
  --text-muted: #9e9e9e;
  --text-faint: #6b6b6b;
  --text-accent: #FFD600;
  --text-on-accent: #111111;
  --text-error: #f87171;
  --interactive-accent: #FFD600;
  --interactive-accent-hover: #ffe14d;
  --icon-color: #9e9e9e;
  --icon-color-hover: #dadada;
  --shadow-s: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-m: 0 4px 16px rgba(0, 0, 0, 0.5);
  --sv-scrim: rgba(0, 0, 0, 0.55);
  --sv-brand: #FFD600;
}
:root {
  --size-2-1: 2px;
  --size-2-2: 4px;
  --size-2-3: 6px;
  --size-4-1: 4px;
  --size-4-2: 8px;
  --size-4-3: 12px;
  --size-4-4: 16px;
  --size-4-6: 24px;
  --size-4-8: 32px;
  --radius-s: 4px;
  --radius-m: 8px;
  --radius-l: 12px;
  --font-ui-smaller: 12px;
  --font-ui-small: 13px;
  --font-ui-medium: 15px;
  --font-semibold: 600;
  --font-interface: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --icon-size: 18px;
  --icon-stroke: 1.75px;
  --sv-header-h: 48px;
}

/* ---------- 2. Base widgets ---------- */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  font-family: var(--font-interface);
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-normal);
  background-color: var(--background-primary);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
input[type="range"] { accent-color: var(--interactive-accent); }
input[type="checkbox"] { accent-color: var(--interactive-accent); width: 16px; height: 16px; }
input[type="text"] {
  background: var(--background-primary);
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-s);
  padding: 4px 6px;
  color: var(--text-normal);
}
input[type="text"]:focus { outline: 2px solid var(--interactive-accent); outline-offset: -1px; }
select {
  background: var(--background-primary);
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-s);
  padding: 4px 6px;
}
svg.svg-icon {
  width: var(--icon-size);
  height: var(--icon-size);
  stroke-width: var(--icon-stroke);
  display: block;
}
.clickable-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--size-2-2) var(--size-2-3);
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--icon-color);
  cursor: pointer;
  touch-action: manipulation;
}
.clickable-icon:hover { background-color: var(--background-modifier-hover); color: var(--icon-color-hover); }
.clickable-icon:active { background-color: var(--background-modifier-active-hover); }
button.mod-cta {
  background: var(--interactive-accent);
  color: var(--text-on-accent);
  border: 0;
  border-radius: var(--radius-m);
  padding: 8px 16px;
  font-weight: var(--font-semibold);
  margin-top: var(--size-4-3);
}
button.mod-cta:hover { background: var(--interactive-accent-hover); }

/* Context menu */
.menu {
  position: fixed;
  z-index: 1000;
  min-width: 180px;
  padding: var(--size-2-2);
  background: var(--background-secondary);
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-m);
  font-size: var(--font-ui-small);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--size-4-2);
  padding: 6px 10px;
  border-radius: var(--radius-s);
  cursor: pointer;
}
.menu-item:hover { background: var(--background-modifier-hover); }
.menu-item.is-disabled { opacity: 0.5; pointer-events: none; }
.menu-item-icon { display: flex; color: var(--icon-color); }
.menu-item-icon svg { width: 16px; height: 16px; }
.menu-separator { height: 1px; margin: 4px 0; background: var(--background-modifier-border); }

/* Notices */
.notice-container {
  position: fixed;
  top: calc(var(--sv-header-h) + 8px);
  right: 12px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}
.notice {
  pointer-events: auto;
  background: var(--background-secondary);
  color: var(--text-normal);
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-m);
  padding: 10px 14px;
  font-size: var(--font-ui-small);
  cursor: pointer;
  animation: sv-in 0.18s ease-out;
}
.notice.is-leaving { opacity: 0; transition: opacity 0.18s; }

/* Markdown inside annotations */
.step-viewer-annot p { margin: 0 0 4px; }
.step-viewer-annot p:last-child { margin-bottom: 0; }
.step-viewer-annot code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.92em; }
.step-viewer-annot a { color: var(--text-accent); }

/* ---------- 3. App shell ---------- */
.sv-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}
.sv-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--size-4-3);
  height: calc(var(--sv-header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--size-4-3) 0;
  background: var(--background-secondary);
  border-bottom: 1px solid var(--background-modifier-border);
  -webkit-app-region: drag;
  app-region: drag;
}
.sv-header button, .sv-header input { -webkit-app-region: no-drag; app-region: no-drag; }
.sv-brand { display: flex; align-items: center; gap: 8px; font-weight: var(--font-semibold); white-space: nowrap; background: none; border: 0; padding: 4px 6px 4px 0; color: var(--text-normal); border-radius: var(--radius-s); }
.sv-brand:hover { background: var(--background-modifier-hover); }
.sv-logo { display: block; width: 26px; height: 26px; border-radius: 7px; background: url(./icons/icon.svg) no-repeat center / contain; }
.sv-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: var(--font-ui-small);
}
.sv-actions { display: flex; align-items: center; gap: var(--size-2-2); }

.sv-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-m);
  background: var(--background-primary);
  color: var(--text-normal);
  font-size: var(--font-ui-small);
  font-weight: 500;
  white-space: nowrap;
  touch-action: manipulation;
}
.sv-btn:hover { background: var(--background-modifier-hover); }
.sv-btn:disabled { opacity: 0.6; cursor: default; }
.sv-btn svg { width: 16px; height: 16px; }
.sv-btn-icon { display: flex; }
.sv-btn-primary { background: var(--interactive-accent); border-color: var(--interactive-accent); color: var(--text-on-accent); font-weight: 600; }
.sv-btn-primary:hover { background: var(--interactive-accent-hover); }
.sv-btn-lg { padding: 10px 18px; font-size: var(--font-ui-medium); }
.sv-btn-sm { padding: 4px 10px; font-size: var(--font-ui-smaller); }
.sv-btn-icon-only { padding: 6px; }
.sv-btn-update { border-color: var(--interactive-accent); color: var(--text-accent); }
.sv-units {
  height: 32px;
  padding: 4px 8px;
  border-radius: var(--radius-m);
  font-size: var(--font-ui-small);
  font-weight: 500;
  background: var(--background-primary);
}
.sv-btn-update.is-checking svg { animation: sv-spin 1s linear infinite; }

.sv-main { position: relative; flex: 1 1 auto; min-height: 0; }
.sv-host { position: absolute; inset: 0; }
/* Touch / stylus: the canvas owns every gesture (no page scroll, pinch-zoom of
   the page, long-press callouts or text selection on iOS). */
.sv-host, .sv-host canvas {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.sv-host .step-viewer-tree, .sv-host .step-viewer-annots, .sv-host input, .sv-host [contenteditable] {
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
}
/* Comfortable hit targets for fingers and pencils. */
body.is-mobile .step-viewer-btn { min-width: 40px; min-height: 40px; }
body.is-mobile .step-viewer-tree-row, body.is-mobile .step-viewer-annots-row { min-height: 36px; }
/* Company mark — top-left of the viewport in every mode, deliberately quiet. */
.sv-company {
  position: absolute;
  left: 12px;
  top: 10px;
  z-index: 30;
  pointer-events: none;
  opacity: 0.55;
}
/* 3D: the tree / annotations rail starts below the mark. */
.sv-host .step-viewer-left { top: 48px; max-height: calc(100% - 56px); }
/* 2D: the library's dock panel (Layers / Measurements) gets a top inset too. */
.sv-cad2d-ui .ml-ex-ui-dock-panel { padding-top: 44px; box-sizing: border-box; }
.sv-company-mark {
  display: block;
  width: 112px;
  height: 32px;
  background-color: var(--sv-brand);
  -webkit-mask: url(./brand/tds-wordmark.svg) no-repeat left center / contain;
  mask: url(./brand/tds-wordmark.svg) no-repeat left center / contain;
}
body.theme-light .sv-company { opacity: 0.7; }
/* Full CAD interface: its own toolbar owns the top-left corner, so the mark
   moves into the header (right of the file name) instead of covering icons. */
body.is-cad .sv-main > .sv-company { display: none; }
.sv-header-mark {
  display: none;
  flex: 0 0 auto;
  width: 84px;
  height: 24px;
  opacity: 0.7;
  background-color: var(--sv-brand);
  -webkit-mask: url(./brand/tds-wordmark.svg) no-repeat center / contain;
  mask: url(./brand/tds-wordmark.svg) no-repeat center / contain;
}
body.is-cad .sv-header-mark { display: block; }
.sv-host-cad { overflow: hidden; background: #22282f; }

/* ---------- Welcome page ---------- */
.sv-welcome {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 32px 24px 56px;
  display: grid;
  grid-template-columns: minmax(280px, 460px) minmax(280px, 420px);
  justify-content: center;
  align-content: start;
  gap: 40px 56px;
  background: var(--background-primary);
}
.sv-welcome-left { display: flex; flex-direction: column; gap: 20px; }
.sv-welcome-right { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.sv-hero { display: flex; align-items: center; gap: 18px; }
.sv-hero-logo {
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  border-radius: 20px;
  background: url(./icons/icon.svg) no-repeat center / contain;
  box-shadow: var(--shadow-m);
}
.sv-hero-text h1 { margin: 0 0 4px; font-size: 32px; letter-spacing: -0.02em; line-height: 1.1; }
.sv-hero-text p { margin: 0; }
.sv-hero-by { margin-top: 4px !important; color: var(--text-faint); }

.sv-dropbox {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 36px 24px 28px;
  border: 2px dashed var(--background-modifier-border);
  border-radius: var(--radius-l);
  background: var(--background-secondary);
  color: var(--text-normal);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, transform 0.15s;
}
.sv-dropbox:hover, body.is-dragover .sv-dropbox { border-color: var(--interactive-accent); background: var(--background-modifier-hover); }
.sv-dropbox:active { transform: scale(0.99); }
.sv-dropbox-icon { color: var(--interactive-accent); }
.sv-dropbox-icon svg { width: 44px; height: 44px; stroke-width: 1.5px; }
.sv-dropbox-title { font-size: 18px; font-weight: var(--font-semibold); }
.sv-dropbox-sub { font-size: var(--font-ui-small); }
.sv-formats { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 8px; }
.sv-chip {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--background-primary);
  border: 1px solid var(--background-modifier-border);
  color: var(--text-muted);
}
.sv-version { color: var(--text-faint); }

.sv-recent-head { display: flex; align-items: center; justify-content: space-between; }
.sv-recent-head h2 { margin: 0; font-size: 15px; font-weight: var(--font-semibold); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.sv-recent-list { display: flex; flex-direction: column; gap: 8px; }
.sv-recent-empty { padding: 20px 16px; border: 1px dashed var(--background-modifier-border); border-radius: var(--radius-m); }
.sv-recent {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-m);
  background: var(--background-secondary);
  color: var(--text-normal);
  text-align: left;
  cursor: pointer;
  min-height: 64px;
}
.sv-recent:hover { background: var(--background-modifier-hover); }
.sv-recent-thumb {
  flex: 0 0 auto;
  width: 64px;
  height: 48px;
  border-radius: var(--radius-s);
  background: var(--background-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-faint);
}
.sv-recent-thumb img { width: 100%; height: 100%; object-fit: cover; }
.sv-recent-thumb svg { width: 24px; height: 24px; }
.sv-recent-body { flex: 1 1 auto; min-width: 0; }
.sv-recent-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-recent-meta { font-size: var(--font-ui-smaller); }
.sv-recent-rm { flex: 0 0 auto; }
.sv-recent-rm svg { width: 16px; height: 16px; }

/* Narrow screens (phones, split-view tablets): one centred column. */
@media (max-width: 860px) {
  .sv-welcome { grid-template-columns: minmax(0, 460px); gap: 28px; padding: 24px 16px 64px; }
  .sv-welcome-left { align-items: center; text-align: center; }
  .sv-hero { flex-direction: column; text-align: center; gap: 12px; }
  .sv-dropbox { width: 100%; }
}

/* Settings popover */
.sv-pop {
  position: fixed;
  z-index: 900;
  width: min(360px, calc(100vw - 16px));
  padding: 6px;
  background: var(--background-secondary);
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-m);
  animation: sv-in 0.15s ease-out;
  max-height: calc(100vh - var(--sv-header-h) - 24px);
  overflow: auto;
}
.sv-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 8px 8px; border-bottom: 1px solid var(--background-modifier-border); }
.sv-row:last-of-type { border-bottom: 0; }
.sv-row-text { flex: 1 1 160px; min-width: 0; }
.sv-row-label { font-size: var(--font-ui-small); font-weight: 500; }
.sv-row-desc { font-size: var(--font-ui-smaller); color: var(--text-muted); }
.sv-row-ctl { flex: 0 1 auto; display: flex; align-items: center; margin-left: auto; max-width: 100%; }
.sv-row-ctl select { max-width: 200px; text-overflow: ellipsis; }
.sv-about { padding: 8px; }

/* Modal */
.sv-scrim {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: var(--sv-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: sv-in 0.15s ease-out;
}
.sv-modal {
  width: min(460px, 100%);
  background: var(--background-primary);
  border: 1px solid var(--background-modifier-border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-m);
  overflow: hidden;
}
.sv-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--background-modifier-border); }
.sv-modal-head h2 { margin: 0; font-size: 16px; }
.sv-modal-body { padding: 16px 18px 18px; }
.sv-modal-body p { margin: 0 0 12px; }
.sv-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.sv-steps { margin: 0 0 8px; padding-left: 20px; }
.sv-steps li { margin-bottom: 6px; }

@keyframes sv-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes sv-spin { to { transform: rotate(360deg); } }

/* Phones: hide button labels in the header to save space. */
@media (max-width: 600px) {
  .sv-header { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .sv-brand-name { display: none; }
  .sv-btn .sv-btn-label { display: none; }
  .sv-btn { padding: 8px; }
  .sv-btn-primary .sv-btn-label { display: none; }
  .sv-units { display: none !important; } /* still available in Settings */
}

/* ---------- 2D (DWG / DXF) viewer host ---------- */
.sv-host-2d { position: absolute; inset: 0; overflow: hidden; background: var(--background-primary); }
.sv-cad2d-ui { position: relative; width: 100% !important; height: 100% !important; min-height: 0; }
.sv-cad2d-container { position: relative; flex: 1 1 auto; min-height: 0; width: 100%; height: 100%; }
.sv-cad2d-container canvas { display: block; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.sv-cad2d-overlay { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.sv-cad2d-overlay .step-viewer-overlay { pointer-events: auto; }


/* Touch CAD (phones, tablets): the drawing and its own controls take the whole screen; the
   touch controls' top row has the way back. */
body.is-cad-touch .sv-header { display: none; }
body.is-cad-touch .sv-host-cad { touch-action: none; }
