/* =============================================================================
   Image Gallery Component
   Styles for image-picker (3-tab picker) and gallery-grid (thumbnail grid).
   ============================================================================= */

/* =============================================================================
   Image Picker Container
   ============================================================================= */

.image-picker {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  overflow: hidden;
}

/* =============================================================================
   Tab Bar
   ============================================================================= */

.image-picker-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-primary);
  background: var(--bg-secondary);
}

.image-picker-tab {
  flex: 1;
  padding: 0.625rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  min-height: 44px; /* touch target */
}

.image-picker-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.image-picker-tab.active {
  color: var(--accent-red);
  border-bottom-color: var(--accent-red);
  background: var(--bg-primary);
}

/* =============================================================================
   Tab Panel (content area below tabs)
   ============================================================================= */

.image-picker-panel {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* =============================================================================
   Upload Tab — drag-and-drop zone
   ============================================================================= */

.image-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem 1rem;
  border: 2px dashed var(--border-primary);
  border-radius: 6px;
  background: var(--bg-secondary);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
  min-height: 160px;
}

.image-upload-zone:hover,
.image-upload-zone.drag-over {
  border-color: var(--accent-red);
  background: var(--bg-hover);
}

.upload-zone-icon {
  font-size: 2rem;
  line-height: 1;
}

.upload-zone-label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin: 0;
}

.upload-browse-btn {
  margin-top: 0.25rem;
}

/* Hide the raw file input (we use the overlay button to trigger it) */
.image-file-input {
  display: none;
}

.upload-zone-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin: 0;
  text-align: center;
}

/* =============================================================================
   URL Tab — paste field + preview
   ============================================================================= */

.image-url-input {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.image-url-field,
.image-caption-field {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 1rem; /* 16px — prevents iOS zoom on focus */
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.image-url-field:focus,
.image-caption-field:focus {
  outline: none;
  border-color: var(--accent-red);
}

.image-url-field::placeholder,
.image-caption-field::placeholder {
  color: var(--text-disabled);
}

.image-url-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  overflow: hidden;
  max-height: 160px;
}

.image-url-preview img {
  max-width: 100%;
  max-height: 160px;
  object-fit: contain;
  display: block;
}

.url-preview-error {
  color: var(--error);
  font-size: 0.8125rem;
  margin: 0;
  padding: 0.5rem;
}

.form-label {
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
}

/* =============================================================================
   Library Section Heading — heading + optional about tooltip
   ============================================================================= */

.image-library-section-heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.image-library-section-heading h3 {
  margin: 0;
}

.image-library-gallery {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-primary);
}

/* =============================================================================
   About Tooltip — info icon with hover text
   ============================================================================= */

.about-tooltip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 600;
  cursor: help;
  flex-shrink: 0;
}

.about-tooltip:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* =============================================================================
   Gallery Tab Hint
   ============================================================================= */

.gallery-tab-hint {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin: 0;
}

/* =============================================================================
   Gallery Grid — shared by gallery tab and gallery-grid component
   ============================================================================= */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
}

.gallery-item {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--bg-secondary);
  border: 2px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 44px; /* touch target */
}

.gallery-item:hover {
  border-color: var(--text-secondary);
}

.gallery-item.selected {
  border-color: var(--accent-red);
  box-shadow: 0 0 0 1px var(--accent-red);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-item-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.25rem 0.375rem;
  background: rgba(0, 0, 0, 0.65);
  color: var(--text-primary);
  font-size: 0.6875rem;
  line-height: 1.3;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.gallery-item-delete {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  width: 20px;
  height: 20px;
  padding: 0;
  background: rgba(0, 0, 0, 0.7);
  border: none;
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 0.875rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 1;
}

.gallery-item-delete:hover {
  background: var(--accent-red);
}

/* =============================================================================
   Copy-to-Library Button (gallery tab thumbnails)
   ============================================================================= */

.gallery-item-copy {
  position: absolute;
  top: 0.25rem;
  left: 0.25rem;
  width: 24px;
  height: 24px;
  padding: 0;
  background: rgba(0, 0, 0, 0.7);
  border: none;
  border-radius: 50%;
  color: var(--success);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
  z-index: 1;
  opacity: 0;
}

.gallery-item:hover .gallery-item-copy {
  opacity: 1;
}

.gallery-item-copy:hover {
  background: var(--success);
  color: #000;
  transform: scale(1.1);
}

/* =============================================================================
   Source Badge (URL / Upload indicator)
   ============================================================================= */

.gallery-item-source-badge {
  position: absolute;
  top: 0.25rem;
  left: 0.25rem;
  padding: 0.125rem 0.375rem;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 3px;
  color: var(--info);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  z-index: 1;
  pointer-events: none;
}

/* =============================================================================
   Responsive — 768px (tablet)
   ============================================================================= */

@media (max-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.375rem;
  }

  .image-upload-zone {
    padding: 1.5rem 0.75rem;
    min-height: 130px;
  }

  .image-picker-tab {
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
  }

  /* Copy button always visible on touch devices */
  .gallery-item-copy {
    opacity: 1;
  }
}

/* =============================================================================
   Responsive — 480px (mobile)
   ============================================================================= */

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.25rem;
  }

  .image-picker-panel {
    padding: 0.75rem;
  }

  .image-upload-zone {
    padding: 1.25rem 0.5rem;
    min-height: 110px;
  }

  .upload-zone-icon {
    font-size: 1.5rem;
  }

  .image-picker-tab {
    font-size: 0.75rem;
    padding: 0.5rem 0.5rem;
    min-height: 44px;
  }

  /* Ensure URL input doesn't zoom on iOS (font-size already 1rem above) */
  .image-url-field,
  .image-caption-field {
    font-size: 1rem;
  }
}
