/* Congenia INV · mobile-first */
:root {
  --marca: #1F4E78; --marca-2: #2E75B6; --marca-suave: #E8F0F9;
  --fondo: #F2F4F8; --sup: #FFFFFF; --sup-2: #F7F9FC; --borde: #E1E6EE;
  --txt: #17202B; --txt-2: #5F6B7A; --txt-3: #8A95A3;
  --verde: #1A7F37; --verde-suave: #E6F4EA; --rojo: #C62828; --rojo-suave: #FDECEA;
  --ambar: #B26A00; --ambar-suave: #FFF4E0; --azul: #2F80ED;
  --radio: 16px; --radio-s: 10px;
  --sombra: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --tab-h: 64px;
  --sa-b: env(safe-area-inset-bottom, 0px); --sa-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --marca: #5B9BD5; --marca-2: #6AA9E9; --marca-suave: #1B2A3A;
    --fondo: #0E131A; --sup: #161D26; --sup-2: #1B2430; --borde: #263140;
    --txt: #E7ECF2; --txt-2: #A3AEBC; --txt-3: #76828F;
    --verde: #4CC26E; --verde-suave: #14301E; --rojo: #FF6B6B; --rojo-suave: #3A1A1A;
    --ambar: #F0A443; --ambar-suave: #352812; --azul: #6AA9E9;
    --sombra: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fondo); color: var(--txt);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
.oculto { display: none !important; }

/* ---------- splash / login ---------- */
.splash { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 18px; background: var(--fondo); z-index: 50; }
.splash img { border-radius: 18px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--borde); border-top-color: var(--marca-2); border-radius: 50%; animation: gira .8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }

.login { min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + var(--sa-t)) 20px calc(24px + var(--sa-b));
  background: radial-gradient(120% 80% at 50% 0%, #2E75B6 0%, #1F4E78 55%, #14324E 100%); }
.login-caja { width: 100%; max-width: 380px; background: var(--sup); border-radius: 24px; padding: 32px 24px 24px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-logo { border-radius: 20px; box-shadow: var(--sombra); }
.login h1 { margin: 14px 0 24px; font-size: 26px; letter-spacing: -.3px; color: var(--marca); }
.g-btn { display: flex; justify-content: center; min-height: 44px; }
.login-pie { margin: 20px 0 0; font-size: 12px; color: var(--txt-3); }

/* ---------- barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--sa-t)) 16px 10px;
  background: color-mix(in srgb, var(--fondo) 85%, transparent);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar.sombra { border-bottom-color: var(--borde); }
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: -.4px; }
.topbar small { color: var(--txt-2); font-size: 12px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; border: none; padding: 0; overflow: hidden; background: var(--marca); color: #fff; font-weight: 700; cursor: pointer; flex: none; display: grid; place-items: center; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar img:not([src]), .avatar img[src=""] { display: none; }

main { max-width: 720px; margin: 0 auto; padding: 8px 16px calc(var(--tab-h) + var(--sa-b) + 28px); }
.vista { display: none; animation: entra .18s ease-out; }
.vista.on { display: block; }
@keyframes entra { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- tarjetas y campos ---------- */
.card { background: var(--sup); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px; margin: 12px 0; box-shadow: var(--sombra); }
.campos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.campo { display: block; min-width: 0; }
.campo.full { grid-column: 1 / -1; }
.campo > span { display: block; font-size: 12px; font-weight: 500; color: var(--txt-2); margin-bottom: 5px; }
input[type=text], input[type=date], input[type=number] {
  width: 100%; height: 48px; padding: 0 12px; font-size: 17px; /* >=16px: iOS no hace zoom */
  color: var(--txt); background: var(--sup-2); border: 1px solid var(--borde); border-radius: var(--radio-s);
  appearance: none; -webkit-appearance: none; transition: border-color .15s, box-shadow .15s;
}
input[type=date] { min-width: 0; }
input:focus { outline: none; border-color: var(--marca-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--marca-2) 22%, transparent); background: var(--sup); }
input[aria-invalid=true] { border-color: var(--rojo); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--borde); border-radius: 12px; padding: 3px; gap: 3px; margin-top: 4px; }
.seg button { border: none; background: transparent; border-radius: 9px; height: 38px; font-size: 14px; font-weight: 500; color: var(--txt-2); cursor: pointer; }
.seg button.on { background: var(--sup); color: var(--txt); font-weight: 600; box-shadow: var(--sombra); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.kpis.k2 { grid-template-columns: 1fr 1fr; margin-bottom: 4px; }
.kpi { background: var(--sup); border: 1px solid var(--borde); border-radius: var(--radio-s); padding: 10px; min-width: 0; }
.card .kpi { background: var(--sup-2); }
.kpi span { display: block; font-size: 11px; color: var(--txt-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi b { display: block; font-size: 16px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi i { display: block; font-style: normal; font-size: 12px; }

.plegable summary { list-style: none; cursor: pointer; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.plegable summary::-webkit-details-marker { display: none; }
.plegable summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--txt-3); border-bottom: 2px solid var(--txt-3); transform: rotate(45deg); transition: transform .2s; margin-right: 4px; }
.plegable[open] summary::after { transform: rotate(-135deg); }
.plegable summary small { font-weight: 400; color: var(--txt-3); margin-left: 6px; margin-right: auto; }
.plegable[open] summary { margin-bottom: 12px; }

.pos { color: var(--verde); } .neg { color: var(--rojo); }

/* ---------- botones ---------- */
.acciones { display: grid; gap: 10px; margin: 14px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 18px; border: none; border-radius: 14px; font-size: 16px; font-weight: 600; cursor: pointer; transition: transform .08s, opacity .15s, background .15s; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primario { background: #2E75B6; color: #fff; }
.btn.exito { background: #1A7F37; color: #fff; }
.btn.peligro { background: #C62828; color: #fff; }
.btn.secundario { background: var(--marca-suave); color: var(--marca); }
.btn.chico { min-height: 40px; font-size: 14px; padding: 0 14px; border-radius: 11px; }
.btn.fantasma { background: transparent; color: var(--txt-2); }
.btn.cargando { pointer-events: none; opacity: .7; }

/* ---------- avisos ---------- */
.aviso { font-size: 13.5px; padding: 10px 12px; border-radius: 12px; margin: 10px 0; }
.aviso.mal { background: var(--rojo-suave); color: var(--rojo); }
.aviso.bien { background: var(--verde-suave); color: var(--verde); }
.aviso.info { background: var(--ambar-suave); color: var(--ambar); }
.nota { font-size: 12.5px; color: var(--txt-2); margin: 10px 2px; }
.vacio { text-align: center; color: var(--txt-2); padding: 40px 16px; }
.vacio b { display: block; font-size: 32px; margin-bottom: 6px; }
.sec-t { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--txt-2); margin: 26px 4px 8px; font-weight: 600; }

/* ---------- listas ---------- */
.lista { list-style: none; margin: 0; padding: 0; background: var(--sup); border: 1px solid var(--borde); border-radius: var(--radio); overflow: hidden; }
.lista li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--borde); }
.lista li:last-child { border-bottom: none; }
.lista .grow { flex: 1; min-width: 0; }
.lista small { display: block; color: var(--txt-2); font-size: 12px; }
.check { width: 24px; height: 24px; accent-color: var(--marca-2); flex: none; }
.icono-btn { width: 40px; height: 40px; border: none; background: transparent; border-radius: 10px; cursor: pointer; display: grid; place-items: center; color: var(--txt-3); flex: none; }
.icono-btn:active { background: var(--sup-2); }
.icono-btn.del { color: var(--rojo); }
.icono-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- operación (tarjeta) ---------- */
.op { background: var(--sup); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px; margin: 12px 0; box-shadow: var(--sombra); }
.op-cab { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.op-cab b { font-size: 16px; }
.op-cab small { color: var(--txt-2); font-size: 12px; }
.op-fila { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; margin-top: 6px; }
.op-fila span:first-child { color: var(--txt-2); }
.op-fila span:last-child { text-align: right; }
.op-gan { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--borde); display: flex; justify-content: space-between; align-items: baseline; }
.op-gan b { font-size: 18px; }
.barra { height: 6px; background: var(--sup-2); border-radius: 3px; overflow: hidden; margin: 10px 0 4px; border: 1px solid var(--borde); }
.barra i { display: block; height: 100%; background: var(--verde); border-radius: 3px; }
.ventas { list-style: none; margin: 8px 0 0; padding: 0; }
.ventas li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 6px 0; border-top: 1px solid var(--borde); color: var(--txt-2); }
.ventas li .grow { flex: 1; }
.ventas .icono-btn { width: 34px; height: 34px; }
.sim { font-size: 13px; margin: 10px 0 0; padding: 10px; border-radius: 10px; background: var(--sup-2); }
.vender { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; align-items: end; }
.vender .campo input { height: 44px; }
.vender .fila-btn { display: flex; gap: 6px; }
.op-acc { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.op-acc svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.estado { font-size: 11px; font-weight: 600; border-radius: 20px; padding: 3px 9px; white-space: nowrap; }
.estado.arq { background: var(--ambar-suave); color: var(--ambar); }
.estado.parcial { background: color-mix(in srgb, var(--azul) 15%, transparent); color: var(--azul); }
.estado.vendida { background: var(--verde-suave); color: var(--verde); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--borde); background: var(--sup); border-radius: 20px; height: 36px; padding: 0 14px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--txt); color: var(--sup); border-color: var(--txt); }

/* ---------- resumen ---------- */
.periodos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.periodo { background: var(--sup); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px 10px; box-shadow: var(--sombra); min-width: 0; }
.periodo.total { grid-column: 1 / -1; background: linear-gradient(135deg, var(--marca) 0%, var(--marca-2) 100%); color: #fff; border: none; }
.periodo.total .pos, .periodo.total .neg, .periodo.total small { color: #fff; }
.periodo span { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; opacity: .75; }
.periodo b { display: block; font-size: 16px; margin: 4px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.periodo.total { padding: 16px; }
.periodo.total span { font-size: 12px; }
.periodo.total b { font-size: 30px; }
.periodo.total small { font-size: 13px; }
.periodo small { display: block; font-size: 11.5px; color: var(--txt-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meses { background: var(--sup); border: 1px solid var(--borde); border-radius: var(--radio); overflow: hidden; }
.mes { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--borde); font-size: 13.5px; }
.mes:last-child { border-bottom: none; }
.mes .mb { height: 8px; border-radius: 4px; background: var(--sup-2); overflow: hidden; }
.mes .mb i { display: block; height: 100%; border-radius: 4px; background: var(--verde); }
.mes .mb i.neg { background: var(--rojo); }
.mes b { text-align: right; }
.info-nube p { margin: 6px 0 0; font-size: 13.5px; color: var(--txt-2); }

/* ---------- barra inferior ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + var(--sa-b)); padding-bottom: var(--sa-b);
  background: color-mix(in srgb, var(--sup) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--borde);
}
.tabbar button { position: relative; border: none; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--txt-3); font-size: 10.5px; font-weight: 500; cursor: pointer; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--marca-2); }
.badge { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--ambar); color: #fff; font-size: 11px; font-style: normal; font-weight: 700; display: grid; place-items: center; }

/* ---------- hoja inferior ---------- */
.hoja { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.hoja-fondo { position: absolute; inset: 0; background: rgba(10, 15, 25, .45); animation: aparece .2s; }
.hoja-panel { position: relative; width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto; background: var(--sup); border-radius: 22px 22px 0 0; padding: 8px 18px calc(18px + var(--sa-b)); animation: sube .25s cubic-bezier(.2, .9, .3, 1); }
.hoja-asa { width: 38px; height: 5px; border-radius: 3px; background: var(--borde); margin: 0 auto 12px; }
.hoja h2 { margin: 0 0 12px; font-size: 19px; }
.hoja-filas { background: var(--sup-2); border-radius: 12px; padding: 4px 12px; margin-bottom: 12px; }
.hoja-filas div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--borde); font-size: 14px; }
.hoja-filas div:last-child { border-bottom: none; }
.hoja-filas span { color: var(--txt-2); }
.hoja-filas b { text-align: right; }
.hoja p { color: var(--txt-2); font-size: 13.5px; margin: 0 0 12px; }
.hoja-acciones { display: grid; gap: 8px; margin-top: 6px; }
.hoja-usuario { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.hoja-usuario img { width: 48px; height: 48px; border-radius: 50%; }
.hoja-usuario small { display: block; color: var(--txt-2); }
@keyframes sube { from { transform: translateY(100%); } to { transform: none; } }
@keyframes aparece { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 600px) { .hoja { align-items: center; } .hoja-panel { border-radius: 22px; } }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--sa-b) + 14px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 70;
  background: var(--txt); color: var(--sup); padding: 12px 16px; border-radius: 14px; font-size: 14px; font-weight: 500; max-width: calc(100% - 32px); width: max-content; box-shadow: 0 10px 30px rgba(0,0,0,.2); transition: opacity .2s, transform .2s; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.mal { background: var(--rojo); color: #fff; }

.pie { text-align: center; font-size: 11px; color: var(--txt-3); padding: 0 16px calc(var(--tab-h) + var(--sa-b) + 16px); margin-top: -12px; }
#login:not(.oculto) ~ .pie, body:has(#app.oculto) .pie { display: none; }

/* ---------- pantallas grandes ---------- */
@media (min-width: 900px) {
  .tabbar { top: 0; bottom: 0; right: auto; width: 96px; height: auto; grid-template-columns: 1fr; grid-auto-rows: 76px; align-content: center; border-top: none; border-right: 1px solid var(--borde); padding: 0; }
  .topbar, main, .pie { margin-left: 96px; }
  main { padding-bottom: 40px; }
  .pie { padding-bottom: 20px; }
  .toast { bottom: 24px; }
  .acciones { grid-auto-flow: column; justify-content: start; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
