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

:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e4e9f0;
  --text: #1a2332;
  --muted: #6b7a8f;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
}

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

.hidden { display: none !important; }

/* TOPBAR */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 22px; }
.brand .name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }

.status-area { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

#meliStatusContainer {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.meli-site-block {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  background: #f1f5f9;
  font-size: 12px;
  font-weight: 500;
}
.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.status-pill.ok .dot { background: var(--success); box-shadow: 0 0 0 3px rgba(16,185,129,0.15); }
.status-pill.error .dot { background: var(--danger); }

/* BUTTONS */
.btn {
  border: none;
  padding: 9px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }

/* CONTAINER */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px;
}

/* SEARCH CARD */
.search-card {
  background: var(--card);
  border-radius: 12px;
  padding: 32px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.search-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--muted);
  margin-bottom: 24px;
  max-width: 720px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr 180px 140px;
  gap: 12px;
}
.search-row input,
.search-row select {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.search-row input:focus,
.search-row select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.hint {
  margin-top: 16px;
  padding: 12px 16px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: 13px;
  color: #78350f;
}
.hint a { color: #92400e; font-weight: 600; }
.hint code {
  background: #fbbf24;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* RESULTS */
.results-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.results-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.results-header h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 2px;
}
.muted { color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
th, td {
  padding: 12px 16px;
  text-align: left;
  vertical-align: middle;
}
th {
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
th.num, td.num { text-align: right; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: ' ⇅'; opacity: 0.4; }
th.sortable.asc::after { content: ' ↑'; opacity: 1; color: var(--primary); }
th.sortable.desc::after { content: ' ↓'; opacity: 1; color: var(--primary); }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:hover { background: #f8fafc; }

.product-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 420px;
}
.product-cell img {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: #f1f5f9;
  flex-shrink: 0;
}
.product-cell .info { min-width: 0; }
.product-cell .title {
  font-weight: 500;
  font-size: 13px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  text-decoration: none;
}
.product-cell .title:hover { color: var(--primary); }
.product-cell .id {
  font-size: 11px;
  color: var(--muted);
  font-family: 'SF Mono', monospace;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.badge.green { background: #d1fae5; color: #065f46; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.gray { background: #f1f5f9; color: var(--muted); }
.badge.gold { background: #fef3c7; color: #92400e; }
.badge.platinum { background: #e0e7ff; color: #3730a3; }
.badge.fire {
  background: linear-gradient(135deg, #fef3c7 0%, #fed7aa 100%);
  color: #c2410c;
  border: 1px solid #fed7aa;
  font-weight: 700;
  font-size: 11px;
}

.rating-cell {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  color: #b45309;
}
.rating-count {
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
}

/* LOADING */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e4e9f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadingText { font-weight: 500; color: var(--muted); }
