/**
 * @file
 * EP File Upload Styles - File upload component styles
 * 
 * Purpose: Centralized file upload zone styles for all EP modules
 * Location: /themes/custom/occasia_elegant/css/ep/components/ep-file-upload.css
 * Category: components/ (reusable UI components)
 * 
 * This file contains:
 * - Upload zone container styles
 * - Upload icon and text styles
 * - Image preview styles
 * - Delete button styles
 * - Drupal managed_file widget overrides
 * 
 * Decision Rule: If it's a reusable UI component → components/
 * 
 * See: /bitnami/drupal/modules/.cursor/THEME_STRUCTURE.md for structure documentation
 */

/**
 * ========================================
 * EP UPLOAD ZONE - BASE STYLES
 * ========================================
 * 
 * These styles apply to all EP file upload zones using the .ep-upload-zone class.
 * The PHP service (ManagedFileHandler) automatically adds this class to managed_file widgets.
 */

/* Upload zone wrapper - container around the entire field */
.ep-upload-zone-wrapper {
  /* Wrapper styles if needed */
}

/* Upload zone - the main upload container (Drupal's .form-managed-file) */
.ep-upload-zone,
.form-managed-file.ep-upload-zone {
  position: relative;
  border: 2px solid var(--ep-color-input-border);
  border-radius: 0; /* Square edges - match form fields */
  padding: calc(var(--ep-spacing-2xl) * 1.25) var(--ep-spacing-2xl);
  text-align: center;
  background: var(--ep-color-bg-primary);
  transition: border-color 0.3s ease;
  cursor: pointer;
  margin-top: var(--ep-spacing-md);
  margin-bottom: var(--ep-spacing-md);
  height: 200px; /* Fixed height */
  min-height: 200px; /* Fixed height */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* Hide overflow from absolute positioned elements */
}

.ep-upload-zone:hover {
  border-color: var(--ep-color-input-focus);
}

.ep-upload-zone:focus-within {
  outline: none;
  border-color: var(--ep-color-input-focus);
  box-shadow: 0 0 0 3px var(--ep-color-primary-light);
}

/* Hide the default file input button but keep the input functional */
.ep-upload-zone input[type="file"]::file-selector-button {
  display: none;
}

/* Style the file input - make it overlay the entire zone but invisible */
.ep-upload-zone input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 20; /* On top of everything so it's clickable */
  font-size: 0; /* Hide the "No file chosen" text */
  margin: 0;
  padding: 0;
}

/* Hide the upload button visually but keep it functional for AJAX */
/* JavaScript auto-clicks it, so users don't need to see it */
.ep-upload-zone button[type="submit"],
.ep-upload-zone input[type="submit"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  z-index: 5;
  pointer-events: auto; /* Keep it clickable for programmatic clicks */
}

/**
 * ========================================
 * UPLOAD ICON AND TEXT
 * ========================================
 */

/* Upload icon - cloud icon displayed in upload zone */
.ep-upload-zone__icon,
.ep-upload-zone .upload-icon {
  color: var(--ep-color-text-tertiary);
  margin-bottom: var(--ep-spacing-md);
  display: block;
  position: relative;
  z-index: 15; /* Visible but below file input */
  pointer-events: none; /* Clicks pass through to file input below */
}

.ep-upload-zone__icon svg,
.ep-upload-zone .upload-icon svg {
  width: 48px;
  height: 48px;
  display: block;
  margin: 0 auto;
}

/* Upload text - instruction text displayed in upload zone */
.ep-upload-zone__text,
.ep-upload-zone .upload-text {
  color: var(--ep-color-text-secondary);
  font-size: var(--ep-font-size-base);
  margin: 0;
  line-height: var(--ep-line-height-normal);
  position: relative;
  z-index: 15; /* Visible but below file input */
  pointer-events: none; /* Clicks pass through to file input below */
}

/* Browse link - clickable link within upload text */
.ep-upload-zone__browse-link,
.ep-upload-zone .browse-link {
  color: var(--ep-color-primary);
  text-decoration: underline;
  font-weight: var(--ep-font-weight-medium);
  cursor: pointer;
  position: relative;
  z-index: 25; /* Above file input so it can receive clicks */
  pointer-events: auto; /* Make the link clickable - JS will handle it */
}

.ep-upload-zone__browse-link:hover,
.ep-upload-zone .browse-link:hover {
  color: var(--ep-color-primary);
  opacity: 0.8;
}

/**
 * ========================================
 * IMAGE PREVIEW
 * ========================================
 */

/* Preview container - displays uploaded image */
.ep-upload-zone__preview,
.ep-upload-zone .cover-photo-preview,
.ep-upload-zone .upload-preview,
.ep-upload-zone .preview {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: var(--ep-spacing-md); /* Add padding around the image */
  text-align: center;
  display: flex !important; /* Use flex to center the image */
  align-items: center;
  justify-content: center;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 10; /* Above the upload zone background */
  box-sizing: border-box; /* Include padding in width/height calculation */
}

/* Preview image - the actual uploaded image */
.ep-upload-zone__preview img,
.ep-upload-zone .cover-photo-preview img,
.ep-upload-zone .upload-preview img,
.ep-upload-zone .preview img {
  max-width: calc(100% - var(--ep-spacing-md) * 2); /* Account for padding */
  max-height: calc(100% - var(--ep-spacing-md) * 2); /* Account for padding */
  width: auto;
  height: auto;
  object-fit: contain; /* Fit image within container without cropping */
  display: block;
  border-radius: 4px;
}

/**
 * ========================================
 * DELETE BUTTON
 * ========================================
 */

/* Delete/trash button - appears on preview to remove uploaded file */
.ep-upload-zone__delete,
.ep-upload-zone .cover-photo-delete,
.ep-upload-zone .upload-delete {
  position: absolute !important;
  bottom: var(--ep-spacing-sm) !important;
  right: var(--ep-spacing-sm) !important;
  padding: var(--ep-spacing-xs);
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--ep-color-text-primary) !important;
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: center;
  z-index: 30 !important; /* Above preview image */
  transition: all 0.2s ease;
  box-shadow: none;
  visibility: visible !important;
  opacity: 1 !important;
}

.ep-upload-zone__delete:hover,
.ep-upload-zone .cover-photo-delete:hover,
.ep-upload-zone .upload-delete:hover {
  color: rgba(220, 53, 69, 1); /* Red on hover */
  transform: scale(1.1);
}

.ep-upload-zone__delete:active,
.ep-upload-zone .cover-photo-delete:active,
.ep-upload-zone .upload-delete:active {
  transform: scale(0.95);
}

/* Delete button icon (Font Awesome) */
.ep-upload-zone__delete i,
.ep-upload-zone .cover-photo-delete i,
.ep-upload-zone .upload-delete i {
  font-size: 18px;
  display: block;
  line-height: 1;
}

/**
 * ========================================
 * DRUPAL WIDGET ELEMENTS - HIDDEN
 * ========================================
 */

/* Hide Drupal default file widget elements - but let JS extract URL first */
/* Use visibility instead of display so JS can still read the data */
.ep-upload-zone .file,
.ep-upload-zone .js-form-file,
.ep-upload-zone .form-file,
.ep-upload-zone .file-filename,
.ep-upload-zone .file-size,
.ep-upload-zone details {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  /* Don't use display:none - JS needs to read the href from links */
}

/* Hide progress indicators and AJAX elements during upload */
.ep-upload-zone .ajax-progress,
.ep-upload-zone .ajax-progress-bar,
.ep-upload-zone .ajax-progress-throbber {
  display: none !important;
}

/**
 * ========================================
 * STATE MANAGEMENT
 * ========================================
 */

/* Hide upload icon and text when file is uploaded */
/* Use JavaScript class instead of :has() for better browser support */
.ep-upload-zone.has-file .ep-upload-zone__icon,
.ep-upload-zone.has-file .ep-upload-zone__text,
.ep-upload-zone.has-file .upload-icon,
.ep-upload-zone.has-file .upload-text {
  display: none; /* Hide when file is uploaded */
  visibility: hidden;
  opacity: 0;
}

/* Show icon/text when has-file class is removed (after deletion) */
.ep-upload-zone:not(.has-file) .ep-upload-zone__icon,
.ep-upload-zone:not(.has-file) .ep-upload-zone__text,
.ep-upload-zone:not(.has-file) .upload-icon,
.ep-upload-zone:not(.has-file) .upload-text {
  display: block;
  visibility: visible;
  opacity: 1;
}

/* Fallback: hide icon/text if file element exists (modern browsers) */
@supports selector(:has(*)) {
  .ep-upload-zone:has(.file) .ep-upload-zone__icon,
  .ep-upload-zone:has(.file) .ep-upload-zone__text,
  .ep-upload-zone:has(.file) .upload-icon,
  .ep-upload-zone:has(.file) .upload-text {
    display: none;
  }
}


