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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #fff6e7;
  padding: 1rem;
  color: #4a3b25;
}

.app {
  max-width: 980px;
  margin: 0 auto;
}

/* HEADER */
.app-header {
  margin-bottom: 1.2rem;
}

.app-header h1 {
  font-size: 1.8rem;
  margin-bottom: 0.3rem;
}

.app-header p {
  font-size: 0.95rem;
  opacity: 0.8;
}

/* Cards y layout */
.card {
  background: #ffffff;
  padding: 1rem;
  border-radius: 14px;
  margin-bottom: 1.2rem;
  box-shadow: 0 3px 10px #0000001a;
}

.section-header {
  margin-bottom: 0.8rem;
}

.section-subtitle {
  font-size: 0.85rem;
  opacity: 0.7;
}

.layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1rem;
}

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

/* Toggle Categoría */
.categoria-toggle {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.cat-btn {
  flex: 1;
  padding: 0.6rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: #e8d5b5;
  font-weight: bold;
  font-size: 0.95rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s;
}

.cat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px #00000026;
}

.cat-btn.active {
  background: #ffbb55;
}

/* Botón ocultar catálogo */
.toggle-catalogo-btn {
  margin-top: 0.6rem;
}

/* Buscador */
.buscador-input {
  width: 100%;
  padding: 0.6rem;
  margin-bottom: 0.4rem;
  border-radius: 10px;
  border: 1px solid #e0c7a3;
  font-size: 0.9rem;
}

/* Filtro favoritos */
.catalog-filters {
  font-size: 0.8rem;
  margin-bottom: 0.6rem;
}

.catalog-filters label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Catálogo */
.catalog-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
}

.product-card {
  position: relative;
  border-radius: 12px;
  background: #fffaf2;
  cursor: pointer;
  overflow: hidden;
  border: 1px solid #e6d3af;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 3px 10px #00000026;
}

.product-image-wrapper {
  width: 100%;
  height: 120px;
  overflow: hidden;
  border-radius: 10px 10px 0 0;
  background: #f8f8f8;
  display: flex;
  justify-content: center;
  align-items: center;
}

.product-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
}

.product-body {
  padding: 0.5rem 0.6rem 0.7rem;
}

.product-name {
  font-weight: bold;
  margin-bottom: 0.2rem;
}

.product-meta {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Botón favoritos */
.fav-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  border: none;
  background: #ffffffcc;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  color: #c7a019;
  box-shadow: 0 1px 3px #00000033;
}

.fav-btn.fav-active {
  background: #ffd966;
  color: #805200;
}

/* LISTA */
.list-header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}

.list-actions {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

@media (max-width: 600px) {
  .list-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .list-actions {
    flex-direction: row;
    width: 100%;
    flex-wrap: wrap;
  }
  .list-actions button {
    flex: 1 1 45%;
  }
}

.lista-bloque {
  margin-bottom: 1.4rem;
}

.lista-subtitulo {
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
  font-weight: bold;
  color: #6e5427;
}

/* Lista ul */
.lista {
  list-style: none;
  margin: 0;
  padding: 0;
  background: #fffdf8;
  border-radius: 8px;
  border: 1px solid #ebd8b9;
}

/* Item */
.item {
  padding: 0.6rem;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #f0e4cf;
  transition: background-color 0.3s ease, opacity 0.3s ease;
}

.item:last-child {
  border-bottom: none;
}

.item-main {
  flex: 1;
}

.item-nombre {
  font-weight: bold;
  margin-bottom: 0.25rem;
}

.badge {
  background: #ffdb92;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.7rem;
  margin-left: 4px;
}

/* Pendientes / comprados visual */
.item-comprado {
  background: #e8e8e8;
  opacity: 0.8;
}

.item-comprado .item-nombre {
  text-decoration: line-through;
  color: #666;
}

.item-comprado .item-nombre::before {
  content: "✔ ";
  color: #1f7a1f;
  font-weight: bold;
}

/* Detalle cantidad/unidad/precio */
.item-detalle-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.item-detalle-row label {
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.item-detalle-row input,
.item-detalle-row select {
  width: 80px;
  padding: 0.25rem;
  border-radius: 6px;
  border: 1px solid #e0c7a3;
  font-size: 0.8rem;
}

/* Acciones item */
.item-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-left: 0.6rem;
}

/* Form manual */
.manual-form {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.manual-form input {
  flex: 1;
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
  border: 1px solid #e0c7a3;
  font-size: 0.9rem;
}

.btn-small {
  font-size: 0.85rem;
  padding: 0.3rem 0.7rem;
}

@media (max-width: 600px) {
  .manual-form {
    flex-direction: column;
  }

  .manual-form button {
    width: 100%;
  }
}

/* Botones */
.btn-primary {
  background: #ffa733;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: none;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.btn-secondary {
  background: #c7b292;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
}

.btn-danger {
  background: #ff6b6b;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
}

.btn-success {
  background: #22a06b;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Stats rápidas */
.stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat {
  background: #fff0d1;
  padding: 0.4rem;
  border-radius: 6px;
  text-align: center;
  flex: 1;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  opacity: 0.7;
}

.stat-value {
  font-size: 1rem;
  font-weight: bold;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: #00000066;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
}

.modal.oculto {
  display: none;
}

.modal-contenido {
  background: #ffffff;
  padding: 1rem;
  border-radius: 12px;
  width: 340px;
  max-width: 95%;
  box-shadow: 0 4px 16px #00000044;
}

.modal-producto-nombre {
  font-weight: bold;
  margin-bottom: 0.7rem;
}

.modal-grid {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.modal-grid label {
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1 1 90px;
}

.modal-grid input,
.modal-grid select {
  width: 100%;
  max-width: 100%;
  padding: 0.25rem 0.4rem;
  border-radius: 8px;
  border: 1px solid #e0c7a3;
  font-size: 0.9rem;
  box-sizing: border-box;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Colapsable comprados */
.collapsible {
  cursor: pointer;
  user-select: none;
}

.lista.oculta {
  display: none;
}

/* Sección historial */
.history-section {
  margin-top: 0.5rem;
}

.history-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.6rem;
}

.history-controls label {
  font-size: 0.85rem;
}

.history-controls select,
.history-controls input[type="date"] {
  margin-left: 0.3rem;
  padding: 0.25rem 0.4rem;
  border-radius: 8px;
  border: 1px solid #e0c7a3;
  font-size: 0.85rem;
}

.history-summary {
  font-size: 0.85rem;
}

.history-summary table {
  width: 100%;
  border-collapse: collapse;
}

.history-summary th,
.history-summary td {
  border-bottom: 1px solid #f0e4cf;
  padding: 0.3rem 0.2rem;
  text-align: left;
  font-size: 0.8rem;
}

.history-summary th {
  font-weight: 600;
}

/* Gráficos del historial */
.history-charts {
  margin-top: 0.8rem;
  font-size: 0.8rem;
}

.chart-block h4 {
  margin-bottom: 0.3rem;
}

.chart-bars {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chart-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.chart-label {
  flex: 0 0 90px;
}

.chart-bar-wrapper {
  flex: 1;
  background: #f3e0c4;
  border-radius: 999px;
  overflow: hidden;
  height: 10px;
}

.chart-bar {
  height: 100%;
  border-radius: 999px;
  background: #ffa733;
}

.chart-value {
  flex: 0 0 60px;
  text-align: right;
}

/* Extra acciones historial */
.history-extra-actions {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.backup-input-label {
  font-size: 0.8rem;
  border-radius: 999px;
  border: 1px solid #c7b292;
  padding: 0.35rem 0.7rem;
  background: #fffaf2;
  cursor: pointer;
}

.backup-input-label input {
  display: none;
}

/* Footer */
.app-footer {
  margin-top: 0.8rem;
  font-size: 0.75rem;
  display: flex;
  justify-content: space-between;
  color: #7a6848;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.online-pill {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid #c7b292;
}

.online-pill.offline {
  background: #ffd4d4;
  border-color: #ff8b8b;
  color: #a33;
}

.footer-theme-btn {
  margin-left: 0.4rem;
}

/* Ocultar bloques */
.hidden-block {
  display: none !important;
}

/* Botón guardar historial bajo la lista */
.guardar-historial-lista-btn {
  margin-top: 0.4rem;
}
