/*
 * ImageGarage canonical editor shell
 *
 * The Photo Editor is the reference implementation for every focused editing
 * tool.  Tool pages provide their own controls and canvas rendering; this file
 * owns the stable app frame that keeps those regions in predictable tracks.
 */

html.ig-editor-open,
html.ig-editor-open body {
  overflow: hidden;
  overscroll-behavior: none;
}

.ig-editor {
  --ig-rail-width: 68px;
  --ig-inspector-width: clamp(232px, 20vw, 272px);
  --ig-header-height: 56px;
  --ig-inspector-height: var(--ig-mobile-inspector-height, min(210px, 38dvh));
  --ig-bottom-safe: max(8px, env(safe-area-inset-bottom));
  --ig-mobile-rail-height: calc(55px + var(--ig-bottom-safe));
  position: fixed;
  inset: 0;
  z-index: 8000;
  display: flex;
  width: 100%;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--surface);
}

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

.ig-editor-header {
  position: relative;
  z-index: 5;
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: var(--ig-header-height);
  flex: 0 0 var(--ig-header-height);
  align-items: center;
  gap: 8px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 7px 12px;
}

/* Shared history controls mirror the Photo Editor's compact header actions. */
.ig-editor-history {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 2px;
}

.ig-editor-icon-button {
  display: inline-grid;
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  color: var(--ink-soft);
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}

.ig-editor-icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.ig-editor-icon-button:hover:not(:disabled) {
  color: var(--brand);
  border-color: color-mix(in srgb, var(--brand) 38%, var(--line));
  background: color-mix(in srgb, var(--brand) 14%, var(--surface));
}

.ig-editor-icon-button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.ig-editor-icon-button:disabled {
  opacity: .38;
  cursor: not-allowed;
}

/* Primary editor-header actions shared by scanner, passport, and collage. */
.ig-editor-header-button {
  display: inline-grid;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  touch-action: manipulation;
}

.ig-editor-header-button:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
}

.ig-editor-header-button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.ig-editor-header-button:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.ig-editor-header-button svg {
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.ig-editor-shell {
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  grid-template-columns: var(--ig-rail-width) var(--ig-inspector-width) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.ig-editor-rail {
  display: flex;
  width: var(--ig-rail-width);
  min-width: 0;
  min-height: 0;
  grid-column: 1;
  grid-row: 1;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 7px 5px;
}

.ig-editor-inspector {
  position: relative;
  z-index: 3;
  width: 100%;
  min-width: 0;
  min-height: 0;
  grid-column: 2;
  grid-row: 1;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 8px 0 22px rgba(28, 30, 60, .045);
}

.ig-editor-stage {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  grid-column: 3;
  grid-row: 1;
  overflow: hidden;
  background: var(--dropzone);
}

@media (max-width: 640px) {
  .ig-editor-header-button {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
  }

  .ig-editor {
    --ig-header-height: 52px;
    --ig-inspector-height: var(--ig-mobile-inspector-height, min(210px, 38dvh));
  }

  .ig-editor-header {
    gap: 4px;
    padding: 6px 8px;
  }

  .ig-editor-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) var(--ig-inspector-height) var(--ig-mobile-rail-height);
  }

  .ig-editor-stage {
    grid-column: 1;
    grid-row: 1;
  }

  .ig-editor-inspector {
    grid-column: 1;
    grid-row: 2;
    height: 100%;
    border-top: 1px solid var(--line);
    border-right: 0;
    box-shadow: 0 -8px 22px rgba(28, 30, 60, .05);
  }

  .ig-editor-rail {
    width: 100%;
    height: var(--ig-mobile-rail-height);
    min-height: var(--ig-mobile-rail-height);
    grid-column: 1;
    grid-row: 3;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    border-top: 1px solid var(--line);
    border-right: 0;
    box-shadow: 0 -6px 18px rgba(17, 19, 39, .08);
    padding: 3px 4px var(--ig-bottom-safe);
    scrollbar-width: none;
  }

  .ig-editor-rail::-webkit-scrollbar { display: none; }
}
