/* Mi Mercadito — Sistema creado por Freddy Steven Coloma · Base Digital */
:root {
  --verde: #1e8e4f; --verde-2: #157040; --verde-suave: #e3f3e9;
  --rojo: #d52b3a; --azul: #1f4fa8; --amarillo: #f2b705;
  --fondo: #f5f4ef; --tarjeta: #ffffff; --texto: #1c2420; --suave: #66706a; --borde: #e3e2db;
  --sombra: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 14px rgba(20, 30, 25, .06);
  --radio: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="claro"]) {
    --fondo: #101411; --tarjeta: #1a201c; --texto: #e9eee9; --suave: #9aa59e; --borde: #2a322d;
    --verde-suave: #1d3326; --sombra: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="oscuro"] {
  --fondo: #101411; --tarjeta: #1a201c; --texto: #e9eee9; --suave: #9aa59e; --borde: #2a322d;
  --verde-suave: #1d3326; --sombra: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fondo); color: var(--texto); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--verde); }
[hidden] { display: none !important; }

.app { max-width: 640px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.splash { margin: auto; text-align: center; color: var(--suave); }
.splash img { border-radius: 18px; }

/* Barra superior */
.top { position: sticky; top: 0; z-index: 20; background: var(--verde); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; display: flex; align-items: center; gap: 8px; }
.top h1 { font-size: 1.1rem; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { font-size: .78rem; opacity: .85; font-weight: 400; display: block; }
.icon-btn { background: rgba(255,255,255,.14); border: 0; color: inherit; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.15rem; position: relative; flex: none; }
.icon-btn:active { background: rgba(255,255,255,.28); }
.badge { position: absolute; top: -4px; right: -4px; background: var(--rojo); color: #fff; font-size: .7rem; font-weight: 700; min-width: 19px; height: 19px; border-radius: 10px; display: grid; place-items: center; padding: 0 5px; border: 2px solid var(--verde); }
.group-select { background: rgba(255,255,255,.14); border: 0; color: #fff; border-radius: 12px; padding: 8px 10px; font-weight: 700; max-width: 100%; appearance: none; }
.group-select option { color: #000; }
.franja { height: 4px; background: linear-gradient(90deg, var(--azul) 0 33%, #fff 33% 66%, var(--rojo) 66%); }

.content { padding: 14px; flex: 1; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--suave); margin: 18px 4px 8px; font-weight: 700; }

/* Tarjetas */
.card { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px; margin-bottom: 10px; border: 1px solid var(--borde); }
.list-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.list-card .ico { width: 46px; height: 46px; border-radius: 12px; background: var(--verde-suave); display: grid; place-items: center; font-size: 1.4rem; flex: none; }
.list-card .info { flex: 1; min-width: 0; }
.list-card .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-card .meta { font-size: .85rem; color: var(--suave); }
.progress { height: 6px; background: var(--borde); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--verde); border-radius: 4px; }
.progress.over > i { background: var(--rojo); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; background: var(--verde-suave); color: var(--verde-2); font-size: .78rem; font-weight: 600; }
:root[data-theme="oscuro"] .chip { color: #8fd8ac; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="claro"]) .chip { color: #8fd8ac; } }

.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tpl { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px; text-align: left; box-shadow: var(--sombra); }
.tpl b { display: block; margin-top: 4px; }
.tpl span { font-size: 1.6rem; }
.tpl small { color: var(--suave); display: block; font-size: .78rem; margin-top: 2px; }

/* Botones */
.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; background: var(--verde); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn:active { background: var(--verde-2); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--verde); border: 1.5px solid var(--verde); }
.btn.soft { background: var(--verde-suave); color: var(--verde-2); }
.btn.danger { background: transparent; color: var(--rojo); border: 1.5px solid var(--rojo); }
.btn.small { padding: 7px 11px; font-size: .85rem; border-radius: 10px; }
.btn.wa { background: #25d366; color: #fff; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* Formularios */
label.f { display: block; font-size: .85rem; font-weight: 600; color: var(--suave); margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; padding: 12px 13px; border-radius: 12px; border: 1.5px solid var(--borde); background: var(--tarjeta); outline: none; }
.input:focus { border-color: var(--verde); }
textarea.input { resize: vertical; min-height: 64px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-opt { border: 1.5px solid var(--borde); background: var(--tarjeta); border-radius: 999px; padding: 7px 12px; font-size: .88rem; }
.chip-opt.on { background: var(--verde); border-color: var(--verde); color: #fff; font-weight: 600; }

/* Login */
.login { padding: 28px 20px; margin: auto 0; }
.logo-big { text-align: center; margin-bottom: 22px; }
.logo-big img { width: 88px; height: 88px; border-radius: 22px; box-shadow: var(--sombra); }
.logo-big h1 { margin: 12px 0 4px; font-size: 1.8rem; }
.logo-big p { margin: 0; color: var(--suave); }
.tabs { display: flex; background: var(--borde); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 10px; font-weight: 600; color: var(--suave); }
.tabs button.on { background: var(--tarjeta); color: var(--texto); box-shadow: var(--sombra); }
.or { display: flex; align-items: center; gap: 10px; color: var(--suave); font-size: .85rem; margin: 16px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--borde); }
#gbtn { display: flex; justify-content: center; min-height: 44px; }
.error { color: var(--rojo); font-size: .9rem; min-height: 1.2em; }

/* Lista */
.list-head-info { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 10px 14px 0; }
.sugs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 14px 2px; scrollbar-width: none; }
.sugs::-webkit-scrollbar { display: none; }
.sug { flex: none; border: 1.5px dashed var(--verde); color: var(--verde); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: .88rem; font-weight: 600; }
.items { padding: 4px 14px 170px; }
.sec { margin-top: 14px; }
.sec h3 { font-size: .82rem; margin: 0 4px 6px; color: var(--suave); text-transform: uppercase; letter-spacing: .05em; display: flex; gap: 6px; align-items: center; }
.sec h3 .n { margin-left: auto; font-weight: 600; }
.item { display: flex; align-items: center; gap: 10px; background: var(--tarjeta); border: 1px solid var(--borde); padding: 10px 12px; border-radius: 12px; margin-bottom: 6px; }
.check { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--verde); background: transparent; flex: none; display: grid; place-items: center; color: #fff; font-size: 1rem; padding: 0; }
.item.done .check { background: var(--verde); }
.item .body { flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 0; }
.item .nm { font-weight: 600; }
.item .qty { color: var(--verde-2); font-weight: 700; margin-right: 4px; }
:root[data-theme="oscuro"] .item .qty { color: #8fd8ac; }
.item .det { font-size: .82rem; color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .det.note { color: #b26b00; white-space: normal; }
.item .pr { font-size: .9rem; font-weight: 700; flex: none; text-align: right; }
.item .pr.hint { color: var(--suave); font-weight: 500; font-size: .8rem; }
.item.done { opacity: .62; }
.item.done .nm { text-decoration: line-through; }
.item .ph { font-size: .9rem; }
.empty { text-align: center; color: var(--suave); padding: 40px 10px; }
.empty .big { font-size: 3rem; }

.addbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--fondo) 18%); }
.addbar-in { max-width: 620px; margin: 0 auto; }
.totals { display: flex; justify-content: space-between; font-size: .88rem; color: var(--suave); padding: 0 6px 6px; gap: 10px; }
.totals b { color: var(--texto); }
.totals .over { color: var(--rojo); }
.addform { display: flex; gap: 6px; background: var(--tarjeta); border-radius: 16px; padding: 6px; box-shadow: 0 4px 22px rgba(0,0,0,.14); border: 1px solid var(--borde); }
.addform input { flex: 1; border: 0; background: transparent; outline: none; padding: 10px 8px; min-width: 0; }
.addform .icon-btn { background: var(--verde-suave); color: var(--verde-2); }
.addform .icon-btn.go { background: var(--verde); color: #fff; }
.addform .icon-btn.rec { background: var(--rojo); color: #fff; animation: pulso 1s infinite; }
@keyframes pulso { 50% { transform: scale(1.08); } }
.ac { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 14px; box-shadow: var(--sombra); margin-bottom: 6px; overflow: hidden; }
.ac button { display: flex; width: 100%; text-align: left; border: 0; background: none; padding: 10px 14px; gap: 8px; align-items: center; border-bottom: 1px solid var(--borde); }
.ac button:last-child { border-bottom: 0; }
.ac small { color: var(--suave); margin-left: auto; font-size: .78rem; }

/* Hoja inferior */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--fondo); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
.sheet .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--borde); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 1.2rem; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.menu-list button { display: flex; width: 100%; gap: 12px; align-items: center; border: 0; background: var(--tarjeta); padding: 14px; border-radius: 12px; margin-bottom: 6px; text-align: left; font-weight: 600; }
.menu-list button.red { color: var(--rojo); }
.price-hist { font-size: .88rem; background: var(--verde-suave); border-radius: 12px; padding: 10px 12px; }
.price-hist div { display: flex; justify-content: space-between; padding: 2px 0; }
.price-hist .up { color: var(--rojo); font-weight: 600; }
.price-hist .down { color: var(--verde); font-weight: 600; }
.photo-prev { width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; background: var(--tarjeta); }

/* Panel admin */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.stat { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px; }
.stat b { font-size: 1.6rem; display: block; }
.stat span { color: var(--suave); font-size: .82rem; }
.notif { display: flex; gap: 10px; padding: 11px 12px; background: var(--tarjeta); border: 1px solid var(--borde); border-radius: 12px; margin-bottom: 6px; align-items: flex-start; }
.notif.unread { border-color: var(--verde); background: var(--verde-suave); }
.notif .t { font-size: .78rem; color: var(--suave); }
.urow { display: flex; gap: 10px; align-items: center; }
.urow .info { flex: 1; min-width: 0; }
.urow .info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prov { font-size: .72rem; padding: 2px 7px; border-radius: 6px; background: var(--borde); }
.prov.google { background: #e8f0fe; color: #1a56c4; }
.member { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--borde); }
.member:last-child { border-bottom: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--verde-suave); display: grid; place-items: center; font-weight: 700; color: var(--verde-2); flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.order-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--borde); }
.order-row span { flex: 1; }
.order-row button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--borde); background: var(--tarjeta); }

.footer { text-align: center; font-size: .78rem; color: var(--suave); padding: 22px 14px calc(18px + env(safe-area-inset-bottom)); }
.footer a { color: var(--suave); }
.footer .firma { display: inline-flex; align-items: center; gap: 6px; opacity: .9; }
.footer .firma::before { content: ""; width: 14px; height: 2px; background: linear-gradient(90deg, var(--azul) 0 33%, #ccc 33% 66%, var(--rojo) 66%); border-radius: 2px; }

.offline { position: sticky; top: 0; z-index: 60; background: #3b3b3b; color: #fff; font-size: .82rem; text-align: center; padding: 6px 10px; }
.toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 70; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.muted { color: var(--suave); font-size: .88rem; }
.center { text-align: center; }
.legal { padding: 20px; }
.legal h1 { font-size: 1.4rem; }
.list-card .name, .list-card .meta, .list-card .progress { display: block; }
.list-card .meta { margin-top: 2px; }
:root[data-theme="oscuro"] .btn.soft, :root[data-theme="oscuro"] .addform .icon-btn:not(.go):not(.rec) { color: #8fd8ac; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="claro"]) .btn.soft, :root:not([data-theme="claro"]) .addform .icon-btn:not(.go):not(.rec) { color: #8fd8ac; } }
