/* Ecom Workflow System V1 - Main Stylesheet */

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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --green-100: #d1fae5;
  --green-600: #059669;
  --green-700: #047857;
  --red-100: #fee2e2;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --yellow-100: #fef3c7;
  --yellow-600: #d97706;
  --blue-100: #dbeafe;
  --blue-600: #2563eb;
  --purple-100: #ede9fe;
  --purple-600: #7c3aed;
  --sidebar-width: 240px;
  --header-height: 56px;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--gray-900);
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  padding: 16px 20px;
  font-size: 1.1rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand svg {
  width: 24px;
  height: 24px;
}

.sidebar-nav {
  padding: 12px 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  text-decoration: none;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
  text-decoration: none;
}

.sidebar-nav a.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-left-color: var(--primary);
}

.sidebar-nav a svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.main-area {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
}

.topbar {
  height: var(--header-height);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-800);
}

.page-content {
  padding: 24px;
  max-width: 1280px;
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

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

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gray-800);
}

/* ─── Stats Grid ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gray-900);
}

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--gray-200);
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}

.data-table tr:hover td {
  background: var(--gray-50);
}

.data-table tbody tr {
  cursor: pointer;
}

/* ─── Status Badges ────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}

.badge-pending {
  background: var(--yellow-100);
  color: var(--yellow-600);
}

.badge-running {
  background: var(--blue-100);
  color: var(--blue-600);
}

.badge-completed {
  background: var(--green-100);
  color: var(--green-700);
}

.badge-failed {
  background: var(--red-100);
  color: var(--red-700);
}

.badge-cancelled {
  background: var(--gray-200);
  color: var(--gray-500);
}

.badge-planning,
.badge-main_image,
.badge-detail_image,
.badge-sku_image,
.badge-exporting,
.badge-uploading {
  background: var(--blue-100);
  color: var(--blue-600);
}

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 4px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--gray-800);
  background: #fff;
  transition: border-color 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.form-row-4 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 16px;
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #fff;
  color: var(--gray-700);
  border-color: var(--gray-300);
}

.btn-secondary:hover {
  background: var(--gray-50);
}

.btn-danger {
  background: var(--red-600);
  color: #fff;
}

.btn-danger:hover {
  background: var(--red-700);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

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

/* ─── Toolbar ──────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar .form-input,
.toolbar .form-select {
  width: auto;
  min-width: 200px;
}

.ml-auto {
  margin-left: auto;
}

/* ─── Upload Zone ──────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--gray-400);
  cursor: pointer;
  transition: all 0.15s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.upload-zone svg {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
}

.upload-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.upload-item {
  position: relative;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.upload-item .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.upload-item .remove-btn:hover {
  background: rgba(220, 38, 38, 0.8);
}

/* ─── Variant/Spec Config ──────────────────────────────────────────────────── */
.config-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.config-row .form-input {
  flex: 1;
}

.config-row .btn {
  flex-shrink: 0;
}

.sku-result {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.sku-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 999px;
  font-size: 0.8rem;
}

/* ─── Detail Page ──────────────────────────────────────────────────────────── */
.detail-section {
  margin-bottom: 24px;
}

.detail-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-200);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-field-label {
  font-size: 0.8rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-field-value {
  font-size: 0.9rem;
  color: var(--gray-800);
  word-break: break-all;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.image-grid-item {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}

.image-grid-item img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}

.image-grid-item .image-label {
  padding: 6px 8px;
  font-size: 0.75rem;
  color: var(--gray-500);
  text-align: center;
  background: var(--gray-50);
}

/* ─── Loading ──────────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--gray-400);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ─── Pagination ───────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  padding: 16px 0;
}

.pagination .btn {
  min-width: 36px;
  justify-content: center;
}

.pagination-info {
  font-size: 0.8rem;
  color: var(--gray-500);
  padding: 0 8px;
}

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  min-width: 400px;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

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

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--gray-400);
}

.modal-close:hover {
  color: var(--gray-600);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ─── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 0.9rem;
}

/* ─── Toast ────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  animation: slideIn 0.2s ease;
  min-width: 280px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast-success { border-left: 3px solid var(--green-600); }
.toast-error { border-left: 3px solid var(--red-600); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ─── Progress Bar ─────────────────────────────────────────────────────────── */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--gray-200);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s;
}

/* ─── Job Timeline ─────────────────────────────────────────────────────────── */
.timeline {
  position: relative;
  padding-left: 20px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--gray-200);
}

.timeline-item {
  position: relative;
  padding-bottom: 16px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -17px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gray-300);
}

.timeline-item.active::before {
  background: var(--primary);
}

.timeline-item.completed::before {
  background: var(--green-600);
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    width: 56px;
  }

  .sidebar-brand span {
    display: none;
  }

  .sidebar-nav a span {
    display: none;
  }

  .main-area {
    margin-left: 56px;
  }

  .form-row,
  .form-row-3,
  .form-row-4 {
    grid-template-columns: 1fr;
  }

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

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .form-input,
  .toolbar .form-select {
    width: 100%;
    min-width: 0;
  }

  .ml-auto {
    margin-left: 0;
  }

  .modal {
    min-width: 0;
    width: 90%;
  }
}
