/* ==========================================================================
   Waeyuk Specialist Profile Image Editor — Desktop & Web Studio (AAA UX)
   ========================================================================== */

#editImageModal {
  padding: clamp(12px, 3vw, 28px);
  z-index: 10001;
  display: none;
  align-items: center;
  justify-content: center;
}

#editImageModal.active {
  display: flex !important;
  animation: pimFadeIn 0.25s ease;
}

@keyframes pimFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Modal Dialog Card (Optimized for Web & Desktop) */
#editImageModal .waeyuk-modal-content.pim-editor-dialog {
  width: min(94vw, 780px) !important;
  max-width: 780px !important;
  max-height: min(92dvh, 720px) !important;
  padding: 0 !important;
  border: 1px solid rgba(56, 189, 248, 0.25) !important;
  border-radius: 28px !important;
  background: radial-gradient(circle at 85% 0%, rgba(56, 189, 248, 0.12), transparent 45%),
              linear-gradient(150deg, #0f172a 0%, #090d16 100%) !important;
  color: #f8fafc !important;
  direction: rtl !important;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.85), 0 0 30px rgba(56, 189, 248, 0.15) !important;
  animation: pimScale 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
  font-family: 'Tajawal', sans-serif !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

@keyframes pimScale {
  from { transform: translateY(12px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* Header */
#editImageModal .pim-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

#editImageModal .pim-editor-title {
  margin: 0;
  color: #f8fafc;
  font-size: 1.25rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#editImageModal .pim-title-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(14, 165, 233, 0.1));
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  letter-spacing: 0.3px;
}

#editImageModal .pim-editor-subtitle {
  margin: 6px 0 0;
  color: #94a3b8;
  font-size: 0.85rem;
  line-height: 1.5;
}

#editImageModal .pim-editor-close {
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#editImageModal .pim-editor-close:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  transform: rotate(90deg);
}

/* Body & Studio Grid (Desktop Web Split Layout) */
#editImageModal .pim-editor-body {
  padding: 24px 28px;
  overflow-y: auto;
  flex: 1;
}

.pim-studio-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 28px;
  align-items: center;
}

.pim-studio-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.pim-studio-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Circular Viewport */
#editImageModal .pim-preview-frame {
  width: 260px;
  height: 260px;
  position: relative;
  margin: 0 auto 10px;
  overflow: hidden;
  border-radius: 50%;
  border: 3px solid #38bdf8;
  background: #0f172a;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7), 0 0 25px rgba(56, 189, 248, 0.3);
  touch-action: none;
  cursor: grab;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

#editImageModal .pim-preview-frame:active {
  cursor: grabbing;
}

#editImageModal .pim-preview-frame.drag-over {
  border-color: #38bdf8 !important;
  box-shadow: 0 0 35px rgba(56, 189, 248, 0.6) !important;
  transform: scale(1.02);
}

#editImageModal #image-preview {
  display: block;
  width: 100%;
  height: 100%;
}

#editImageModal .pim-preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  background: radial-gradient(circle, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.95) 100%);
}

#editImageModal .pim-preview-empty[hidden] {
  display: none;
}

#editImageModal .pim-preview-empty i {
  font-size: 2.2rem;
  color: #38bdf8;
  margin-bottom: 10px;
  filter: drop-shadow(0 4px 12px rgba(56, 189, 248, 0.4));
}

#editImageModal .pim-crop-guide {
  position: absolute;
  inset: 0;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  pointer-events: none;
}

#editImageModal .pim-image-hint {
  margin: 0;
  text-align: center;
  color: #94a3b8;
  font-size: 11.5px;
}

/* Backdrop Presets */
.pim-backdrop-presets {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin: 4px 0;
}

.pim-backdrop-presets span {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 600;
}

.pim-backdrop-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
}

.pim-backdrop-dot:hover, .pim-backdrop-dot.active {
  transform: scale(1.2);
  border-color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

/* AI Toggle Bar */
#pim-ai-toggle-bar {
  margin-bottom: 4px;
}

.pim-ai-pill-group {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4px;
  border-radius: 30px;
  gap: 4px;
}

.pim-ai-pill {
  padding: 6px 14px;
  border-radius: 20px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.pim-ai-pill.active {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #fff;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.pim-ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

.pim-ai-badge.working {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #38bdf8;
  animation: pimPulse 1.8s infinite;
}

@keyframes pimPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Zoom Row */
#editImageModal .pim-zoom-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}

#editImageModal .pim-zoom-row label {
  color: #cbd5e1;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

#editImageModal .pim-zoom-row input[type=range] {
  flex: 1;
  accent-color: #38bdf8;
  cursor: pointer;
}

#editImageModal .pim-zoom-btn {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#editImageModal .pim-zoom-btn:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.2);
  border-color: #38bdf8;
}

/* File Picker Button */
#editImageModal .pim-file {
  display: none !important;
}

#editImageModal .pim-file-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 16px;
  border: 1.5px dashed rgba(56, 189, 248, 0.5);
  border-radius: 14px;
  background: rgba(56, 189, 248, 0.06);
  color: #38bdf8;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.25s;
  box-sizing: border-box;
}

#editImageModal .pim-file-label:hover {
  background: rgba(56, 189, 248, 0.14);
  border-color: #38bdf8;
  transform: translateY(-1px);
}

#editImageModal .pim-file-name {
  margin: 0;
  text-align: right;
  font-size: 11px;
  color: #cbd5e1;
  min-height: 14px;
}

#editImageModal .pim-status {
  min-height: 18px;
  margin: 0;
  text-align: right;
  font-size: 11.5px;
  font-weight: 600;
  color: #38bdf8;
  transition: color 0.2s;
}

#editImageModal .pim-status[data-kind=error] { color: #f87171 !important; }
#editImageModal .pim-status[data-kind=success] { color: #34d399 !important; }

/* Action Buttons */
#editImageModal .pim-actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 10px;
  margin-top: 4px;
}

#editImageModal .pim-actions button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
}

#editImageModal .pim-actions button:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

#editImageModal .pim-cancel {
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  background: rgba(255, 255, 255, 0.06) !important;
  color: #cbd5e1 !important;
}

#editImageModal .pim-save {
  border: none !important;
  background: linear-gradient(135deg, #0284c7, #0369a1) !important;
  color: #ffffff !important;
  box-shadow: 0 6px 20px rgba(2, 132, 199, 0.4) !important;
}

#editImageModal .pim-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none !important;
  transform: none !important;
}

#editImageModal .pim-remove {
  grid-column: 1 / -1;
  min-height: 34px !important;
  border: 1px solid rgba(239, 68, 68, 0.25) !important;
  background: rgba(239, 68, 68, 0.06) !important;
  color: #f87171 !important;
  font-size: 11.5px !important;
  font-weight: 700 !important;
}

#editImageModal .pim-remove:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: rgba(239, 68, 68, 0.5) !important;
}

#editImageModal .pim-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: pimSpin 0.7s linear infinite;
  display: inline-block;
}

@keyframes pimSpin { to { transform: rotate(360deg); } }

/* Responsive Adjustments for Mobile & Tablets */
@media (max-width: 767px) {
  #editImageModal {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  #editImageModal .waeyuk-modal-content.pim-editor-dialog {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 94dvh !important;
    border-radius: 26px 26px 0 0 !important;
    border-bottom: none !important;
  }

  .pim-studio-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 14px !important;
  }

  #editImageModal .pim-preview-frame {
    width: 220px !important;
    height: 220px !important;
  }

  #editImageModal .pim-editor-head {
    padding: 16px 20px 12px;
  }

  #editImageModal .pim-editor-body {
    padding: 16px 20px 22px;
  }

  #editImageModal .pim-status,
  #editImageModal .pim-file-name {
    text-align: center !important;
  }
}
