/* SVG Editor -- layout, toolbar, stage, sidebar, selection handles */

.app--wide {
  max-width: 1400px;
}

.main--editor {
  margin-bottom: var(--space-lg);
}

/* Editor card */
.editor {
  padding: 0;
  overflow: hidden;
}

/* Toolbar */
.editor__toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.editor__tools {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.tool {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.tool svg {
  width: 20px;
  height: 20px;
}

.tool:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tool.is-active {
  background: var(--primary);
  color: var(--active-text);
}

[data-theme="dark"] .tool.is-active {
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
}

.tool:active {
  transform: scale(0.92);
}

.editor__sep {
  width: 1px;
  height: 32px;
  background: var(--border);
  flex-shrink: 0;
}

.editor__prop {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.editor__prop-label {
  white-space: nowrap;
}

.editor__prop input[type="color"] {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface);
  padding: 2px;
}

.editor__prop input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.editor__prop input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}

.editor__prop--range {
  min-width: 120px;
}

.editor__prop--range .range {
  width: 80px;
}

.editor__actions {
  display: flex;
  gap: 4px;
}

.editor__actions .btn {
  padding: 8px 10px;
  font-size: 12px;
  min-width: 36px;
  text-align: center;
}

.editor__zoom-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 42px;
  text-align: center;
  align-self: center;
  font-variant-numeric: tabular-nums;
}

.editor__actions--align {
  gap: 2px;
}

.editor__actions--align .btn {
  padding: 8px 6px;
  font-size: 14px;
}

.editor__actions select.btn {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 5px center;
  background-size: 10px;
  cursor: pointer;
}

/* Rotation handle */
.editor__rotate {
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: 50%;
  pointer-events: auto;
  cursor: grab;
  z-index: 12;
  transform: translate(-50%, -50%);
}

.editor__rotate:active {
  cursor: grabbing;
}

.editor__rotate::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 20px;
  background: var(--primary);
  transform: translateX(-50%);
}

/* Grid overlay */
.editor__grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 1;
}

.editor__grid.is-visible {
  opacity: 0.4;
}

/* Snap button active state */
.editor__stage.is-snapping {
  cursor: crosshair;
}

.btn.is-toggled {
  background: var(--primary);
  color: var(--active-text);
}

/* Body layout */
.editor__body {
  display: flex;
  min-height: 520px;
}

/* Stage */
.editor__stage {
  flex: 1;
  position: relative;
  background: var(--bg);
  overflow: hidden;
  cursor: crosshair;
  min-width: 0;
  min-height: 400px;
}

.editor__stage[data-tool="select"] {
  cursor: default;
}

.editor__stage svg {
  display: block;
  width: 100%;
  height: 100%;
}

#artboard [data-hidden="true"] {
  display: none;
}

#artboard [data-locked="true"] {
  pointer-events: none;
}

/* Checkerboard background for stage to show transparency */
.editor__stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%),
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%),
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  opacity: 0.3;
  pointer-events: none;
}

/* Overlay for selection handles */
.editor__overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.editor__selbox {
  position: absolute;
  border: 2px solid var(--primary);
  border-radius: 2px;
  pointer-events: none;
  z-index: 10;
}

.editor__handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: 50%;
  pointer-events: auto;
  cursor: pointer;
  z-index: 11;
  transform: translate(-50%, -50%);
}

.editor__handle[data-h="nw"],
.editor__handle[data-h="se"] {
  cursor: nwse-resize;
}

.editor__handle[data-h="ne"],
.editor__handle[data-h="sw"] {
  cursor: nesw-resize;
}

.editor__handle[data-h="n"],
.editor__handle[data-h="s"] {
  cursor: ns-resize;
}

.editor__handle[data-h="e"],
.editor__handle[data-h="w"] {
  cursor: ew-resize;
}

.editor__path-nodes {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.editor__path-guide {
  position: absolute;
  height: 1px;
  background: color-mix(in srgb, var(--primary) 70%, transparent);
  transform-origin: 0 50%;
  pointer-events: none;
}

.editor__path-node {
  position: absolute;
  width: 13px;
  height: 13px;
  padding: 0;
  border: 2px solid var(--primary);
  background: var(--surface);
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: move;
  touch-action: none;
  user-select: none;
  box-shadow: 0 1px 4px rgb(0 0 0 / 24%);
}

.editor__path-node--anchor {
  border-radius: 3px;
}

.editor__path-node--control {
  width: 11px;
  height: 11px;
  border-width: 1px;
  border-radius: 50%;
  background: var(--surface-2);
}

.editor__path-node.is-active {
  background: var(--primary);
  outline: 2px solid var(--surface);
  outline-offset: 1px;
}

/* Sidebar */
.editor__sidebar {
  width: 280px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.editor__panel {
  border-bottom: 1px solid var(--border);
  padding: var(--space);
}

.editor__panel:last-child {
  border-bottom: none;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.editor__panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
}

.editor__panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.editor__panel-actions {
  display: flex;
  gap: 4px;
}

.editor__panel-actions .btn {
  padding: 6px 8px;
}

.editor__panel-sub {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
}

.editor__canvas-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.editor__canvas-size {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 8px;
}

.editor__canvas-times {
  padding-bottom: 8px;
  color: var(--text-dim);
  font-size: 12px;
}

.editor__field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

.editor__field input,
.editor__field select {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.editor__field input:focus,
.editor__field select:focus {
  outline: none;
  border-color: var(--primary);
}

.editor__props {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.prop-section {
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.prop-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.prop-lock {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
}

.prop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.prop-grid label {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
}

.prop-grid input {
  width: 100%;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.prop-grid input:focus {
  outline: none;
  border-color: var(--primary);
}

.prop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.prop-actions .btn {
  flex: 1 1 90px;
}

.prop-hint {
  margin: 7px 0 0;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.45;
}

.prop-hint--mobile {
  display: none;
}

/* Property row in sidebar */
.prop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.prop-row label {
  width: 70px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-weight: 600;
}

.prop-row input[type="color"] {
  width: 36px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: var(--surface-2);
  padding: 2px;
}

.prop-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.prop-row input[type="text"],
.prop-row input[type="number"],
.prop-row select {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}

.prop-row input[type="text"]:focus,
.prop-row input[type="number"]:focus,
.prop-row select:focus {
  outline: none;
  border-color: var(--primary);
}

.prop-row .range {
  flex: 1;
}

.prop-row .prop-value {
  width: 32px;
  text-align: right;
  flex-shrink: 0;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.prop-row--swatches {
  flex-wrap: wrap;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.is-active {
  border-color: var(--text);
  transform: scale(1.1);
}

/* Element list / layers */
.editor__layers {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: background 0.15s;
}

.layer-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.layer-item.is-active {
  background: var(--primary);
  color: var(--active-text);
}

.layer-item.is-hidden {
  opacity: 0.58;
}

.layer-item.is-locked .layer-item__label {
  font-style: italic;
}

.layer-item__swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.layer-item__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-item__name-input {
  flex: 1;
  min-width: 0;
  padding: 3px 5px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.layer-item__button {
  display: grid;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}

.layer-item__button:hover,
.layer-item__button:focus-visible {
  background: color-mix(in srgb, currentColor 14%, transparent);
  outline: none;
}

.layer-item__button:disabled {
  cursor: default;
  opacity: 0.28;
}

.layer-item__type {
  font-size: 10px;
  opacity: 0.6;
  text-transform: uppercase;
}

/* Code view */
.editor__code {
  flex: 1;
  min-height: 120px;
  resize: none;
  padding: var(--space-sm);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
}

.editor__code:focus {
  outline: none;
  border-color: var(--primary);
}

/* Responsive */
@media (max-width: 900px) {
  .editor__toolbar {
    padding: var(--space-xs) var(--space-sm);
  }

  .editor__sep {
    display: none;
  }

  .editor__body {
    flex-direction: column;
    min-height: auto;
  }

  .editor__stage {
    min-height: 300px;
    flex: none;
    aspect-ratio: 4 / 3;
  }

  .editor__sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: none;
  }
}

@media (max-width: 640px) {
  .editor__toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }

  .editor__tools,
  .editor__actions,
  .editor__prop,
  .editor__toolbar > .btn {
    flex: 0 0 auto;
  }

  .editor__stage {
    height: min(58vh, 520px);
    min-height: 320px;
    aspect-ratio: auto;
  }

  .editor__panel {
    padding: var(--space-sm);
  }

  .editor__panel-actions .btn {
    min-height: 34px;
  }

  .layer-item {
    min-height: 40px;
  }

  .layer-item__button {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
  }

  .editor__path-node {
    width: 18px;
    height: 18px;
  }

  .editor__path-node--control {
    width: 16px;
    height: 16px;
  }

  .prop-hint--mobile {
    display: block;
    color: var(--warning, #b45309);
  }
}

@media (pointer: coarse) {
  .editor__handle {
    width: 18px;
    height: 18px;
  }

  .editor__rotate {
    width: 18px;
    height: 18px;
  }


  .editor__path-node {
    width: 20px;
    height: 20px;
  }

  .editor__path-node--control {
    width: 18px;
    height: 18px;
  }
}
