/* ==========================================================================
   Luma Image: workspace styles. Built on the shared Luma tokens/components from style.css.
   Only the photo stage background (neutral grey, so colors are judged fairly) is defined here.
   ========================================================================== */
.img-body { height: 100dvh; overflow: hidden; }
.img-app { --img-panel-width: 340px; --img-stage: #0b0b0e; display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100dvh; }
[data-theme="light"] .img-app { --img-stage: #e9e9ee; }
.img-app[data-view="library"] .img-editor-only { display: none !important; }
.img-app[hidden], [hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.img-topbar { display: flex; align-items: center; gap: var(--space-3); min-height: 56px; padding: var(--space-2) var(--space-3); background: var(--luma-bg); border-bottom: 1px solid var(--luma-border); }
.img-topbar__left, .img-topbar__right, .img-tools { display: flex; align-items: center; gap: var(--space-1); flex: none; }
.img-topbar__right { margin-left: auto; }
.img-topbar__center { display: flex; align-items: center; gap: var(--space-3); min-width: 0; flex: 1 1 auto; justify-content: center; }
.img-wordmark { margin-left: var(--space-2); font-size: 1.25rem; }
.img-product { cursor: pointer; font: inherit; font-size: var(--font-size-xs); font-weight: 550; }
.img-name { width: min(280px, 100%); min-width: 0; height: 34px; padding: 0 var(--space-2); background: transparent; color: var(--luma-text); border: 1px solid transparent; border-radius: var(--radius-sm); font: inherit; font-weight: 550; text-align: center; text-overflow: ellipsis; }
.img-name:hover { border-color: var(--luma-border-strong); }
.img-name:focus-visible { border-color: var(--luma-focus); outline: none; box-shadow: 0 0 0 3px var(--luma-accent-soft); }
.img-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--font-size-xs); color: var(--luma-text-muted); white-space: nowrap; }
.img-status__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--luma-success); }
.img-status[data-state="unsaved"] .img-status__dot, .img-status[data-state="saving"] .img-status__dot { background: var(--luma-warning); }
.img-status[data-state="error"] .img-status__dot { background: var(--luma-error); }
.img-zoomlabel { min-width: 56px; padding: 0 var(--space-2); font-variant-numeric: tabular-nums; }
.img-panel-toggle { display: none; }
.luma-icon-button[aria-pressed="true"] { background: var(--luma-accent-soft); color: var(--luma-accent); }

/* ---------- Library ---------- */
.img-library { overflow: auto; outline: none; }
.img-library__inner { max-width: 1040px; margin: 0 auto; padding: var(--space-12) var(--gutter) var(--space-16); display: flex; flex-direction: column; gap: var(--space-12); }
.img-welcome { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-4); padding: var(--space-12) var(--space-6); border: 1.5px dashed var(--luma-border-strong); border-radius: var(--radius-xl); background: var(--luma-bg-secondary); }
.img-welcome__title { margin: 0; font-size: var(--font-size-2xl); letter-spacing: -0.03em; line-height: var(--line-tight); }
.img-welcome__lead { margin: 0; max-width: 52ch; color: var(--luma-text-secondary); }
.img-welcome__actions { display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: center; margin-top: var(--space-2); }
.img-welcome__drop { margin: 0; font-size: var(--font-size-sm); color: var(--luma-text-muted); }
.img-link { background: none; border: 0; padding: 0; color: var(--luma-accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.img-facts { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); justify-content: center; font-size: var(--font-size-xs); color: var(--luma-text-muted); }
.img-facts li { display: inline-flex; align-items: center; gap: 6px; }
.img-error { margin: 0; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--luma-error-soft); color: var(--luma-error); font-size: var(--font-size-sm); text-align: left; max-width: 62ch; }
.img-note { margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--luma-accent-soft); color: var(--luma-text-secondary); font-size: var(--font-size-sm); }
.img-note[data-level="warning"] { background: var(--luma-warning-soft); color: var(--luma-text); }
.img-recent__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-3); }
.img-recent__title { margin: 0; font-size: var(--font-size-xl); letter-spacing: -0.02em; }
.img-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-4); }
.img-card { position: relative; background: var(--luma-surface); border: 1px solid var(--luma-border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.img-card:hover { border-color: var(--luma-border-strong); box-shadow: var(--shadow-md); }
.img-card__open { display: flex; flex-direction: column; width: 100%; padding: 0; text-align: left; background: none; border: 0; color: inherit; font: inherit; cursor: pointer; }
.img-card__thumb { aspect-ratio: 3 / 2; background: var(--luma-bg-secondary); display: grid; place-items: center; }
.img-card__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-card__meta { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3); min-width: 0; }
.img-card__name { font-weight: 550; font-size: var(--font-size-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.img-card__del { position: absolute; top: var(--space-2); right: var(--space-2); background: color-mix(in srgb, var(--luma-bg) 80%, transparent); }

/* ---------- Editor ---------- */
.img-editor { display: grid; grid-template-columns: minmax(0, 1fr) var(--img-panel-width); min-height: 0; }
.img-editor.is-panel-hidden { grid-template-columns: minmax(0, 1fr) 0; }
.img-editor.is-panel-hidden .img-panel { visibility: hidden; border: 0; }
.img-stage { min-width: 0; min-height: 0; background: var(--img-stage); position: relative; }
.img-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.img-viewport:active { cursor: grabbing; }
.img-viewport canvas { position: absolute; left: 0; top: 0; display: block; }
.img-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: var(--space-3); background: color-mix(in srgb, var(--img-stage) 85%, transparent); color: var(--luma-text-secondary); font-size: var(--font-size-sm); z-index: 5; }
.img-spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--luma-border-strong); border-top-color: var(--luma-accent); animation: img-spin 0.8s linear infinite; }
@keyframes img-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .img-spinner { animation-duration: 2.4s; } }
.img-hint { position: absolute; left: 50%; bottom: var(--space-4); transform: translateX(-50%); max-width: calc(100% - var(--space-8)); padding: var(--space-2) var(--space-3); background: var(--luma-surface-raised); border: 1px solid var(--luma-border); border-radius: var(--radius-md); font-size: var(--font-size-xs); color: var(--luma-text-secondary); box-shadow: var(--shadow-md); pointer-events: none; z-index: 4; }

.img-split { position: absolute; width: 28px; margin-left: -14px; cursor: ew-resize; z-index: 3; touch-action: none; }
.img-split::before { content: ""; position: absolute; left: 13px; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); }
.img-split::after { content: "‹ ›"; position: absolute; left: 0; top: 50%; width: 28px; height: 28px; margin-top: -14px; display: grid; place-items: center; border-radius: 50%; background: #fff; color: #111; font-size: 13px; line-height: 1; box-shadow: var(--shadow-md); }
.img-split:focus-visible { outline: none; }
.img-split:focus-visible::after { box-shadow: 0 0 0 3px var(--luma-focus); }

/* Crop overlay */
.img-crop { position: absolute; inset: 0; z-index: 2; }
.img-crop__box { position: absolute; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55); outline: 1.5px solid #fff; cursor: move; touch-action: none; }
.img-crop__box:focus-visible { outline: 2px solid var(--luma-focus); }
.img-crop__grid { position: absolute; inset: 0; background-image: linear-gradient(to right, transparent calc(33.33% - 0.5px), rgba(255,255,255,.45) calc(33.33% - 0.5px), rgba(255,255,255,.45) calc(33.33% + 0.5px), transparent calc(33.33% + 0.5px), transparent calc(66.66% - 0.5px), rgba(255,255,255,.45) calc(66.66% - 0.5px), rgba(255,255,255,.45) calc(66.66% + 0.5px), transparent calc(66.66% + 0.5px)), linear-gradient(to bottom, transparent calc(33.33% - 0.5px), rgba(255,255,255,.45) calc(33.33% - 0.5px), rgba(255,255,255,.45) calc(33.33% + 0.5px), transparent calc(33.33% + 0.5px), transparent calc(66.66% - 0.5px), rgba(255,255,255,.45) calc(66.66% - 0.5px), rgba(255,255,255,.45) calc(66.66% + 0.5px), transparent calc(66.66% + 0.5px)); }
.img-crop__info { position: absolute; left: 50%; top: 6px; transform: translateX(-50%); padding: 1px 8px; border-radius: var(--radius-full); background: rgba(0,0,0,.6); color: #fff; font-size: 11px; white-space: nowrap; pointer-events: none; }
.img-crop__handle { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; touch-action: none; }
.img-crop__handle::after { content: ""; position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; background: #fff; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.45); }
.img-crop__handle--nw { left: 0; top: 0; cursor: nwse-resize; } .img-crop__handle--n { left: 50%; top: 0; cursor: ns-resize; } .img-crop__handle--ne { left: 100%; top: 0; cursor: nesw-resize; }
.img-crop__handle--e { left: 100%; top: 50%; cursor: ew-resize; } .img-crop__handle--se { left: 100%; top: 100%; cursor: nwse-resize; } .img-crop__handle--s { left: 50%; top: 100%; cursor: ns-resize; }
.img-crop__handle--sw { left: 0; top: 100%; cursor: nesw-resize; } .img-crop__handle--w { left: 0; top: 50%; cursor: ew-resize; }

/* ---------- Panel ---------- */
.img-panel { display: flex; flex-direction: column; min-height: 0; background: var(--luma-bg); border-left: 1px solid var(--luma-border); }
.img-histogram { padding: var(--space-3) var(--space-4) var(--space-2); }
.img-histogram canvas { width: 100%; height: 64px; display: block; background: var(--luma-bg-secondary); border-radius: var(--radius-sm); }
.img-panel__body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.img-panel__foot { display: flex; justify-content: space-between; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--luma-border); }
.img-group { border-top: 1px solid var(--luma-border); }
.img-group__title { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); font-size: var(--font-size-sm); font-weight: 600; cursor: pointer; list-style: none; }
.img-group__title::-webkit-details-marker { display: none; }
.img-group__title .luma-icon { transition: transform var(--duration-fast) var(--ease); color: var(--luma-text-muted); }
.img-group[open] > .img-group__title .luma-icon { transform: rotate(180deg); }
.img-group__title:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--luma-focus); }
.img-group__body { display: flex; flex-direction: column; gap: var(--space-3); padding: 0 var(--space-4) var(--space-4); }

.img-slider { display: flex; flex-direction: column; gap: 4px; }
.img-slider__top { display: flex; align-items: center; gap: var(--space-2); }
.img-slider__label { flex: 1; font-size: var(--font-size-xs); color: var(--luma-text-secondary); cursor: default; }
.img-slider.is-changed .img-slider__label { color: var(--luma-text); font-weight: 550; }
.img-slider__num { width: 58px; height: 26px; padding: 0 6px; text-align: right; background: var(--luma-bg-secondary); color: var(--luma-text); border: 1px solid transparent; border-radius: var(--radius-xs); font: inherit; font-size: var(--font-size-xs); font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.img-slider__num::-webkit-outer-spin-button, .img-slider__num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.img-slider__num:hover { border-color: var(--luma-border-strong); }
.img-slider__num:focus-visible { outline: none; border-color: var(--luma-focus); }
.img-slider__reset { width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--luma-text-muted); cursor: pointer; visibility: hidden; }
.img-slider.is-changed .img-slider__reset { visibility: visible; }
.img-slider__reset:hover { color: var(--luma-text); background: var(--luma-bg-secondary); }
.img-slider__reset:focus-visible { outline: none; box-shadow: var(--luma-focus-ring); }
.img-slider__range { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; margin: 0; background: transparent; cursor: pointer; --fill-from: 0%; --fill-to: 0%; }
.img-slider__range::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--luma-border-strong) 0, var(--luma-border-strong) var(--fill-from), var(--luma-accent) var(--fill-from), var(--luma-accent) var(--fill-to), var(--luma-border-strong) var(--fill-to)); }
.img-slider__range::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--luma-border-strong) 0, var(--luma-border-strong) var(--fill-from), var(--luma-accent) var(--fill-from), var(--luma-accent) var(--fill-to), var(--luma-border-strong) var(--fill-to)); }
.img-slider__range::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: #fff; border: 1px solid rgba(0,0,0,.3); box-shadow: var(--shadow-sm); }
.img-slider__range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 1px solid rgba(0,0,0,.3); }
.img-slider__range:focus-visible { outline: none; }
.img-slider__range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--luma-focus); }
.img-slider__range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--luma-focus); }
.img-slider__range--hue::-webkit-slider-runnable-track { background: linear-gradient(to right, hsl(0 80% 55%), hsl(60 80% 55%), hsl(120 70% 45%), hsl(180 70% 45%), hsl(240 80% 60%), hsl(300 70% 55%), hsl(360 80% 55%)); }
.img-slider__range--hue::-moz-range-track { background: linear-gradient(to right, hsl(0 80% 55%), hsl(60 80% 55%), hsl(120 70% 45%), hsl(180 70% 45%), hsl(240 80% 60%), hsl(300 70% 55%), hsl(360 80% 55%)); }

.img-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.img-preset { display: flex; flex-direction: column; gap: 4px; padding: 4px; background: var(--luma-surface); border: 1px solid var(--luma-border); border-radius: var(--radius-sm); cursor: pointer; color: var(--luma-text); font: inherit; }
.img-preset:hover { border-color: var(--luma-border-strong); }
.img-preset.is-active { border-color: var(--luma-accent); box-shadow: 0 0 0 1px var(--luma-accent); }
.img-preset:focus-visible { outline: none; box-shadow: var(--luma-focus-ring); }
.img-preset__thumb { width: 100%; height: auto; aspect-ratio: 3 / 2; border-radius: 4px; background: var(--luma-bg-secondary); display: block; }
.img-preset__name { font-size: 11px; text-align: center; color: var(--luma-text-secondary); }

.img-seg { display: flex; gap: 2px; padding: 2px; background: var(--luma-bg-secondary); border-radius: var(--radius-sm); }
.img-seg--wrap { flex-wrap: wrap; }
.img-seg__btn { flex: 1; min-width: 0; height: 28px; padding: 0 var(--space-2); border: 0; border-radius: 6px; background: transparent; color: var(--luma-text-secondary); font: inherit; font-size: var(--font-size-xs); cursor: pointer; white-space: nowrap; }
.img-seg__btn:hover { color: var(--luma-text); }
.img-seg__btn.is-active { background: var(--luma-surface-raised); color: var(--luma-text); box-shadow: var(--shadow-sm); font-weight: 550; }
.img-seg__btn:focus-visible { outline: none; box-shadow: var(--luma-focus-ring); }
.img-swatches { display: flex; gap: var(--space-2); }
.img-swatch { position: relative; width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; background: var(--sw); cursor: pointer; padding: 0; }
.img-swatch.is-active { border-color: var(--luma-text); }
.img-swatch.is-changed::after { content: ""; position: absolute; right: -2px; top: -2px; width: 8px; height: 8px; border-radius: 50%; background: var(--luma-text); border: 2px solid var(--luma-bg); }
.img-swatch:focus-visible { outline: none; box-shadow: var(--luma-focus-ring); }
.img-hsl__band { display: flex; flex-direction: column; gap: var(--space-3); }
.img-grade { display: flex; flex-direction: column; gap: var(--space-2); }
.img-grade__title { margin: 0; font-size: var(--font-size-xs); font-weight: 600; color: var(--luma-text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.img-curve-wrap { background: var(--luma-bg-secondary); border-radius: var(--radius-sm); padding: var(--space-4); }
.img-curve { overflow: visible; display: block; width: 100%; max-width: 280px; margin: 0 auto; aspect-ratio: 1; touch-action: none; }
.img-curve__grid { stroke: var(--luma-border-strong); stroke-width: 1; }
.img-curve__diag { stroke: var(--luma-border-strong); stroke-width: 1; stroke-dasharray: 3 4; }
.img-curve__line { fill: none; stroke-width: 2; }
.img-curve__pt { fill: var(--luma-bg); stroke: var(--luma-accent); stroke-width: 2; cursor: grab; }
.img-curve__pt:focus-visible { outline: none; stroke: var(--luma-focus); stroke-width: 3; r: 7; }
.img-croptools { display: flex; gap: var(--space-2); }
.img-geo { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.img-geo .luma-button { justify-content: flex-start; gap: 6px; padding: 0 var(--space-2); }
.img-history { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.img-history__btn { width: 100%; text-align: left; padding: 5px var(--space-2); border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--luma-text-secondary); font: inherit; font-size: var(--font-size-xs); cursor: pointer; }
.img-history__btn:hover { background: var(--luma-bg-secondary); }
.img-history__item.is-active .img-history__btn { background: var(--luma-accent-soft); color: var(--luma-accent); font-weight: 550; }
.img-history__item.is-future .img-history__btn { opacity: 0.5; }
.img-history__btn:focus-visible { outline: none; box-shadow: var(--luma-focus-ring); }

/* ---------- Dialogs ---------- */
.img-form { display: flex; flex-direction: column; gap: var(--space-4); }
.img-progress { height: 8px; border-radius: 4px; background: var(--luma-bg-secondary); overflow: hidden; }
.img-progress__bar { height: 100%; width: 0; background: var(--luma-accent); transition: width var(--duration-fast) linear; }
.img-plus-list { margin: 0 0 var(--space-3); padding-left: var(--space-5); color: var(--luma-text-secondary); }
.img-dropveil { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; background: var(--luma-overlay); pointer-events: none; }
.img-dropveil > div { padding: var(--space-8) var(--space-12); border: 2px dashed var(--luma-accent); border-radius: var(--radius-xl); background: var(--luma-surface-raised); font-weight: 600; font-size: var(--font-size-lg); }
.luma-dropdown__item { text-decoration: none; }

/* ---------- Small screens: simplified layout, panel as bottom sheet ---------- */
@media (max-width: 900px) {
  .img-hide-sm { display: none !important; }
  .img-topbar { gap: var(--space-2); flex-wrap: wrap; padding: var(--space-2); }
  .img-topbar__center { order: 5; flex: 1 0 100%; justify-content: space-between; }
  .img-tools .luma-divider, .img-zoombtn { display: none; }
  .img-name { flex: 1 1 auto; text-align: left; }
  .img-wordmark { display: none; }
  .img-panel-toggle { display: inline-flex; }
  .img-editor, .img-editor.is-panel-hidden { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 46dvh); }
  .img-editor.is-panel-hidden { grid-template-rows: minmax(0, 1fr) 0; }
  .img-panel { border-left: 0; border-top: 1px solid var(--luma-border); }
  .img-histogram { display: none; }
  .img-library__inner { padding-top: var(--space-6); gap: var(--space-8); }
  .img-welcome { padding: var(--space-8) var(--space-4); }
  .img-presets { grid-template-columns: repeat(3, 1fr); }
  .img-crop__handle { width: 30px; height: 30px; margin: -15px 0 0 -15px; }
}
@media (max-width: 420px) { .img-tools { gap: 0; } .img-zoomlabel { min-width: 48px; } }
