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

:root {
  --primary-color: #111827;
  --secondary-color: #6b7280;
  --background-color: #f8fafc;
  --surface-color: #ffffff;
  --border-color: #e5e7eb;
  --text-color: #1f2937;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  font-family: Arial, sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

/* ========================================
HEADER
======================================== */

header {
  background-color: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

header nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.5rem;

  display: flex;
  align-items: center;
  gap: 2rem;
}

header nav > a {
  order: 1;

  color: var(--primary-color);
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

header nav > a:hover {
  color: #374151;
}

/* ========================================
DESKTOP MENU STRUCTURE
======================================== */

#mobile-menu {
  display: contents;
}

/* ========================================
SEARCH
======================================== */

#product-search {
  order: 2;

  flex: 1;

  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#product-search label {
  position: absolute;

  width: 1px;
  height: 1px;

  padding: 0;
  margin: -1px;

  overflow: hidden;

  clip: rect(0, 0, 0, 0);

  white-space: nowrap;

  border: 0;
}

#product-search input {
  width: 100%;
  max-width: 500px;

  padding: 0.7rem 0.9rem;

  border: 1px solid var(--border-color);
  border-radius: 6px;

  background-color: var(--surface-color);
  color: var(--text-color);

  outline: none;
}

#product-search input:focus {
  border-color: var(--primary-color);
}

#product-search button {
  padding: 0.7rem 1rem;

  border: none;
  border-radius: 6px;

  background-color: var(--primary-color);
  color: #ffffff;

  font-weight: 600;

  transition: background-color 0.2s ease;
}

#product-search button:hover {
  background-color: #374151;
}

/* ========================================
HEADER ACTIONS
======================================== */

#header-actions {
  order: 3;

  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#cart-link {
  color: var(--text-color);
  text-decoration: none;

  font-size: 0.95rem;
  font-weight: 600;

  transition: color 0.2s ease;
}

#cart-link:hover {
  color: #6b7280;
}

/* ========================================
AUTH NAVIGATION
======================================== */

#auth-navigation {
  order: 4;

  display: flex;
  align-items: center;
  gap: 1.25rem;
}

#auth-navigation a,
#auth-navigation button {
  color: var(--text-color);

  text-decoration: none;

  font-size: 0.95rem;
  font-weight: 600;
}

#auth-navigation a {
  transition: color 0.2s ease;
}

#auth-navigation a:hover,
#auth-navigation button:hover {
  color: #6b7280;
}

#auth-navigation button {
  padding: 0;

  border: none;
  background: none;
}

/* ========================================
MENU BUTTON
======================================== */

#menu-toggle {
  display: none;

  min-width: 42px;
  min-height: 42px;

  padding: 0.5rem;

  border: 1px solid var(--border-color);
  border-radius: 6px;

  background-color: var(--surface-color);
  color: var(--text-color);

  font-size: 1.25rem;
  line-height: 1;

  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
}

#menu-toggle:hover {
  background-color: #f3f4f6;
  border-color: #9ca3af;
}

/* ========================================
MAIN STORE FRONT CONTENT
======================================== */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

main section {
  width: 100%;
}

main section h1 {
  margin-bottom: 2rem;

  color: var(--primary-color);
  font-size: 2rem;
  line-height: 1.2;
}

/* PRODUCT LOADER */

.products-loader {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 220px;
  color: var(--secondary-color);
}

.loader-spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: store-loader-spin 0.8s linear infinite;
}

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

.products-loader p {
  margin: 0;
}

.products-error {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--secondary-color);
  padding: 3rem 1rem;
}

/* ========================================
PRODUCT FILTERS
======================================== */

#product-filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;

  margin-bottom: 2.5rem;
  padding: 1.5rem;

  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

#product-filters > div {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#product-filters label {
  color: var(--text-color);
  font-size: 0.85rem;
  font-weight: 600;
}

#product-filters select,
#product-filters input {
  width: 100%;
  min-height: 42px;

  padding: 0.65rem 0.75rem;

  border: 1px solid var(--border-color);
  border-radius: 6px;

  background-color: var(--surface-color);
  color: var(--text-color);

  outline: none;
}

#product-filters select:focus,
#product-filters input:focus {
  border-color: var(--primary-color);
}

#product-filters > button {
  min-height: 42px;
  padding: 0.65rem 1rem;

  border-radius: 6px;

  font-size: 0.9rem;
  font-weight: 600;

  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}

#product-filters > button[type="submit"] {
  border: 1px solid var(--primary-color);
  background-color: var(--primary-color);
  color: #ffffff;
}

#product-filters > button[type="submit"]:hover {
  background-color: #374151;
  border-color: #374151;
}

#product-filters > button[type="button"] {
  border: 1px solid #b1b9c9;
  background-color: #afb9cc;
  color: #3b3737;
}

#product-filters > button[type="button"]:hover {
  background-color: #ffffff;
  color: #374151;
  border-color: #6b7280;
}

#filter-error {
  grid-column: 1 / -1;

  min-height: 1.25rem;

  color: #dc2626;
  font-size: 0.85rem;
  font-weight: 500;
}

/* ========================================
PRODUCT GRID
======================================== */

#product-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
}

.product-card {
  display: flex;
  flex-direction: column;

  overflow: hidden;

  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;

  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.product-card:hover {
  transform: translateY(-3px);

  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.product-image {
  width: 100%;
  height: 220px;

  display: block;

  object-fit: cover;

  background-color: #f3f4f6;
}

.product-info {
  display: flex;
  flex-direction: column;

  flex: 1;

  padding: 1.25rem;
}

.product-name {
  margin-bottom: 0.5rem;

  color: var(--primary-color);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.4;
}

.product-brand,
.product-category {
  color: var(--secondary-color);
  font-size: 0.85rem;
}

.product-brand {
  margin-bottom: 0.15rem;
}

.product-category {
  margin-bottom: 0.75rem;
}

.product-price {
  margin-bottom: 0.35rem;

  color: var(--primary-color);
  font-size: 1.1rem;
  font-weight: 700;
}

.product-stock {
  margin-bottom: 1rem;

  color: var(--secondary-color);
  font-size: 0.8rem;
}

.product-link {
  display: inline-block;

  margin-bottom: 0.75rem;

  color: var(--primary-color);
  font-size: 0.9rem;
  font-weight: 600;

  text-decoration: none;

  transition: color 0.2s ease;
}

.product-link:hover {
  color: #6b7280;
}

.add-to-cart {
  width: 100%;
  min-height: 42px;

  margin-bottom: 0.6rem;
  padding: 0.65rem 1rem;

  border: 1px solid var(--primary-color);
  border-radius: 6px;

  background-color: var(--primary-color);
  color: #ffffff;

  font-size: 0.9rem;
  font-weight: 600;

  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
}

.add-to-cart:hover {
  background-color: #374151;
  border-color: #374151;
}

.add-to-cart:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.wishlist-button {
  width: 100%;
  min-height: 40px;

  padding: 0.6rem 1rem;

  border: 1px solid var(--border-color);
  border-radius: 6px;

  background-color: #f3f4f6;
  color: var(--text-color);

  font-size: 0.85rem;
  font-weight: 600;

  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
}

.wishlist-button:hover {
  background-color: #ffffff;
  border-color: #9ca3af;
}

.wishlist-button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

#product-list > p {
  grid-column: 1 / -1;

  padding: 3rem 1.5rem;

  border: 1px solid var(--border-color);
  border-radius: 8px;

  background-color: var(--surface-color);

  color: var(--secondary-color);

  text-align: center;
  font-size: 0.95rem;
}

/* ========================================
PRODUCT PAGINATION
======================================== */

#pagination {
  margin-top: 2.5rem;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

#pagination span {
  color: var(--secondary-color);
  font-size: 0.9rem;
  font-weight: 600;
}

#pagination button {
  min-width: 90px;
  min-height: 40px;

  padding: 0.6rem 1rem;

  border: 1px solid var(--border-color);
  border-radius: 6px;

  background-color: var(--surface-color);
  color: var(--text-color);

  font-size: 0.85rem;
  font-weight: 600;

  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
}

#pagination button:hover {
  background-color: #f3f4f6;
  border-color: #9ca3af;
}

/* ========================================
FOOTER
======================================== */

footer {
  margin-top: 3rem;
  padding: 1.5rem;

  border-top: 1px solid var(--border-color);

  background-color: var(--surface-color);

  text-align: center;
}

footer p {
  color: var(--secondary-color);
  font-size: 0.85rem;
}

/* ========================================
RESPONSIVENESS
======================================== */

/* TABLET */

@media (max-width: 1024px) {
  header nav {
    gap: 1.25rem;
  }

  #product-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* PHONE */

@media (max-width: 768px) {
  header nav {
    flex-wrap: wrap;
    gap: 0;
  }

  /* STORE */

  header nav > a {
    order: 1;
    flex: 1;
  }

  /* MOBILE HEADER ACTIONS */

  #header-actions {
    order: 2;
    gap: 0.5rem;
  }

  #cart-link {
    display: flex;
    align-items: center;

    min-height: 42px;
    padding: 0.5rem 0.7rem;
  }

  /* MENU BUTTON */

  #menu-toggle {
    display: block;
  }

  /*
    IMPORTANT FIX:

    The mobile menu must ALWAYS appear
    BELOW the Store / Cart / Menu row.
  */

  #mobile-menu {
    order: 3;

    display: none;

    flex-basis: 100%;
    width: 100%;

    flex-direction: column;
    align-items: stretch;

    gap: 1rem;

    padding: 1rem 0 0;
  }

  #mobile-menu.menu-open {
    display: flex;
  }

  /* SEARCH */

  #product-search {
    order: initial;

    width: 100%;

    display: flex;
    flex-direction: column;
    align-items: stretch;

    gap: 0.5rem;
  }

  #product-search input {
    max-width: none;
  }

  #product-search button {
    width: 100%;
  }

  /* AUTH NAVIGATION */

  #auth-navigation {
    order: initial;

    display: flex;

    flex-direction: column;
    align-items: stretch;

    gap: 0;

    padding-top: 0.5rem;

    border-top: 1px solid var(--border-color);
  }

  #auth-navigation a,
  #auth-navigation button {
    width: 100%;

    padding: 0.85rem 0.5rem;

    text-align: left;
  }

  #auth-navigation a:hover,
  #auth-navigation button:hover {
    background-color: #f3f4f6;
    color: var(--text-color);
  }

  /* FILTERS */

  #product-filters {
    grid-template-columns: repeat(2, 1fr);
  }

  /* PRODUCTS */

  #product-list {
    grid-template-columns: 1fr;
  }
}

/* SMALL PHONES */

@media (max-width: 600px) {
  main {
    padding: 2rem 1rem;
  }

  main section h1 {
    font-size: 1.7rem;
  }

  #product-filters {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  .product-image {
    height: 200px;
  }

  .product-info {
    padding: 1rem;
  }

  #pagination {
    gap: 0.75rem;
  }
}
