/*
 * NJ External Products Sync — Frontend Styles
 * Depends on CSS custom properties injected by the shortcode renderer:
 *   --njeps-radius, --njeps-primary, --njeps-btn, --njeps-btn-hover
 */

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
.njeps-container *,
.njeps-container *::before,
.njeps-container *::after {
  box-sizing: border-box;
}

.njeps-container {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  color: #2c3e50;
  margin: 0;
  padding: 0;
}

/* ── Grid ─────────────────────────────────────────────────────────────────── */
.njeps-grid {
  display: grid;
  gap: 24px;
}

.njeps-grid-cols-1 { grid-template-columns: 1fr; }
.njeps-grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.njeps-grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.njeps-grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.njeps-grid-cols-5 { grid-template-columns: repeat(5, 1fr); }
.njeps-grid-cols-6 { grid-template-columns: repeat(6, 1fr); }

/* Responsive breakpoints */
@media (max-width: 1200px) {
  .njeps-grid-cols-6 { grid-template-columns: repeat(4, 1fr); }
  .njeps-grid-cols-5 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .njeps-grid-cols-6,
  .njeps-grid-cols-5,
  .njeps-grid-cols-4 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  .njeps-grid-cols-6,
  .njeps-grid-cols-5,
  .njeps-grid-cols-4,
  .njeps-grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 420px) {
  .njeps-grid { grid-template-columns: 1fr !important; }
}

/* ── Product Card ─────────────────────────────────────────────────────────── */
.njeps-product-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: var(--njeps-radius, 12px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
  overflow: hidden;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Hover lift — only when .njeps-hover-enabled is present on the grid */
.njeps-hover-enabled .njeps-product-card:hover {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
  transform: translateY(-4px);
}

/* ── Badge ────────────────────────────────────────────────────────────────── */
.njeps-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  line-height: 1.4;
}

.njeps-badge-sale  { background: var(--njeps-primary, #2ecc71); }
.njeps-badge-stock { background: #e74c3c; top: 12px; left: auto; right: 12px; }

/* ── Card Image ───────────────────────────────────────────────────────────── */
.njeps-card-image-wrap {
  overflow: hidden;
  aspect-ratio: 1 / 1;
  background: #f8f9fa;
}

.njeps-card-image-wrap a {
  display: block;
  width: 100%;
  height: 100%;
}

.njeps-product-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease, opacity 0.4s ease;
  opacity: 0;
}

.njeps-product-img.njeps-img-loaded {
  opacity: 1;
}

.njeps-hover-enabled .njeps-product-card:hover .njeps-product-img {
  transform: scale(1.05);
}

/* ── Card Body ────────────────────────────────────────────────────────────── */
.njeps-card-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px;
  gap: 10px;
}

/* ── Product Name ─────────────────────────────────────────────────────────── */
.njeps-product-name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  /* Clamp to 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.njeps-product-name a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s;
}

.njeps-product-name a:hover {
  color: var(--njeps-primary, #2ecc71);
}

/* ── Price ────────────────────────────────────────────────────────────────── */
.njeps-product-price {
  font-size: 16px;
  font-weight: 700;
  color: #2c3e50;
  margin-top: auto;
  /* WooCommerce price_html uses <del> and <ins> */
}

.njeps-product-price del {
  color: #999;
  font-weight: 400;
  font-size: 14px;
  text-decoration: line-through;
  margin-right: 4px;
}

.njeps-product-price ins {
  color: #e74c3c;
  text-decoration: none;
}

/* ── Action Buttons ───────────────────────────────────────────────────────── */
.njeps-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.njeps-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: calc(var(--njeps-radius, 12px) * 0.6);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
  white-space: nowrap;
  border: 2px solid transparent;
  line-height: 1.2;
  flex: 1;
  min-width: 0;
  text-align: center;
}

/* Outline variant — "View Product" */
.njeps-btn-outline {
  background: transparent;
  color: #2c3e50;
  border-color: #dce1e7;
}

.njeps-btn-outline:hover {
  background: #f4f6f9;
  border-color: #b0b9c5;
  color: #2c3e50;
}

/* Primary variant — "Add to Cart" */
.njeps-btn-primary {
  background: var(--njeps-btn, #27ae60);
  color: #fff;
  border-color: var(--njeps-btn, #27ae60);
}

.njeps-btn-primary:hover {
  background: var(--njeps-btn-hover, #1e8449);
  border-color: var(--njeps-btn-hover, #1e8449);
  color: #fff;
  box-shadow: 0 4px 12px rgba(39, 174, 96, 0.35);
}

/* Disabled variant — out of stock */
.njeps-btn-disabled {
  background: #f4f4f4;
  color: #aaa;
  border-color: #e8e8e8;
  cursor: not-allowed;
  pointer-events: none;
  flex: 1;
  text-align: center;
  padding: 9px 16px;
  border-radius: calc(var(--njeps-radius, 12px) * 0.6);
  font-size: 13px;
  font-weight: 600;
  border: 2px solid transparent;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Skeleton Loading ─────────────────────────────────────────────────────── */
.njeps-skeleton-wrapper {
  display: grid;
  gap: 24px;
}

/* Mirror grid columns for skeleton */
.njeps-grid-cols-1 ~ .njeps-skeleton-wrapper { grid-template-columns: 1fr; }

/* We set the skeleton columns via JS to match the shortcode columns attr. */
.njeps-skeleton-card {
  border-radius: var(--njeps-radius, 12px);
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.njeps-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 37%, #f0f0f0 63%);
  background-size: 400% 100%;
  animation: njeps-shimmer 1.4s ease infinite;
  border-radius: 4px;
}

.njeps-skeleton-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 0;
}

.njeps-skeleton-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.njeps-skeleton-title { height: 18px; width: 80%; }
.njeps-skeleton-price { height: 20px; width: 50%; }
.njeps-skeleton-btn   { height: 38px; width: 100%; border-radius: 8px; }

@keyframes njeps-shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position:   0% 50%; }
}

/* ── Load More ────────────────────────────────────────────────────────────── */
.njeps-load-more-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 32px;
}

.njeps-load-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 32px;
  background: var(--njeps-btn, #27ae60);
  color: #fff;
  border: none;
  border-radius: calc(var(--njeps-radius, 12px) * 0.6);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, transform 0.15s;
  letter-spacing: 0.02em;
}

.njeps-load-more-btn:hover:not(:disabled) {
  background: var(--njeps-btn-hover, #1e8449);
  box-shadow: 0 4px 14px rgba(39, 174, 96, 0.3);
  transform: translateY(-1px);
}

.njeps-load-more-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

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

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

.njeps-page-info {
  font-size: 13px;
  color: #888;
  margin: 0;
}

/* ── Notices ──────────────────────────────────────────────────────────────── */
.njeps-notice {
  padding: 14px 18px;
  border-radius: var(--njeps-radius, 12px);
  font-size: 14px;
  line-height: 1.5;
}

.njeps-notice p { margin: 0; }

.njeps-notice--error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.njeps-notice--info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
}

/* ── Out-of-stock card dimming ────────────────────────────────────────────── */
.njeps-out-of-stock .njeps-card-image-wrap {
  opacity: 0.6;
  filter: grayscale(40%);
}

/* ── Elementor compatibility ──────────────────────────────────────────────── */
.elementor-widget-shortcode .njeps-container,
.elementor-shortcode .njeps-container {
  width: 100%;
}
