/* =================================================================
   uv-crop-modal.css — Crop/position modal overlay (Sprint 9.2)
   No external dependencies. Works with uv-crop-modal.js.
   z-index: 200000 — sits above the editor toolbar + floatbar (both 100000).
   Sprint 15 (Bug 3): bumped from 9000 (was below the toolbar, so the modal
   rendered behind it on mobile). The toolbar + floatbar are also hidden via
   body.uv-crop-open while the modal is open.
   ================================================================= */

/* ---------------------------------------------------------------
   Overlay backdrop
   --------------------------------------------------------------- */
.uv-crop-modal {
  position: fixed;
  inset: 0;
  z-index: 200000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  /* Respect prefers-reduced-motion: skip the fade-in */
  animation: uv-crop-fadein 160ms ease both;
  padding: 16px;
  box-sizing: border-box;
  /* Prevent page scroll while modal is open */
  overscroll-behavior: contain;
}

/* Sprint 15 (Bug 3): while the crop modal is open, hide the editor chrome and
   lock the page so the modal is the only interactive surface (the toolbar at
   z-index 100000 used to bleed through on top of the modal on mobile). The
   body class is toggled by uv-crop-modal.js on open/close. */
body.uv-crop-open {
  overflow: hidden;
}
body.uv-crop-open .uv-toolbar,
body.uv-crop-open .uv-floatbar {
  display: none !important;
}

@keyframes uv-crop-fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .uv-crop-modal {
    animation: none;
  }
}

/* ---------------------------------------------------------------
   Modal panel
   --------------------------------------------------------------- */
.uv-crop-modal__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 520px;
  /* Prevent panel from overflowing on very short phones */
  max-height: calc(100dvh - 32px);
  max-height: calc(100vh - 32px);
}

/* ---------------------------------------------------------------
   Header row: title + close button
   --------------------------------------------------------------- */
.uv-crop-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  color: #fff;
}

.uv-crop-modal__title {
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0;
  color: #fff;
}

.uv-crop-modal__close {
  appearance: none;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 120ms, background 120ms;
  line-height: 1;
}

.uv-crop-modal__close:hover,
.uv-crop-modal__close:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.uv-crop-modal__close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------
   Crop frame — the visible viewport the user drags within.
   Its aspect ratio is set inline by JS via padding-bottom.
   --------------------------------------------------------------- */
.uv-crop-modal__frame-wrap {
  width: 100%;
  position: relative;
  /* Aspect ratio shim: padding-bottom set inline by JS */
  overflow: hidden;
  border-radius: 6px;
  background: #111;
  cursor: grab;
  touch-action: none;   /* hand off all touch events to JS */
  user-select: none;
  -webkit-user-select: none;
}

.uv-crop-modal__frame-wrap:active {
  cursor: grabbing;
}

/* The img lives inside the frame-wrap; position + scale applied via JS */
.uv-crop-modal__img {
  position: absolute;
  top: 0;
  left: 0;
  /* width/height will be set by JS to match natural aspect + current scale */
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  /* Smooth dragging on desktop */
  will-change: transform;
}

/* Crosshair guide overlay — subtle 1px centre lines */
.uv-crop-modal__guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.uv-crop-modal__guide::before,
.uv-crop-modal__guide::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.25);
}

/* Horizontal centre */
.uv-crop-modal__guide::before {
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  transform: translateY(-50%);
}

/* Vertical centre */
.uv-crop-modal__guide::after {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
}

/* ---------------------------------------------------------------
   Zoom slider row
   --------------------------------------------------------------- */
.uv-crop-modal__zoom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  color: rgba(255, 255, 255, 0.7);
}

.uv-crop-modal__zoom-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

.uv-crop-modal__zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.uv-crop-modal__zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 100ms;
}

.uv-crop-modal__zoom-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.uv-crop-modal__zoom-slider:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
  border-radius: 2px;
}

.uv-crop-modal__zoom-label {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  min-width: 3.2ch;
  text-align: right;
  color: rgba(255, 255, 255, 0.6);
}

/* ---------------------------------------------------------------
   Action buttons row
   --------------------------------------------------------------- */
.uv-crop-modal__actions {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.uv-crop-modal__btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 120ms, color 120ms, opacity 120ms;
  min-width: 80px;
  text-align: center;
}

.uv-crop-modal__btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}

/* Reset — ghost */
.uv-crop-modal__btn--reset {
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
}

.uv-crop-modal__btn--reset:hover,
.uv-crop-modal__btn--reset:focus-visible {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.65);
}

/* Cancel — subtle */
.uv-crop-modal__btn--cancel {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  border: 1.5px solid transparent;
}

.uv-crop-modal__btn--cancel:hover,
.uv-crop-modal__btn--cancel:focus-visible {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

/* Save — primary accent */
.uv-crop-modal__btn--save {
  background: #c4912b;
  color: #fff;
  border: 1.5px solid transparent;
  margin-left: auto;
}

.uv-crop-modal__btn--save:hover,
.uv-crop-modal__btn--save:focus-visible {
  background: #d4a13b;
}

/* ---------------------------------------------------------------
   Instruction hint
   --------------------------------------------------------------- */
.uv-crop-modal__hint {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.45);
  text-align: center;
  margin: 0;
  line-height: 1.4;
}

/* ---------------------------------------------------------------
   Responsive: taller phones — give the frame more vertical room
   --------------------------------------------------------------- */
@media (max-width: 420px) {
  .uv-crop-modal__btn {
    padding: 10px 14px;
    font-size: 0.8125rem;
    min-width: 64px;
  }
  /* Sprint 15 (Bug 3E): use the full available height and keep the action row
     clear of the home indicator so Save/Cancel/Reset are always reachable. */
  .uv-crop-modal {
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .uv-crop-modal__panel {
    max-height: 100%;
    flex: 1 1 auto;
  }
  /* The draggable frame can flex; the slider + buttons must stay visible. */
  .uv-crop-modal__frame-wrap {
    flex: 1 1 auto;
    min-height: 0;
  }
  .uv-crop-modal__zoom-row,
  .uv-crop-modal__actions {
    flex-shrink: 0;
  }
}

@media (max-height: 560px) {
  .uv-crop-modal__hint {
    display: none;
  }
}
