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

body {
  font-family: system-ui, sans-serif;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  max-width: 600px;
  margin: 0 auto;
  background: #fff9f9;
  color: #222;
  -webkit-tap-highlight-color: transparent;
}

header { text-align: center; margin-bottom: 1rem; }
.logo { width: 48px; height: 48px; margin-bottom: 0.3rem; }
header h1 { font-size: 1.5rem; color: #E36B7A; }
header p { font-size: 0.85rem; color: #888; }

/* Buscador */
.buscador {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff9f9;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
}

#buscar {
  width: 100%;
  padding: 0.85rem;
  font-size: 1rem;
  border: 2px solid #F4A0A8;
  border-radius: 8px;
}
#buscar:focus { outline: none; border-color: #E36B7A; }

#resultados {
  list-style: none;
  position: absolute;
  width: 100%;
  background: #fff;
  border: 1px solid #f0d0d3;
  border-radius: 0 0 8px 8px;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  z-index: 10;
}
#resultados.visible { display: block; }
#resultados li {
  padding: 0.75rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid #fbeaea;
  font-size: 0.9rem;
}
#resultados li:active { background: #fef0f0; }

/* Tabla */
.lista-compra h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }

.total-bar {
  position: sticky;
  top: 60px;
  z-index: 15;
  background: #E36B7A;
  color: #fff;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: bold;
  text-align: right;
  margin-bottom: 0.5rem;
}

.empty-msg { text-align: center; color: #ccc; padding: 1rem 0; font-size: 0.9rem; }
.empty-msg.hidden { display: none; }

#tabla-lista {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
#tabla-lista th, #tabla-lista td {
  padding: 0.5rem 0.25rem;
  text-align: center;
  border-bottom: 1px solid #fbeaea;
}
#tabla-lista th { background: #E36B7A; color: #fff; }
#tabla-lista th:first-child, #tabla-lista td:first-child { text-align: left; }

.precio-unit { font-size: 0.75rem; color: #bbb; }

.btn-qty {
  width: 32px;
  height: 32px;
  border: 1px solid #F4A0A8;
  background: #fff;
  color: #E36B7A;
  font-size: 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  vertical-align: middle;
}
.btn-qty:active { background: #fef0f0; }

#tabla-lista input[type="number"] {
  width: 2.5rem;
  padding: 0.4rem 0;
  min-height: 32px;
  text-align: center;
  font-size: 1rem;
  border: 1px solid #F4A0A8;
  border-radius: 4px;
  vertical-align: middle;
  margin: 0 0.2rem;
}

.btn-eliminar {
  background: none;
  border: none;
  color: #E36B7A;
  font-size: 1.4rem;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

#btn-limpiar {
  margin-top: 1rem;
  width: 100%;
  padding: 0.85rem;
  font-size: 1rem;
  background: #E36B7A;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
#btn-limpiar:active { background: #c94d5c; }

/* Inventario */
.inventario-section { margin-top: 2rem; }
.inventario-section h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.inv-actions { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.inv-actions button {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.8rem;
  border: 1px solid #A3C960;
  background: #fff;
  color: #5a7a2a;
  border-radius: 6px;
  cursor: pointer;
}
.inv-actions button:active { background: #f0fbe0; }
.inventario-section details { margin-bottom: 0.3rem; }
.inventario-section summary {
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.7rem;
  min-height: 44px;
  cursor: pointer;
  background: #f0fbe0;
  color: #5a7a2a;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
}
.inventario-section summary::-webkit-details-marker { display: none; }
.inventario-section summary::after {
  content: "▼";
  font-size: 0.7rem;
  transition: transform 0.3s ease;
}
.inventario-section details[open] summary::after {
  transform: rotate(180deg);
}
.inventario-section details .inv-cat-table {
  overflow: hidden;
  animation: slideDown 0.3s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.inv-cat-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin: 0.3rem 0 0.5rem; }
.inv-cat-table td { padding: 0.4rem 0.5rem; border-bottom: 1px solid #f0f5e8; }
.inv-cat-table td:last-child { text-align: right; font-weight: 500; color: #5a7a2a; }
