/* VaultX image editor (image-editor.js / image-tools.js). Uses design tokens from app.css.
   Only the colour swatches (.swatch-N) use literal colours: they are drawing colours, not theme colours. */
.image-editor { width: 1240px; height: 90svh; max-height: 94svh; }
.image-editor-shell { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.image-editor-shell h2 { margin: 0; font-size: 16px; font-weight: 600; }

.image-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); flex-shrink: 0; }
.image-toolbar button, .image-zoom-toolbar button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 34px; min-height: 34px; padding: 6px 10px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font-size: 13px; font-weight: 500;
  transition: background-color .12s, border-color .12s, color .12s;
}
.image-toolbar button:hover:not(:disabled), .image-zoom-toolbar button:hover:not(:disabled) { background: var(--hover); border-color: var(--line); }
.image-toolbar button[aria-expanded=true], .image-toolbar button[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.image-toolbar .icon { width: 17px; height: 17px; }
.image-tool-divider { width: 1px; height: 22px; margin: 0 4px; background: var(--line); }
.image-toolbar-spacer { flex: 1; }
#image-clipboard { color: var(--accent); }

.image-zoom-toolbar { display: flex; align-items: center; gap: 4px; padding: 4px 12px; border-bottom: 1px solid var(--line); background: var(--surface); flex-shrink: 0; }
.image-zoom-toolbar button { min-width: 28px; min-height: 28px; padding: 2px 7px; border-radius: var(--radius-xs); font-size: 12px; }
.image-zoom-toolbar .icon { width: 15px; height: 15px; }
.image-zoom-toolbar output { min-width: 46px; text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
#image-dimensions { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.image-workarea { position: relative; display: flex; flex: 1; min-height: 120px; overflow: hidden; }
.image-toolbox { width: 224px; flex: none; padding: 10px; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; background: var(--surface); border-right: 1px solid var(--line); }
.image-tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.image-tool-grid button { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 7px 6px; white-space: nowrap; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-size: 12px; text-align: left; transition: background-color .12s, color .12s, border-color .12s; }
.image-tool-grid .icon { width: 17px; height: 17px; flex: none; }
.image-tool-grid button:hover { background: var(--hover); color: var(--text); }
.image-tool-grid button[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.image-tool-grid button[aria-pressed=true] .icon { color: var(--accent); }

.image-options { display: grid; gap: 10px; margin-top: 14px; font-size: 12px; color: var(--muted); }
.image-colour-label { display: flex; align-items: center; justify-content: space-between; color: var(--text); }
.image-colour-label input { width: 62px; height: 30px; min-height: 0; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius-xs); background: var(--input-bg); cursor: pointer; }
.image-swatches { display: flex; justify-content: space-between; gap: 6px; }
.image-swatches button { width: 20px; height: 20px; min-height: 0; padding: 0; border-radius: 50%; border: 1px solid var(--line-strong); box-shadow: 0 0 0 2px var(--surface); transition: transform .12s; }
.image-swatches button:hover { transform: scale(1.12); }
.swatch-0 { background: #ff4545; }
.swatch-1 { background: #ffca45; }
.swatch-2 { background: #4fd596; }
.swatch-3 { background: #4d98ff; }
.swatch-4 { background: #bd8cff; }
.swatch-5 { background: #ffffff; }
.swatch-6 { background: #101216; }

.image-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px; }
.image-option input[type=range] { flex: 1; width: 80px; min-width: 40px; height: 18px; min-height: 0; padding: 0; accent-color: var(--accent-strong); }
.image-option output { width: 38px; text-align: right; font-size: 11px; font-variant-numeric: tabular-nums; }
.image-option input[type=number], .image-option select { width: 100px; min-height: 30px; padding: 4px 7px; font-size: 12px; }
.image-option select { padding-right: 26px; background-position: right 6px center; }
.image-check { display: flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; }
.image-check input { width: 14px; height: 14px; min-height: 0; margin: 0; accent-color: var(--accent-strong); }
.image-check-row { display: flex; gap: 14px; padding-top: 4px; }
.image-options details { padding-top: 10px; border-top: 1px solid var(--line-soft); }
.image-options summary { padding: 3px 0; color: var(--text); font-size: 12px; font-weight: 500; cursor: pointer; }
.image-options details[open] > summary { margin-bottom: 10px; }
.image-options details > label { margin-top: 8px; }
.image-options small { display: block; margin-top: 10px; font-size: 11px; line-height: 1.5; color: var(--text-soft); }
.image-resize-inputs { display: flex; gap: 8px; }
.image-resize-inputs label { display: flex; flex: 1; flex-direction: column; gap: 5px; min-width: 0; }
.image-resize-inputs input { width: 100%; min-height: 30px; padding: 5px 6px; font-size: 12px; }
.image-option-button { width: 100%; margin-top: 10px; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface2); color: var(--text); font-size: 12px; font-weight: 500; }
.image-option-button:hover { background: var(--surface3); }

/* Canvas stage with a subtle checkerboard for transparency */
.image-stage {
  position: relative; flex: 1; min-width: 0; min-height: 120px; overflow: hidden; cursor: grab; touch-action: none; overscroll-behavior: contain;
  background-color: var(--surface2);
  background-image: linear-gradient(45deg, var(--hover) 25%, transparent 25%), linear-gradient(-45deg, var(--hover) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--hover) 75%), linear-gradient(-45deg, transparent 75%, var(--hover) 75%);
  background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
.image-stage[data-tool=pen], .image-stage[data-tool=marker], .image-stage[data-tool=line], .image-stage[data-tool=arrow], .image-stage[data-tool=rect], .image-stage[data-tool=ellipse], .image-stage[data-tool=crop], .image-stage[data-tool=picker], .image-stage[data-tool=blur], .image-stage[data-tool=blur-area] { cursor: crosshair; }
.image-stage[data-tool=text] { cursor: text; }
.image-stage.panning { cursor: grabbing; }
.image-space { position: relative; display: flex; align-items: center; justify-content: center; min-width: 100%; min-height: 100%; }
.image-surface { position: relative; flex: none; overflow: hidden; box-shadow: var(--shadow-md); }
.image-stage canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; max-width: none; max-height: none; pointer-events: none; }
.image-text-entry { position: absolute; z-index: 2; min-width: 0; min-height: 0; margin: 0; padding: 0; overflow: hidden; resize: none; border: 0; border-radius: 0; background: var(--accent-soft); outline: 1px dashed var(--accent); outline-offset: 3px; box-shadow: none; white-space: pre; overflow-wrap: normal; }
.image-editor[aria-busy=true] .image-stage { cursor: progress; }

.image-edit-status { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; padding: 5px 14px; border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 12px; flex-shrink: 0; }
#image-pending-actions { display: flex; flex: none; gap: 6px; }
#image-pending-actions button, .image-export-link { padding: 4px 10px; border: 1px solid var(--line); border-radius: var(--radius-xs); background: var(--surface2); color: var(--text); font-size: 12px; font-weight: 500; }
#image-pending-actions button:hover, .image-export-link:hover { background: var(--accent-soft); border-color: var(--accent); text-decoration: none; }
.image-export-link { flex: none; white-space: nowrap; color: var(--accent); }

.image-editor form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 8px 14px; max-height: 35%; padding: 12px 16px; overflow: auto; border-top: 1px solid var(--line); background: var(--surface); flex-shrink: 0; }
.image-editor .field { margin: 0; }
.image-editor .field > span { font-size: 12px; }
.image-editor .field input, .image-editor .field select { width: 100%; height: 36px; min-height: 36px; }
.image-save-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.image-note { grid-column: 1 / -1; margin: 0; font-size: 11px; color: var(--text-soft); }
#image-error { grid-column: 1 / -1; margin: 0; }

#image-draw-options, #image-blur-options { display: grid; gap: 10px; }
#image-blur-options { padding: 10px; border: 1px solid var(--accent-soft); border-radius: var(--radius-sm); background: var(--accent-soft); }
#image-blur-options .image-option { flex-wrap: wrap; gap: 5px; }
#image-blur-options input[type=range] { min-width: 60px; }
#image-blur-options output { width: 42px; }
#image-blur-options small { margin-top: 0; }

@media (max-width: 800px) {
  .image-toolbar { gap: 4px; padding: 6px 8px; }
  .image-toolbar button { padding: 6px; }
  .image-toolbar button span { display: none; }
  .image-zoom-toolbar { padding: 4px 8px; }
  .image-editor form { grid-template-columns: 1fr 1fr; max-height: 34%; padding: 10px; }
  .image-save-actions { grid-column: 1 / -1; }
  .image-save-actions .button { flex: 1; }
  .image-toolbox { width: 208px; }
  .image-edit-status { padding: 5px 9px; font-size: 11px; }
}
@media (max-width: 700px) {
  .image-editor { width: 100%; max-width: calc(100% - 16px); height: 94svh; max-height: 96svh; border-radius: 12px; }
  .image-editor .viewer-header { padding: 8px 10px 8px 14px; }
  .image-editor-shell h2 { font-size: 15px; }
  .image-toolbox { position: absolute; inset: 0 auto 0 0; z-index: 5; box-shadow: var(--shadow-lg); }
  .image-tool-grid button { min-height: 38px; }
  .image-toolbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .image-toolbar button { width: 100%; min-width: 31px; min-height: 36px; padding: 6px; }
  .image-toolbar .icon { width: 17px; height: 17px; }
  .image-toolbar-spacer, .image-tool-divider { display: none; }
  .image-edit-status { min-height: 39px; }
  .image-edit-status > span { line-height: 1.4; }
  .image-editor form { gap: 7px 10px; }
  .image-note { font-size: 10px; }
  .image-editor .field input, .image-editor .field select { height: 38px; min-height: 38px; font-size: 16px; }
  .image-save-actions .button { min-height: 38px; font-size: 13px; padding: 8px; }
  .image-options input, .image-options select { font-size: 16px !important; }
}
