/* ============================================================
   APP COMPRA — Styles
   ============================================================ */

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

:root {
  --green:     #00833E;
  --green-lt:  #e6f4ee;
  --red:       #e74c3c;
  --gray-50:   #f8f9fa;
  --gray-100:  #f1f3f4;
  --gray-200:  #e0e0e0;
  --gray-400:  #9e9e9e;
  --gray-700:  #444;
  --white:     #fff;
  --radius:    12px;
  --shadow:    0 2px 12px rgba(0,0,0,.1);
  --header-h:  56px;
  --nav-h:     64px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body { height: 100%; background: var(--gray-50); font-family: var(--font); color: var(--gray-700); }

/* ---- Header ---- */
#app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--green);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.header-left { display: flex; align-items: center; gap: 4px; font-size: 1.15rem; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 8px; }
.btn-icon {
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 1.6rem; line-height: 1; padding: 4px 8px; border-radius: 8px;
  transition: background .15s;
}
.btn-icon:hover { background: rgba(255,255,255,.2); }

/* ---- Bottom nav ---- */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--white);
  display: flex;
  border-top: 1px solid var(--gray-200);
  box-shadow: 0 -2px 8px rgba(0,0,0,.08);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; gap: 2px;
  font-size: .72rem; color: var(--gray-400); padding: 6px 0;
  transition: color .15s;
}
.nav-btn.active { color: var(--green); }
.nav-btn .nav-icon { font-size: 1.4rem; }

/* ---- Main / views ---- */
#app-main {
  position: fixed; top: var(--header-h); bottom: var(--nav-h);
  left: 0; right: 0; overflow: hidden;
}
.view {
  position: absolute; inset: 0; overflow-y: auto;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  display: none;
}
.view.active { display: block; }

/* ============================================================
   LLISTES
   ============================================================ */
.list-card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px; overflow: hidden;
  cursor: pointer; transition: transform .1s;
}
.list-card:active { transform: scale(.99); }
.list-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-left: 5px solid var(--green);
}
.list-card-title { font-size: 1rem; font-weight: 600; }
.list-card-sub   { font-size: .78rem; color: var(--gray-400); margin-top: 2px; }
.list-card-body  { padding: 0 16px 14px; display: flex; align-items: center; gap: 16px; }
.list-progress-wrap { flex: 1; }
.list-progress-bar { height: 6px; background: var(--gray-200); border-radius: 3px; overflow: hidden; }
.list-progress-fill { height: 100%; background: var(--green); border-radius: 3px; transition: width .3s; }
.list-price  { font-size: .9rem; font-weight: 700; color: var(--green); white-space: nowrap; }
.list-actions { display: flex; gap: 6px; padding: 0 8px 8px; justify-content: flex-end; }
.btn-sm {
  font-size: .78rem; padding: 4px 12px; border-radius: 8px; border: none; cursor: pointer;
  transition: opacity .15s;
}
.btn-sm:hover { opacity: .8; }
.btn-sm.danger { background: #fdecea; color: var(--red); }

/* ============================================================
   LLISTA ACTIVA
   ============================================================ */
.list-header-info {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 12px;
}
.list-header-info select {
  flex: 1; padding: 8px 10px; border: 1px solid var(--gray-200);
  border-radius: 10px; font-size: .85rem; background: var(--white);
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  padding-right: 28px;
}
.price-badge {
  background: var(--green); color: #fff;
  font-weight: 700; font-size: 1rem;
  padding: 8px 14px; border-radius: 20px;
  white-space: nowrap; min-width: 80px; text-align: center;
}

/* Aisle group */
.aisle-group { margin-bottom: 8px; }
.aisle-label {
  font-size: .72rem; font-weight: 700; color: var(--gray-400);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 4px 4px 2px;
}

/* Item */
.list-item {
  background: var(--white); border-radius: var(--radius);
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; margin-bottom: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  transition: opacity .2s, background .15s;
  position: relative;
}
.list-item.checked { opacity: .45; }
.list-item.checked .item-name { text-decoration: line-through; }

.item-check {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--gray-200);
  background: var(--white);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 1rem; transition: all .15s;
}
.list-item.checked .item-check { background: var(--green); border-color: var(--green); color: #fff; }

/* Item thumbnail */
.item-thumb {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 8px; object-fit: contain;
  background: var(--gray-50); border: 1px solid var(--gray-100);
}
.item-thumb-placeholder {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 8px; background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}

.item-info { flex: 1; min-width: 0; }
.item-name { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: .75rem; color: var(--gray-400); margin-top: 2px; }

.item-qty-ctrl { display: flex; align-items: center; gap: 4px; }
.qty-btn {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--gray-200);
  background: var(--gray-50); cursor: pointer; font-size: 1rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .1s;
}
.qty-btn:hover { background: var(--gray-100); }
.qty-val { font-size: .9rem; font-weight: 600; min-width: 22px; text-align: center; }

.item-price { font-size: .85rem; font-weight: 600; color: var(--green); width: 52px; text-align: right; }

.item-delete {
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--gray-200); font-size: 1.1rem; line-height: 1;
  transition: color .15s;
}
.item-delete:hover { color: var(--red); }

/* FAB */
.fab-area { position: sticky; bottom: 8px; display: flex; justify-content: flex-end; pointer-events: none; }
.fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--green); color: #fff;
  border: none; font-size: 2rem; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,131,62,.4);
  display: flex; align-items: center; justify-content: center;
  pointer-events: all;
  transition: transform .15s, box-shadow .15s;
}
.fab:hover { transform: scale(1.07); box-shadow: 0 6px 20px rgba(0,131,62,.5); }

/* ============================================================
   CATÀLEG
   ============================================================ */
.search-bar { margin-bottom: 10px; }
.search-bar input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--gray-200);
  border-radius: var(--radius); font-size: .95rem; background: var(--white);
  outline: none; transition: border-color .15s;
}
.search-bar input:focus { border-color: var(--green); }

.category-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.category-chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 5px 12px; border-radius: 20px;
  border: 1.5px solid var(--gray-200); background: var(--white);
  font-size: .78rem; cursor: pointer; white-space: nowrap;
  transition: all .15s;
}
.chip.active { color: #fff; border-color: transparent; }

.cat-section { margin-bottom: 20px; }
.cat-section-header {
  display: flex; align-items: center; gap: 8px;
  font-size: .85rem; font-weight: 700; margin-bottom: 8px;
  color: var(--gray-700);
}
.cat-dot { width: 10px; height: 10px; border-radius: 50%; }

.catalog-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px;
}

.product-card {
  background: var(--white); border-radius: var(--radius);
  padding: 12px 10px; box-shadow: 0 1px 4px rgba(0,0,0,.07);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; text-align: center;
  transition: transform .1s, box-shadow .1s;
  position: relative;
}
.product-card:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.12); }
.product-card:active { transform: scale(.97); }
.product-card.in-list { border: 2px solid var(--green); }
.product-card.in-list::after {
  content: '✓'; position: absolute; top: 6px; right: 8px;
  font-size: .75rem; color: var(--green); font-weight: 700;
}
.product-img {
  width: 72px; height: 72px; object-fit: contain;
  border-radius: 8px; background: var(--gray-50);
}
.product-icon  { font-size: 1.8rem; }
.product-name  { font-size: .78rem; line-height: 1.3; font-weight: 500; color: var(--gray-700); }
.product-price { font-size: .78rem; color: var(--green); font-weight: 600; }

/* Wrapper de la imatge per permetre el badge */
.product-img-wrap { position: relative; display: inline-flex; align-items: center; justify-content: center; }

/* Badge 📷 quan no hi ha imatge */
.product-no-img-badge {
  position: absolute; bottom: -4px; right: -4px;
  font-size: .7rem; background: #fff3cd; border-radius: 50%;
  width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

/* Botó d'editar imatge — apareix en hover sobre la targeta */
.product-edit-img-btn {
  position: absolute; top: 5px; left: 5px;
  background: rgba(255,255,255,.9); border: none; border-radius: 6px;
  font-size: .75rem; padding: 2px 5px; cursor: pointer;
  opacity: 0; transition: opacity .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
  z-index: 2;
}
.product-card:hover .product-edit-img-btn { opacity: 1; }

/* ============================================================
   VISTA ORDENACIÓ
   ============================================================ */
.order-header { margin-bottom: 12px; }
.order-header label { display: block; font-size: .85rem; margin-bottom: 4px; font-weight: 600; }
.order-header select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--gray-200);
  border-radius: 10px; font-size: .9rem; background: var(--white);
}
.order-hint { font-size: .78rem; color: var(--gray-400); margin-top: 8px; }

.order-aisle-group { margin-bottom: 16px; }
.order-aisle-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--gray-400); margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
}
.order-aisle-input {
  border: none; background: transparent; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; color: var(--gray-400);
  width: 140px;
}

.order-item {
  background: var(--white); border-radius: 10px;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 5px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  cursor: grab; user-select: none;
}
.order-item:active { cursor: grabbing; }
.sortable-ghost { opacity: .3; background: var(--green-lt); }
.sortable-drag   { box-shadow: 0 8px 24px rgba(0,0,0,.18) !important; }
.drag-handle { font-size: 1.1rem; color: var(--gray-200); flex-shrink: 0; }
.order-item-thumb {
  width: 36px; height: 36px; border-radius: 6px;
  object-fit: contain; background: var(--gray-50);
  border: 1px solid var(--gray-100); flex-shrink: 0;
}
.order-item-icon  { font-size: 1.1rem; }
.order-item-name  { flex: 1; font-size: .88rem; }
.order-item-price { font-size: .78rem; color: var(--green); }

.order-save-bar {
  position: sticky; bottom: 0;
  background: var(--gray-50); padding: 12px 0 4px;
  display: flex; justify-content: center;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45);
  display: none; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-overlay.open { display: flex; }

@media (min-width: 480px) {
  .modal-overlay { align-items: center; padding: 20px; }
  .modal { border-radius: var(--radius) !important; }
}

.modal {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px;
  padding: 24px 20px 32px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 -4px 30px rgba(0,0,0,.15);
  max-height: 80vh; overflow-y: auto;
}
.modal h3 { font-size: 1.1rem; font-weight: 700; }
.modal input, .modal select {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--gray-200); border-radius: 10px;
  font-size: .95rem; outline: none;
  transition: border-color .15s;
}
.modal input:focus, .modal select:focus { border-color: var(--green); }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary, .btn-secondary {
  flex: 1; padding: 12px; border: none; border-radius: 10px;
  font-size: .95rem; font-weight: 600; cursor: pointer; transition: opacity .15s;
}
.btn-primary   { background: var(--green); color: #fff; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-primary:hover, .btn-secondary:hover { opacity: .85; }

/* ============================================================
   TOAST
   ============================================================ */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 9px 18px;
  border-radius: 20px; font-size: .85rem;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 300; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   MISCEL·LANI
   ============================================================ */
.total-banner {
  text-align: center; padding: 48px 20px;
  color: var(--gray-400); font-size: .95rem; line-height: 1.8;
}

.section-sep {
  height: 1px; background: var(--gray-200); margin: 8px 0;
}

/* Desktop layout */
@media (min-width: 768px) {
  #app-header { padding: 0 24px; }
  #app-main, .view { padding-left: 20px; padding-right: 20px; }
  .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
