.product-grid-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.category-tabs {
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--p-surface-200);
}

.cat-chip {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1.5px solid var(--p-surface-300);
  background: transparent;
  color: var(--p-surface-700);
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  transition: 0.2s;

  &.active {
    background: #1a237e;
    color: white;
    border-color: #1a237e;
  }

  &:hover:not(.active) {
    background: var(--p-surface-100);
  }
}

.products-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
  align-content: start;
}

.product-card {
  background: white;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  text-align: center;
  transition: 0.2s;
  border: 1.5px solid transparent;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);

  &:hover {
    border-color: #1a237e;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  &:active {
    transform: scale(0.97);
  }
}

.product-img {
  width: 60px;
  height: 60px;
  margin: 0 auto 6px;
  border-radius: 8px;
  background: var(--p-surface-100);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;

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

  i {
    font-size: 24px;
    color: var(--p-surface-400);
  }
}

.product-name {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--p-surface-800);
}

.product-price {
  font-size: 13px;
  font-weight: 700;
  color: #1a237e;
  margin-top: 4px;
}

.product-stock {
  font-size: 11px;
  margin-top: 2px;
  color: #4caf50;
  font-weight: 600;

  &.low {
    color: #ff9800;
  }

  &.out {
    color: #f44336;
  }
}

.empty-grid {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--p-surface-400);
}

.cat-count {
  font-size: 11px;
  opacity: 0.7;
  margin-inline-start: 2px;
}

.load-more-bar {
  flex-shrink: 0;
  padding: 8px 12px;
  text-align: center;
  border-top: 1px solid var(--p-surface-200);
}

.load-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 24px;
  border: 1.5px solid var(--p-surface-300);
  border-radius: 20px;
  background: transparent;
  color: var(--p-surface-600);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;

  &:hover:not(:disabled) {
    background: #1a237e;
    color: white;
    border-color: #1a237e;
  }

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  .products-count {
    font-size: 11px;
    opacity: 0.7;
  }
}

// ===== Retail Mode =====
.product-grid-container.retail {
  background: #f5f6f8;
  padding: 24px;

  .category-tabs {
    gap: 8px;
    padding: 0 0 20px;
    border-bottom: none;
    overflow-x: auto;
    scrollbar-width: none;
    &::-webkit-scrollbar { display: none; }
  }

  .cat-chip {
    padding: 8px 16px;
    border-radius: 9999px;
    border: 1px solid #e2e8f0;
    font-size: 14px;
    font-weight: 500;
    background: #fff;
    color: #64748b;

    &.active {
      background: #0b50da;
      color: #fff;
      border-color: #0b50da;
    }

    &:hover:not(.active) {
      background: #f8fafc;
    }
  }

  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    padding: 0;
  }

  .product-card {
    background: #fff;
    border-radius: 12px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: none;
    text-align: start;

    &:hover {
      border-color: #0b50da;
      transform: none;
      box-shadow: none;
    }

    &:active {
      transform: none;
    }
  }

  .product-img {
    width: 100%;
    height: 0;
    padding-bottom: 100%; // aspect-square
    margin: 0 0 12px;
    border-radius: 8px;
    background: #f1f5f9;
    position: relative;

    img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.2s;
    }

    i {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 32px;
      color: #94a3b8;
    }
  }

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

  .product-name {
    font-size: 14px;
    font-weight: 500;
    color: #1e293b;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
  }

  .product-price {
    font-size: 15px;
    font-weight: 700;
    color: #0b50da;
    margin-top: 4px;
  }

  .product-stock {
    display: none;
  }
}

// Dark mode
:host-context(.dark) {
  .product-card {
    background: rgba(255, 255, 255, 0.05);
  }

  .product-name {
    color: white;
  }

  .product-grid-container.retail {
    background: var(--p-surface-950);

    .cat-chip {
      background: rgba(255, 255, 255, 0.08);
      color: #90caf9;

      &.active {
        background: #283593;
        color: #fff;
      }
    }

    .product-card {
      background: var(--p-surface-900);

      &:hover {
        border-color: #5c6bc0;
      }
    }

    .product-img {
      background: rgba(255, 255, 255, 0.05);
    }

    .product-name {
      color: #e0e0e0;
    }
  }
}
