/* =========================================================
   Compras Inteligentes — estilos (web + APK)
   Paleta de mercado: verde hoja, crema, tomate y maíz
   ========================================================= */
:root {
  --verde: #1f4d3a;
  --verde-2: #2f6b52;
  --verde-claro: #e3efe7;
  --crema: #f7f3ea;
  --papel: #ffffff;
  --tinta: #1d2420;
  --gris: #6b736e;
  --linea: #e4dfd3;
  --tomate: #e4572e;
  --maiz: #f2b134;
  --ok: #2e8b57;
  --sombra: 0 1px 2px rgba(31, 77, 58, .06), 0 8px 24px rgba(31, 77, 58, .08);
  --radio: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--crema);
  color: var(--tinta);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--verde-2); }
.oculto { display: none !important; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--verde); color: #fff;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .marca { display: flex; align-items: center; gap: 8px; }
.icono-btn { background: rgba(255,255,255,.12); border: 0; border-radius: 12px; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; color: #fff; flex: none; }
.icono-btn svg { width: 22px; height: 22px; }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-bottom)); }
main.ancho { max-width: 1100px; }

.navbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--papel); border-top: 1px solid var(--linea);
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + var(--safe-bottom));
}
.navbar a {
  flex: 1; max-width: 160px; text-decoration: none; color: var(--gris);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; padding: 6px 0; border-radius: 12px;
}
.navbar a svg { width: 24px; height: 24px; }
.navbar a.activo { color: var(--verde); background: var(--verde-claro); font-weight: 600; }

/* ---------- Tarjetas y formularios ---------- */
.card { background: var(--papel); border-radius: var(--radio); box-shadow: var(--sombra); padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 4px; font-size: 18px; }
.sub { color: var(--gris); font-size: 14px; margin: 0; }
.titulo-seccion { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--gris); margin: 22px 4px 10px; font-weight: 600; }

label { display: block; font-size: 14px; color: var(--gris); margin: 12px 0 6px; font-weight: 500; }
input, select {
  width: 100%; padding: 13px 14px; border: 1.5px solid var(--linea); border-radius: 12px;
  background: #fffdf8; outline: none; transition: border-color .15s;
}
input:focus, select:focus { border-color: var(--verde-2); background: #fff; }
.fila { display: flex; gap: 10px; }
.fila > * { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 600; cursor: pointer;
  background: var(--verde); color: #fff; width: 100%; font-size: 16px; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 20px; height: 20px; }
.btn.sec { background: var(--verde-claro); color: var(--verde); }
.btn.linea { background: transparent; color: var(--verde); border: 1.5px solid var(--verde); }
.btn.peligro { background: #fbe9e4; color: var(--tomate); }
.btn.chico { width: auto; padding: 9px 14px; font-size: 14px; border-radius: 12px; }
.btn.grande { padding: 18px; font-size: 17px; border-radius: 18px; background: var(--tomate); box-shadow: 0 8px 20px rgba(228, 87, 46, .3); }

.tabs { display: flex; background: var(--verde-claro); border-radius: 14px; padding: 4px; gap: 4px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 11px; cursor: pointer; color: var(--verde); font-weight: 500; font-size: 14px; }
.tabs button.activo { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--linea); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chip:active { background: var(--verde-claro); }

/* ---------- Login ---------- */
.hero { text-align: center; padding: 36px 8px 18px; }
.hero .logo { width: 72px; height: 72px; margin: 0 auto 10px; }
.hero h1 { font-size: 28px; margin: 0; color: var(--verde); letter-spacing: -.02em; }
.hero p { color: var(--gris); margin: 6px 0 0; }

.mapa { height: 260px; border-radius: 14px; overflow: hidden; border: 1.5px solid var(--linea); margin-top: 10px; z-index: 1; }
.mapa.alto { height: 340px; }
.ubic-estado { font-size: 13px; color: var(--gris); margin-top: 8px; display: flex; align-items: center; gap: 6px; }
.ubic-estado.ok { color: var(--ok); }

/* ---------- Listas ---------- */
.lista-card { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.fecha-caja { flex: none; width: 56px; height: 60px; border-radius: 14px; background: var(--verde-claro); color: var(--verde); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; }
.fecha-caja b { font-size: 22px; }
.fecha-caja span { font-size: 12px; text-transform: uppercase; }
.lista-card .info { flex: 1; min-width: 0; }
.lista-card h3 { margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--verde-claro); color: var(--verde); font-weight: 600; }
.badge.pendiente { background: #fff3d6; color: #8a5a00; }
.badge.comprada { background: #e9e9e9; color: #555; }
.badge.demo { background: #fff3d6; color: #8a5a00; font-weight: 500; }
.punto { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.vacio { text-align: center; padding: 40px 20px; color: var(--gris); }
.vacio svg { width: 84px; height: 84px; opacity: .9; }

.fab { position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(84px + var(--safe-bottom)); z-index: 15; width: 60px; height: 60px; border-radius: 20px; border: 0; background: var(--tomate); color: #fff; box-shadow: 0 10px 24px rgba(228,87,46,.35); display: grid; place-items: center; cursor: pointer; }
.fab svg { width: 28px; height: 28px; }

/* ---------- Detalle de lista ---------- */
.agregar { display: grid; grid-template-columns: 1fr 76px 84px 48px; gap: 8px; align-items: end; }
.agregar input, .agregar select { padding: 12px 10px; }
.agregar .btn { height: 48px; padding: 0; border-radius: 12px; }
@media (max-width: 420px) {
  .agregar { grid-template-columns: 1fr 64px 48px; }
  .agregar .producto { grid-column: 1 / -1; }
}
.item { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--linea); }
.item:last-child { border-bottom: 0; }
.item .check { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--linea); background: #fff; flex: none; cursor: pointer; display: grid; place-items: center; color: #fff; }
.item.hecho .check { background: var(--ok); border-color: var(--ok); }
.item.hecho .nom { text-decoration: line-through; color: var(--gris); }
.item .nom { flex: 1; min-width: 0; }
.item .cant { font-size: 14px; color: var(--gris); }
.item .borrar { border: 0; background: none; color: #b8b2a5; cursor: pointer; padding: 6px; }
.item .borrar svg { width: 20px; height: 20px; }

.pie-accion { position: sticky; bottom: calc(68px + var(--safe-bottom)); background: linear-gradient(transparent, var(--crema) 22%); padding: 22px 0 8px; z-index: 5; }
.segmentado { display: flex; gap: 6px; margin-bottom: 10px; }
.segmentado button { flex: 1; border: 1.5px solid var(--linea); background: #fff; border-radius: 12px; padding: 8px 4px; font-size: 13px; cursor: pointer; }
.segmentado button.activo { border-color: var(--verde); background: var(--verde-claro); color: var(--verde); font-weight: 600; }

/* ---------- Resultados ---------- */
.cargando { text-align: center; padding: 50px 16px; }
.carrito-anim { width: 90px; height: 90px; animation: rodar 1.2s ease-in-out infinite; }
@keyframes rodar { 0%,100% { transform: translateX(-10px) } 50% { transform: translateX(10px) } }
.pasos { list-style: none; padding: 0; margin: 20px auto 0; max-width: 300px; text-align: left; }
.pasos li { padding: 6px 0; color: var(--gris); display: flex; gap: 10px; align-items: center; }
.pasos li.hecho { color: var(--verde); }
.pasos li::before { content: ''; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; flex: none; }
.pasos li.hecho::before { background: currentColor; }

.ganador { background: var(--verde); color: #fff; border-radius: 22px; padding: 20px; margin-bottom: 14px; position: relative; overflow: hidden; }
.ganador .etq { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; opacity: .8; }
.ganador h2 { font-size: 28px; margin: 4px 0 2px; }
.ganador .total { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.ganador .meta { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 14px; opacity: .92; }
.ganador .meta span { display: inline-flex; align-items: center; gap: 5px; }
.ganador .meta svg { width: 16px; height: 16px; }
.ganador .acciones { display: flex; gap: 8px; margin-top: 14px; }
.ganador .acciones .btn { background: #fff; color: var(--verde); }
.ganador .acciones .btn.ghost { background: rgba(255,255,255,.14); color: #fff; }
.ganador::after { content: ''; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(242,177,52,.22); }

.resultados-grid { display: grid; gap: 14px; }
@media (min-width: 900px) {
  .resultados-grid { grid-template-columns: 1fr 420px; align-items: start; }
  .resultados-grid .lateral { position: sticky; top: 80px; }
}

.rank { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; border-left: 6px solid var(--c, var(--verde)); }
.rank .pos { flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--crema); display: grid; place-items: center; font-weight: 700; color: var(--verde); }
.rank.primero .pos { background: var(--maiz); color: #3d2a00; }
.rank .cuerpo { flex: 1; min-width: 0; }
.rank .cab { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.rank h3 { margin: 0; font-size: 18px; }
.rank .monto { font-size: 20px; font-weight: 700; white-space: nowrap; }
.rank .suc { font-size: 13px; color: var(--gris); margin: 2px 0 8px; }
.motivos { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.motivos span { font-size: 12px; background: var(--crema); padding: 3px 8px; border-radius: 8px; }
.barras { display: grid; grid-template-columns: auto 1fr 34px; gap: 4px 8px; align-items: center; font-size: 12px; color: var(--gris); margin: 8px 0; }
.barra { height: 6px; background: var(--crema); border-radius: 6px; overflow: hidden; }
.barra i { display: block; height: 100%; background: var(--verde-2); border-radius: 6px; }
.anillo { flex: none; width: 52px; height: 52px; }
.rank .botones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

table.detalle { flex-basis: 100%; width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
table.detalle td { padding: 7px 4px; border-top: 1px solid var(--linea); vertical-align: top; }
table.detalle td.num { text-align: right; white-space: nowrap; }
table.detalle .busc { color: var(--gris); font-size: 12px; }
table.detalle tr.falta td { color: var(--tomate); }
.tachado { text-decoration: line-through; color: var(--gris); font-size: 11px; display: block; }

.aviso { background: #fff3d6; color: #6b4600; border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }

/* ---------- Toast y modal ---------- */
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px); background: var(--tinta); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; opacity: 0; transition: .25s; z-index: 50; max-width: calc(100% - 32px); pointer-events: none; }
.toast.ver { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--tomate); }

.modal-fondo { position: fixed; inset: 0; background: rgba(20,30,25,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--papel); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + var(--safe-bottom)); animation: subir .2s ease-out; }
@media (min-width: 600px) { .modal-fondo { align-items: center; } .modal { border-radius: 22px; } }
@keyframes subir { from { transform: translateY(40px); opacity: .4 } }
.modal h2 { margin: 0 0 6px; }

.leaflet-container { font-family: inherit; }
.pin-num { background: var(--c, #1f4d3a); color: #fff; border: 2px solid #fff; border-radius: 50%; width: 28px !important; height: 28px !important; display: grid; place-items: center; font-weight: 700; font-size: 13px; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.pin-casa { background: var(--tomate); color: #fff; border: 3px solid #fff; border-radius: 50%; width: 22px !important; height: 22px !important; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.ubic-estado svg { width: 16px; height: 16px; flex: none; }
a.btn { text-decoration: none; white-space: nowrap; }
