:root {
  --navy: #0D2036; --navy-2: #142E48; --tinta: #0F2237; --teal: #336E82; --acento: #3E8AA0; --aqua: #7CC4D6;
  --aqua-suave: #E3F1F5; --fondo: #F3F6F9; --linea: #DCE3EA; --gris: #56687A; --verde: #1E9E5A; --ambar: #C98A12; --rojo: #C8402F;
  --wa: #1FAF5A;
}
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--fondo); }
body { font-family: 'Sora', system-ui, sans-serif; color: var(--tinta); line-height: 1.45; font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.cargando { padding: 40vh 0; text-align: center; color: var(--gris); }

/* Estructura */
.top { position: sticky; top: 0; z-index: 10; background: var(--navy); color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px; }
.top .marca { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; flex: 1; min-width: 0; }
.top .marca img { width: 32px; height: 32px; flex: none; border-radius: 9px; border: 1px solid rgba(255,255,255,.18); }
.top .volver { background: none; border: 0; color: #fff; width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.top .volver:hover { background: rgba(255,255,255,.08); }
.top .titulo { font-weight: 700; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.estado { font-size: 12px; display: inline-flex; align-items: center; gap: 6px; color: #BFD0DE; background: rgba(255,255,255,.07); border: 0; padding: 6px 10px; border-radius: 999px; cursor: pointer; flex: none; }
.estado i { width: 8px; height: 8px; border-radius: 50%; background: var(--verde); }
.estado.pend i { background: var(--ambar); }
.estado.off i { background: #8A9BAB; }
.estado.err i { background: var(--rojo); }
main { max-width: 680px; margin: 0 auto; padding: 16px 14px calc(96px + env(safe-area-inset-bottom)); }
nav.abajo { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: #fff; border-top: 1px solid var(--linea); display: flex; padding-bottom: env(safe-area-inset-bottom); }
nav.abajo button { flex: 1; background: none; border: 0; padding: 9px 4px 10px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11.5px; color: var(--gris); cursor: pointer; }
nav.abajo button svg { width: 23px; height: 23px; }
nav.abajo button.on { color: var(--teal); font-weight: 700; }

h2 { font-size: 19px; margin: 6px 0 12px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--teal); margin: 22px 2px 10px; }
.sub { color: var(--gris); font-size: 13.5px; }
.vacio { text-align: center; color: var(--gris); padding: 28px 16px; background: #fff; border: 1px dashed var(--linea); border-radius: 16px; }
.vacio b { display: block; color: var(--tinta); margin-bottom: 4px; font-size: 16px; }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 12px; padding: 12px 16px; font-weight: 600; border: 0; cursor: pointer; text-decoration: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.prim { background: var(--acento); color: #fff; }
.btn.prim:hover { background: var(--teal); }
.btn.sec { background: #fff; border: 1.5px solid var(--linea); color: var(--tinta); }
.btn.peligro { background: #fff; border: 1.5px solid #F0C9C2; color: var(--rojo); }
.btn.wa { background: var(--wa); color: #fff; }
.btn.bloque { width: 100%; }
.btn.chico { padding: 8px 12px; font-size: 13.5px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.fila-btn { display: flex; gap: 10px; flex-wrap: wrap; }
.fila-btn > .btn { flex: 1; }

/* Formularios */
label.campo { display: block; margin-bottom: 12px; }
label.campo span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
label.campo small { display: block; color: var(--gris); font-size: 12px; margin-top: 4px; }
.inp { width: 100%; border: 1.5px solid var(--linea); border-radius: 12px; padding: 12px 13px; background: #fff; font-size: 16px; }
.inp:focus { outline: none; border-color: var(--acento); }
textarea.inp { min-height: 180px; resize: vertical; line-height: 1.5; }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 30px 20px; max-width: 420px; margin: 0 auto; }
.login .logo-grande { display: block; width: 190px; height: 190px; border-radius: 34px; margin: 0 auto 16px; box-shadow: 0 14px 34px rgba(13,32,54,.22); }
.login p.intro { text-align: center; }
.login p.intro { color: var(--gris); margin-bottom: 22px; }
.caja { background: #fff; border: 1px solid var(--linea); border-radius: 20px; padding: 20px; }
.error { background: #FCEDEA; color: #8E2A1E; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.ok { background: #E6F5EC; color: #17633B; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.cambiar { text-align: center; margin-top: 14px; font-size: 14px; color: var(--gris); }
.cambiar button { background: none; border: 0; color: var(--teal); font-weight: 700; cursor: pointer; text-decoration: underline; }
.config { max-width: 520px; margin: 18vh auto; padding: 22px; background: #fff; border-radius: 18px; border: 1px solid var(--linea); }

/* Tarjetas de compras */
.compra { background: #fff; border: 1px solid var(--linea); border-radius: 18px; padding: 16px; margin-bottom: 12px; cursor: pointer; }
.compra:hover { border-color: var(--acento); }
.compra .cab { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.compra b { font-size: 16.5px; }
.compra .monto { text-align: right; font-weight: 700; white-space: nowrap; }
.compra .monto small { display: block; font-weight: 400; color: var(--gris); font-size: 12px; }
.compra .pie { display: flex; gap: 8px; margin-top: 12px; }
.barra { height: 9px; border-radius: 99px; background: #E5EBF0; overflow: hidden; margin-top: 8px; }
.barra i { display: block; height: 100%; border-radius: 99px; background: var(--verde); transition: width .25s; }
.barra.cerca i { background: var(--ambar); }
.barra.pasado i { background: var(--rojo); }
.etq { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--aqua-suave); color: var(--teal); }

/* Resumen de la compra (arriba de la lista) */
.resumen { background: var(--navy); color: #fff; border-radius: 18px; padding: 11px 14px 11px; position: sticky; top: 62px; z-index: 5; box-shadow: 0 10px 24px rgba(13,32,54,.18); }
.resumen .linea1 { display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 13px; color: #BFD0DE; }
.resumen .linea1 button { background: rgba(255,255,255,.08); border: 0; color: #fff; border-radius: 9px; padding: 5px 9px; font-size: 12.5px; cursor: pointer; max-width: 60%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resumen .grande { display: flex; align-items: baseline; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.resumen .grande b { font-size: 26px; letter-spacing: -.8px; line-height: 1.15; }
.resumen .grande span { color: #BFD0DE; font-size: 14px; }
.resumen .grande button { background: none; border: 0; color: var(--aqua); font-size: 14px; text-decoration: underline; cursor: pointer; padding: 0; }
.resumen .barra { background: rgba(255,255,255,.14); }
.resumen .linea3 { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; font-size: 13px; color: #BFD0DE; }
.resumen .linea3 b { color: #fff; }
.resumen .alerta { margin-top: 8px; border-radius: 10px; padding: 7px 10px; font-size: 13px; font-weight: 600; }
.resumen .alerta.roja { background: #5B2420; color: #FFD9D3; }
.resumen .alerta.ambar { background: #4A3A12; color: #FFE7B0; }

.acciones-lista { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 6px; }
form.agregar { display: flex; gap: 8px; margin: 10px 0 4px; }
form.agregar .inp { flex: 1; }
form.agregar .btn { flex: none; padding: 0 16px; }

/* Productos */
.item { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; background: #fff; border: 1px solid var(--linea); border-radius: 14px; padding: 10px 10px 10px 8px; margin-bottom: 8px; }
.item.ok { background: #F2FAF5; border-color: #CBE9D7; }
.check { width: 30px; height: 30px; border-radius: 9px; border: 2px solid #B9C7D3; background: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; color: #fff; padding: 0; }
.check svg { width: 18px; height: 18px; }
.item.ok .check { background: var(--verde); border-color: var(--verde); }
.item .nom { min-width: 0; cursor: pointer; }
.item .nom b { display: block; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.item.ok .nom b { color: #3E5A4A; }
.item .nom small { display: block; color: var(--gris); font-size: 12.5px; }
.item .nom small.ref { color: var(--teal); }
.item .nom small.ref.caro { color: var(--ambar); }
.item .nom small.ref.barato { color: var(--verde); }
.item .precio { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.item .precio label { display: flex; align-items: center; border: 1.5px solid var(--linea); border-radius: 10px; background: #fff; padding-left: 8px; }
.item .precio label:focus-within { border-color: var(--acento); }
.item .precio label span { color: var(--gris); font-size: 14px; }
.item .precio input { width: 88px; border: 0; padding: 9px 8px 9px 4px; text-align: right; font-size: 16px; background: transparent; border-radius: 10px; }
.item .precio input:focus { outline: none; }
.item .precio small { font-size: 12.5px; color: var(--gris); min-height: 15px; }
.item .precio small b { color: var(--tinta); }

/* Súpers y comparador */
.super { background: #fff; border: 1px solid var(--linea); border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; display: flex; gap: 12px; align-items: center; }
.super .txt { flex: 1; min-width: 0; }
.super .txt b { display: block; }
.prod { background: #fff; border: 1px solid var(--linea); border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; }
.prod > b { display: block; font-size: 15.5px; margin-bottom: 8px; }
.prod table, .tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.prod td, .tabla td, .tabla th { padding: 7px 4px; border-top: 1px solid #EEF2F5; vertical-align: top; }
.tabla th { text-align: left; font-size: 12px; color: var(--gris); font-weight: 600; border-top: 0; }
.prod td.p, .tabla td.p { text-align: right; font-weight: 700; white-space: nowrap; }
.prod td small, .tabla td small { display: block; color: var(--gris); font-size: 12px; font-weight: 400; }
tr.mejor td { color: var(--verde); }
tr.mejor td.p::before { content: '★ '; }

/* Modal */
#modal .fondo { position: fixed; inset: 0; background: rgba(9,22,38,.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
#modal .hoja { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { #modal .fondo { align-items: center; } #modal .hoja { border-radius: 22px; } }
#modal .hoja h2 { margin-top: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
#modal .cerrar { background: var(--fondo); border: 0; width: 34px; height: 34px; border-radius: 10px; cursor: pointer; font-size: 18px; flex: none; }
.vista-previa { max-height: 260px; overflow: auto; border: 1px solid var(--linea); border-radius: 12px; padding: 4px 12px; margin: 8px 0 14px; font-size: 14px; }
.vista-previa div.cat { font-size: 11.5px; font-weight: 700; color: var(--teal); text-transform: uppercase; letter-spacing: 1px; margin: 10px 0 4px; }
.vista-previa div.p { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }
.vista-previa div.p span { color: var(--gris); white-space: nowrap; }

/* Aviso para instalar la app */
.instalar { display: flex; gap: 14px; align-items: flex-start; background: var(--navy); color: #fff; border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.instalar img { width: 46px; height: 46px; border-radius: 12px; flex: none; border: 1px solid rgba(255,255,255,.18); }
.instalar .txt { flex: 1; min-width: 0; }
.instalar b { display: block; font-size: 15.5px; margin-bottom: 4px; }
.instalar p { color: #C9D7E3; font-size: 13.5px; }
.instalar p b { display: inline; font-size: inherit; color: #fff; margin: 0; }
.instalar .botones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.instalar .btn { padding: 9px 16px; }
.btn.fantasma { background: transparent; color: #C9D7E3; border: 1.5px solid rgba(255,255,255,.22); }
.legal { text-align: center; color: var(--gris); font-size: 12.5px; margin-top: 16px; }
.legal a { color: var(--teal); }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60; }
#toast div { background: var(--tinta); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 20px rgba(0,0,0,.2); max-width: 90vw; }
