/* --- CSS Custom Properties for Customization --- */
:root {
  --bga-primary-color: #1976f6; /* Main accent color */
  --bga-secondary-color: #d6b06c; /* Secondary accent (buttons, icons) */
  --bga-bg-color: #fff; /* Main background */
  --bga-border-radius: 12px; /* Border radius for containers */
  --bga-upload-border: 2px dashed #181818; /* Upload box border */
  --bga-upload-icon-bg: #d6b06c; /* Upload icon background */
  --bga-upload-btn-bg: #d6b06c; /* Upload button background */
  --bga-upload-btn-hover-bg: #c49a4a; /* Upload button hover background */
  --bga-upload-btn-color: #181818; /* Upload button text color */
  --bga-step-active-bg: var(--bga-primary-color);
  --bga-step-active-color: #fff;
  --bga-edit-panel-bg: #222;
  --bga-edit-panel-radius: 12px;
  --bga-edit-btn-bg: #aaa;
  --bga-edit-btn-hover-bg: #888;
  --bga-edit-btn-active-bg: #444;
  --bga-edit-btn-color: #222;
  --bga-edit-btn-active-color: #fff;
  --bga-thumb-selected-border: 2px solid #222;
  --bga-thumb-border: 2px solid #ccc;
  --bga-crop-handle-color: #1976f6;
}

#image-module-layout {
  padding-top: 40px;
  font-family: 'Inter', Arial, sans-serif;
  display: grid;
  gap: 10px 40px;
  justify-content: center;
  align-items: start;
}

#image-module-layout.edit-step {
  grid-template-columns: repeat(3, auto);
  grid-template-rows: 70px auto;
}

#image-module-layout.edit-step .step {
  grid-column: 1;
}

#image-module-layout.edit-step #thumbnails-container {
  grid-column: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px;

}

#image-module-layout.edit-step .frame-preview-container {
  grid-column: 2;
  grid-row: 1 / 3;
}

#image-module-layout.edit-step .edit-box {
  grid-column: 3;
  grid-row: 1 / 3;
}

.left-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 440px;
}

.step {
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size: 18px;
  font-weight: 500;
  gap: 12px;
  color: var(--bga-primary-color);
}

.step .icon.material-icons {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #f3f3f3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bga-primary-color);
  color: #fff;
}

.frame-preview {
  display: block;
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
}

/* --- Upload Component Styles --- */
.upload-box {
  border: var(--bga-upload-border);
  border-radius: var(--bga-border-radius);
  width: 420px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px 24px 24px 24px;
  background: var(--bga-bg-color);
  box-sizing: border-box;
  position: relative;
}

.upload-icon {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.upload-icon svg circle {
  fill: var(--bga-upload-icon-bg);
}

.upload-text {
  text-align: center;
  margin-bottom: 18px;
}

.drag-drop {
  font-size: 26px;
  font-weight: 500;
  color: #181818;
}

.eller {
  font-size: 18px;
  color: #888;
  margin-top: 2px;
}

.upload-btn, .upload-preview-btn {
  background: var(--bga-upload-btn-bg);
  color: var(--bga-upload-btn-color);
  font-size: 20px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 12px 48px;
  margin-bottom: 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.2s;
}

.support-text {
  color: #888;
  font-size: 15px;
  margin-top: 8px;
}

.arrow-svg {
  display: block;
} 

.dragover {
  border-color: #bfa05a;
  background: #fffbe6;
}

.file-input {
  display: none;
}

.upload-preview-btn {
  background: #d6b06c;
  color: #181818;
  font-size: 16px;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  padding: 12px 48px;
  margin-bottom: 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.2s;
}

#upload-continue-btn:disabled {
  background: #888;
  color: #fff;
  cursor: not-allowed;
}

.upload-btn:hover, .upload-preview-btn:hover {
  background: var(--bga-upload-btn-hover-bg);
}

.back-to-edit-btn {
  margin-top: 20px;
  font-size: 14px;
  font-weight: 500;
}

.upload-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
}

.item-preview {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 10px;
}

.item-img {
  width: 100%;
  min-width: 100px;
  margin-top: auto;
}

.item-title {
  font-size: 12px;
  margin-top: auto;
}

.upload-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
}

.upload-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.98);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  z-index: 10;
}

.upload-loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.upload-loading-spinner {
  font-size: 48px;
  color: #d6b06c;
  animation: spin 1s linear infinite;
}

.upload-loading-text {
  font-size: 18px;
  font-weight: 500;
  color: #181818;
}

/* --- Edit Component Styles --- */
.edit-box {
  display: flex;
  gap: 30px;
  align-items: flex-start;
}
.edit-panel {
  background: var(--bga-edit-panel-bg);
  border-radius: var(--bga-edit-panel-radius);
  padding: 24px 24px 32px 24px;
  width: 300px;
  color: #fff;
  box-sizing: border-box;
  position: relative;
}
.edit-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: #aaa;
  border-radius: 24px;
  padding: 4px;
}
.tab {
  flex: 1;
  background: transparent;
  color: #222;
  border: none;
  border-radius: 20px;
  padding: 12px 0;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, color 0.2s;
}
.tab-active {
  background: #444;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.edit-content {
  margin-bottom: 16px;
}
.edit-label {
  display: block;
  margin: 18px 0 6px 0;
  font-size: 14px;
  font-weight: 500;
}
.slider {
  width: 100%;
  margin: 8px 0 16px 0;
  accent-color: #aaa;
}
.edit-row {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}
.edit-btn {
  flex: 1;
  background: var(--bga-edit-btn-bg);
  color: var(--bga-edit-btn-color);
  border: none;
  border-radius: 6px;
  padding: 10px 0;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s, color 0.2s;
}
.crop-btn {
  width: 100%;
}
.edit-actions {
  margin-top: 30px;
}
.edit-actions > :last-child {
  margin-bottom: 0px;
}
.edit-btn:hover {
  background: var(--bga-edit-btn-hover-bg);
  color: var(--bga-edit-btn-active-color);
}
.active-edit-btn {
  background: var(--bga-edit-btn-active-bg);
  color: var(--bga-edit-btn-active-color);
}
.tab:hover {
  background: #888;
  color: #fff;
}
.tab-active:hover {
  background: #444;
  color: #fff;
}
.thumb-item {
  border: var(--bga-thumb-border);
  border-radius: 6px;
  width: 90px;
  height: 120px;
  overflow: visible;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  cursor: pointer;
}
.thumb-selected {
  border: var(--bga-thumb-selected-border);
}
.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- Delete Button Styles --- */
.delete-thumb-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e74c3c;
  color: white;
  border: 2px solid white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 14px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: all 0.2s ease;
  z-index: 10;
}

.delete-thumb-btn:hover {
  background: #c0392b;
  transform: scale(1.1);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.delete-thumb-btn:active {
  transform: scale(0.95);
}

.delete-thumb-btn .material-icons {
  font-size: 16px;
  line-height: 1;
}

.add-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  border: 2px dashed #aaa;
  background: none;
}
.add-thumb .material-icons {
  font-size: 36px;
}
.tab .material-icons {
  font-size: 22px;
}
.flip-vertical {
  transform: rotate(90deg);
  display: inline-block;
}
.filters-label { 
  margin-top: 0px;
}
.frame-preview-container {
  display: none;
  position: relative;
  /* Transparent background - let the image define the space */
  background: repeating-conic-gradient(#f0f0f0 0% 25%, transparent 0% 50%) 50% / 20px 20px;
}

/* For circular mode, mask the background to be circular */
.frame-preview-container.circular {
  /* Remove background from container for circular mode */
  background: none;
}

/* Add circular background via pseudo-element so it doesn't clip handles */
.frame-preview-container.circular::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-conic-gradient(#f0f0f0 0% 25%, transparent 0% 50%) 50% / 20px 20px;
  border-radius: 50%;
  z-index: -1;
}

.frame-preview-container.circular .frame-preview.circular {
  border-radius: 50%;
  position: relative;
  z-index: 1;
}

.edit-step .frame-preview-container {
  display: block;
}

/* --- Crop Overlay Styles --- */
.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 1000;
}

.crop-overlay .crop-selection {
    position: absolute;
    border: 2px solid #fff;
    background: transparent;
    pointer-events: all;
    cursor: move;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.crop-overlay .crop-selection::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 1px solid var(--bga-crop-handle-color);
    pointer-events: none;
}

.crop-overlay .crop-selection::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        linear-gradient(90deg, transparent 0%, transparent calc(33.33% - 1px), rgba(255,255,255,0.3) calc(33.33% - 1px), rgba(255,255,255,0.3) calc(33.33% + 1px), transparent calc(33.33% + 1px), transparent 66.66%, rgba(255,255,255,0.3) 66.66%, rgba(255,255,255,0.3) calc(66.66% + 2px), transparent calc(66.66% + 2px)),
        linear-gradient(0deg, transparent 0%, transparent calc(33.33% - 1px), rgba(255,255,255,0.3) calc(33.33% - 1px), rgba(255,255,255,0.3) calc(33.33% + 1px), transparent calc(33.33% + 1px), transparent 66.66%, rgba(255,255,255,0.3) 66.66%, rgba(255,255,255,0.3) calc(66.66% + 2px), transparent calc(66.66% + 2px));
    pointer-events: none;
}

.edit-loading-overlay {
  border-radius: var(--bga-edit-panel-radius);
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
 .edit-loading-spinner {
   width: 48px;
   height: 48px;
   border: 6px solid #fff;
   border-top: 6px solid #1976f6;
   border-radius: 50%;
   animation: spin 1s linear infinite;
 }

 .crop-instruction {
   font-size: 12px;
   color: #888;
   text-align: center;
   margin-top: 8px;
   font-style: italic;
 }

 .crop-btn.active-edit-btn {
   animation: pulse 2s infinite;
 }

 @keyframes pulse {
   0% { transform: scale(1); }
   50% { transform: scale(1.05); }
   100% { transform: scale(1); }
 }
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* --- Tablet and mobile Styles --- */
@media (min-width: 1025px) {
  .tablet-only {
    display: none !important;
  }
}
@media (max-width: 1024px) {
  .crop-instruction {
    display: none;
  }
  #image-module-layout.edit-step {
    grid-template-columns: auto !important;
    grid-template-rows: auto !important;
    row-gap: 30px;
  }
  .step {
    display: none;
  }
  #thumbnails-container {
    grid-row: 3 !important;
  }
  .frame-preview-container {
    grid-row: 2 !important;
    grid-column: 1 !important;
  }
  .edit-box {
    flex-direction: column-reverse;
    gap: 20px;
    align-items: center;
    grid-column: 1 !important;
    grid-row: 1 !important;
  }
  .edit-box, .edit-panel {
    width: 100%;
  }
  .edit-content > :not(.tablet-only) {
    display: none !important;
  }
  .tablet-tab-content > .slider, .tablet-tab-content > span {
    align-self: center;
    margin-top: 0px;
    margin-bottom: 0px;
  }
}
