@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e4e8f0;
  --border-focus: #4361ee;
  --text: #1a1d2e;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --accent: #4361ee;
  --accent-hover: #3451d1;
  --accent-light: #eef1fd;
  --green: #16a34a;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --yellow: #ca8a04;
  --yellow-light: #fef9c3;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Layout ─── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
}

.logo-icon {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 18px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
}

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ─── Login Page ─── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #eef1fd 0%, #f4f6fa 100%);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 36px 32px;
}

.auth-header {
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo {
  font-size: 40px;
  margin-bottom: 8px;
  display: inline-block;
}

.auth-header h2 {
  font-size: 24px;
  font-weight: 700;
}

.auth-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
  transition: all 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

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

.stat-box {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
}

.stat-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.stat-val {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.stat-lbl {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.admin-section {
  padding: 24px;
}

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

/* ─── Modals ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.2s ease;
}

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

@keyframes popIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ─── Panels / Cards ─── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* ─── Upload Panel ─── */
.upload-panel {
  padding: 32px;
}

.upload-panel h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.upload-panel .subtitle {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 14px;
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 52px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--surface-2);
  position: relative;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}

.drop-zone.drag-over {
  transform: scale(1.01);
}

.drop-zone input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-zone-icon {
  font-size: 48px;
  margin-bottom: 12px;
  display: block;
}

.drop-zone-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.drop-zone-hint {
  font-size: 13px;
  color: var(--text-muted);
}

/* File previews */
.previews {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.preview-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-item .remove-btn,
.modal-header .remove-btn {
  position: absolute;
  top: 3px; right: 3px;
  width: 22px; height: 22px;
  background: rgba(0,0,0,0.6);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

.modal-header .remove-btn {
  position: relative;
  top: 0; right: 0;
}

.preview-count {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* Settings row */
.settings-row {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Source selector */
.source-selector {
  display: flex;
  gap: 8px;
}

.source-btn {
  padding: 7px 16px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.source-btn:hover { border-color: var(--accent); color: var(--accent); }
.source-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* API key input */
.api-key-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.api-key-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-family: 'Inter', monospace;
  color: var(--text);
  background: var(--surface-2);
  min-width: 280px;
  transition: border-color 0.15s;
}

.api-key-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-xs);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(67,97,238,0.3); }
.btn-primary:disabled { background: var(--text-light); cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-success {
  background: var(--green);
  color: #fff;
}
.btn-success:hover { background: #15803d; }

.btn-sm { padding: 6px 14px; font-size: 13px; }

.start-btn {
  margin-top: 24px;
  width: 100%;
  justify-content: center;
  padding: 14px;
  font-size: 15px;
}

/* ─── Progress Panel ─── */
.progress-panel { padding: 28px 32px; }

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

.progress-title {
  font-size: 18px;
  font-weight: 700;
}

.progress-elapsed {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.progress-bar-track {
  height: 8px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #7c3aed);
  border-radius: 100px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
}

.stat-chip.found { background: var(--green-light); color: var(--green); }
.stat-chip.not-found { background: var(--surface-2); color: var(--text-muted); }
.stat-chip.errors { background: var(--red-light); color: var(--red); }
.stat-chip.total { background: var(--accent-light); color: var(--accent); }

/* ─── Results Panel ─── */
.results-panel { margin-top: 24px; }

.results-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.results-title {
  font-size: 16px;
  font-weight: 700;
}

.results-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Table */
.results-table-wrap {
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.results-table th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.results-table td {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  max-width: 260px;
}

.results-table tbody tr:hover { background: var(--surface-2); }
.results-table tbody tr:last-child td { border-bottom: none; }

/* Thumbnail cell */
.thumb-cell {
  width: 72px;
  padding: 6px 8px 6px 16px;
}

.thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  display: block;
}

.thumb-placeholder {
  width: 60px; height: 60px;
  border-radius: var(--radius-xs);
  border: 1px dashed var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 20px;
}

/* Status badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-success { background: var(--green-light); color: var(--green); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }
.badge-error { background: var(--red-light); color: var(--red); }
.badge-pending { background: var(--yellow-light); color: var(--yellow); }

/* Result link */
.result-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s;
}

.result-link:hover { color: var(--accent-hover); }

/* Price tag */
.price-tag {
  font-weight: 600;
  color: var(--green);
  font-size: 13px;
}

/* Result product image */
.result-product-img {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

/* Filename truncate */
.filename {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

/* ─── Done banner ─── */
.done-banner {
  padding: 20px 32px;
  background: var(--green-light);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.done-banner-text {
  display: flex;
  align-items: center;
  gap: 12px;
}

.done-banner-icon { font-size: 28px; }

.done-banner h3 { font-size: 16px; font-weight: 700; color: var(--green); }
.done-banner p { font-size: 13px; color: #166534; }

/* ─── Spinner ─── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

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

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

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

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .main-content { padding: 16px; }
  .app-header { padding: 0 16px; }
  .upload-panel { padding: 20px; }
  .settings-row { flex-direction: column; align-items: flex-start; }
  .api-key-input { min-width: 100%; }
  .results-header { flex-direction: column; align-items: flex-start; }
  .done-banner { flex-direction: column; }
}
