/* AI image editor workspace */
.workspaceImagePane {
  display: none;
  position: absolute;
  inset: 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.workspacePanel[data-workspace-tab="ai-image"] .workspaceCodePane,
.workspacePanel[data-workspace-tab="ai-image"] .workspacePreviewPane {
  display: none !important;
}

.workspacePanel[data-workspace-tab="ai-image"] .workspaceImagePane {
  display: block;
}

.workspacePanel[data-workspace-tab="ai-image"] .workspaceToolbarSlot {
  visibility: hidden;
  pointer-events: none;
}

.aiImageEditorRoot {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 290px) minmax(0, 1fr);
  color: var(--text);
  background: var(--bg);
}

.aiImageEditorGallery {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-inline-end: 1px solid var(--border);
  background: var(--panelSolid);
}

.aiImageEditorGalleryHead,
.aiImageEditorTopbar {
  flex: 0 0 auto;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.aiImageEditorGalleryHead strong {
  font-size: 13px;
  letter-spacing: .08em;
}

.aiImageEditorGalleryCount,
.aiImageEditorPath,
.aiImageEditorStatus {
  min-width: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aiImageEditorGalleryCount { margin-inline-start: auto; }

.aiImageEditorIconBtn,
.aiImageEditorBtn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  border-radius: 10px;
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  transition: background .18s ease, border-color .18s ease, opacity .18s ease, transform .18s ease;
}

.aiImageEditorIconBtn {
  width: 36px;
  padding: 0;
  font-size: 17px;
}

.aiImageEditorBtn:hover,
.aiImageEditorIconBtn:hover {
  border-color: var(--border2);
  background: rgba(56, 189, 248, .10);
}

.aiImageEditorBtn:active,
.aiImageEditorIconBtn:active { transform: translateY(1px); }
.aiImageEditorBtn:disabled,
.aiImageEditorIconBtn:disabled { opacity: .45; cursor: default; transform: none; }
.aiImageEditorBtn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.aiImageEditorBtn.danger { color: #fff; background: #dc2626; border-color: transparent; }

.aiImageEditorGalleryList {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 8px;
  padding: 10px;
}

.aiImageEditorThumb {
  position: relative;
  min-width: 0;
  aspect-ratio: 1 / 1;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--panel2);
  cursor: pointer;
  color: var(--text);
}

.aiImageEditorThumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.aiImageEditorThumb span {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  padding: 7px 8px;
  color: #fff;
  background: rgba(0, 0, 0, .60);
  backdrop-filter: blur(6px);
  font-size: 10px;
  text-align: start;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aiImageEditorThumb.active {
  border-color: var(--accent3);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, .20);
}

.aiImageEditorGalleryEmpty,
.aiImageEditorEmpty {
  grid-column: 1 / -1;
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  line-height: 1.65;
}

.aiImageEditorMain {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.aiImageEditorTopbar {
  background: var(--panelSolid);
}

.aiImageEditorPath { flex: 1; }
.aiImageEditorBrushLabel { color: var(--muted); font-size: 11px; white-space: nowrap; }
.aiImageEditorBrushRange { width: 110px; accent-color: var(--accent3); }

.aiImageEditorStage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 15%, rgba(56, 189, 248, .07), transparent 34%),
    var(--bg);
}

.aiImageEditorSurface {
  position: relative;
  display: none;
  line-height: 0;
  max-width: 100%;
  max-height: 100%;
  user-select: none;
  touch-action: none;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .24);
  background: repeating-conic-gradient(rgba(128,128,128,.14) 0 25%, transparent 0 50%) 50% / 18px 18px;
}

.aiImageEditorSurface.open { display: inline-block; }

.aiImageEditorSource,
.aiImageEditorSelectionCanvas,
.aiImageEditorWorkingFx {
  display: block;
  max-width: min(100%, 1500px);
  max-height: calc(100vh - 190px);
}

.aiImageEditorSource {
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
}

.aiImageEditorSelectionCanvas,
.aiImageEditorWorkingFx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.aiImageEditorSelectionCanvas {
  cursor: crosshair;
  z-index: 3;
}

.aiImageEditorWorkingFx {
  z-index: 4;
  display: none;
  pointer-events: none;
  background: linear-gradient(110deg,
    rgba(255,255,255,.02) 0%,
    rgba(56,189,248,.65) 35%,
    rgba(167,139,250,.80) 50%,
    rgba(56,189,248,.65) 65%,
    rgba(255,255,255,.02) 100%);
  background-size: 240% 100%;
  mix-blend-mode: screen;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  animation: aiImageEditorWorkingSweep 1.25s linear infinite;
}

.aiImageEditorSurface.is-working .aiImageEditorWorkingFx { display: block; }
.aiImageEditorSurface.is-working .aiImageEditorSelectionCanvas { pointer-events: none; }

@keyframes aiImageEditorWorkingSweep {
  from { background-position: 170% 0; filter: brightness(.85); }
  50% { filter: brightness(1.35); }
  to { background-position: -70% 0; filter: brightness(.85); }
}

.aiImageEditorBubble {
  position: absolute;
  z-index: 7;
  display: none;
  width: min(360px, calc(100% - 18px));
  padding: 9px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  background: rgba(13, 17, 23, .92);
  color: #fff;
  box-shadow: 0 18px 54px rgba(0, 0, 0, .34);
  backdrop-filter: blur(14px);
  line-height: normal;
}

.aiImageEditorBubble.open { display: block; }
.aiImageEditorBubble textarea {
  width: 100%;
  min-height: 62px;
  max-height: 150px;
  resize: vertical;
  border: 0;
  outline: 0;
  border-radius: 9px;
  padding: 9px 10px;
  background: rgba(255,255,255,.09);
  color: #fff;
  font: 13px/1.45 var(--font);
}
.aiImageEditorBubble textarea::placeholder { color: rgba(255,255,255,.58); }
.aiImageEditorBubbleActions { display: flex; gap: 7px; margin-top: 8px; }
.aiImageEditorBubble .aiImageEditorBtn { flex: 1; color: #fff; background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.13); }
.aiImageEditorBubble .aiImageEditorBtn.primary { background: #2563eb; }
.aiImageEditorBubble .aiImageEditorBtn.danger { flex: 0 0 auto; background: #dc2626; }

.aiImageEditorCompare {
  display: none;
  width: min(100%, 1400px);
  flex-direction: column;
  gap: 12px;
}
.aiImageEditorCompare.open { display: flex; }
.aiImageEditorCompareFrame {
  position: relative;
  overflow: hidden;
  margin: auto;
  max-width: 100%;
  max-height: calc(100vh - 245px);
  line-height: 0;
  box-shadow: 0 24px 70px rgba(0,0,0,.25);
  background: #111;
}
.aiImageEditorCompareFrame img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 245px);
  width: auto;
  height: auto;
  object-fit: contain;
}
.aiImageEditorCompareAfter {
  position: absolute;
  inset: 0;
  overflow: hidden;
  clip-path: inset(0 50% 0 0);
}
.aiImageEditorCompareAfter img { width: 100%; height: 100%; object-fit: fill; }
.aiImageEditorCompareLine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-1px);
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.34), 0 0 18px rgba(0,0,0,.45);
  pointer-events: none;
}
.aiImageEditorCompareLine::after {
  content: "↔";
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #111;
  background: #fff;
  font: 18px var(--font);
  box-shadow: 0 8px 26px rgba(0,0,0,.28);
}
.aiImageEditorCompareRange {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: ew-resize;
}
.aiImageEditorCompareLabels {
  position: absolute;
  inset: 12px 12px auto;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.aiImageEditorCompareLabels span {
  padding: 5px 8px;
  border-radius: 999px;
  color: #fff;
  background: rgba(0,0,0,.56);
  font: 11px var(--font);
  backdrop-filter: blur(6px);
}
.aiImageEditorResultActions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.aiImageEditorStatusBar {
  flex: 0 0 auto;
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  background: var(--panelSolid);
}
.aiImageEditorStatus { flex: 1; }
.aiImageEditorCost { color: var(--accent); font-size: 11px; font-family: var(--mono); }

@media (max-width: 980px) {
  .aiImageEditorRoot { grid-template-columns: 190px minmax(0, 1fr); }
  .aiImageEditorGalleryList { grid-template-columns: 1fr; }
  .aiImageEditorTopbar { flex-wrap: wrap; }
  .aiImageEditorPath { flex-basis: 100%; order: 3; }
}

@media (prefers-reduced-motion: reduce) {
  .aiImageEditorWorkingFx { animation-duration: 2.5s; }
  .aiImageEditorBtn,
  .aiImageEditorIconBtn { transition: none; }
}
