/* ============================================
   IMAGE RESIZER & CROPPER — Premium Styles
   Dark AI SaaS theme with blue/purple glow
   ============================================ */

/* ─── Crop Editor Card ─── */
.crop-editor-card {
  margin-top: 20px;
  padding: 24px;
  background: var(--glass-bg, rgba(255,255,255,0.04));
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: var(--card-radius, 20px);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: cropFadeIn 0.5s ease-out;
}

@keyframes cropFadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Preview Container ─── */
.crop-preview-container {
  position: relative;
  width: 100%;
  margin-bottom: 20px;
}

.crop-preview-glass {
  position: relative;
  width: 100%;
  max-height: 520px;
  overflow: hidden;
  border-radius: var(--card-radius-sm, 14px);
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  display: flex;
  align-items: center;
  justify-content: center;
}

.crop-image-wrapper {
  position: relative;
  display: inline-block;
  line-height: 0;
  user-select: none;
  -webkit-user-select: none;
}

.crop-image-wrapper img {
  display: block;
  max-width: 100%;
  max-height: 480px;
  object-fit: contain;
  transition: transform 0.2s ease;
}

/* ─── Crop Overlay ─── */
.crop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  cursor: crosshair;
  touch-action: none;
}

.crop-selection {
  position: absolute;
  border: 2px solid rgba(124, 111, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(124, 111, 255, 0.3), 0 0 20px rgba(124, 111, 255, 0.15);
  cursor: move;
  touch-action: none;
  transition: box-shadow 0.2s ease;
}

.crop-selection::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 8px,
    rgba(255,255,255,0.03) 8px,
    rgba(255,255,255,0.03) 9px
  ),
  repeating-linear-gradient(
    90deg,
    transparent,
    transparent 8px,
    rgba(255,255,255,0.03) 8px,
    rgba(255,255,255,0.03) 9px
  );
  pointer-events: none;
}

.crop-selection.dragging {
  box-shadow: 0 0 0 1px rgba(124, 111, 255, 0.5), 0 0 40px rgba(124, 111, 255, 0.25);
}

/* ─── Crop Handles ─── */
.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #7c6fff;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(124, 111, 255, 0.5), 0 2px 4px rgba(0,0,0,0.3);
  z-index: 10;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.crop-handle:hover {
  transform: scale(1.25);
  box-shadow: 0 0 12px rgba(124, 111, 255, 0.7), 0 2px 6px rgba(0,0,0,0.4);
}

.crop-handle-nw { top: -7px; left: -7px; cursor: nw-resize; }
.crop-handle-ne { top: -7px; right: -7px; cursor: ne-resize; }
.crop-handle-sw { bottom: -7px; left: -7px; cursor: sw-resize; }
.crop-handle-se { bottom: -7px; right: -7px; cursor: se-resize; }
.crop-handle-n  { top: -7px; left: 50%; margin-left: -7px; cursor: n-resize; }
.crop-handle-s  { bottom: -7px; left: 50%; margin-left: -7px; cursor: s-resize; }
.crop-handle-w  { top: 50%; left: -7px; margin-top: -7px; cursor: w-resize; }
.crop-handle-e  { top: 50%; right: -7px; margin-top: -7px; cursor: e-resize; }

/* ─── Crop Dimensions Badge ─── */
.crop-dimensions {
  position: absolute;
  bottom: -32px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 12px;
  background: rgba(124, 111, 255, 0.15);
  border: 1px solid rgba(124, 111, 255, 0.25);
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: #b8b0ff;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ─── Aspect Ratio Row ─── */
.crop-aspect-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.crop-aspect-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted, #6b6b8a);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.crop-aspect-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.crop-aspect-btn {
  padding: 6px 14px;
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  background: var(--glass-bg, rgba(255,255,255,0.04));
  color: var(--text-muted, #6b6b8a);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.crop-aspect-btn:hover {
  background: var(--glass-bg-hover, rgba(255,255,255,0.07));
  border-color: var(--glass-border-hover, rgba(255,255,255,0.14));
  color: var(--text-primary, #eeeeff);
}

.crop-aspect-btn.active {
  background: rgba(124, 111, 255, 0.12);
  border-color: rgba(124, 111, 255, 0.35);
  color: #b8b0ff;
  box-shadow: 0 0 12px rgba(124, 111, 255, 0.08);
}

/* ─── Crop Controls Row ─── */
.crop-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.crop-controls-left {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.crop-controls-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.crop-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  background: var(--glass-bg, rgba(255,255,255,0.04));
  color: var(--text-muted, #6b6b8a);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
  line-height: 1;
}

.crop-btn:hover {
  background: var(--glass-bg-hover, rgba(255,255,255,0.07));
  border-color: var(--glass-border-hover, rgba(255,255,255,0.14));
  color: var(--text-primary, #eeeeff);
}

.crop-btn:active {
  transform: scale(0.95);
}

.crop-btn svg {
  flex-shrink: 0;
}

.crop-btn-danger:hover {
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.25);
  color: #ff6b6b;
}

.crop-divider {
  width: 1px;
  height: 24px;
  background: var(--glass-border, rgba(255,255,255,0.08));
  margin: 0 4px;
  flex-shrink: 0;
}

/* ─── Action Row ─── */
.crop-action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid var(--glass-border, rgba(255,255,255,0.08));
}

.crop-export-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.crop-format-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  background: var(--glass-bg, rgba(255,255,255,0.04));
  color: var(--text-muted, #6b6b8a);
  cursor: pointer;
  transition: all 0.25s ease;
}

.crop-format-label:hover {
  background: var(--glass-bg-hover, rgba(255,255,255,0.07));
  border-color: var(--glass-border-hover, rgba(255,255,255,0.14));
}

.crop-format-label select {
  border: none;
  background: transparent;
  color: var(--text-primary, #eeeeff);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  padding: 0;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b6b8a' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0 center;
  padding-right: 16px;
}

.crop-format-label select option {
  background: #1a1a2e;
  color: #eeeeff;
}

/* ─── Resize Card (legacy) ─── */
.resize-card {
  margin-top: 20px;
  padding: 24px;
  background: var(--glass-bg, rgba(255,255,255,0.04));
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: var(--card-radius, 20px);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.resize-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  font-family: 'Syne', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary, #eeeeff);
}

.resize-header svg {
  color: var(--accent-violet, #7c6fff);
}

.resize-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.resize-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.resize-field label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted, #6b6b8a);
}

.resize-unit {
  color: var(--text-dim, #4a4a6a);
  font-weight: 400;
}

.resize-field input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: 10px;
  color: var(--text-primary, #eeeeff);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  outline: none;
  transition: all 0.25s ease;
  box-sizing: border-box;
}

.resize-field input[type="number"]:focus {
  border-color: rgba(124, 111, 255, 0.4);
  box-shadow: 0 0 0 3px rgba(124, 111, 255, 0.08);
}

.resize-ratio-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  color: var(--text-muted, #6b6b8a);
  cursor: pointer;
  user-select: none;
}

.resize-ratio-label input[type="checkbox"] {
  display: none;
}

.resize-checkmark {
  width: 18px;
  height: 18px;
  border: 2px solid var(--glass-border, rgba(255,255,255,0.12));
  border-radius: 4px;
  background: rgba(0,0,0,0.3);
  position: relative;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.resize-ratio-label input:checked + .resize-checkmark {
  background: rgba(124, 111, 255, 0.2);
  border-color: rgba(124, 111, 255, 0.4);
}

.resize-ratio-label input:checked + .resize-checkmark::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 5px;
  width: 4px;
  height: 8px;
  border: solid #7c6fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ─── Output Area ─── */
.output-area {
  padding: 12px;
  margin-top: 12px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
  border-radius: var(--card-radius-sm, 14px);
  text-align: center;
}

.output-area img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 10px;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .crop-editor-card {
    padding: 16px;
  }

  .crop-preview-glass {
    max-height: 360px;
  }

  .crop-image-wrapper img {
    max-height: 340px;
  }

  .crop-aspect-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .crop-controls-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .crop-controls-left {
    width: 100%;
    justify-content: center;
  }

  .crop-controls-right {
    width: 100%;
    justify-content: center;
  }

  .crop-action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .crop-export-group {
    justify-content: stretch;
  }

  .crop-format-label {
    flex: 1;
  }

  .crop-format-label select {
    width: 100%;
  }

  .crop-btn {
    padding: 8px;
  }

  .resize-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .crop-editor-card {
    padding: 12px;
  }

  .crop-preview-glass {
    max-height: 280px;
  }

  .crop-image-wrapper img {
    max-height: 260px;
  }

  .crop-aspect-presets {
    gap: 4px;
  }

  .crop-aspect-btn {
    padding: 5px 10px;
    font-size: 0.72rem;
  }

  .crop-dimensions {
    font-size: 0.65rem;
    padding: 2px 8px;
    bottom: -28px;
  }

  .crop-handle {
    width: 12px;
    height: 12px;
  }

  .crop-handle-nw { top: -6px; left: -6px; }
  .crop-handle-ne { top: -6px; right: -6px; }
  .crop-handle-sw { bottom: -6px; left: -6px; }
  .crop-handle-se { bottom: -6px; right: -6px; }
  .crop-handle-n  { top: -6px; margin-left: -6px; }
  .crop-handle-s  { bottom: -6px; margin-left: -6px; }
  .crop-handle-w  { left: -6px; margin-top: -6px; }
  .crop-handle-e  { right: -6px; margin-top: -6px; }
}
