/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Arial', sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f8f9fa;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header Styles */
header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1rem 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.8rem;
  font-weight: bold;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 2rem;
}

.nav-links a {
  color: white;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 25px;
  transition: background-color 0.3s ease;
}

.nav-links a:hover,
.nav-links a.active {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  animation: fadeIn 0.3s ease;
}

.modal-content {
  background: white;
  margin: 5% auto;
  padding: 0;
  border-radius: 20px;
  width: 90%;
  max-width: 450px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideDown 0.3s ease;
  overflow: hidden;
}

.modal-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 2rem;
  text-align: center;
  position: relative;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.8rem;
}

.close {
  position: absolute;
  right: 20px;
  top: 20px;
  color: white;
  font-size: 2rem;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.close:hover {
  transform: scale(1.2);
}

.modal-body {
  padding: 2rem;
}

.auth-tabs {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
}

.auth-tab {
  flex: 1;
  padding: 0.8rem;
  border: none;
  background: #f8f9fa;
  border-radius: 10px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
}

.auth-tab.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #333;
}

.form-group input {
  width: 100%;
  padding: 0.8rem;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: 1rem;
  transition: border-color 0.3s ease;
}

.form-group input:focus {
  outline: none;
  border-color: #667eea;
}

.submit-btn {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(45deg, #ff6b6b, #ff8e8e);
  color: white;
  border: none;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

.forgot-password {
  text-align: center;
  margin-top: 1rem;
}

.forgot-password a {
  color: #667eea;
  text-decoration: none;
}

/* Main Content Layout */
main {
  padding: 2rem 0;
  flex: 1;
}

.page-title {
  text-align: center;
  font-size: 2.5rem;
  color: #2c3e50;
  margin-bottom: 2rem;
}

/* Main Content Grid with proper layout */
.main-content {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  margin-top: 2rem;
  align-items: start;
}

/* Proper sticky sidebar that follows scroll */
.filters-sidebar {
  background: white;
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  padding: 1.5rem;
  position: sticky;
  top: 120px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid #e9ecef;
  width: 280px;
  min-width: 280px;
  align-self: start;
}

/* Sidebar header */
.filters-sidebar h3 {
  font-size: 1.2rem;
  color: #2c3e50;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid #667eea;
  padding-bottom: 0.5rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: sticky;
  top: 0;
  background: white;
  z-index: 5;
}

/* Custom scrollbar */
.filters-sidebar::-webkit-scrollbar {
  width: 4px;
}

.filters-sidebar::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 2px;
}

.filters-sidebar::-webkit-scrollbar-thumb {
  background: #667eea;
  border-radius: 2px;
}

.filters-sidebar::-webkit-scrollbar-thumb:hover {
  background: #5a67d8;
}

.filter-section {
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.filter-section h4 {
  font-size: 0.95rem;
  color: #667eea;
  margin-bottom: 0.8rem;
  font-weight: 600;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.filter-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
}

.filter-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.2rem 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.filter-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #667eea;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
}

.filter-option label {
  cursor: pointer;
  font-size: 0.85rem;
  color: #555;
  flex: 1;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.3;
  max-width: calc(100% - 22px);
}

.filter-option label:hover {
  color: #667eea;
}

/* Price Range */
.price-range {
  margin: 0.8rem 0;
  width: 100%;
  overflow: hidden;
}

.price-inputs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
  width: 100%;
}

.price-inputs input {
  flex: 1;
  padding: 0.4rem;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 0.8rem;
  min-width: 0;
  max-width: 100%;
}

.price-inputs input:focus {
  outline: none;
  border-color: #667eea;
}

/* Search input in sidebar */
.filter-section input[type="text"] {
  width: 100%;
  max-width: 100%;
  padding: 0.8rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.85rem;
  box-sizing: border-box;
}

.filter-section input[type="text"]:focus {
  outline: none;
  border-color: #667eea;
}

/* Clear Filters Button */
.clear-filters-btn {
  width: 100%;
  max-width: 100%;
  padding: 0.7rem;
  background: linear-gradient(135deg, #ff6b6b, #ff5252);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 1rem;
  box-sizing: border-box;
}

.clear-filters-btn:hover {
  background: linear-gradient(135deg, #ff5252, #ff4444);
  transform: translateY(-2px);
}

/* Content Area */
.content-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

/* Controls Bar */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 1.5rem;
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.results-info {
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}

.results-count {
  font-size: 1rem;
  font-weight: 600;
  color: #667eea;
}

.items-per-page {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.items-per-page label {
  font-size: 0.9rem;
  color: #555;
  font-weight: 600;
}

.items-per-page select {
  padding: 0.5rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sort-controls select {
  padding: 0.5rem 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

/* Products Grid */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
  width: 100%;
  align-items: stretch;
}

@media (min-width: 1200px) {
  .products-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (min-width: 900px) and (max-width: 1199px) {
  .products-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Product Cards */
.product-card {
  background: white;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
  border: 1px solid #f0f0f0;
  height: 400px;
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}

.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0,0,0,0.15);
}

/* Use a fixed aspect ratio for images to avoid layout shifts */
.product-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  transition: all 0.3s ease;
  font-size: 4rem;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  display: block;
  cursor: pointer;
}

.product-image:hover {
  opacity: 0.9;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

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

/* Content inside card */
.product-card h3 {
  font-size: 1rem;
  margin: 0.6rem 1rem 0.3rem 1rem;
  color: #2c3e50;
  word-wrap: break-word;
}

.product-description {
  font-size: 0.75rem;
  color: #7f8c8d;
  margin: 0.3rem 1rem;
  line-height: 1.3;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-seller {
  font-size: 0.7rem;
  color: #666;
  margin: 0.2rem 0;
  padding: 0 1rem;
}

.product-seller a {
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
}

.product-seller a:hover {
  text-decoration: underline;
}

.product-price {
  font-weight: bold;
  color: #27ae60;
  font-size: 1rem;
  margin: 0.6rem 0;
  text-align: center;
}

.buy-button {
  background: linear-gradient(135deg, #ff6b6b, #ff5252);
  color: white;
  border: none;
  padding: 0.5rem 0.8rem;
  border-radius: 20px;
  cursor: pointer;
  margin: 0 1rem 1rem 1rem;
  font-size: 0.8rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
  width: calc(100% - 2rem);
  margin-top: auto;
  flex-shrink: 0;
}

.buy-button:hover {
  background: linear-gradient(135deg, #ff5252, #ff4444);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin: 2rem 0;
  flex-wrap: wrap;
}

.pagination button {
  padding: 0.8rem 1rem;
  border: 2px solid #e0e0e0;
  background: white;
  color: #555;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 600;
  min-width: 45px;
}

.pagination button:hover {
  border-color: #667eea;
  color: #667eea;
}

.pagination button.active {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border-color: transparent;
}

.pagination button:disabled {
  background: #f8f9fa;
  color: #ccc;
  cursor: not-allowed;
  border-color: #e9ecef;
}

.pagination .page-info {
  padding: 0.8rem 1rem;
  color: #555;
  font-size: 0.9rem;
}

/* Loading State */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4rem;
  font-size: 1.2rem;
  color: #667eea;
}

.loading::after {
  content: '⏳';
  margin-left: 0.5rem;
  animation: spin 1s linear infinite;
}

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

/* Empty State */
.empty-products {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  background: white;
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.empty-products-icon {
  font-size: 5rem;
  margin-bottom: 1.5rem;
  opacity: 0.5;
}

/* Footer */
footer {
  background-color: #2c3e50;
  color: white;
  text-align: center;
  padding: 2rem 0;
  margin-top: auto;
}

/* Filter Toggle for Mobile */
.filter-toggle {
  display: none;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  margin-bottom: 1rem;
  width: 100%;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideDown {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Image Modal - Full Picture Only */
#imageModal .modal-content {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  margin: 2% auto;
}

#imageModal .modal-header {
  display: none;
}

#imageModal .modal-body {
  padding: 0 !important;
  background: transparent;
}

#imageModal .close {
  position: fixed;
  top: 20px;
  right: 30px;
  font-size: 40px;
  color: white;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  z-index: 1001;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.5);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

#imageModal .close:hover {
  background: rgba(0, 0, 0, 0.8);
  transform: scale(1.1);
}

#imageModal #modalImage {
  border-radius: 0;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

/* Responsive Design */
@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .filters-sidebar {
    position: static;
    top: auto;
    width: 100%;
    max-width: 100%;
    max-height: none;
    display: none;
    margin-bottom: 2rem;
    align-self: auto;
  }

  .filter-toggle {
    display: block;
  }

  .filters-sidebar.show {
    display: block;
  }

  .products-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}

@media (max-width: 768px) {
  .nav-links {
    flex-direction: column;
    gap: 1rem;
  }

  .controls-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .results-info {
    justify-content: center;
  }

  .products-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }

  .pagination {
    gap: 0.3rem;
  }

  .pagination button {
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 15px;
  }

  .page-title {
    font-size: 2rem;
  }

  .filters-sidebar {
    padding: 1rem;
  }

  .products-grid {
    grid-template-columns: 1fr;
  }
  
  #imageModal .close {
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    font-size: 30px;
  }
}