:root {
  --primary: #d32f2f;
  --text: #1a1a1a;
  --muted: #666;
  --bg: #fff;
  --bg-alt: #f5f5f5;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: white;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
  text-decoration: none;
}

.site-header nav a {
  margin-left: 1.5rem;
  color: var(--text);
  text-decoration: none;
}

main { padding: 2rem; max-width: 1400px; margin: 0 auto; }

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

.hero h1 { font-size: 2.5rem; margin: 0 0 0.5rem; }
.hero p { color: var(--muted); margin: 0 0 2rem; }

.search-form {
  display: flex;
  max-width: 600px;
  margin: 0 auto;
  gap: 0.5rem;
}
.search-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
}
.search-form button {
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: white;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  list-style: none;
  padding: 0;
}
.cat-grid a {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-alt);
  border-radius: 4px;
  text-decoration: none;
  color: var(--text);
}
.cat-count { color: var(--muted); font-size: 0.9rem; }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.product-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  transition: box-shadow 0.15s;
}
.product-card:hover { box-shadow: var(--shadow); }
.card-link { text-decoration: none; color: inherit; display: block; }
.card-img {
  aspect-ratio: 1;
  background: var(--bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-img img { width: 100%; height: 100%; object-fit: contain; }
.placeholder { color: var(--muted); font-size: 0.9rem; }
.placeholder-lg { min-height: 400px; }
.card-body { padding: 0.75rem; }
.card-title {
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  background: var(--bg-alt);
  border-radius: 3px;
  color: var(--muted);
}
.card-price { font-weight: 700; color: var(--primary); font-size: 1.1rem; }
.card-codigo { color: var(--muted); font-size: 0.75rem; }

.categoria-wrap { display: grid; grid-template-columns: 240px 1fr; gap: 2rem; }
.filtros { position: sticky; top: 80px; align-self: start; }
.filtros details { margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.filtros summary { font-weight: 600; cursor: pointer; padding: 0.25rem 0; }
.filtros ul { list-style: none; padding: 0.5rem 0 0 0; margin: 0; }
.filtros li { padding: 0.15rem 0; font-size: 0.9rem; }
.cat-total { color: var(--muted); }

.producto-detalle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  max-width: 1000px;
  margin: 0 auto;
}
.detalle-media { background: var(--bg-alt); border-radius: 8px; padding: 2rem; }
.detalle-media img { max-width: 100%; }
.detalle-info h1 { font-size: 1.5rem; margin: 0 0 1rem; }
.detalle-info .precio { font-size: 2rem; color: var(--primary); font-weight: 700; margin: 0.5rem 0; }
.detalle-info .codigo { color: var(--muted); }
.atributos { margin: 1.5rem 0; }
.atributos dt { font-weight: 600; margin-top: 0.75rem; }
.atributos dd { margin: 0.25rem 0 0; color: var(--muted); }
.btn-consultar {
  display: inline-block;
  margin-top: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: #25d366;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 600;
}

/* Meta de Pagefind: no lo mostramos, pero Pagefind lo lee del contenido */
.pagefind-meta { position: absolute; left: -9999px; width: 1px; height: 1px; }

/* Buscador principal + sugerencias */
.search-container { position: relative; max-width: 600px; margin: 0 auto; }
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  z-index: 20;
  max-height: 480px;
  overflow-y: auto;
}
.sug-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--bg-alt);
  gap: 1rem;
}
.sug-item:hover { background: var(--bg-alt); }
.sug-title { font-size: 0.9rem; line-height: 1.3; }
.sug-price { color: var(--primary); font-weight: 700; white-space: nowrap; }
.sug-more {
  display: block;
  padding: 0.75rem 1rem;
  text-align: center;
  background: var(--bg-alt);
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}
.sug-more:hover { background: #eee; }
.sug-empty { padding: 1rem; color: var(--muted); text-align: center; }

/* Página /buscar con filtros */
.buscar-wrap {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 2rem;
}
.resultados-col { min-width: 0; }
.buscar-header { margin-bottom: 1rem; }
.buscar-header .search-form { max-width: none; margin-bottom: 0.5rem; }
.results-count { color: var(--muted); font-size: 0.9rem; margin: 0; }
.results-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 0.75rem 0;
  flex-wrap: wrap;
}
.sort-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.sort-control select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  font-size: 0.9rem;
  cursor: pointer;
}
.filtros h2 { margin-top: 0; }
.filtros .hint { color: var(--muted); font-size: 0.9rem; }
.facet-list { list-style: none; padding: 0.5rem 0 0 0; margin: 0; max-height: 240px; overflow-y: auto; }
.facet-list li { padding: 0.1rem 0; font-size: 0.85rem; }
.facet-list label { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.facet-list .fval { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-list .fcount { color: var(--muted); font-size: 0.75rem; margin-left: auto; }
#limpiar-filtros {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
#loading, #empty { padding: 2rem; text-align: center; color: var(--muted); }

footer { padding: 2rem; text-align: center; color: var(--muted); border-top: 1px solid var(--border); }

@media (max-width: 720px) {
  .categoria-wrap { grid-template-columns: 1fr; }
  .producto-detalle { grid-template-columns: 1fr; }
  main { padding: 1rem; }
}
