/* Resize & Crop Image: styles for this tool only. Shared styles live in /tools/shared/tools.css. */

/* The dropzone shows its own file card; this tool shows the editor instead once an image is added */
.rz-has-file .dropzone-root {
  display: none;
}

/* ---------- editor (left side) ---------- */

.rz-editor {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: var(--stage-pad);
}
.rz-has-file .rz-editor {
  display: flex;
}
.rz-area {
  position: relative;
  padding: 8px;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}
.rz-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.rz-loading[hidden] {
  display: none;
}

/* The picture, on a checkerboard so transparent areas are visible */
.rz-frame {
  position: relative;
  flex: none;
  border-radius: var(--radius-md);
  background-color: var(--color-field);
  background-image:
    linear-gradient(45deg, rgba(128, 128, 128, 0.18) 25%, transparent 25%, transparent 75%, rgba(128, 128, 128, 0.18) 75%),
    linear-gradient(45deg, rgba(128, 128, 128, 0.18) 25%, transparent 25%, transparent 75%, rgba(128, 128, 128, 0.18) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.rz-frame[data-mode="crop"] {
  cursor: crosshair;
}
.rz-frame canvas {
  display: block;
  border-radius: var(--radius-md);
  width: 100%;
  height: 100%;
}

/* The crop box: the shade dims everything outside it, its clip keeps the dimming inside the picture.
   Colours stay white in both themes because they sit on top of the photo. */
.rz-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: var(--radius-md);
  pointer-events: none;
}
.rz-shade {
  position: absolute;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55);
}
.rz-crop {
  position: absolute;
  outline: 1.5px solid #fff;
  outline-offset: -1px;
  background-image:
    linear-gradient(to right, transparent calc(33.333% - 0.5px), rgba(255, 255, 255, 0.45) calc(33.333% - 0.5px), rgba(255, 255, 255, 0.45) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px), transparent calc(66.666% - 0.5px), rgba(255, 255, 255, 0.45) calc(66.666% - 0.5px), rgba(255, 255, 255, 0.45) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px)),
    linear-gradient(to bottom, transparent calc(33.333% - 0.5px), rgba(255, 255, 255, 0.45) calc(33.333% - 0.5px), rgba(255, 255, 255, 0.45) calc(33.333% + 0.5px), transparent calc(33.333% + 0.5px), transparent calc(66.666% - 0.5px), rgba(255, 255, 255, 0.45) calc(66.666% - 0.5px), rgba(255, 255, 255, 0.45) calc(66.666% + 0.5px), transparent calc(66.666% + 0.5px));
  cursor: move;
}
.rz-crop:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 0;
}
/* On the Resize tab the box only shows what is kept */
.rz-frame[data-mode="resize"] .rz-crop {
  pointer-events: none;
  background-image: none;
}
.rz-frame[data-mode="resize"] .rz-crop.is-full {
  display: none;
}
.rz-frame[data-mode="resize"] .rz-handle {
  display: none;
}

.rz-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 1.5px solid var(--color-accent);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: transform var(--duration) ease-out;
}
/* A bigger invisible target for fingers */
.rz-handle::before {
  content: "";
  position: absolute;
  inset: -10px;
}
.rz-handle:hover {
  transform: scale(1.2);
}
.rz-handle.is-held,
.rz-handle:active {
  transform: scale(0.9);
}
.rz-handle[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.rz-handle[data-h="n"] { left: 50%; top: 0; cursor: ns-resize; }
.rz-handle[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.rz-handle[data-h="e"] { left: 100%; top: 50%; cursor: ew-resize; }
.rz-handle[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.rz-handle[data-h="s"] { left: 50%; top: 100%; cursor: ns-resize; }
.rz-handle[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.rz-handle[data-h="w"] { left: 0; top: 50%; cursor: ew-resize; }

.rz-hint {
  flex: none;
  margin-top: var(--space-3);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .rz-handle {
    transition: none;
  }
  .rz-handle:hover,
  .rz-handle:active,
  .rz-handle.is-held {
    transform: none;
  }
}

/* ---------- settings panel ---------- */

.rz-pane {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.rz-pane[hidden] {
  display: none;
}
.rz-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
.rz-pair > div {
  min-width: 0;
  display: flex; /* same label-to-input gap as a label that sits directly in the panel */
  flex-direction: column;
  gap: 0.5rem;
}
.rz-field-unit {
  flex: none;
  margin-left: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-muted);
}
.panel-body .slider {
  margin-top: 1.75rem; /* room for the value bubble above the thumb */
}
#rz-quality-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#rz-quality-row .slider {
  margin-top: 0; /* the "Quality" label sits right above, like the Format label above its menu */
}
.rz-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-1) var(--space-3);
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--color-field);
  font-size: var(--text-sm);
}
.rz-stats dt {
  color: var(--color-muted);
}
.rz-stats dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--color-ink);
}
.rz-stats dd.is-result {
  font-weight: var(--weight-bold);
}

@media (max-width: 860px) {
  /* The picture comes first and the settings follow it, instead of a sheet covering the picture */
  body.panel-open .panel {
    position: static;
    box-shadow: none;
  }
  .panel-body {
    max-height: none;
  }
  .panel-foot > .rz-stats {
    flex: 1 1 100%;
  }
  .rz-area {
    min-height: 55vh;
  }
}

/* Crop: the ratio tiles sit on the left and Reset crop on the right, between the top bar and the picture */
.rz-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  width: 100%;
  min-width: 0;
  margin-bottom: var(--space-1);
}
/* With the bar above, the picture sits right under it instead of floating in the middle of the leftover height */
.rz-editor:has(.rz-bar) {
  justify-content: flex-start;
}
.rz-editor:has(.rz-bar) .rz-area {
  align-items: flex-start;
}
.rz-bar .ratio-picker {
  max-width: 100%;
}
.rz-bar .btn {
  flex: none;
}
.rz-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}
.rz-tools .btn {
  padding: 0;
}
