/* Hallmark · genre: modern-minimal · macrostructure: Workbench
 * design-system: design.md · designed-as-app
 */

.tool-runner {
  position: relative;
}

.tool-runner.is-busy .tool-dropzone {
  pointer-events: none;
  opacity: 0.55;
}

/* Dropzone — the workbench frame */

.tool-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  min-height: 16rem;
  padding: var(--space-xl) var(--space-md);
  border: 1.5px dashed var(--color-rule-2);
  border-radius: var(--radius-md);
  background: var(--color-paper-2);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-short) var(--ease-out), background-color var(--dur-short) var(--ease-out);
}

.tool-dropzone:hover,
.tool-dropzone:focus-visible {
  border-color: var(--color-accent);
}

.tool-dropzone.is-dragging {
  border-color: var(--color-accent);
  border-style: solid;
  background: color-mix(in oklch, var(--color-accent) 6%, var(--color-paper-2));
}

.tool-dropzone__icon {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-accent);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-xs);
}

.tool-dropzone__prompt {
  font-weight: 500;
  color: var(--color-ink);
}

.tool-dropzone__hint {
  font-size: var(--text-sm);
  color: var(--color-muted);
}

/* Source bar — the active image, choose-another, and library link */

.tool-source {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-md);
  background: var(--color-paper-2);
}

.tool-source__name {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-ink);
  overflow-wrap: anywhere;
}

.tool-disclaimer__tick {
  color: var(--color-accent);
  flex-shrink: 0;
}

.tool-error {
  margin-top: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-error);
  border-radius: var(--radius-sm);
  background: color-mix(in oklch, var(--color-error) 8%, var(--color-paper));
  color: var(--color-error);
  font-size: var(--text-sm);
}

.tool-output {
  margin-top: var(--space-lg);
}

.tool-output__media img,
.tool-compare__before,
.tool-compare__after {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-md);
}
.tool-compare {
  position: relative;
  display: grid;
  /* Hug the result image so the before overlay, clip percentages and
     divider all resolve against the image's own box, not the column. */
  width: fit-content;
  max-width: 100%;
}
/* Extra qualifier outranks `.tool-output__media img` (0,1,1) so the overlay
   stretches to the result image's box instead of sizing itself naturally.
   border-box keeps the 1px frame inside the container's box. */
.tool-compare .tool-compare__before {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  object-fit: contain;
}
.tool-compare__divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-accent);
  cursor: ew-resize;
  touch-action: none;
}
.tool-compare__divider::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.2rem;
  height: 1.2rem;
  margin: -0.6rem 0 0 -0.6rem;
  border-radius: 50%;
  background: var(--color-accent);
  border: 2px solid var(--color-paper);
}
.tool-compare__toggle {
  margin-top: var(--space-xs);
}
.tool-controls__reset {
  grid-column: 1 / -1;
  justify-self: start;
}

.tool-output__report {
  margin: var(--space-sm) 0 0;
  padding: var(--space-md);
  background: var(--color-graphite);
  color: var(--color-on-graphite-2);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.tool-output__name {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
  margin: var(--space-sm) 0;
}

.tool-output__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

/* Controls — bordered instrument sliders */

.tool-controls {
  margin-top: var(--space-lg);
  padding: var(--space-lg);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-md);
  background: var(--color-paper-2);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: var(--space-md);
}

.control {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  min-width: 0;
}

.control-group {
  display: contents;
}

.control__label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-muted);
}

.control__row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-xs);
}
.control__value {
  min-width: 2.5rem;
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-ink);
  background: var(--color-paper);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.4rem;
}
.control input[type="range"] {
  width: 100%;
  accent-color: var(--color-accent);
  min-height: 44px;
}
.control input[type="range"]:focus-visible,
.control select:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}
.control__hint {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
  grid-column: 1 / -1;
}
.tool-rotate__guide {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  gap: var(--space-2xs);
  padding: var(--space-sm);
  border: 1px dashed var(--color-rule-2);
  border-radius: var(--radius-sm);
  background: color-mix(in oklch, var(--color-accent) 4%, var(--color-paper-2));
}
.tool-rotate__grid {
  width: 4rem;
  height: 4rem;
  border: 1px solid var(--color-rule);
  background-image: linear-gradient(to right, var(--color-rule) 1px, transparent 1px), linear-gradient(to bottom, var(--color-rule) 1px, transparent 1px);
  background-size: 1.33rem 1.33rem;
  opacity: 0.6;
}
.tool-rotate__hint {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
}

.control input[type="text"],
.control select,
.control input[type="color"] {
  width: 100%;
  padding: 0.45rem 0.6rem;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-ink);
  background: var(--color-paper);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
}

.control input[type="text"]:focus-visible,
.control select:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.control input[type="color"] {
  padding: 0.2rem;
  height: 2.2rem;
}

/* Busy states */

.editor-workspace.is-busy .editor-canvas-wrap,
.tool-runner.is-busy .tool-dropzone {
  opacity: 0.7;
}

.tool-busy {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  margin-top: var(--space-md);
  padding: var(--space-xs) var(--space-md);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
  background: var(--color-paper-2);
  color: var(--color-ink);
  font-size: var(--text-sm);
  font-weight: 500;
}

.tool-busy[hidden] {
  display: none;
}

.spinner {
  width: 0.9rem;
  height: 0.9rem;
  flex-shrink: 0;
  border: 2px solid var(--color-rule-2);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Error boundary toast — stacked, fixed, silent */

.error-boundary {
  position: fixed;
  bottom: var(--space-md);
  right: var(--space-md);
  z-index: var(--z-toast);
  max-width: min(22rem, calc(100vw - 2rem));
  padding: var(--space-sm) var(--space-md);
  background: var(--color-error);
  color: var(--color-on-error);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-size: var(--text-sm);
  line-height: 1.5;
}

/* Mask surface (object removal) */

.mask-surface {
  position: relative;
  margin-top: var(--space-md);
}

.mask-surface__frame {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.mask-surface__image {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-rule);
  display: block;
}

.mask-surface__overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  cursor: crosshair;
  touch-action: none;
}

.mask-surface__hint {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
  margin: var(--space-xs) 0 var(--space-2xs);
}

.mask-surface__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

/* JS-generated buttons (mask-painter controller) — mapped to the .btn language */
.mask-surface__actions .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2xs);
  padding: 0.55rem 1.1rem;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--text-sm);
  line-height: 1.3;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-ink);
  border: 1px solid var(--color-rule-2);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 100ms var(--ease-out), background-color var(--dur-short) var(--ease-out),
              border-color var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out);
}

.mask-surface__actions .button:hover {
  border-color: var(--color-accent);
}

.mask-surface__actions .button:active {
  transform: translateY(1px);
}

.mask-surface__actions .button--primary {
  background: var(--color-accent);
  color: var(--color-accent-ink);
  border: 1px solid var(--color-accent);
}

.mask-surface__actions .button--primary:hover {
  filter: brightness(1.06);
  border-color: var(--color-accent);
}

/* Crop overlay — drag-select surface */
.crop-overlay {
  display: grid;
  gap: var(--space-sm);
}
.crop-overlay__stage {
  position: relative;
  width: 100%;
  max-width: 640px;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-paper-2);
}
.crop-overlay__image {
  display: block;
  width: 100%;
  height: auto;
}
.crop-overlay__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
.crop-overlay__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
}
.crop-overlay__readout {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
}

/* Annotation overlay (watermark / arrows / steps / marker) */
.annotation-overlay { display: grid; gap: var(--space-sm); margin-top: var(--space-sm); }
.annotation-overlay__stage { position: relative; width: 100%; max-width: 640px; border: 1px solid var(--color-rule); border-radius: var(--radius-md); overflow: hidden; background: var(--color-paper-2); }
.annotation-overlay__image { display: block; width: 100%; height: auto; }
.annotation-overlay__canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.annotation-overlay__toolbar { display: flex; align-items: center; gap: var(--space-sm); }
.annotation-overlay__readout { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-muted); }

/* Image-diff two-dropzone */
.tool-dropzones--pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}
@media (max-width: 640px) {
  .tool-dropzones--pair { grid-template-columns: 1fr; }
}
.tool-dropzone__name {
  margin-top: var(--space-2xs);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-accent);
}
.tool-compare__diff {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-md);
  margin-top: var(--space-sm);
}