*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: #f4f4f4;
  color: #222;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */

.cm-header {
  background-color: #1e40af;
  color: #fff;
  padding: 0.75rem 1rem;
  overflow-x: hidden;
  width: 100%;
  box-sizing: border-box;
}

.cm-header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
}

.cm-logo-wrap {
  width: auto;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cm-logo {
  height: 3rem;
  width: auto;
  display: block;
  object-fit: contain;
  max-width: 100%;
}

.cm-header-title {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 1.1rem;
  line-height: 1.2;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Ajustes para móviles */
@media (max-width: 640px) {
  .cm-header {
    padding: 0.5rem 0.5rem;
  }
  
  .cm-header-inner {
    gap: 0.3rem;
  }
  
  .cm-logo {
    height: 1.8rem;
  }
  
  .cm-header-title {
    font-size: 0.7rem;
    letter-spacing: 0.01em;
  }
}

/* Carrito */
.cm-cart-wrapper {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.cm-cart-btn {
  position: relative;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  transition: background-color 0.2s;
}

.cm-cart-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.cm-cart-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #dc2626;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  border: 2px solid #1e40af;
}

/* Botón agregar producto */
.cm-btn-add {
  background: #1e40af;
  color: white;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.5rem;
  font-weight: 600;
  flex-shrink: 0;
  transition: all 0.2s;
  padding: 0;
  margin-left: 0.5rem;
}

.cm-btn-add:hover {
  background: #1e3a8a;
  transform: scale(1.1);
}

.cm-btn-add:active {
  transform: scale(0.95);
}

.cm-btn-add-animate {
  animation: addPulse 0.3s ease;
}

@keyframes addPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); background: #10b981; }
  100% { transform: scale(1); }
}

/* Ajustar layout del precio para incluir botón */
.cm-product-price {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 0.75rem;
  width: 100%;
  margin-top: 0.25rem;
  flex-wrap: wrap;
}

/* Modal Carrito */
.cm-cart-modal {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.cm-cart-modal-content {
  background: white;
  border-radius: 1rem;
  padding: 1.5rem;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
}

.cm-cart-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #e5e7eb;
}

.cm-cart-summary-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.cm-cart-items-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  max-height: 400px;
  overflow-y: auto;
}

.cm-cart-item-summary {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.75rem;
  background: #f9fafb;
  border-radius: 0.5rem;
  gap: 1rem;
  position: relative;
}

.cm-cart-item-info {
  flex: 1;
  min-width: 0;
}

.cm-cart-item-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  word-break: break-word;
}

.cm-cart-item-details {
  font-size: 0.8rem;
  color: #666;
}

.cm-cart-item-price {
  font-weight: 600;
  color: #1e40af;
  white-space: nowrap;
}

.cm-cart-summary-footer {
  border-top: 2px solid #e5e7eb;
  padding-top: 1rem;
}

.cm-cart-summary-total {
  text-align: center;
  color: #1e40af;
}

/* Vista Detallada */
.cm-cart-detail-content {
  max-width: 700px;
}

.cm-cart-detail-content-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.cm-cart-detail-items {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
  max-height: 450px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.cm-cart-detail-item {
  padding: 1rem;
  background: #f9fafb;
  border-radius: 0.75rem;
  border: 2px solid #e5e7eb;
}

.cm-cart-detail-item-main {
  margin-bottom: 1rem;
}

.cm-cart-detail-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.cm-cart-detail-item-name {
  font-weight: 700;
  font-size: 1rem;
  color: #1e40af;
  flex: 1;
  word-break: break-word;
}

.cm-btn-remove {
  background: #fee2e2;
  color: #dc2626;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.25rem;
  font-weight: 600;
  flex-shrink: 0;
  transition: all 0.2s;
  padding: 0;
}

.cm-btn-remove:hover {
  background: #dc2626;
  color: white;
}

.cm-btn-remove-summary {
  background: #fee2e2;
  color: #dc2626;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.25rem;
  font-weight: 600;
  flex-shrink: 0;
  transition: all 0.2s;
  padding: 0;
}

.cm-btn-remove-summary:hover {
  background: #dc2626;
  color: white;
  transform: scale(1.1);
}

.cm-cart-detail-item-marca {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.25rem;
}

.cm-cart-detail-item-code {
  font-size: 0.8rem;
  color: #999;
}

.cm-cart-detail-item-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.cm-quantity-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  padding: 0.25rem;
}

.cm-btn-quantity {
  background: #1e40af;
  color: white;
  border: none;
  border-radius: 0.25rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.25rem;
  font-weight: 600;
  transition: all 0.2s;
  padding: 0;
}

.cm-btn-quantity:hover {
  background: #1e3a8a;
}

.cm-quantity-input {
  width: 50px;
  text-align: center;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  padding: 0;
  background: transparent;
}

.cm-cart-detail-item-total {
  text-align: right;
  flex: 1;
  min-width: 150px;
}

.cm-cart-detail-item-price-unit {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.25rem;
}

.cm-cart-detail-item-price-total {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1e40af;
}

.cm-cart-detail-totals {
  border-top: 2px solid #e5e7eb;
  padding-top: 1rem;
  margin-bottom: 1.5rem;
}

.cm-cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  font-size: 1rem;
}

.cm-cart-total-final {
  font-size: 1.3rem;
  font-weight: 700;
  color: #1e40af;
  border-top: 2px solid #e5e7eb;
  margin-top: 0.5rem;
  padding-top: 1rem;
}

.cm-cart-detail-actions {
  margin-top: auto;
}

/* Responsive */
@media (max-width: 640px) {
  .cm-cart-btn {
    width: 36px;
    height: 36px;
  }
  
  .cm-cart-btn svg {
    width: 20px;
    height: 20px;
  }

  .cm-btn-add {
    width: 32px;
    height: 32px;
    font-size: 1.25rem;
  }

  .cm-cart-modal-content {
    padding: 1rem;
    max-height: 95vh;
  }

  .cm-cart-items-list {
    max-height: 300px;
  }

  .cm-cart-detail-items {
    max-height: 350px;
  }

  .cm-cart-detail-item-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .cm-cart-detail-item-total {
    text-align: left;
  }

  .cm-product-price {
    flex-direction: column;
    align-items: flex-end;
  }
}

/* Main layout */

.cm-main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem 1rem 1.25rem;
}

/* Filters */

.cm-filters {
  background-color: #fff;
  border-radius: 0.75rem;
  padding: 0.75rem 0.9rem 0.95rem;
  margin-bottom: 0.9rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.cm-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: #dbeafe;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

.cm-filters-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.cm-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.cm-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
}

.cm-field input,
.cm-field select {
  border-radius: 999px;
  border: 1px solid #ddd;
  padding: 0.45rem 0.8rem;
  font-size: 0.9rem;
  outline: none;
}

.cm-field input:focus,
.cm-field select:focus {
  border-color: #1e40af;
  box-shadow: 0 0 0 1px rgba(30, 64, 175, 0.25);
}

.cm-filters-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .cm-filters-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.cm-filters-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cm-btn {
  border-radius: 999px;
  padding: 0.45rem 1.1rem;
  font-size: 0.9rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cm-btn-primary {
  background-color: #1e40af;
  color: #fff;
  border-color: #1e40af;
}

.cm-btn-primary:hover {
  filter: brightness(0.95);
}

.cm-btn-ghost {
  background-color: #fff;
  color: #444;
  border-color: #ddd;
}

.cm-btn-ghost:hover {
  background-color: #f3f4f6;
}

.cm-summary {
  margin-top: 0.55rem;
  font-size: 0.8rem;
  color: #555;
}

.cm-summary-tag {
  margin-left: 0.3rem;
  color: #1e40af;
}

/* Product list */

.cm-list {
  margin-bottom: 0.9rem;
}

.cm-product-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.cm-product-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.65rem;
  background-color: #fff;
  border: 2.5px solid #d1d5db;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.cm-product-main {
  width: 100%;
}

.cm-product-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  word-wrap: break-word;
  word-break: break-word;
  width: 100%;
}

.cm-product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  font-size: 0.68rem;
  color: #666;
  margin-top: 0.05rem;
}

.cm-product-tags {
  margin-top: 0.1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
}

.cm-tag {
  font-size: 0.65rem;
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  background-color: #dbeafe;
  color: #1e3a8a;
}

.cm-tag-muted {
  background-color: #e5e7eb;
  color: #374151;
}

.cm-product-price {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 0.75rem;
  width: 100%;
  margin-top: 0.25rem;
}

.cm-price-adicionales {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: flex-end;
  flex-shrink: 0;
}

.cm-price-main {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.cm-price-normal {
  font-size: 0.9rem;
  font-weight: 700;
}

.cm-price-offer {
  font-size: 0.9rem;
  font-weight: 800;
  color: #dc2626;
}

.cm-price-list {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.3rem;
}

.cm-price-list-strike {
  font-size: 0.7rem;
  color: #6b7280;
  text-decoration: line-through;
}

.cm-badge-offer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.02rem 0.35rem;
  border-radius: 999px;
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.cm-price-bulto {
  font-size: 0.65rem;
  color: #166534;
  background-color: #dcfce7;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  text-align: right;
  line-height: 1.2;
}

.cm-empty {
  text-align: center;
  font-size: 0.9rem;
  color: #666;
  padding: 1.2rem 0.5rem;
}

/* Pagination */

.cm-pagination {
  display: flex;
  justify-content: center;
}

.cm-pagination-inner {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background-color: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.cm-page-btn {
  font-size: 0.8rem;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  border: 1px solid #e5e7eb;
  text-decoration: none;
  color: #374151;
  cursor: pointer;
}

.cm-page-btn:hover {
  background-color: #f3f4f6;
}

.cm-page-btn-disabled {
  opacity: 0.55;
  cursor: default;
}

.cm-page-info {
  font-size: 0.8rem;
  color: #6b7280;
}

/* Footer */

.cm-footer {
  font-size: 0.75rem;
  color: #6b7280;
  text-align: center;
  padding: 0.5rem 1rem 0.9rem;
}

/* Modal de bienvenida */

.cm-modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  touch-action: none;
}

.cm-modal {
  width: 100%;
  max-width: 380px;
  margin: 0 1.5rem;
  background: linear-gradient(135deg, #ffffff 0%, #eff6ff 60%, #dbeafe 100%);
  border-radius: 1rem;
  padding: 1.1rem 1.2rem 1rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.45);
  border-top: 4px solid #1e40af;
}

.cm-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: #1e40af;
}

.cm-modal-text {
  font-size: 0.87rem;
  color: #4b5563;
  margin-bottom: 0.8rem;
  line-height: 1.4;
}

.cm-modal-actions {
  display: flex;
  justify-content: flex-end;
}

.cm-modal-hidden {
  display: none;
}

/* Evita scroll del fondo cuando el modal está abierto */
.cm-modal-open {
  overflow: hidden;
}
