/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #fff;
  color: #333;
  line-height: 1.5;
  min-height: 100vh;
}

#widget-container {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* === Steps === */
.step {
  display: none;
  width: 100%;
  max-width: 1100px;
}

.step.active {
  display: block;
}

/* === Utility === */
.hidden {
  display: none !important;
}

/* === Step: Upload === */
#step-upload {
  max-width: 800px;
  margin: 0 auto;
  text-align: center;
}

#step-upload h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}

.step-desc {
  color: #666;
  margin-bottom: 24px;
  font-size: 14px;
}

/* Two-column upload grid */
.upload-grid {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.upload-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upload-col-title {
  font-size: 14px;
  font-weight: 600;
  color: #444;
  text-align: left;
  margin: 0;
}

/* Drop zone */
.drop-zone {
  position: relative;
  border: 2px dashed #ccc;
  border-radius: 12px;
  min-height: 180px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: #ff6955;
  background: #fff5f3;
}

.dz-validating {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 16px;
  color: #ff6955;
  font-weight: 600;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.dz-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 16px;
}

.dz-content svg {
  opacity: 0.5;
}

.dz-content p {
  font-size: 14px;
  color: #666;
}

.hint {
  font-size: 12px !important;
  color: #999 !important;
}

.btn-browse {
  background: #ff6955;
  color: #fff;
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-browse:hover {
  background: #e55a48;
}

/* Drop zone preview (after photo selected) */
.dz-preview {
  width: 100%;
  height: 100%;
  min-height: 180px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dz-preview img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  display: block;
}

.dz-change-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.dz-change-btn:hover {
  background: rgba(0,0,0,0.75);
}

/* Insert URL box (preview area above URL input) */
.insert-url-box {
  border: 2px dashed #ccc;
  border-radius: 12px;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Hint below URL input */
.url-hint {
  text-align: left;
}

/* URL input row (below insert preview box) */
.url-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.url-or {
  font-size: 13px;
  color: #999;
  white-space: nowrap;
}

.url-input {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
}

.url-input:focus {
  border-color: #ff6955;
}

.btn-url-ok {
  background: #ff6955;
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn-url-ok:hover {
  background: #e55a48;
}

/* "Next" button (full width below grid) */
.upload-next-btn {
  width: 100%;
}

/* === Insert preview in sidebar === */
.insert-sidebar-thumb {
  border-radius: 8px;
  overflow: hidden;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

.insert-sidebar-thumb img {
  max-width: 100%;
  max-height: 100px;
  object-fit: contain;
  display: block;
}

/* === Step: Editor === */
.editor-layout {
  display: flex;
  gap: 20px;
  min-height: 500px;
}

.photo-wrapper {
  flex: 1;
  background: #f5f5f5;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}

.photo-wrapper img {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: #444;
}

/* === Picker grid === */
.picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.picker-btn {
  flex: 1 1 calc(50% - 4px);
  min-width: 100px;
  padding: 12px 8px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
}

.picker-btn:hover {
  border-color: #ff6955;
  background: #fff5f3;
}

.picker-btn.selected {
  border-color: #ff6955;
  background: #ffe8e5;
}

.picker-name {
  font-size: 13px;
  font-weight: 500;
  color: #333;
}

/* === Sidebar actions === */
.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

/* === Buttons === */
.btn {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  text-align: center;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: #ff6955;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #e55a48;
}

.btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.btn-secondary:hover {
  background: #e5e5e5;
}

/* === Step: Loading === */
.loading-container {
  text-align: center;
  max-width: 400px;
  margin: 0 auto;
}

.spinner {
  width: 48px;
  height: 48px;
  will-change: transform;
  border: 4px solid #f0f0f0;
  border-top-color: #ff6955;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 24px;
}

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

.loading-container h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.loading-container p {
  color: #666;
  margin-bottom: 24px;
  font-size: 14px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: #f0f0f0;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #ff6955;
  width: 0;
  transition: width 0.5s ease;
  border-radius: 3px;
}

/* === Step: Result === */
.result-layout {
  text-align: center;
}

.result-image-container {
  margin-bottom: 20px;
}

.result-image-container img {
  max-width: 100%;
  max-height: 65vh;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.result-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* === Step: Error === */
.error-container {
  text-align: center;
  max-width: 400px;
  margin: 0 auto;
}

.error-container svg {
  margin-bottom: 16px;
}

.error-container h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.error-container p {
  color: #666;
  margin-bottom: 24px;
  font-size: 14px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .upload-grid {
    flex-direction: column;
  }

  .editor-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
  }

  .photo-wrapper {
    min-height: 240px;
  }

  .picker-btn {
    flex: 1 1 calc(33% - 6px);
    min-width: 80px;
    padding: 10px 6px;
  }

  .picker-name {
    font-size: 12px;
  }

  .result-actions {
    flex-direction: column;
  }

  .result-actions .btn {
    width: 100%;
  }
}
