/* Edit mode: the card's edit section (panel/edit.js). Simple first (undo / redo / History, Drop /
   Duplicate / Delete, turn left / right 90°, Reset position / rotation / both, Align and Space for
   2+ parts, Group / Ungroup / Select more when they apply), then a folded Exact position (number
   fields for X / Y / Z and the turn or Rotation X / Y / Z, Precise with Move | Turn and World |
   Local, Snap to parts, Reset all); and the copy icon of a copy's row in the parts list (tree.js). */
.sv-edit {
  --sv-off: #8c8983; /* disabled text and icons: clearly off, still readable (3.5:1 on white) */
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--sv-border);
}

#viewer .sv-edit button:disabled,
#viewer .sv-edit button[aria-disabled="true"] {
  color: var(--sv-off);
  opacity: 1;
  cursor: default;
}

#viewer .sv-edit button[aria-disabled="true"]:hover {
  background: var(--sv-surface);
}

.sv-edit__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Icon buttons: undo, redo, History | Drop, Duplicate, Delete. */
.sv-edit__tools {
  display: flex;
  gap: 2px;
}

#viewer .sv-edit__tools button {
  display: grid;
  place-items: center;
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-color: transparent;
  background: none;
}

#viewer .sv-edit__tools button:hover:not(:disabled) {
  background: var(--sv-hover);
}

#viewer .sv-edit__tools button[aria-expanded="true"] {
  color: var(--sv-accent);
  background: var(--sv-accent-soft);
}

/* History: newest step on top (current: accent), "Original" last, then the undone ones greyed
   under an "Undone" divider. */
.sv-edit__steps {
  display: flex;
  flex-direction: column;
  max-height: 188px;
  margin-top: 6px;
  padding: 3px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--sv-border);
  border-radius: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--sv-border-strong) transparent;
}

#viewer .sv-edit__step {
  flex: none;
  min-height: 28px;
  padding: 0 8px;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 12px;
  font-weight: 450;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#viewer .sv-edit__step[aria-current] {
  color: var(--sv-accent);
  background: var(--sv-accent-soft);
  font-weight: 650;
  cursor: default;
}

#viewer .sv-edit__step.is-original {
  color: var(--sv-muted);
  font-style: italic;
}

#viewer .sv-edit__step.is-undone {
  color: var(--sv-muted);
}

.sv-edit__divider {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  margin: 4px 8px 2px;
  color: var(--sv-faint);
  font-size: 11px;
  font-weight: 550;
}

.sv-edit__divider::before,
.sv-edit__divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--sv-border);
}

.sv-edit__turn90 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

#viewer .sv-edit__turn90 button {
  padding: 0 6px;
  font-size: 12px;
}

/* Reset:  Position · Rotation · Both; only once the part has moved or turned. */
.sv-edit__resets {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 4px;
  font-size: 12px;
}

.sv-edit__resets:not(:has(.sv-link:enabled)) {
  display: none;
}

.sv-edit__resets > span {
  margin-right: 4px;
}

.sv-edit__resets > span::after {
  content: ":";
}

#viewer .sv-edit__resets .sv-link {
  font-size: 12px;
}

/* Align and Space (2+ parts): per axis, min / centre / max joined, then Space evenly (3+). */
.sv-edit__align {
  display: grid;
  grid-template-columns: 14px 1fr 40px;
  align-items: center;
  gap: 4px 8px;
  margin-top: 10px;
}

.sv-edit__axis {
  display: contents;
}

.sv-edit__caption {
  color: var(--sv-muted);
  font-size: 11px;
  font-weight: 550;
  line-height: 16px;
}

.sv-edit__axis-name {
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* The gizmo's axis colours, darkened for small text on white. */
.sv-edit__axis--x .sv-edit__axis-name {
  color: #d81e3d;
}

.sv-edit__axis--y .sv-edit__axis-name {
  color: #3f7d00;
}

.sv-edit__axis--z .sv-edit__axis-name {
  color: #1667c9;
}

/* Y is the height: its icons stand up (min = bottom). */
.sv-edit__axis--y svg {
  transform: rotate(-90deg);
}

.sv-edit__join {
  display: flex;
}

#viewer .sv-edit__icon {
  display: grid;
  place-items: center;
  min-height: 30px;
  padding: 0;
}

#viewer .sv-edit__join .sv-edit__icon {
  flex: 1;
  border-radius: 0;
}

#viewer .sv-edit__join .sv-edit__icon + .sv-edit__icon {
  margin-left: -1px;
}

#viewer .sv-edit__join .sv-edit__icon:first-child {
  border-radius: 8px 0 0 8px;
}

#viewer .sv-edit__join .sv-edit__icon:last-child {
  border-radius: 0 8px 8px 0;
}

#viewer .sv-edit__join .sv-edit__icon:hover,
#viewer .sv-edit__join .sv-edit__icon:focus-visible {
  position: relative; /* its border and focus ring over the neighbour's */
}

.sv-edit__rename {
  margin-top: 10px;
}

/* Select more (touch), Group, Ungroup. */
.sv-edit__group {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.sv-edit__group .sv-edit__more {
  flex: 1;
}

#viewer .sv-edit__group button {
  padding: 0 12px;
  font-size: 12px;
}

/* Group stays focusable and keeps its tooltip (why it can't group) while unavailable. */
#viewer .sv-edit__group button[aria-disabled="true"] {
  background: var(--sv-surface);
}

.sv-edit__exact {
  margin-top: 10px;
}

/* Its content sits in a shadow slot that inherits content-box, not #viewer's border-box. */
#viewer .sv-edit__exact > * {
  box-sizing: border-box;
}

.sv-edit__exact > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  color: var(--sv-muted);
  font-weight: 550;
  cursor: pointer;
  list-style: none;
}

.sv-edit__exact > summary::-webkit-details-marker {
  display: none;
}

.sv-edit__exact > summary::before {
  content: "";
  width: 6px;
  height: 6px;
  margin: 0 3px 2px 1px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 120ms;
}

.sv-edit__exact[open] > summary::before {
  transform: rotate(45deg);
}

/* Precise, then (when it is on) Move | Turn and World | Local. */
.sv-edit__modes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.sv-edit__seg {
  display: flex;
}

#viewer .sv-edit__seg button {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

#viewer .sv-edit__seg button:first-child {
  border-radius: 8px 0 0 8px;
}

#viewer .sv-edit__seg button:last-child {
  margin-left: -1px;
  border-radius: 0 8px 8px 0;
}

#viewer .sv-edit__seg button[aria-pressed="true"] {
  position: relative; /* its accent border over the neighbour's */
  border-color: var(--sv-accent);
  color: var(--sv-accent);
  background: var(--sv-accent-soft);
}

/* Three equal columns: X / Y / Z, the turn, or Rotation X / Y / Z. */
.sv-edit__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: 8px 6px;
  margin-top: 4px;
}

.sv-edit__field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  color: var(--sv-muted);
  font-size: 11px;
  font-weight: 550;
  line-height: 16px;
}

.sv-edit__field > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The label scrubs the value (drag sideways); a click types in the field. */
.sv-edit__label {
  cursor: ew-resize;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.sv-edit__label:hover,
.sv-edit__label.is-scrubbing {
  color: var(--sv-ink);
}

.sv-edit__label.is-scrubbing {
  color: var(--sv-accent);
}

/* The value left, its unit (not part of the text) muted inside on the right. */
.sv-edit__box {
  position: relative;
  display: block;
}

.sv-edit__unit {
  position: absolute;
  top: 50%;
  right: 8px;
  color: var(--sv-faint);
  font-size: 11px;
  font-weight: 450;
  transform: translateY(-50%);
  pointer-events: none;
}

#viewer .sv-edit__field input {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--sv-border-strong);
  border-radius: 8px;
  color: var(--sv-ink);
  background: var(--sv-surface);
  font-size: 13px;
  font-weight: 450;
  font-variant-numeric: tabular-nums;
}

#viewer .sv-edit__box input {
  padding-right: 28px;
}

#viewer .sv-edit__field input:focus {
  outline: 2px solid var(--sv-accent);
  outline-offset: -1px;
}

#viewer .sv-edit__field input::placeholder {
  color: var(--sv-faint);
  font-style: italic;
}

#viewer .sv-edit__field input:disabled {
  color: var(--sv-off);
  background: var(--sv-hover);
}

#viewer .sv-edit__field input:disabled + .sv-edit__unit {
  color: var(--sv-off);
}

#viewer .sv-edit__field input.is-invalid {
  border-color: var(--sv-danger);
  outline-color: var(--sv-danger);
  animation: sv-shake 180ms linear;
}

@keyframes sv-shake {
  0%, 100% { transform: none; }
  17%, 50%, 83% { transform: translateX(-4px); }
  33%, 67% { transform: translateX(4px); }
}

.sv-edit__foot {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}

.sv-edit__check {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  cursor: pointer;
}

.sv-edit__check input {
  margin: 0;
  accent-color: var(--sv-accent);
}

/* A copy's row in the parts list: two overlapping boxes before its name (like a group's icon). */
.sv-row.is-copy > .sv-row__name::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  vertical-align: -2px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.5' stroke-linejoin='round'%3E%3Crect x='5.5' y='5.5' width='8.5' height='8.5' rx='1.5'/%3E%3Cpath d='M10.5 3v-.5a1 1 0 0 0-1-1h-7a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1H3'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
}

/* Touch: 44px rows for the switches and icon buttons, 40px fields and buttons. */
@media (pointer: coarse) {
  #viewer .sv-edit__field input,
  #viewer .sv-edit__seg button,
  #viewer .sv-edit__icon {
    height: 40px;
    min-height: 40px;
  }

  #viewer .sv-hinge-edit__range input {
    height: 44px;
    min-height: 44px;
  }

  #viewer .sv-edit__tools button {
    width: 42px; /* six fit the 270 px card */
    min-height: 44px;
  }

  #viewer .sv-edit__step {
    min-height: 40px;
  }

  .sv-edit__steps {
    max-height: 240px;
  }

  .sv-edit__align {
    grid-template-columns: 14px 1fr 48px;
  }

  .sv-edit__check,
  .sv-edit__exact > summary {
    min-height: 44px;
  }

  .sv-edit__check input {
    width: 22px;
    height: 22px;
  }
}

/* Add ▾: a button, its short list below (Label…). */
.sv-edit__add {
  position: relative;
  margin-top: 8px;
}

#viewer .sv-edit__addbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
}

#viewer .sv-edit__addbtn[aria-expanded="true"] {
  color: var(--sv-accent);
  background: var(--sv-accent-soft);
}

.sv-edit__addlist {
  position: absolute;
  z-index: 3;
  top: calc(100% + 4px);
  left: 0;
  display: grid;
  min-width: 160px;
  padding: 4px;
  border: 1px solid var(--sv-border);
  border-radius: 8px;
  background: var(--sv-surface);
  box-shadow: var(--sv-shadow);
}

#viewer .sv-edit__addlist button {
  min-height: 32px;
  border-color: transparent;
  background: none;
  text-align: left;
}

#viewer .sv-edit__addlist button:hover {
  background: var(--sv-hover);
}

@media (pointer: coarse) {
  #viewer .sv-edit__addbtn,
  #viewer .sv-edit__addlist button {
    min-height: 44px;
  }
}
