:root {
  --red-700: #8a120f;
  --red-600: #b41814;
  --red-500: #d1332c;
  --red-100: #f9e6e5;
  --accent-500: #b41814;
  --charcoal-900: #262626;
  --charcoal-700: #333333;
  --gray-500: #6b6b6b;
  --bg: #f7f7f6;
  --surface: #ffffff;
  --text: #262626;
  --text-muted: #6b6b6b;
  --border: #e3e3e2;
  --danger: #a83232;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(20, 20, 20, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { text-decoration: none; color: inherit; }

.hidden { display: none; }

/* Íconos Lucide (ver <script data-lucide> + lucide.createIcons() en app.js /
   admin.js): tamaño fijo y alineados con el texto de al lado. currentColor
   hace que hereden el color del botón/link/span que los contiene. */
.icon {
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  flex-shrink: 0;
}

.icon-spin { animation: icon-spin 0.8s linear infinite; }
@keyframes icon-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Header */
.site-header {
  background: var(--charcoal-900);
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.3rem;
  font-weight: 700;
}

.brand-logo {
  height: 36px;
  width: 36px;
  object-fit: contain;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.admin-link {
  font-size: 0.9rem;
  opacity: 0.9;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 6px 14px;
  border-radius: 20px;
  transition: background 0.15s;
}
.admin-link:hover { background: rgba(255,255,255,0.12); }

.cart-btn {
  position: relative;
  background: var(--accent-500);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 24px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.1s, box-shadow 0.15s;
}
.cart-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,0.15); }

.cart-count {
  background: var(--charcoal-700);
  color: #fff;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.page-title {
  margin: 0 0 4px;
  font-size: 1.6rem;
}
.page-subtitle {
  color: var(--text-muted);
  margin: 0 0 20px;
}

/* Filters */
.filters-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.search-wrap { position: relative; }

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.6;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--surface);
}
.search-input:focus { outline: 2px solid var(--red-500); }

/* Una sola fila con scroll horizontal: con 40+ categorías reales del catálogo,
   envolver en múltiples líneas (flex-wrap) empujaba el grid de productos muy
   abajo. */
.category-chips-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.category-chips-scroll {
  position: relative;
  flex: 1;
  min-width: 0;
}

.category-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-behavior: smooth;
  /* Barra nativa oculta a propósito: el difuminado + las flechas ya comunican
     que se puede desplazar, y así el contenedor mide justo lo de los chips,
     necesario para que las flechas centren bien verticalmente. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.category-chips::-webkit-scrollbar { display: none; }

/* Difuminado en los bordes: se activa por JS (updateChipScrollUI) solo del
   lado en el que sí hay chips ocultos, para que no sugiera scroll donde ya
   se llegó al final. */
.chip-fade {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.chip-fade-left { left: 0; background: linear-gradient(to right, var(--bg), transparent); }
.chip-fade-right { right: 0; background: linear-gradient(to left, var(--bg), transparent); }
.chip-fade.visible { opacity: 1; }

.chip-scroll-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.chip-scroll-btn:hover { border-color: var(--red-500); color: var(--red-700); }
.chip-scroll-btn.hidden { visibility: hidden; }

.category-chip {
  flex-shrink: 0;
  white-space: nowrap;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-muted);
  transition: all 0.15s;
}
.category-chip.active {
  background: var(--red-600);
  color: #fff;
  border-color: var(--red-600);
}
.category-chip:hover:not(.active) { border-color: var(--red-500); color: var(--red-700); }

/* Product grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 20px;
}

.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s;
}
.product-card:hover { transform: translateY(-3px); }

.product-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--red-100);
}

/* Skeleton screens: placeholders con la misma forma que .product-card
   mientras se espera la respuesta de /api/productos, en vez de dejar el
   grid en blanco. Puro CSS, sin librería. */
.skeleton-card { pointer-events: none; }

.skeleton {
  border-radius: 4px;
  background: linear-gradient(90deg, var(--border) 25%, var(--surface) 37%, var(--border) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.skeleton-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 0;
}

.skeleton-line { height: 12px; }

/* Transición al pasar de skeleton a contenido real: las tarjetas reales
   entran con un fade/slide corto apenas se pintan (se re-dispara solo, cada
   vez que renderProducts() reemplaza el HTML del grid). Las skeleton-card no
   la llevan, ya tienen su propia animación de shimmer. */
@keyframes card-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.product-card:not(.skeleton-card) {
  animation: card-fade-in 0.3s ease both;
}

.product-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.product-category {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--red-600);
  font-weight: 600;
}

.product-name {
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-presentation {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.product-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin: 0;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.product-price {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--red-700);
}

.add-btn {
  background: var(--red-600);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.add-btn:hover { background: var(--red-700); }
.add-btn:disabled { background: #c9c9c8; cursor: not-allowed; }

.stock-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.stock-tag.low { color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

/* Cart drawer */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
}
.overlay.open { opacity: 1; pointer-events: auto; }

.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 400px;
  max-width: 92vw;
  background: var(--surface);
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 21;
  display: flex;
  flex-direction: column;
}
.cart-drawer.open { transform: translateX(0); }

.cart-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cart-header h2 { margin: 0; font-size: 1.15rem; }

.cart-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
}

.cart-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.cart-item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--red-100);
}

.cart-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cart-item-name { font-weight: 600; font-size: 0.9rem; }
.cart-item-price { color: var(--text-muted); font-size: 0.82rem; }

.qty-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qty-control button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qty-control button .icon {
  width: 13px;
  height: 13px;
  vertical-align: 0;
}
.qty-control button:hover { background: var(--red-100); }
.qty-control button:disabled { cursor: not-allowed; opacity: 0.4; background: var(--surface); }

.cart-item-remove {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0;
}

.cart-item-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
}

.cart-disclaimer {
  padding: 0 20px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.cart-footer {
  padding: 18px 20px;
  border-top: 1px solid var(--border);
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.checkout-btn {
  width: 100%;
  background: var(--accent-500);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}
.checkout-btn:hover { filter: brightness(0.97); }

.cart-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

/* Admin */
.admin-body {
  background: var(--bg);
}

.admin-header {
  background: var(--charcoal-900);
}

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-primary { background: var(--red-600); color: #fff; }
.btn-primary:hover { background: var(--red-700); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--red-500); }

.admin-table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
}
.admin-table th, .admin-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.admin-table th {
  background: var(--red-100);
  color: var(--red-700);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--red-100);
}
.admin-table .empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 30px;
}

/* Botones con estado idle/loading: ambas variantes viven en el HTML y se
   alterna cuál se ve con .hidden, en vez de reescribir el innerHTML del
   botón desde JS. */
.btn-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
/* Modal (checkout, ver index.html) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,20,20,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  width: 480px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}

/* Overlay que cubre el modal mientras se envía el pedido: sin esto, el clic
   en "Confirmar pedido" no daba ninguna señal de que algo estaba pasando
   (parecía trabado) y era fácil hacer doble clic por error. */
.modal-loading {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: var(--radius);
  z-index: 5;
  font-weight: 600;
  color: var(--red-700);
}
.modal-loading.visible { display: flex; }
.modal-loading .icon { width: 28px; height: 28px; }

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }

.modal-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.form-group input, .form-group textarea, .form-group select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--red-700);
  color: #fff;
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 40;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat-card .label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; color: var(--red-700); margin-top: 4px; }

@media (max-width: 640px) {
  .site-header { padding: 0 14px; }
  .brand span.brand-text { display: none; }
  .container { padding: 16px; }
}
