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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

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

/* ============ HEADER ============ */
.header {
  background: #FFFFFF;
  border-bottom: 1px solid #E5E5E5;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.header-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: #111;
}

.header-desc {
  font-size: 13px;
  color: #666;
  margin-top: 2px;
  font-weight: 400;
}

/* ============ MAIN LAYOUT ============ */
.main-layout {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 540px 1fr;
  gap: 28px;
  align-items: start;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.right-column {
  min-width: 0;
}

/* ============ CARD ============ */
.card {
  background: #FFFFFF;
  border: 1px solid #E5E5E5;
  border-radius: 12px;
  padding: 20px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: #111;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

/* ============ UPLOAD SECTION ============ */
.upload-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-card {
  border-bottom: 1px solid #F0F0F0;
  padding-bottom: 12px;
}

.upload-card:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.upload-label {
  font-size: 13px;
  font-weight: 600;
  color: #111;
  margin-bottom: 8px;
}

.upload-label .required {
  color: #E53935;
  margin-left: 2px;
}

.upload-label .optional {
  color: #999;
  font-weight: 400;
  font-size: 12px;
}

.upload-dropzone {
  position: relative;
  border: 2px dashed #E5E5E5;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #FAFAFA;
}

.upload-dropzone:hover {
  border-color: #111;
  background: #F5F5F5;
}

.upload-dropzone.dragover {
  border-color: #111;
  background: #F0F0F0;
}

.upload-dropzone.has-image {
  border-style: solid;
  border-color: #E5E5E5;
  padding: 0;
}

.upload-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px;
  color: #999;
  pointer-events: none;
}

.upload-placeholder span {
  font-size: 13px;
  font-weight: 500;
  color: #666;
}

.upload-placeholder small {
  font-size: 11px;
  color: #aaa;
}

.upload-preview {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-preview img {
  max-width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: 6px;
}

.btn-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  z-index: 3;
}

.btn-remove:hover {
  background: rgba(0,0,0,0.8);
}

/* ============ SETTINGS ============ */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: #444;
}

.form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #E5E5E5;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: #111;
  background: #FFF;
  cursor: pointer;
  transition: border-color 0.2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23999' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-select:focus {
  outline: none;
  border-color: #111;
}

.form-select option:first-child {
  color: #999;
}

/* ============ GENERATE BUTTON ============ */
.btn-generate {
  width: 100%;
  padding: 14px 24px;
  background: #111;
  color: #FFF;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  font-family: inherit;
  letter-spacing: 0.5px;
}

.btn-generate:hover:not(:disabled) {
  background: #222;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn-generate:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #FFF;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============ ERROR MESSAGE ============ */
.error-message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #FFF0F0;
  border: 1px solid #FFCDD2;
  border-radius: 8px;
  font-size: 13px;
  color: #C62828;
}

/* ============ RESULTS SECTION ============ */
.results-section {
  min-height: 400px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.results-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.results-header-title {
  font-size: 15px;
  font-weight: 700;
  color: #111;
}

.result-count {
  font-size: 12px;
  font-weight: 500;
  color: #999;
}

.btn-download-all {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-download-all:hover:not(:disabled) {
  background: #333;
}

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

.btn-zalo {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: #0068FF;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-zalo:hover {
  background: #0052CC;
}

.results-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #ccc;
  text-align: center;
  gap: 8px;
}

.results-empty p {
  font-size: 14px;
  color: #999;
  margin-top: 8px;
}

.results-empty small {
  font-size: 12px;
  color: #bbb;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.result-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #E5E5E5;
  cursor: pointer;
  background: #FAFAFA;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
}

/* Skeleton loading */
.result-loading {
  cursor: default;
  border-color: #eee;
}

.skeleton {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #F5F5F5;
  overflow: hidden;
}

.skeleton-pulse {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #F5F5F5 25%, #E8E8E8 50%, #F5F5F5 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

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

.skeleton-spinner {
  position: relative;
  z-index: 1;
}

.spinner-sm {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(0,0,0,0.1);
  border-top-color: #111;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.skeleton-text {
  position: relative;
  z-index: 1;
  font-size: 11px;
  color: #999;
  font-weight: 500;
}

.result-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.result-item:hover img {
  transform: scale(1.03);
}

.result-item-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 0.2s;
}

.result-item:hover .result-item-actions {
  opacity: 1;
}

.btn-action {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-action:hover {
  background: #FFF;
}

.btn-action svg {
  stroke: #111;
}

/* ============ LIGHTBOX ============ */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.92);
}

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
}

.lightbox-header {
  position: absolute;
  top: -48px;
  right: 0;
  display: flex;
  gap: 8px;
  z-index: 2;
}

.lightbox-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  backdrop-filter: blur(4px);
}

.lightbox-btn:hover {
  background: rgba(255,255,255,0.2);
}

.lightbox-close {
  background: rgba(255,255,255,0.15);
}

.lightbox-close:hover {
  background: rgba(255,80,80,0.6);
}

.lightbox-image-container {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 8px;
}

.lightbox-image-container img {
  max-width: 85vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  transition: transform 0.2s ease;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-image-container img:active {
  cursor: grabbing;
}

/* ============ FOOTER ============ */
.footer {
  border-top: 1px solid #E5E5E5;
  margin-top: 24px;
  background: #FFF;
}

.footer-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 24px;
  text-align: center;
}

.footer p {
  font-size: 11px;
  color: #999;
  line-height: 1.4;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
    max-width: 720px;
  }

  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }

  .results-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .header-inner {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-title {
    font-size: 17px;
  }

  .header-right {
    width: 100%;
    justify-content: flex-start;
  }

  .btn-zalo {
    font-size: 12px;
    padding: 6px 12px;
  }

  .header-desc {
    font-size: 12px;
  }

  .main-layout {
    padding: 16px;
    gap: 16px;
  }

  .card {
    padding: 16px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .results-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .result-item {
    min-height: 140px;
  }

  .results-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .btn-download-all {
    font-size: 11px;
    padding: 5px 10px;
  }

  .lightbox-image-container img {
    max-width: 95vw;
    max-height: 70vh;
  }
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}
