:root {
  /* --- BẢNG MÀU GRADIENT --- */
  --sdm-grad-start: #ec4899; /* Hồng đậm */
  --sdm-grad-end: #a855f7; /* Tím */
  --sdm-primary: #d946ef; /* Màu active */

  --sdm-bg-card: #ffffff;
  --sdm-text-main: #111827;
  --sdm-text-sub: #6b7280;
  --sdm-border: #e5e7eb;

  --sdm-radius-lg: 16px; /* Bo góc to mềm mại */
  --sdm-radius-sm: 8px;
  --sdm-shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --sdm-shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.sdm-container {
  padding-top: 60px; /* Tăng padding trên để tránh bị che bởi badge token */
  display: flex;
  flex-wrap: wrap;
  gap: 40px; /* Khoảng cách rộng hơn */
  font-family: "Inter", sans-serif;
  max-width: 1200px;
  margin: 0 auto;
  color: var(--sdm-text-main);
}

/* --- CỘT TRÁI --- */
.sdm-col-controls {
  flex: 1;
  min-width: 340px;
}

/* Tiêu đề bước (1. Upload, 2. Choose Style) */
.sdm-step-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 1. Upload Zone (Minimalist) */
.sdm-upload-zone {
  border: 2px dashed var(--sdm-border);
  border-radius: var(--sdm-radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  background: #f9fafb;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sdm-upload-zone:hover {
  border-color: var(--sdm-primary);
  background: #fdf4ff;
}
.sdm-upload-content svg {
  width: 40px;
  height: 40px;
  fill: #9ca3af;
  margin-bottom: 10px;
}
.sdm-upload-text h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.sdm-upload-text p {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--sdm-text-sub);
}

.sdm-preview-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: absolute;
  top: 0;
  left: 0;
  background: #fff;
  display: none;
  padding: 10px;
  box-sizing: border-box;
}
.sdm-preview-img.active {
  display: block;
}

/* 2. Style Grid (Big Cards like screenshot) */
.sdm-style-grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fill,
    minmax(140px, 1fr)
  ); /* Card to hơn */
  gap: 15px;
}

.sdm-style-card {
  position: relative;
  border-radius: var(--sdm-radius-lg);
  overflow: hidden;
  aspect-ratio: 1/1;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.2s ease;
}

.sdm-style-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}
/* Hiệu ứng zoom nhẹ khi hover */
.sdm-style-card:hover img {
  transform: scale(1.05);
}

/* Lớp phủ gradient đen bên dưới để đọc chữ */
.sdm-card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  padding: 20px 12px 12px;
  color: white;
}
.sdm-card-title {
  font-size: 15px;
  font-weight: 700;
  display: block;
}
.sdm-card-desc {
  font-size: 11px;
  opacity: 0.8;
  display: block;
  margin-top: 2px;
  font-weight: 400;
}

/* ACTIVE STATE (Viền hồng + Checkmark) */
.sdm-style-card.active {
  border-color: var(--sdm-primary);
  box-shadow: 0 10px 20px rgba(217, 70, 239, 0.3);
}
.sdm-checkmark {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  background: var(--sdm-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  opacity: 0;
  transform: scale(0);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 10;
}
.sdm-style-card.active .sdm-checkmark {
  opacity: 1;
  transform: scale(1);
}

/* BUTTON (Gradient Masterpiece) */
.sdm-btn-submit {
  width: 100%;
  padding: 18px;
  margin-top: 30px;
  background: linear-gradient(
    90deg,
    var(--sdm-grad-start),
    var(--sdm-grad-end)
  );
  color: white;
  border: none;
  border-radius: 50px; /* Bo tròn kiểu viên thuốc */
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(168, 85, 247, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.sdm-btn-submit:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 30px rgba(168, 85, 247, 0.4);
}
.sdm-btn-submit:active {
  transform: scale(0.98);
}

/* --- CỘT PHẢI: RESULT --- */
.sdm-col-result {
  flex: 1.5;
  min-width: 340px;
  background: #f3f4f6; /* Nền xám tổng thể */
  border-radius: 24px;
  padding: 10px; /* Padding nhỏ để tạo viền giả */
}

.sdm-result-inner {
  min-height: 500px !important;
  height: auto;
  padding: 15px; /* Giảm padding */

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
}

.sdm-result-banner-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  z-index: 1;
  transition: opacity 0.3s;
}

.sdm-result-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.1),
    rgba(0, 0, 0, 0.6)
  );
  z-index: 2;
}

.sdm-result-image.show ~ .sdm-result-banner-bg {
  opacity: 0;
}
.sdm-result-image.show ~ .sdm-result-overlay {
  opacity: 0;
}

.sdm-result-image {
  max-height: 600px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
}
.sdm-result-image.show {
  display: block;
}

.sdm-empty-state {
  z-index: 3;
}
.sdm-empty-state-icon {
  width: 50px; /* Nhỏ lại (cũ là 80px) */
  height: 50px;
  margin-bottom: 10px;
}
.sdm-empty-state-icon .dashicons {
  font-size: 24px !important; /* Icon nhỏ lại */
  width: 24px;
  height: 24px;
  line-height: 24px;
}

.sdm-empty-state-text h3 {
  font-size: 16px; /* Font tiêu đề nhỏ lại */
  margin-bottom: 5px;
}
.sdm-empty-state-text p {
  font-size: 13px;
  margin-top: 0;
  color: #999;
}

/* Loading */
.sdm-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 20px;
}

.sdm-history-section {
  width: 100%;
  margin-top: 15px;
  border-top: 1px solid #eee;
  padding-top: 10px;
}

/* Mobile */
@media (max-width: 768px) {
  .sdm-container {
    flex-direction: column;
  }
  .sdm-col-result {
    order: -1;
    min-height: 400px;
  }
  .sdm-result-inner {
    min-height: 250px; /* Mobile cho nhỏ hơn nữa */
  }
}
.hidden {
  display: none !important;
}

/* =========================================
   TEXT TO IMAGE SPECIFIC STYLES (Creative Studio)
   ========================================= */

/* 1. Prompt Box "Magic Input" */
.sdm-t2i-prompt-container {
  position: relative;
  margin-bottom: 25px;
}

.sdm-t2i-textarea {
  width: 100%;
  min-height: 140px;
  padding: 20px;
  padding-bottom: 50px; /* Chỗ cho nút Inspire */
  border: 2px solid #f3f4f6;
  border-radius: 20px;
  background: #f9fafb;
  font-size: 16px;
  line-height: 1.6;
  color: var(--sdm-text-main);
  resize: vertical;
  transition: all 0.3s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.sdm-t2i-textarea:focus {
  background: #fff;
  border-color: var(--sdm-grad-end); /* Màu tím khi focus */
  outline: none;
  box-shadow: 0 4px 20px rgba(168, 85, 247, 0.15);
}

.sdm-t2i-inspire-btn {
  padding: 0px 5px !important;
  position: absolute;
  bottom: 15px;
  right: 15px;
  background: white;
  border: 1px solid #e5e7eb;
  padding: 8px 16px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  color: var(--sdm-grad-start); /* Màu hồng */
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  transition: all 0.2s;
}
.sdm-t2i-inspire-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
  background: linear-gradient(90deg, #fff0f5, #f3e8ff);
  border-color: transparent;
}

/* 2. Aspect Ratio "Visual Shapes" */
.sdm-t2i-ratio-grid {
  display: flex;
  gap: 15px;
  overflow-x: auto;
  padding-bottom: 5px; /* Cho thanh cuộn nếu tràn */
}

.sdm-t2i-ratio-card {
  flex: 1;
  min-width: 80px;
  background: white;
  border: 2px solid #f3f4f6;
  border-radius: 16px;
  padding: 15px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
}

.sdm-t2i-ratio-shape {
  border: 2px solid #d1d5db;
  border-radius: 4px;
  transition: all 0.2s;
}
.sdm-shape-1-1 {
  width: 24px;
  height: 24px;
}
.sdm-shape-16-9 {
  width: 30px;
  height: 17px;
}
.sdm-shape-9-16 {
  width: 17px;
  height: 30px;
}
/* MỚI: Tỷ lệ 2:3 (Thay cho 3:4 cũ) */
.sdm-shape-2-3 {
  width: 18px;
  height: 27px;
}

.sdm-t2i-ratio-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--sdm-text-sub);
}

/* Active State cho Ratio */
.sdm-t2i-ratio-card:hover {
  border-color: #e5e7eb;
  background: #fdf4ff;
}
.sdm-t2i-ratio-card.active {
  border-color: var(--sdm-grad-end); /* Màu tím */
  background: #f3e8ff;
}
.sdm-t2i-ratio-card.active .sdm-t2i-ratio-shape {
  border-color: var(--sdm-grad-end);
  background: var(--sdm-grad-end);
}
.sdm-t2i-ratio-card.active .sdm-t2i-ratio-text {
  color: var(--sdm-grad-end);
}

/* 3. Style Selector (Compact Version) */
/* Dùng lại .sdm-style-grid của Img2Img nhưng chỉnh lại 1 chút cho gọn nếu cần */
.sdm-t2i-style-wrapper {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 5px;
}
/* Custom scrollbar */
.sdm-t2i-style-wrapper::-webkit-scrollbar {
  width: 6px;
}
.sdm-t2i-style-wrapper::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 3px;
}

.dashicons-star-filled {
  width: 30px !important;
}

/* OPTION 1: NEON FLOW */
.sdm-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.95);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.sdm-progress-container {
  width: 80%;
  height: 12px;
  background: #e5e7eb;
  border-radius: 20px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sdm-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ec4899, #a855f7, #ec4899);
  background-size: 200% 100%;
  border-radius: 20px;
  transition: width 0.3s ease-out;
  animation: sdm-shimmer 2s linear infinite;
}

.sdm-loading-status {
  margin-top: 15px;
  font-size: 14px;
  font-weight: 600;
  color: #4b5563;
  display: flex;
  justify-content: space-between;
  width: 80%;
}

@keyframes sdm-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* --- RESULT TOOLBAR (Download/Share) --- */
.sdm-result-wrapper {
  z-index: 15;
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}
.sdm-result-wrapper.hidden {
  display: none;
}

.sdm-result-actions {
  position: absolute;
  bottom: 20px;
  display: flex;
  gap: 10px;
  background: rgba(0, 0, 0, 0.6);
  padding: 8px 15px;
  border-radius: 30px;
  opacity: 0;
  transition: opacity 0.3s;
  transform: translateY(10px);
}
/* Hiện toolbar khi hover vào ảnh */
.sdm-result-wrapper:hover .sdm-result-actions {
  opacity: 1;
  transform: translateY(0);
}

.sdm-action-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 15px;
  transition: background 0.2s;
}
.sdm-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* --- HISTORY SCROLL LIST --- */
.sdm-history-list {
  display: flex;
  flex-direction: row; /* Xếp ngang */
  gap: 10px;
  padding: 10px 5px; /* Padding để không bị cắt bóng đổ */

  width: 100%;
  height: 110px; /* Chiều cao cố định */

  overflow-x: auto; /* Bắt buộc có thanh cuộn ngang */
  overflow-y: hidden;

  /* Quan trọng: Giúp cuộn mượt */
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
/* Thanh cuộn đẹp */
.sdm-history-list::-webkit-scrollbar {
  height: 6px;
}
.sdm-history-list::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.sdm-history-item {
  flex: 0 0 80px; /* CỐ ĐỊNH KÍCH THƯỚC: Không cho co giãn */
  width: 80px;
  height: 80px;

  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}
.sdm-history-item img {
  width: auto;
  height: 100%;
  object-fit: cover;
}
.sdm-history-item:hover {
  transform: translateY(-3px);
  border-color: var(--sdm-grad-start);
}

@keyframes flashNew {
    0% { transform: scale(0.5); opacity: 0; border-color: #ffff00; }
    100% { transform: scale(1); opacity: 1; border-color: #d946ef; }
}

@keyframes popIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
.sdm-history-item.new-item {
  animation: flashNew 0.5s ease-out forwards;
  border-color: #d946ef; /* Viền hồng để biết là ảnh mới */
}
.sdm-no-history {
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: #9ca3af;
}

.sdm-container {
  position: relative;
}

.sdm-token-badge {
  position: absolute; /* Vẫn dùng absolute để ghim góc phải */
  top: 15px; /* Cách mép trên 15px */
  right: 15px; /* Cách mép phải 15px */

  background: #fff;
  padding: 8px 15px;
  border-radius: 20px;
  font-weight: 700;
  color: #d946ef;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08); /* Bóng đổ nhẹ cho nổi bật */
  border: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 50; /* Đảm bảo luôn nổi trên cùng */
}

/* MOBILE FIX v1.3.6 - FINAL OVERRIDE */
@media (max-width: 768px) {
  .sdm-container {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 10px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }
  .sdm-col-controls, .sdm-col-result {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 0 20px 0 !important;
    padding: 15px !important;
    flex: none !important;
    box-sizing: border-box !important;
    border-radius: 12px !important;
  }
  .sdm-token-badge {
    position: static !important;
    margin: 0 auto 15px auto !important;
    display: table !important; 
  }
  .sdm-history-list {
      width: 100% !important;
      height: auto !important;
      overflow-x: auto !important;
      justify-content: flex-start !important;
  }
  .sdm-result-inner {
      min-height: 250px !important;
      width: 100% !important;
  }
}
