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

.editor-workspace {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.editor-page > h1 {
  font-size: var(--text-2xl);
}

.editor-page > p {
  color: var(--color-muted);
  margin: var(--space-xs) 0 var(--space-lg);
}

/* Toolbar */

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2xs);
}

.editor-toolbar button,
.editor-layer-actions button {
  padding: 0.45rem 0.85rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-ink-2);
  background: var(--color-paper-2);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out),
              background-color var(--dur-short) var(--ease-out);
}

.editor-toolbar button:hover,
.editor-layer-actions button:hover {
  border-color: var(--color-accent);
}

.editor-toolbar button.is-active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-accent-ink);
}

.editor-toolbar button:disabled,
.editor-layer-actions button:disabled {
  opacity: 0.5;
  cursor: default;
}

.editor-divider {
  width: 1px;
  height: 1.25rem;
  background: var(--color-rule);
  margin: 0 var(--space-2xs);
}

.editor-busy {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  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;
  align-self: flex-start;
}

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

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

.editor-source {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2xs);
  margin-left: var(--space-2xs);
}

.editor-source__name {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-right: var(--space-2xs);
  overflow-wrap: anywhere;
}

.editor-source button,
.editor-source a {
  padding: 0.45rem 0.85rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-ink-2);
  background: var(--color-paper-2);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: border-color var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out);
}

.editor-source button:hover,
.editor-source a:hover {
  border-color: var(--color-accent);
}

.editor-error {
  color: var(--color-error);
  font-size: var(--text-sm);
  margin-left: var(--space-xs);
}

/* Workspace frame */

.editor-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 20rem);
  gap: var(--space-md);
  align-items: start;
}

.editor-canvas-wrap {
  background: var(--color-paper-2);
  border: 1.5px dashed var(--color-rule-2);
  border-radius: var(--radius-md);
  min-height: 26rem;
  display: grid;
  place-items: center;
  padding: var(--space-md);
  position: relative;
  min-width: 0;
}

.editor-canvas-wrap.is-dragging {
  border-color: var(--color-accent);
  border-style: solid;
}

.editor-canvas-wrap canvas {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--color-rule);
  touch-action: none;
}

/* Scoped to beat ".editor-canvas-wrap canvas" (0,1,1) so border:none actually
   applies — a bare class selector loses and the empty overlay paints a stray
   outlined rectangle over the image.
   Inset by the wrap's padding (not 0): the absolute containing block is the
   padding box, and inset:0 would let the overlay scale larger than the
   workspace canvas once max-width clamps it. Keep in sync with the wrap. */
.editor-canvas-wrap .editor-crop-overlay {
  position: absolute;
  inset: var(--space-md);
  margin: auto;
  border: none;
  box-shadow: none;
  pointer-events: none;
}

.editor-resize-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 15rem;
}

.editor-resize-hint {
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin: 0;
}

.editor-resize-actions {
  display: flex;
  gap: var(--space-xs);
  justify-content: flex-end;
}

.editor-resize-actions button {
  padding: 0.45rem 0.9rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-ink-2);
  background: var(--color-paper-2);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
}

.editor-resize-actions button:first-child {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-accent-ink);
}

/* Sidebar panels */

.editor-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.editor-panel {
  background: var(--color-paper-2);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  min-width: 0;
}

.editor-panel h2 {
  margin: 0 0 var(--space-sm);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-muted);
}

.editor-layer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
  margin-bottom: var(--space-sm);
}

.editor-layer-actions button {
  padding: 0.35rem 0.6rem;
  font-size: var(--text-sm);
}

.editor-layers {
  list-style: none;
  margin: 0 0 var(--space-sm);
  padding: 0;
  max-height: 13rem;
  overflow-y: auto;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-sm);
}

.editor-layer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-xs);
  padding: 0.5rem 0.65rem;
  font-size: var(--text-sm);
  cursor: pointer;
}

.editor-layer + .editor-layer {
  border-top: 1px solid var(--color-rule);
}

.editor-layer.is-active {
  background: color-mix(in oklch, var(--color-accent) 12%, transparent);
}

.editor-layer__meta {
  color: var(--color-muted);
}

/* Controls inside panels */

.editor-panel .control {
  margin-top: var(--space-sm);
}

.control input[type="range"] {
  accent-color: var(--color-accent);
}

.control input[type="text"],
.control select,
.control input[type="color"] {
  width: 100%;
  padding: 0.4rem 0.55rem;
  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);
}

@media (max-width: 40rem) {
  .editor-body {
    grid-template-columns: 1fr;
  }

  .editor-toolbar {
    row-gap: var(--space-2xs);
  }
}

/* ---- Photoshop-grade workbench (engine v2) -------------------------------
 * The three rules above (.editor-canvas-wrap, generic canvas, scoped overlay
 * reset) are frozen: integration tests pin their cascade. Everything below
 * layers the pro workspace on top with HIGHER specificity, so the pinned
 * rules keep passing while the new layout wins in the browser.
 */

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

.editor-backend {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-success);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.5rem;
}

.editor-docmeta {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-muted);
}

.editor-zoom,
.editor-export {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  margin-left: auto;
}

.editor-export { margin-left: 0; }

.editor-zoom button,
.editor-export button,
.editor-export select {
  padding: 0.35rem 0.6rem;
  font-size: var(--text-sm);
  color: var(--color-ink-2);
  background: var(--color-paper);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
}

.editor-body {
  grid-template-columns: 3rem minmax(0, 1fr) minmax(16rem, 20rem);
}

.editor-rail {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  background: var(--color-paper-2);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-md);
  padding: var(--space-xs);
  position: sticky;
  top: var(--space-md);
}

.editor-rail button {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  font-size: 1rem;
  color: var(--color-ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.editor-rail button:hover { border-color: var(--color-rule-2); }

.editor-rail button.is-active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-accent-ink);
}

.editor-viewport {
  overflow: auto;
  max-height: 72vh;
  min-height: 26rem;
  display: grid;
  place-items: center;
  background:
    conic-gradient(var(--color-paper-3) 25%, transparent 0 50%, var(--color-paper-3) 0 75%, transparent 0);
  background-size: 16px 16px;
  border-radius: var(--radius-sm);
  cursor: default;
}

.editor-canvas-wrap .editor-stack {
  position: relative;
  flex: none;
}

.editor-canvas-wrap .editor-stack canvas {
  display: block;
  max-width: none;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.editor-canvas-wrap .editor-stack .editor-crop-overlay {
  position: absolute;
  inset: 0;
  margin: 0;
  pointer-events: none;
}

.editor-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  padding-top: var(--space-sm);
  font-size: var(--text-sm);
  color: var(--color-muted);
}

.editor-options label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.editor-options input[type="range"] { accent-color: var(--color-accent); }

.editor-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2xs);
  margin-top: var(--space-sm);
}

.editor-row button,
.editor-history button {
  padding: 0.35rem 0.6rem;
  font-size: var(--text-sm);
  color: var(--color-ink-2);
  background: var(--color-paper);
  border: 1px solid var(--color-rule-2);
  border-radius: var(--radius-sm);
}

.editor-history {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 12rem;
  overflow-y: auto;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-sm);
}

.editor-history li + li { border-top: 1px solid var(--color-rule); }

.editor-history button {
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  background: transparent;
}

.editor-history button.is-current {
  background: color-mix(in oklch, var(--color-accent) 12%, transparent);
}

.editor-layer__kind {
  font-family: var(--font-mono);
  color: var(--color-muted);
  width: 1.25rem;
  text-align: center;
}

@media (max-width: 60rem) {
  .editor-body { grid-template-columns: 1fr; }
  .editor-rail {
    flex-direction: row;
    flex-wrap: wrap;
    position: static;
  }
  .editor-viewport { max-height: 60vh; }
}

/* ---- Full-bleed Photoshop-style app frame --------------------------------
 * The editor breaks out of the centered `.layout` column and docks the
 * canvas between the tool rail and the sidebar, taking the full viewport.
 * Pinned rules above are untouched; everything here is additive.
 */

/* Full-bleed: only when the page hosts the editor (graceful fallback to the
   centered column where :has() is unavailable). */
.layout:has(> .editor-page) {
  max-width: none;
  padding-top: var(--space-md);
}

/* Compact app header — the canvas owns the vertical space, not the intro. */
.editor-page > .breadcrumb { margin-bottom: var(--space-xs); }
.editor-page > h1 { font-size: var(--text-lg); }
.editor-page > p {
  font-size: var(--text-sm);
  margin: var(--space-2xs) 0 var(--space-md);
  max-width: 90ch;
}

.editor-workspace {
  gap: var(--space-sm);
  min-height: calc(100svh - 16rem);
}

/* Docked three-column frame: rail | canvas | panels. */
.editor-body {
  grid-template-columns: 3.25rem minmax(0, 1fr) minmax(18rem, 22rem);
  align-items: start;
  flex: 1;
  min-height: 0;
}

/* Canvas column stretches to fill; the scrollable viewport takes the room. */
.editor-canvas-wrap {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  min-height: calc(100svh - 24rem);
}

.editor-canvas-wrap .editor-viewport {
  flex: 1 1 auto;
  width: 100%;
  min-height: 24rem;
  max-height: none;
}

.editor-canvas-wrap .editor-options {
  flex: none;
}

/* Docked, independently scrolling rails. */
.editor-rail {
  position: sticky;
  top: var(--space-md);
  max-height: calc(100svh - 2rem);
  overflow-y: auto;
}

.editor-sidebar {
  position: sticky;
  top: var(--space-md);
  max-height: calc(100svh - 2rem);
  overflow-y: auto;
  min-height: 0;
}

/* ---- Mobile: canvas first, tools in thumb reach --------------------------- */
@media (max-width: 60rem) {
  .layout:has(> .editor-page) {
    padding-top: var(--space-md);
  }

  .editor-workspace { min-height: 0; }

  .editor-body {
    display: flex;
    flex-direction: column;
  }

  .editor-rail {
    position: static;
    max-width: 100%;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-height: none;
    order: -1;
  }

  .editor-rail button {
    flex: none;
    width: 2.5rem;
    height: 2.5rem;
  }

  .editor-canvas-wrap { min-height: 0; }

  .editor-canvas-wrap .editor-viewport {
    height: 52svh;
    min-height: 18rem;
    max-height: 62svh;
    flex: none;
  }

  .editor-options {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: var(--space-2xs);
  }

  .editor-sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .editor-topbar { gap: var(--space-2xs); }
  .editor-zoom { margin-left: 0; }
}

/* Flex items must shrink below content width or wide toolbars force page
   overflow (clipped by overflow-x: clip, stranding the rail off-screen). */
.editor-workspace,
.editor-workspace > *,
.editor-topbar,
.editor-toolbar {
  min-width: 0;
}

/* Empty state — no bordered phantom canvas before a document exists. */
.editor-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  min-height: 20rem;
  padding: var(--space-xl);
  text-align: center;
}

.editor-empty__title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-muted);
  margin: 0;
}

.editor-empty__sub {
  color: var(--color-muted);
  font-size: var(--text-sm);
  margin: 0;
}

.editor-empty button {
  padding: 0.55rem 1.1rem;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-accent-ink);
  background: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
}
