.image-workbench {
  --image-canvas: #eef2f7;
  --image-panel-muted: #f8fafc;
  --image-success: #047857;
  --image-success-bg: #ecfdf5;
  --image-danger: #b91c1c;
  --image-danger-bg: #fef2f2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
}

body.dark-theme .image-workbench {
  --image-canvas: #0b1220;
  --image-panel-muted: #111c2f;
  --image-success: #6ee7b7;
  --image-success-bg: #0d2924;
  --image-danger: #fca5a5;
  --image-danger-bg: #35171c;
}

.image-workbench [hidden] { display: none; }

.image-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .05);
  display: flex;
  flex-direction: column;
}

.image-panel__header,
.image-panel__footer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.image-panel__header {
  min-height: 50px;
  justify-content: space-between;
  padding: 8px 12px 8px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, var(--cloud));
}

.image-panel__heading {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
}

.image-panel__badge {
  padding: 3px 7px;
  border-radius: 5px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: .045em;
}

body.dark-theme .image-panel__badge {
  background: #172554;
  color: #7dd3fc;
}

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

.image-icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.image-icon-button:hover {
  background: var(--cloud);
  color: var(--blue);
}

.image-panel__body {
  flex: 1;
  padding: 16px;
}

.image-panel__footer {
  min-height: 38px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.image-panel__footer i { color: var(--image-success); }

.image-source-panel__body {
  min-height: 430px;
  display: flex;
}

.image-drop-zone {
  width: 100%;
  min-height: 398px;
  margin: 0;
  padding: 36px;
  border: 2px dashed var(--border);
  border-radius: 9px;
  background: var(--image-panel-muted);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  transition: border-color .16s ease, background-color .16s ease, transform .16s ease;
}

.image-drop-zone:hover,
.image-drop-zone.is-dragging,
.image-drop-zone:focus-visible {
  border-color: var(--blue);
  background: color-mix(in srgb, var(--surface) 82%, #dbeafe);
}

.image-drop-zone.is-dragging { transform: scale(.995); }

body.dark-theme .image-drop-zone:hover,
body.dark-theme .image-drop-zone.is-dragging,
body.dark-theme .image-drop-zone:focus-visible {
  background: color-mix(in srgb, var(--surface) 82%, #172554);
}

.image-drop-zone:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.image-source-panel.is-dragging .image-preview-canvas { border-color: var(--blue); outline: 3px solid var(--focus); }

.image-drop-zone__icon {
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #dbeafe;
  color: var(--blue);
  font-size: 30px;
}

body.dark-theme .image-drop-zone__icon { background: #172554; color: #7dd3fc; }
.image-drop-zone strong { color: var(--ink); font-size: 20px; }
.image-drop-zone__browse { color: var(--blue); font-weight: 700; }
.image-drop-zone small { margin-top: 10px; }

.image-source-preview {
  width: 100%;
  display: grid;
  grid-template-rows: minmax(280px, 1fr) auto auto;
  gap: 14px;
}

.image-preview-canvas {
  min-height: 280px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--image-canvas);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.image-preview-canvas img {
  display: block;
  max-width: 100%;
  max-height: 330px;
  object-fit: contain;
}

.image-file-summary {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--image-panel-muted);
  display: flex;
  align-items: center;
  gap: 12px;
}

.image-file-summary > i { color: var(--blue); font-size: 22px; }
.image-file-summary > div { min-width: 0; }
.image-file-summary strong,
.image-file-summary span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-file-summary span { margin-top: 2px; color: var(--muted); font-size: 13px; }
.image-source-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.image-output-panel__body {
  min-height: 430px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.image-settings {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.image-settings__title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
}

.image-quality-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 12px;
  align-items: end;
}

.image-quality-row input[type="range"] { margin-bottom: 12px; }

.image-quality-hints {
  margin: -4px 0 8px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.image-workbench .form-text { color: var(--muted); }
.image-settings [data-png-settings][hidden],
.image-settings [data-lossy-settings][hidden] { display: none; }

.image-result-stage {
  flex: 1;
  min-height: 230px;
  display: flex;
  flex-direction: column;
}

.image-result-empty,
.image-result-loading {
  flex: 1;
  min-height: 230px;
  padding: 28px;
  border: 1px dashed var(--border);
  border-radius: 9px;
  color: var(--muted);
  display: grid;
  place-items: center;
  text-align: center;
}

.image-result-empty__content { max-width: 310px; }
.image-result-empty i { display: block; margin-bottom: 12px; color: var(--blue); font-size: 34px; }
.image-result-empty strong { display: block; margin-bottom: 5px; color: var(--ink); font-size: 17px; }

.image-result-loading__content { display: grid; justify-items: center; gap: 12px; }
.image-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: image-spin .8s linear infinite;
}

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

.image-result-error {
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--image-danger) 40%, transparent);
  border-radius: 8px;
  background: var(--image-danger-bg);
  color: var(--image-danger);
}

.image-result-error i { margin-right: 7px; }
.image-result-success { display: grid; gap: 14px; }
.image-result-success .image-preview-canvas { min-height: 210px; }
.image-result-success .image-preview-canvas img { max-height: 250px; }

.image-result-summary {
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--image-success) 35%, var(--border));
  border-radius: 8px;
  background: var(--image-success-bg);
  color: var(--image-success);
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-result-summary i { font-size: 20px; }
.image-result-summary strong { display: block; }
.image-result-summary span { display: block; font-size: 13px; }

.image-result-advisory {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--slate);
  background: var(--image-panel-muted);
  font-size: 13px;
}

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

.image-metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--image-panel-muted);
}

.image-metric span,
.image-metric strong { display: block; overflow-wrap: anywhere; }
.image-metric span { margin-bottom: 3px; color: var(--muted); font-size: 12px; }
.image-metric strong { font-size: 15px; }

.image-information-list {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(120px, .8fr) minmax(0, 1.2fr);
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}

.image-information-list dt,
.image-information-list dd {
  margin: 0;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

.image-information-list dt { color: var(--muted); background: var(--image-panel-muted); font-weight: 400; }
.image-information-list dd { overflow-wrap: anywhere; font-weight: 700; }
.image-information-list > :nth-last-child(-n + 2) { border-bottom: 0; }

.image-panel__actions {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, var(--cloud));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.image-panel__actions .btn-primary { min-width: 150px; }
.image-panel__actions .btn[hidden] { display: none; }
.image-panel__actions-note { color: var(--muted); font-size: 13px; }

.image-workbench.is-processing .image-panel__actions button { cursor: wait; }
.image-workbench.is-processing .image-drop-zone,
.image-workbench.is-processing .image-source-actions { pointer-events: none; opacity: .65; }

@media (prefers-reduced-motion: reduce) {
  .image-drop-zone { transition: none; }
  .image-spinner { animation-duration: 1.8s; }
}

@media (max-width: 980px) {
  .image-workbench { grid-template-columns: 1fr; }
  .image-source-panel__body,
  .image-output-panel__body { min-height: 360px; }
  .image-drop-zone { min-height: 330px; }
}

@media (max-width: 640px) {
  .image-panel__header { padding-left: 12px; }
  .image-panel__badge { display: none; }
  .image-panel__body { padding: 12px; }
  .image-source-panel__body,
  .image-output-panel__body { min-height: 0; }
  .image-drop-zone { min-height: 280px; padding: 28px 18px; }
  .image-source-preview { grid-template-rows: minmax(230px, 1fr) auto auto; }
  .image-preview-canvas { min-height: 230px; padding: 12px; }
  .image-source-actions,
  .image-panel__actions { align-items: stretch; flex-direction: column; }
  .image-source-actions .btn,
  .image-panel__actions .btn { width: 100%; }
  .image-quality-row { grid-template-columns: 1fr 82px; }
  .image-information-list { grid-template-columns: 1fr; }
  .image-information-list dt { padding-bottom: 3px; border-bottom: 0; }
  .image-information-list dd { padding-top: 3px; }
  .image-information-list > :nth-last-child(2) { border-bottom: 0; }
}
