/* Main CSS - Loaded async after critical CSS
 * McMaster-Carr inspired dense, utilitarian styles
 */

/* ========================================
   CATEGORY PAGE LAYOUT - Tight sidebar + content
   ======================================== */

.category-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0;
  align-items: start;
}

@media (max-width: 800px) {
  .category-layout {
    grid-template-columns: 1fr;
  }
}

/* ========================================
   FILTERS SIDEBAR - Compact tree style
   ======================================== */

.filters {
  position: sticky;
  top: 48px;
  height: fit-content;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
  font-size: 0.85rem;
}

.filters::-webkit-scrollbar {
  width: 4px;
}

.filters::-webkit-scrollbar-track {
  background: transparent;
}

.filters::-webkit-scrollbar-thumb {
  background: var(--color-border);
}

.filters h2 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text);
  background: transparent;
  margin: 0;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
}

.filter-group {
  border-bottom: 1px solid var(--color-border-light);
}

.filter-group:last-of-type {
  border-bottom: none;
}

.filter-group summary {
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  background: var(--color-bg-subtle);
}

.filter-group summary::-webkit-details-marker {
  display: none;
}

.filter-group summary::after {
  content: '+';
  font-weight: bold;
  color: var(--color-text-muted);
}

.filter-group[open] summary::after {
  content: '−';
}

.filter-group ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.filter-group li {
  border-top: 1px solid var(--color-border-light);
}

.filter-group a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0.6rem 0.3rem 1rem;
  color: #0066cc;
  text-decoration: none;
  font-size: 0.8rem;
  transition: background 0.1s;
}

.filter-group a:hover {
  background: var(--color-row-hover);
  text-decoration: underline;
}

.filter-group a.active {
  background: var(--color-primary);
  color: #000;
  font-weight: 600;
}

.filter-group a.active:hover {
  text-decoration: none;
}

.filter-group .count {
  color: var(--color-text-light);
  font-size: 0.75rem;
}

.filter-group a.active .count {
  color: rgba(0,0,0,0.6);
}

.clear-filters {
  display: block;
  text-align: center;
  padding: 0.4rem;
  color: var(--color-error);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg-subtle);
}

.clear-filters:hover {
  background: var(--color-error-bg);
  text-decoration: underline;
}

/* Subcategory navigation */
.parent-link {
  color: #fff !important;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.parent-link:hover {
  color: var(--color-primary) !important;
}

.subcategory-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.subcategory-list li {
  border-bottom: 1px solid var(--color-border-light);
}

.subcategory-list li:last-child {
  border-bottom: none;
}

.subcategory-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.6rem;
  color: #0066cc;
  text-decoration: none;
  font-size: 0.85rem;
}

.subcategory-list a:hover {
  background: var(--color-row-hover);
  text-decoration: underline;
}

.subcategory-list li.active a {
  background: var(--color-primary);
  color: #000;
  font-weight: 600;
}

.subcategory-list li.active a:hover {
  text-decoration: none;
}

.subcategory-list .count {
  color: var(--color-text-light);
  font-size: 0.75rem;
}

.subcategory-list li.active .count {
  color: rgba(0,0,0,0.6);
}

.filters-heading {
  margin-top: 0.5rem !important;
}

/* Products section */
.products {
  padding: 0.5rem;
}

/* Products header */
.products-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--color-primary);
}

.products-header h1 {
  margin: 0;
  font-size: 1rem;
}

.result-count {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

/* ========================================
   PRODUCT DETAIL PAGE - Horizontal layout
   ======================================== */

.product-detail {
  display: flex;
  gap: 1rem;
  padding: 0.5rem;
}

.product-detail > .product-images {
  flex: 0 0 200px;
}

.product-detail > .product-info {
  flex: 1;
}

@media (max-width: 700px) {
  .product-detail {
    flex-direction: column;
  }
  .product-detail > .product-images {
    flex: none;
  }
}

/* Product Images - Smaller */
.product-images .main-image {
  width: 100%;
  height: auto;
  max-width: 200px;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  padding: 0.25rem;
}

.product-image-placeholder {
  width: 200px;
  height: 150px;
  border: 1px solid var(--color-border);
}

.thumbnails {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.thumb {
  padding: 0;
  border: 1px solid var(--color-border);
  cursor: pointer;
  background: var(--color-bg);
  transition: border-color 0.1s;
  overflow: hidden;
}

.thumb:hover {
  border-color: var(--color-text-muted);
}

.thumb.active {
  border-color: var(--color-primary);
  border-width: 2px;
}

.thumb img {
  display: block;
  width: 50px;
  height: 50px;
  object-fit: contain;
}

/* Product Info */
.product-info h1 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.product-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  background: var(--color-bg-subtle);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-light);
}

.product-meta dt {
  color: var(--color-text-muted);
}

.product-meta dd {
  margin: 0;
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.price-stock {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
}

.price-stock .price {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
}

.price-stock .stock {
  margin: 0;
}

/* Add to Cart Form - Compact */
.add-to-cart {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
}

.add-to-cart label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.add-to-cart .btn-primary {
  flex: 1;
  padding: 0.5rem 1rem;
}

/* Description & Specs */
.description,
.specifications {
  margin-top: 1rem;
}

.description h2,
.specifications h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fff;
  background: var(--color-header-bg);
  padding: 0.4rem 0.6rem;
  margin-bottom: 0;
}

.description p {
  color: var(--color-text);
  line-height: 1.5;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  margin: 0;
  border: 1px solid var(--color-border);
  border-top: none;
}

.specs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  border: 1px solid var(--color-border);
  border-top: none;
}

.specs-table tr {
  border-bottom: 1px solid var(--color-border-light);
}

.specs-table tr:last-child {
  border-bottom: none;
}

.specs-table th,
.specs-table td {
  padding: 0.35rem 0.6rem;
  text-align: left;
}

.specs-table th {
  width: 35%;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-bg-subtle);
  border-right: 1px solid var(--color-border-light);
}

.specs-table td {
  font-weight: 600;
}

/* Related products */
.related-products {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 2px solid var(--color-border);
}

.related-products h2 {
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

/* Related products as compact list */
.related-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--color-border);
}

.related-list li {
  border-bottom: 1px solid var(--color-border-light);
}

.related-list li:last-child {
  border-bottom: none;
}

.related-list a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.5rem;
  text-decoration: none;
}

.related-list a:hover {
  background: var(--color-row-hover);
}

.related-list img,
.related-thumb {
  width: 40px;
  height: 40px;
  object-fit: contain;
  background: var(--color-bg-subtle);
}

.related-list .info {
  flex: 1;
}

.related-list .name {
  color: #0066cc;
  font-size: 0.85rem;
}

.related-list a:hover .name {
  text-decoration: underline;
}

.related-list .price {
  font-weight: 600;
  font-size: 0.85rem;
}

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

.search-results-header {
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-primary);
}

.search-results-header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.no-results {
  text-align: center;
  padding: 2rem 1rem;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}

.no-results a {
  color: #0066cc;
  text-decoration: none;
}

.no-results a:hover {
  text-decoration: underline;
}

/* ========================================
   HOMEPAGE - Tight sidebar + content
   ======================================== */

.home-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0;
  align-items: start;
}

@media (max-width: 800px) {
  .home-layout {
    grid-template-columns: 1fr;
  }
}

.category-sidebar {
  border-right: 1px solid var(--color-border);
  position: sticky;
  top: 48px;
  height: calc(100vh - 48px);
  overflow-y: auto;
}

.category-sidebar h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #fff;
  background: #333;
  margin: 0;
  padding: 0.3rem 0.5rem;
}

.category-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.category-sidebar li {
  border-bottom: 1px solid var(--color-border-light);
}

.category-sidebar li:last-child {
  border-bottom: none;
}

.category-sidebar a {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0.5rem;
  color: #0066cc;
  text-decoration: none;
  font-size: 0.8rem;
}

.category-sidebar a:hover {
  background: var(--color-row-hover);
  text-decoration: underline;
}

.category-sidebar .count {
  color: var(--color-text-light);
  font-size: 0.75rem;
}

/* Main content area */
.home-content {
  padding: 0.5rem;
}

.home-content h1 {
  font-size: 1rem;
  margin: 0 0 0.25rem;
}

.welcome-text {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 0 0 0.5rem;
}

/* Category table on homepage */
.category-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--color-border);
}

.category-table th {
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  padding: 0.25rem 0.4rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
}

.category-table td {
  border: 1px solid var(--color-border-light);
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
}

.category-table tr:hover td {
  background: var(--color-row-hover);
}

.category-table a {
  color: #0066cc;
  text-decoration: none;
}

.category-table a:hover {
  text-decoration: underline;
}

/* ========================================
   ERROR PAGES
   ======================================== */

.error-page {
  text-align: center;
  padding: 3rem 1rem;
}

.error-page h1 {
  font-size: 2.5rem;
  color: var(--color-error);
  margin-bottom: 0.5rem;
}

.error-page p {
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}

/* ========================================
   CART NOTIFICATION - Compact
   ======================================== */

.cart-notification {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-add-btn);
  color: #fff;
  box-shadow: var(--shadow-md);
  transform: translateY(80px);
  opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
  z-index: 1000;
  font-size: 0.85rem;
  font-weight: 500;
}

.cart-notification.show {
  transform: translateY(0);
  opacity: 1;
}

/* ========================================
   FOCUS STATES (Accessibility)
   ======================================== */

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* ========================================
   RESPONSIVE TWEAKS
   ======================================== */

@media (max-width: 768px) {
  .header {
    flex-wrap: wrap;
    height: auto;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .search-form {
    order: 3;
    width: 100%;
    max-width: none;
  }

  .main {
    padding: 0.5rem;
  }

  .filters {
    position: static;
    max-height: none;
    margin-bottom: 1rem;
  }

  .product-images {
    position: static;
  }

  .product-table {
    font-size: 0.8rem;
  }

  .product-table th,
  .product-table td {
    padding: 0.3rem;
  }

  .product-table .product-thumb {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 600px) {
  /* Stack table cells on very small screens */
  .product-table thead {
    display: none;
  }

  .product-table tr {
    display: block;
    border: 1px solid var(--color-border);
    margin-bottom: 0.5rem;
    padding: 0.5rem;
  }

  .product-table td {
    display: block;
    border: none;
    padding: 0.2rem 0;
  }

  .product-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    display: block;
  }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
  .header,
  .footer,
  .filters,
  .add-to-cart,
  .cart-notification,
  .related-products,
  .accent-bar {
    display: none !important;
  }

  .main {
    padding: 0;
    max-width: none;
  }

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

  .product-images {
    max-width: 200px;
  }
}

/* ========================================
   SELECTION STYLES
   ======================================== */

::selection {
  background: rgba(244, 208, 63, 0.3);
  color: var(--color-text);
}

/* ========================================
   LANGUAGE SWITCHER
   ======================================== */

.lang-switcher {
  position: relative;
  display: inline-block;
}

.lang-current {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: opacity 0.15s;
}

.lang-current:hover {
  opacity: 0.8;
}

.lang-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 120px;
  z-index: 1000;
  border-radius: 4px;
  overflow: hidden;
}

.lang-switcher:hover .lang-dropdown,
.lang-switcher:focus-within .lang-dropdown {
  display: block;
}

.lang-option {
  display: block;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text);
  text-decoration: none;
  transition: background 0.15s;
}

.lang-option:hover {
  background: var(--color-bg-subtle);
}

.lang-option.active {
  background: var(--color-primary);
  color: var(--color-text);
  font-weight: 600;
}
