/* ═══════════════════════════════════════════════════════════════════
   VARIABLES
═══════════════════════════════════════════════════════════════════ */
:root {
  --blue:        #1a73e8;
  --blue-dk:     #1557b0;
  --blue-lt:     #e8f0fe;
  --red:         #ea4335;
  --green:       #34a853;
  --orange:      #fa7b17;
  --bg:          #f1f3f4;
  --surface:     #ffffff;
  --text:        #202124;
  --text-2:      #5f6368;
  --text-3:      #9aa0a6;
  --border:      #dadce0;
  --shadow:      0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:   0 4px 12px rgba(0,0,0,.15);
  --radius:      12px;
  --radius-sm:   8px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --extra-top:   0px;

  /* category colours */
  --c-frutas:    #34a853;
  --c-carne:     #ea4335;
  --c-lacteos:   #fbbc04;
  --c-panaderia: #fa7b17;
  --c-despensa:  #795548;
  --c-congelados:#1a73e8;
  --c-bebidas:   #9334e6;
  --c-limpieza:  #00897b;
  --c-higiene:   #e91e8c;
  --c-otros:     #80868b;
}

/* en modo PWA standalone, añadir margen para la barra de estado */
@media (display-mode: standalone) {
  :root { --extra-top: 28px; }
}

/* ═══════════════════════════════════════════════════════════════════
   RESET / BASE
═══════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; font: inherit; }
a { color: inherit; text-decoration: none; }
input { font: inherit; }

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════
   HEADER (main list)
═══════════════════════════════════════════════════════════════════ */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 12px 0 16px;
  padding-top: max(var(--safe-top), var(--extra-top));
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hdr-left { display: flex; align-items: center; gap: 8px; }
.hdr-logo  { font-size: 22px; }
.hdr-title { font-size: 18px; font-weight: 600; color: var(--text); }
.hdr-right { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-2);
  transition: background .15s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--bg); }

/* ═══════════════════════════════════════════════════════════════════
   SHOPPING MODE BANNER
═══════════════════════════════════════════════════════════════════ */
#shop-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #fff3e0;
  border-bottom: 2px solid var(--orange);
  font-size: 14px;
  font-weight: 600;
  color: #e65100;
}
.btn-close-shop {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--orange);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════════
   FREQUENT BAR
═══════════════════════════════════════════════════════════════════ */
#frequent-bar {
  padding: 10px 16px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.freq-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-3);
  margin-bottom: 6px;
}
#freq-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 2px;
}

.freq-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.freq-chip:active { background: var(--bg); }
.freq-chip .chip-icon { font-size: 13px; }
.chip-img {
  width: 20px;
  height: 20px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.freq-chip-wrap {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  position: relative;
}
.freq-chip-opts {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 1px;
  margin-left: -4px;
  margin-top: -12px;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  transition: background .12s;
}
.freq-chip-opts:active { background: var(--border); }

/* ═══════════════════════════════════════════════════════════════════
   MAIN / PRODUCT LIST
═══════════════════════════════════════════════════════════════════ */
#main {
  padding: 12px 0 100px;
}

/* loading */
#loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 16px;
  color: var(--text-2);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* empty state */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 60px 32px;
  text-align: center;
}
.empty-icon  { font-size: 56px; }
.empty-title { font-size: 20px; font-weight: 600; }
.empty-sub   { font-size: 14px; color: var(--text-2); line-height: 1.6; }

/* category section */
.cat-section { margin-bottom: 6px; }

.cat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 4px;
}
.cat-header-icon  { font-size: 16px; }
.cat-header-name  { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.cat-header-count {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-2);
}

/* ── COMPACT PRODUCT CARD (normal mode) ───────────────────────── */
.product-card {
  display: flex;
  align-items: center;
  margin: 0 12px 5px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 52px;
  transition: opacity .2s;
}
.product-card.status-bought  { opacity: .42; }
.product-card.status-bought .card-name { text-decoration: line-through; color: var(--text-2); }
.product-card.status-not_found { background: #fff8e1; }
.product-card.status-not_found .card-name { color: #bf360c; }

.card-strip {
  width: 4px;
  align-self: stretch;
  flex-shrink: 0;
}

.card-thumb {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  margin-left: 8px;
}

.card-body {
  flex: 1;
  padding: 9px 6px 9px 11px;
  min-width: 0;
}
.card-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge-nofound {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: #ffe0b2;
  color: #bf360c;
  text-transform: uppercase;
}
/* cantidad en tarjeta */
.card-qty {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  background: var(--blue-lt);
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: -.3px;
  margin-right: 2px;
}

/* check button */
.card-btn-check {
  flex-shrink: 0;
  width: 44px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--green);
  transition: background .12s;
}
.card-btn-check:active { background: #e6f4ea; }

/* undo button (for already-bought items) */
.card-btn-undo {
  flex-shrink: 0;
  width: 44px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-3);
  transition: background .12s;
}
.card-btn-undo:active { background: var(--bg); }

/* more options button */
.card-btn-more {
  flex-shrink: 0;
  width: 36px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-3);
  letter-spacing: 1px;
  transition: background .12s;
}
.card-btn-more:active { background: var(--bg); }

/* ── SHOPPING MODE CARDS ────────────────────────────────────────── */
.shop-cat-divider {
  padding: 10px 16px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-3);
}

.shop-card {
  display: flex;
  align-items: center;
  margin: 0 12px 5px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 54px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s;
}
.shop-card:active { background: #f0f4ff; }

.shop-check-circle {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 6px;
}
.shop-check-circle svg {
  width: 24px;
  height: 24px;
  color: var(--border);
}

/* bought items in shopping mode */
.shop-bought-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--green);
  cursor: pointer;
}
.shop-bought-arrow { font-size: 11px; }

.shop-bought-list { margin-bottom: 8px; }

.shop-card-bought {
  display: flex;
  align-items: center;
  margin: 0 12px 4px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-height: 44px;
  opacity: .55;
}
.shop-undo-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: var(--blue);
}
.shop-undo-btn:active { opacity: .6; }

.card-name-bought {
  text-decoration: line-through;
  color: var(--text-2);
}

/* all done screen */
.shop-all-done {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 16px 24px;
}
.shop-done-icon { font-size: 48px; }
.shop-done-text { font-size: 20px; font-weight: 700; color: var(--green); }

/* ── ACTION SHEET ───────────────────────────────────────────────── */
.action-product-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  padding: 0 4px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.action-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 4px;
  font-size: 16px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background .12s;
  text-align: left;
}
.action-item:active { background: var(--bg); }
.action-item-icon { font-size: 18px; width: 24px; text-align: center; }
.action-item-danger { color: var(--red); }
.action-item:last-of-type { border-bottom: none; }

/* chip image search row */
.chip-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.chip-search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
}
.chip-search-input:focus { border-color: var(--blue); }
.chip-search-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.chip-search-btn:active { background: var(--blue-dk); }
.chip-search-btn:disabled { background: var(--border); }
.chip-search-status {
  padding: 6px 16px 2px;
  font-size: 12px;
  color: var(--text-3);
}

/* confirm delete */
.confirm-delete-text {
  font-size: 15px;
  color: var(--text);
  padding: 4px 0 16px;
  line-height: 1.5;
}
.btn-danger {
  display: block;
  width: 100%;
  padding: 15px;
  border-radius: var(--radius);
  background: var(--red);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  transition: opacity .15s;
}
.btn-danger:active { opacity: .85; }

/* ── EDIT MODAL — category grid ─────────────────────────────────── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 4px 0;
}
.cat-grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: var(--bg);
  transition: all .12s;
  cursor: pointer;
}
.cat-grid-item:active { opacity: .8; }
.cat-grid-icon { font-size: 20px; line-height: 1; }
.cat-grid-name {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-2);
  text-align: center;
  line-height: 1.3;
}
.cat-grid-item-active {
  border-color: var(--blue);
  background: var(--blue-lt);
}
.cat-grid-item-active .cat-grid-name { color: var(--blue); }

/* ── DUPLICATE WARNING ──────────────────────────────────────────── */
.dup-warning {
  background: #fff8e1;
  border: 1.5px solid #fbc02d;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  animation: fade-in .2s ease;
}
.dup-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.dup-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.dup-top strong { font-size: 14px; color: var(--text); display: block; }
.dup-hint { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.dup-btns { display: flex; gap: 8px; }
.btn-dup-primary {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  transition: opacity .12s;
}
.btn-dup-primary:active { opacity: .85; }
.btn-dup-ghost {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  transition: background .12s;
}
.btn-dup-ghost:active { background: var(--bg); }

/* ═══════════════════════════════════════════════════════════════════
   UNDO TOAST
═══════════════════════════════════════════════════════════════════ */
#undo-toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: #323232;
  color: #fff;
  border-radius: 28px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: slide-up .2s ease;
  white-space: nowrap;
}
#btn-undo {
  color: #8ab4f8;
  font-weight: 700;
  font-size: 14px;
}
@keyframes slide-up {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* freq-dup toast — aviso al añadir desde frecuentes */
.freq-dup-toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 12px;
  right: 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: slide-up .2s ease;
}
.freq-dup-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}
.freq-dup-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}
.freq-dup-btn-primary {
  flex: 1;
  padding: 9px 0;
  background: var(--blue);
  color: #fff;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.freq-dup-btn-ghost {
  flex: 1;
  padding: 9px 0;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
}
.freq-dup-btn-x {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-3);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   FAB
═══════════════════════════════════════════════════════════════════ */
#fab {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  right: 20px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(26,115,232,.45);
  z-index: 150;
  transition: transform .15s, box-shadow .15s;
}
#fab svg { width: 28px; height: 28px; }
#fab:active { transform: scale(.92); box-shadow: 0 2px 8px rgba(26,115,232,.3); }

/* ═══════════════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: flex-end;
}
.modal-backdrop, .sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
  animation: fade-in .2s ease;
}
.modal-sheet {
  position: relative;
  width: 100%;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  animation: sheet-up .25s ease;
}
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 4px auto 16px;
}
.modal-sheet h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

/* form elements in modal */
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
.form-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 8px;
  line-height: 1.5;
}
.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--blue); }

.share-row { display: flex; gap: 8px; align-items: center; }
.share-input { flex: 1; font-size: 13px; color: var(--text-2); }
.btn-icon-sm {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--blue-lt);
  color: var(--blue);
  transition: background .15s;
}
.btn-icon-sm svg { width: 20px; height: 20px; }
.btn-icon-sm:active { background: #c5d9fc; }

/* category picker in modal */
.cat-pick-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.cat-pick-item:active { background: var(--bg); }
.cat-pick-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.cat-pick-name { font-size: 15px; font-weight: 500; }
.cat-pick-check { margin-left: auto; color: var(--blue); font-size: 20px; }

/* ═══════════════════════════════════════════════════════════════════
   BUTTONS (shared)
═══════════════════════════════════════════════════════════════════ */
.btn-primary {
  display: block;
  width: 100%;
  padding: 15px;
  border-radius: var(--radius);
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  transition: background .15s, transform .1s;
}
.btn-primary:active { background: var(--blue-dk); transform: scale(.98); }

.btn-ghost {
  display: block;
  width: 100%;
  padding: 13px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  border: 1.5px solid var(--border);
}
.btn-ghost:active { background: var(--bg); }

/* ═══════════════════════════════════════════════════════════════════
   ADD PAGE
═══════════════════════════════════════════════════════════════════ */
.add-body { background: var(--surface); }

.add-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 0 16px;
  padding-top: max(var(--safe-top), var(--extra-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--blue);
  font-size: 16px;
  font-weight: 500;
  min-width: 70px;
}
.back-link svg { width: 20px; height: 20px; }
.add-header-title {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
  text-align: center;
  margin-right: 70px; /* balance the back button */
}

.add-main {
  padding: 16px 16px calc(24px + var(--safe-bottom));
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 1 — input nombre */
.add-input-wrap { position: relative; }

.add-big-input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 18px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}
.add-big-input:focus { border-color: var(--blue); }
.add-big-input::placeholder { color: var(--text-3); }

/* 2 — stepper cantidad prominente */
.qty-row-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.qty-main-btn {
  flex: 1;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 300;
  color: var(--blue);
  touch-action: manipulation;
  transition: background .1s;
}
.qty-main-btn:active:not(:disabled) { background: var(--blue-lt); }
.qty-main-btn:disabled { color: var(--border); }
.qty-main-num {
  min-width: 60px;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  user-select: none;
  padding: 0 8px;
}

/* 3 — botón añadir */
.btn-add-compact {
  width: 100%;
  padding: 16px;
  background: var(--blue);
  color: #fff;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  transition: background .15s, transform .1s;
}
.btn-add-compact:active { background: var(--blue-dk); transform: scale(.98); }

/* categoría — secundaria, discreta */
.cat-secondary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}
.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.cat-pill:active { background: var(--bg); }
.cat-pill-edit { font-size: 11px; color: var(--text-3); margin-left: 2px; }
.cat-link {
  font-size: 13px;
  color: var(--text-3);
  background: none;
  border: none;
  padding: 4px 0;
  touch-action: manipulation;
}
.cat-link:active { color: var(--blue); }

/* autocomplete */
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 50;
  overflow: hidden;
}
.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 15px;
  transition: background .1s;
}
.ac-item:not(:last-child) { border-bottom: 1px solid var(--border); }
.ac-item:active { background: var(--bg); }
.ac-icon { font-size: 18px; }

/* cat-badge-flash (animación al autodetectar) */

@keyframes cat-flash {
  0%   { background: var(--surface); }
  40%  { background: var(--blue-lt); }
  100% { background: var(--surface); }
}
.cat-badge-flash { animation: cat-flash .4s ease; }

.input-error { border-color: var(--red) !important; animation: shake .3s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}

/* ── quantity stepper ─────────────────────────────────────────── */
.qty-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.qty-row-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-2);
}
.qty-stepper {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 30px;
  overflow: hidden;
}
.qty-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  font-size: 22px;
  font-weight: 400;
  color: var(--blue);
  background: transparent;
  transition: background .12s;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}
.qty-btn:active:not(:disabled) { background: var(--blue-lt); }
.qty-btn:disabled { color: var(--border); }
.qty-display {
  min-width: 36px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  padding: 0 4px;
  user-select: none;
  -webkit-user-select: none;
}

/* ── big quantity stepper (anadir.php) ──────────────────────────── */
/* optional fields */
.optional-area { margin-top: 4px; }
.expand-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 0;
}
.expand-link svg { width: 14px; height: 14px; }
.extra-fields { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

/* feedback */
.add-feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  background: #e6f4ea;
  border-radius: var(--radius);
  color: var(--green);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
  animation: fade-in .2s ease;
}
.feedback-icon { font-size: 20px; }

/* freq section on add page */
.freq-section { margin-top: 8px; }
#freq-chips-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

/* ═══════════════════════════════════════════════════════════════════
   BOTTOM SHEET (category picker in add page)
═══════════════════════════════════════════════════════════════════ */
.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 300;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
  animation: fade-in .2s ease;
}
.sheet-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + var(--safe-bottom));
  animation: sheet-up .25s ease;
  max-height: 85vh;
  overflow-y: auto;
}
.sheet-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 12px;
}
.sheet-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.sheet-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-2);
  font-size: 16px;
  background: var(--bg);
  transition: background .15s;
}
.sheet-close-btn:active { background: var(--border); }

/* category strip colours */
.strip-frutas    { background: var(--c-frutas); }
.strip-carne     { background: var(--c-carne); }
.strip-lacteos   { background: var(--c-lacteos); }
.strip-panaderia { background: var(--c-panaderia); }
.strip-despensa  { background: var(--c-despensa); }
.strip-congelados{ background: var(--c-congelados); }
.strip-bebidas   { background: var(--c-bebidas); }
.strip-limpieza  { background: var(--c-limpieza); }
.strip-higiene   { background: var(--c-higiene); }
.strip-otros     { background: var(--c-otros); }

.bg-frutas    { background: color-mix(in srgb, var(--c-frutas) 15%, white); }
.bg-carne     { background: color-mix(in srgb, var(--c-carne) 15%, white); }
.bg-lacteos   { background: color-mix(in srgb, var(--c-lacteos) 15%, white); }
.bg-panaderia { background: color-mix(in srgb, var(--c-panaderia) 15%, white); }
.bg-despensa  { background: color-mix(in srgb, var(--c-despensa) 15%, white); }
.bg-congelados{ background: color-mix(in srgb, var(--c-congelados) 15%, white); }
.bg-bebidas   { background: color-mix(in srgb, var(--c-bebidas) 15%, white); }
.bg-limpieza  { background: color-mix(in srgb, var(--c-limpieza) 15%, white); }
.bg-higiene   { background: color-mix(in srgb, var(--c-higiene) 15%, white); }
.bg-otros     { background: color-mix(in srgb, var(--c-otros) 15%, white); }

.text-frutas    { color: var(--c-frutas); }
.text-carne     { color: var(--c-carne); }
.text-lacteos   { color: #b8860b; }
.text-panaderia { color: var(--c-panaderia); }
.text-despensa  { color: var(--c-despensa); }
.text-congelados{ color: var(--c-congelados); }
.text-bebidas   { color: var(--c-bebidas); }
.text-limpieza  { color: var(--c-limpieza); }
.text-higiene   { color: var(--c-higiene); }
.text-otros     { color: var(--c-otros); }

/* ═══════════════════════════════════════════════════════════════════
   HISTORIAL
═══════════════════════════════════════════════════════════════════ */
.hist-main {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}
.hist-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--bg);
  padding: 4px;
  border-radius: 12px;
}
.hist-tab {
  flex: 1;
  padding: 8px 4px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-align: center;
  transition: all .15s;
}
.hist-tab-active {
  background: var(--surface);
  color: var(--blue);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.hist-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 0;
  color: var(--text-2);
  font-size: 14px;
}
.hist-empty {
  text-align: center;
  padding: 48px 20px;
}
.hist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}
.hist-rank {
  font-size: 16px;
  min-width: 28px;
  text-align: center;
  font-weight: 700;
  color: var(--text-2);
}
.hist-icon { font-size: 20px; flex-shrink: 0; }
.hist-info { flex: 1; min-width: 0; }
.hist-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}
.hist-bar-wrap {
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}
.hist-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  transition: width .4s ease;
}
.hist-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  flex-shrink: 0;
  min-width: 50px;
  text-align: right;
}
