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

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --accent: #f97316;
  --accent-light: #fff7ed;
  --green: #10b981;
  --green-bg: #ecfdf5;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --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;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --max-width: 1280px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  color: var(--gray-800);
  min-height: 100vh;
  line-height: 1.5;
}

/* Navbar */
.navbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
  background: rgba(255,255,255,0.95);
}

.navbar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.navbar-brand {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.navbar-brand svg {
  width: 28px;
  height: 28px;
}

.nav-mode {
  display: flex;
  background: var(--gray-100);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}

.nav-mode a {
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
  color: var(--gray-500);
}

.nav-mode a.active {
  background: var(--white);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.nav-mode a:hover:not(.active) {
  color: var(--gray-700);
}

/* Main */
.main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 24px;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 32px;
  align-items: start;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 96px;
}

.sidebar-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  border: 1px solid var(--gray-100);
}

.sidebar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  transition: all 0.2s;
  outline: none;
  font-family: inherit;
}

.form-input:focus {
  border-color: var(--primary);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
  font-family: inherit;
}

.form-select:focus {
  border-color: var(--primary);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.btn {
  width: 100%;
  padding: 11px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-danger {
  background: var(--red);
  color: var(--white);
}

.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.sidebar-divider {
  margin: 20px 0;
  border: none;
  border-top: 1px solid var(--gray-200);
}

/* Results header */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.results-count {
  font-size: 14px;
  color: var(--gray-500);
  font-weight: 500;
}

.results-count strong {
  color: var(--gray-800);
}

/* Product Grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}

.product-card {
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
  transition: all 0.25s ease;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

.product-image-wrapper {
  position: relative;
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  aspect-ratio: 1;
}

.product-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 16px;
  transition: transform 0.35s ease;
}

.product-card:hover .product-image-wrapper img {
  transform: scale(1.08);
}

.product-no-image {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--gray-300);
  gap: 8px;
}

.product-no-image svg {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

.product-no-image span {
  font-size: 12px;
  font-weight: 500;
}

.product-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}

.product-badge.in-stock {
  background: var(--green-bg);
  color: var(--green);
}

.product-badge.out-stock {
  background: var(--red-bg);
  color: var(--red);
}

.product-info {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.product-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-ref {
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.product-price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 8px;
}

.product-price {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
}

.product-cost {
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 500;
}

.product-stock-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 36px;
}

.page-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
  border: 1px solid var(--gray-200);
  background: var(--white);
  color: var(--gray-600);
}

.page-link:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.page-link.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

/* Product detail */
.detail-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 32px 24px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  margin-bottom: 20px;
  transition: all 0.2s;
}

.back-link:hover {
  color: var(--primary-dark);
}

.detail-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--gray-100);
}

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

.detail-image {
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  min-height: 400px;
}

.detail-image img {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.detail-image .product-no-image {
  transform: scale(2);
}

.detail-body {
  padding: 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1.3;
}

.detail-ref {
  font-size: 13px;
  color: var(--gray-400);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-price {
  font-size: 36px;
  font-weight: 800;
  color: var(--primary);
}

.detail-metrics {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.detail-metric {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  border: 1px solid var(--gray-100);
  flex: 1;
  min-width: 100px;
}

.detail-metric-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-metric-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-800);
}

.detail-metric-value.green { color: var(--green); }

.detail-section {
  padding-top: 16px;
  border-top: 1px solid var(--gray-100);
}

.detail-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.detail-description {
  font-size: 14px;
  color: var(--gray-600);
  line-height: 1.7;
  white-space: pre-line;
}

.detail-pricelist {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-pricelist select {
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  font-family: inherit;
  outline: none;
}

.detail-pricelist select:focus {
  border-color: var(--primary);
}

#pricelist-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

/* Variants table */
.detail-variants {
  padding: 36px;
  border-top: 1px solid var(--gray-200);
}

.variants-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 16px;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--gray-200);
}

thead th.right { text-align: right; }

tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

tbody td.right {
  text-align: right;
  font-weight: 600;
}

tr:last-child td { border-bottom: none; }

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

/* Footer */
.footer {
  border-top: 1px solid var(--gray-200);
  padding: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--gray-400);
  background: var(--white);
  margin-top: 60px;
}

/* Error page */
.error-container {
  max-width: 480px;
  margin: 100px auto;
  text-align: center;
}

.error-container h1 {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 12px;
}

.error-container p {
  color: var(--gray-500);
  margin-bottom: 24px;
  font-size: 15px;
}

.error-container .btn {
  display: inline-flex;
  width: auto;
}

/* Loading skeleton */
@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-50) 50%, var(--gray-100) 75%);
  background-size: 200px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

/* Responsive */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }

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

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

  .detail-image {
    min-height: 250px;
    padding: 20px;
  }

  .detail-image img {
    max-height: 250px;
  }

  .detail-body {
    padding: 24px;
  }

  .detail-price {
    font-size: 28px;
  }

  .detail-title {
    font-size: 22px;
  }
}

@media (max-width: 600px) {
  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .product-price {
    font-size: 16px;
  }

  .product-image-wrapper {
    aspect-ratio: 1;
  }

  .navbar-inner {
    padding: 0 16px;
  }

  .main {
    padding: 16px;
  }
}
