/*!
 * The resize tool: resize, resize-heic, resize-jpeg, resize-png, resize-webp.
 * Linked from each page head before head-ui.inc.php, so the shared layout
 * (pt-ui.css) wins a tie.
 */
/* Responsive crop modal styles */
@media (max-width: 768px) {
  #crop-modal-body {
    flex-direction: column !important;
    gap: 16px !important;
  }
  
  #crop-editor-area {
    min-height: 250px !important;
    margin-bottom: 0 !important;
  }
  
  #crop-control-panel {
    width: 100% !important;
    max-height: 200px !important;
    overflow-y: auto !important;
  }
  
  #crop-modal > div {
    width: 98vw !important;
    height: 95vh !important;
    max-height: none !important;
  }
}

@media (max-width: 480px) {
  #crop-modal-body {
    padding: 12px !important;
  }
  
  #crop-editor-area {
    padding: 8px !important;
    min-height: 200px !important;
  }
  
  #crop-control-panel {
    max-height: 180px !important;
  }
}

/* Close button hover effect */
#crop-modal-close:hover {
  background-color: #f8f9fa !important;
  color: #dc3545 !important;
}

/* Responsive rotate modal styles */
@media (max-width: 768px) {
  #rotate-modal-body {
    flex-direction: column !important;
    gap: 16px !important;
  }
  
  #rotate-editor-area {
    min-height: 250px !important;
    margin-bottom: 0 !important;
  }
  
  #rotate-control-panel {
    width: 100% !important;
    max-height: 300px !important;
    overflow-y: auto !important;
  }
  
  #rotate-modal > div {
    width: 98vw !important;
    height: 95vh !important;
    max-height: none !important;
  }
}

@media (max-width: 480px) {
  #rotate-modal-body {
    padding: 12px !important;
  }
  
  #rotate-editor-area {
    padding: 8px !important;
    min-height: 200px !important;
  }
  
  #rotate-control-panel {
    max-height: 250px !important;
  }
}

/* Close button hover effect for rotate modal */
#rotate-modal-close:hover {
  background-color: #f8f9fa !important;
  color: #dc3545 !important;
}

/* Responsive edit modal styles */
@media (max-width: 768px) {
  #edit-modal-body {
    flex-direction: column !important;
    gap: 16px !important;
  }

  #edit-editor-area {
    min-height: 250px !important;
    margin-bottom: 0 !important;
  }

  #edit-control-panel {
    width: 100% !important;
    max-height: 280px !important;
    overflow-y: auto !important;
  }

  #edit-modal > div {
    width: 98vw !important;
    height: 95vh !important;
    max-height: none !important;
  }
}

@media (max-width: 480px) {
  #edit-modal-body {
    padding: 12px !important;
  }

  #edit-editor-area {
    padding: 8px !important;
    min-height: 200px !important;
  }

  #edit-control-panel {
    max-height: 240px !important;
  }
}

/* Close button hover effect for edit modal */
#edit-modal-close:hover {
  background-color: #f8f9fa !important;
  color: #dc3545 !important;
}

/* Edit modal slider layout */
.em-slider-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.em-slider-row .form-range {
  flex: 1;
}

/* Thumbnail panel styles */
.thumbnail-item {
  position: relative;
  width: 120px;
  min-width: 120px;
  border: 2px solid #dee2e6;
  border-radius: 8px;
  background: white;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
}

.thumbnail-item:hover {
  border-color: #007bff;
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
}

.thumbnail-item.active {
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

/* The picture's own button (resize-tool.js says why). */
.thumbnail-select {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.thumbnail-select:focus-visible { outline: 2px solid var(--pt-accent, #0f70e6); outline-offset: -2px; }

.thumbnail-image {
  width: 100%;
  height: 80px;
  object-fit: cover;
  object-position: center;
  display: block;
  border-radius: 0 !important;
  /* High-quality image rendering for photos */
  image-rendering: -webkit-optimize-contrast;
  image-rendering: optimizeQuality;
  /* Smooth scaling for photo content */
  image-rendering: high-quality;
  /* Prevent blurry scaling and improve performance */
  backface-visibility: hidden;
  transform: translateZ(0);
  /* Ensure crisp edges on high-DPI displays */
  -webkit-transform: translateZ(0);
  /* Force zoom to fill the full width of container */
  min-width: 100%;
  min-height: 80px;
}

.thumbnail-info {
  padding: 6px 8px;
  font-size: 0.75rem;
  line-height: 1.2;
}

.thumbnail-filename {
  font-weight: 600;
  color: #333;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thumbnail-dimensions {
  color: #666;
  margin-bottom: 1px;
}

.thumbnail-final-size {
  color: #007bff;
  font-weight: 500;
}

.thumbnail-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: rgba(220, 53, 69, 0.9);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.thumbnail-item:hover .thumbnail-remove {
  opacity: 1;
}

.thumbnail-remove:hover {
  background: #dc3545;
}

.thumbnail-download {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  background: white;
  color: #007bff;
  border: 2px solid #007bff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.thumbnail-item:hover .thumbnail-download {
  opacity: 1;
}

.thumbnail-download:hover {
  background: #f8f9fa;
  border-color: #0056b3;
  color: #0056b3;
}

/* Zoom controls (matched to editor.php) */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.zoom-slider {
  width: 100px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #dee2e6;
  outline: none;
  border-radius: 2px;
}
.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--pt-accent, #0f70e6);
  cursor: pointer;
  border-radius: 50%;
}
.zoom-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--pt-accent, #0f70e6);
  cursor: pointer;
  border-radius: 50%;
  border: none;
}
.zoom-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
}
.zoom-preset-dropdown {
  position: relative;
}
.zoom-preset-btn {
  min-width: 75px;
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.zoom-preset-menu {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 4px;
  background: white;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  z-index: 1000;
  min-width: 100px;
  display: none;
}
.zoom-preset-menu.show {
  display: block;
}
.zoom-preset-item {
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.15s;
}
.zoom-preset-item:hover {
  background: #f8f9fa;
}
.zoom-preset-item.active {
  background: #e7f1ff;
  color: var(--pt-accent, #0f70e6);
  font-weight: 600;
}

/* Crop button icon color handling */
#resize-crop-btn:hover img {
  filter: brightness(0) invert(1);
}

/* Hide text on Crop and Rotate buttons for small screens */
@media (max-width: 768px) {
  #resize-crop-btn .btn-text,
  #resize-rotate-btn .btn-text {
    display: none;
  }
  
  /* Make buttons square (width = height) on small screens */
  #resize-crop-btn,
  #resize-rotate-btn {
    width: 40px !important;
    min-width: 40px !important;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Show shorter text on Reset to Original button for small screens */
  #resize-reset-btn .btn-text-full {
    display: none;
  }
  
  #resize-reset-btn .btn-text-short {
    display: inline !important;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   Layout: the shared tool page (pt-ui.css) and the phone editor (pt-app.css)
   ══════════════════════════════════════════════════════════════════════════ */

/* The photo box. The scroll box inside it is what zooms, so the
   "Showing Original Quality" badge stays put while the photo scrolls. */
#resize-viewport { overflow: hidden; }
#resize-canvas-container {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: auto;
  padding: 16px;
}
#resize-viewport:not(.resize-has-photo) #resize-canvas-container { display: none; }
#resize-viewport.resize-has-photo #resize-empty { display: none; }
/* A transparent PNG shows on the usual checkerboard. */
#resize-editor-canvas { background: repeating-conic-gradient(#eef1f5 0% 25%, #fff 0% 50%) 50% / 16px 16px !important; }

/* Empty: one Upload button and three samples, centred in the box. */
#resize-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.sample-thumbnails { display: flex; justify-content: center; gap: 12px; margin: 10px 0; flex-wrap: wrap; }
.sample-thumbnail {
  cursor: pointer;
  border: 2px solid #dee2e6;
  border-radius: 10px;
  overflow: hidden;
  width: 110px;
  height: 110px;
  padding: 0;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.sample-thumbnail:hover { border-color: var(--pt-accent, #0f70e6); box-shadow: 0 4px 12px rgba(15, 112, 230, 0.25); }
.sample-thumbnail img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 0 !important; }
@media (max-width: 768px) { .sample-thumbnail { width: 90px; height: 90px; } }
@media (max-width: 576px) { .sample-thumbnail { width: 72px; height: 72px; } }

/* Save: Save Photo, and Save All Photos under it once there are several. */
.photo-resize-editor .pt-tool-savebar { flex-direction: column; }
.photo-resize-editor .pt-tool-savebar > .btn { width: 100%; min-height: 50px; font-weight: 600; }
#resize-save-format-row .form-label { width: 90px; text-align: start; }
#format-options-toggle { width: 38px; height: 38px; flex: none; }

/* Under the photo: the tools, then the zoom. */
#resize-zoombar { display: flex; align-items: center; gap: 8px; }
#resize-move-hint { text-align: center; }

/* Several photos: the strip under the photo, and its Add tile. */
.thumbnail-add {
  width: 120px;
  min-width: 120px;
  min-height: 120px;
  border: 2px dashed #c5d3ea;
  border-radius: 8px;
  background: rgba(15, 112, 230, 0.05);
  color: var(--pt-accent, #0f70e6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0;
}
.thumbnail-add:hover { border-color: var(--pt-accent, #0f70e6); }
.thumbnail-add svg { width: 26px; height: 26px; }
/* Touch screens have no hover: show the photo's buttons at all times. */
@media (hover: none) {
  .thumbnail-remove, .thumbnail-download { opacity: 1; }
}

/* In the editor only: Apply beside the width and height, and the Rotate row. */
html:not(.pt-app-open) .resize-app-only { display: none !important; }

/* Phone page between editing sessions: the photo is a picture, and a tap on
   it opens the editor (pt-app.js). */
html.pt-phone:not(.pt-app-open) #resize-viewport.pt-app-loaded #resize-canvas-container { overflow: hidden; pointer-events: none; }

/* ── In the phone editor ─────────────────────────────────────────────────── */
html.pt-app-open #resize-canvas-container { overflow: hidden; padding: 8px; }
html.pt-app-open #resize-editor-canvas { border: 0 !important; touch-action: none; }
html.pt-app-open #original-quality-badge { top: 10px !important; }

/* Size: the presets, then width x height, units and Apply in one row. */
.pt-app-panels > #resize-size-fields.pt-app-panel-on { padding: 2px 4px; }
/* Two rows on a 360px phone: presets | units, then width ⛓ height | Apply.
   The row in the markup steps aside (display: contents) so its cells take
   places in the one grid. */
.pt-app-panels > #resize-size-fields.pt-app-panel.pt-app-panel-on {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 32px minmax(0, 1fr) 104px;
  gap: 8px 6px;
  align-items: center;
}
/* min-width: 0, or the longest preset name widens its cell past the screen. */
.pt-app-panels #resize-size-fields > * { min-width: 0; }
.pt-app-panels #resize-size-fields .form-select,
.pt-app-panels #resize-size-fields .form-control { width: 100%; min-width: 0; }
.pt-app-panels #resize-size-fields > .mb-3 { grid-area: 1 / 1 / 2 / 4; margin: 0 !important; }
.pt-app-panels #resize-size-fields > .row { display: contents; }
.pt-app-panels #resize-size-fields > .row > * { width: auto; max-width: none; min-width: 0; padding: 0; margin: 0; }
.pt-app-panels #resize-size-fields > .row > :nth-child(1) { grid-area: 2 / 1; }
.pt-app-panels #resize-size-fields > .row > :nth-child(2) { grid-area: 2 / 2; justify-content: center; }
.pt-app-panels #resize-size-fields > .row > :nth-child(3) { grid-area: 2 / 3; }
.pt-app-panels #resize-size-fields > .row > .col-4 { grid-area: 1 / 4; }
.pt-app-panels #resize-size-fields > .row > .resize-app-only { grid-area: 2 / 4; }
.pt-app-panels #resize-size-fields > .row > .resize-app-only > .btn { width: 100%; }
.pt-app-panels #resize-dpi-container,
.pt-app-panels #resize-pixel-equivalent { grid-column: 1 / -1; }
.pt-app-panels #resize-size-fields .form-select { padding-left: 10px; padding-right: 28px; background-position: right 8px center; }
.pt-app-panels #resize-size-fields .form-control,
.pt-app-panels #resize-size-fields .form-select {
  min-height: 42px;
  background-color: var(--pt-app-bar);
  border-color: var(--pt-app-line-strong);
  color: var(--pt-app-fg);
  font-size: 16px; /* under 16px, iOS zooms the page in on focus */
}
.pt-app-panels #resize-size-fields .form-select {
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
.pt-app-panels #resize-size-fields .form-select option,
.pt-app-panels #resize-size-fields .form-select optgroup { color: #212529; background: #fff; }
.pt-app-panels #resize-size-fields .form-control::placeholder { color: var(--pt-app-muted); }
.pt-app-panels #resize-maintain-aspect { color: var(--pt-app-fg) !important; min-width: 32px; min-height: 42px; }
.pt-app-panels #resize-size-apply { min-height: 42px; padding: 0 12px; font-weight: 600; }
.pt-app-panels #resize-dpi-container { margin: 0 !important; }
.pt-app-panels #resize-pixel-equivalent { margin: 0 !important; text-align: center; }
.pt-app-panels #resize-pixel-equivalent .text-muted { color: var(--pt-app-muted) !important; }

/* Settings: the size options stay in the sheet whichever tool is open (Scale
   switches the tab, which would leave a blank band where they were). */
html.pt-app-open .pt-app-sheet #by-size-content { display: block !important; opacity: 1 !important; }
html.pt-app-open .pt-app-sheet #by-size-content > .mt-2:first-child { margin-top: 0 !important; }
html.pt-app-open .pt-app-sheet #by-size-content > .mt-2:first-child > small { font-size: 0.875rem !important; }
html.pt-app-open .pt-app-sheet #fixed-dim-group .btn { min-height: 40px; padding-left: 14px; padding-right: 14px; }

/* Rotate: four chips, a tap applies. */
.pt-app-panels > #resize-rotate-strip.pt-app-panel-on { justify-content: center; }

/* Photos: small squares, the selected one outlined, X always showing. */
.pt-app-panels > #thumbnail-container.pt-app-panel-on {
  flex-wrap: nowrap !important;
  background: transparent !important;
  border: 0 !important;
  max-height: none !important;
  padding: 2px 4px 4px !important;
  gap: 8px !important;
}
.pt-app-panels #thumbnail-container .thumbnail-item { width: 64px; min-width: 64px; border-color: var(--pt-app-line-strong); background: transparent; border-radius: 10px; }
.pt-app-panels #thumbnail-container .thumbnail-item.active { border-color: var(--pt-app-accent); box-shadow: none; }
.pt-app-panels #thumbnail-container .thumbnail-image { height: 60px; min-height: 60px; }
.pt-app-panels #thumbnail-container .thumbnail-info,
.pt-app-panels #thumbnail-container .thumbnail-download { display: none; }
.pt-app-panels #thumbnail-container .thumbnail-remove { opacity: 1; width: 24px; height: 24px; font-size: 14px; }
.pt-app-panels #thumbnail-container .thumbnail-add { width: 64px; min-width: 64px; min-height: 64px; border-color: var(--pt-app-line-strong); background: transparent; color: var(--pt-app-fg); }
.pt-app-panels #thumbnail-container .thumbnail-add span { display: none; }

/* ── Crop and Adjustments, full screen on a phone ───────────────────────── */
@media (max-width: 767px) {
  #crop-modal, #edit-modal, #rotate-modal { background: #15171a !important; }
  #crop-modal > div, #edit-modal > div, #rotate-modal > div {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  #crop-modal > div > div:first-child, #edit-modal > div > div:first-child, #rotate-modal > div > div:first-child {
    padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px 16px !important;
  }
  #crop-modal-body, #edit-modal-body, #rotate-modal-body {
    flex-direction: column !important;
    gap: 10px !important;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    min-height: 0;
  }
  #crop-editor-area, #edit-editor-area, #rotate-editor-area {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    padding: 6px !important;
    border-width: 1px !important;
    border-radius: 12px !important;
  }
  #crop-control-panel, #edit-control-panel, #rotate-control-panel {
    width: 100% !important;
    flex: none;
    max-height: 42vh !important;
    overflow-y: auto !important;
  }
  /* Crop: the ratio and the two social pickers, then Crop and Reset side by
     side. The position read-out is for the desktop. */
  #crop-control-panel > div:first-child { padding: 10px !important; margin-bottom: 10px !important; }
  #crop-control-panel > div:first-child > div:last-child { display: none; }
  #crop-control-panel > div:last-child { flex-direction: row !important; gap: 8px !important; }
  #crop-control-panel > div:last-child > .btn { flex: 1 1 0; min-height: 46px; }
  #crop-control-panel .form-select { font-size: 16px !important; min-height: 40px; }
}
/* A finger drags the crop box rather than scrolling the dialog. */
#crop-modal-canvas { touch-action: none; }

#resize-toolbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
