/* ====================================================================
   Contabilidad Familiar — diseño premium, accesible (WCAG 2.2 AA).
   Mobile-first. Sin dependencias externas.
==================================================================== */
:root {
  --green-900: #0f5132;
  --green-700: #15724a;
  --green-500: #1f9d63;
  --green-050: #e7f4ed;

  --bg: #eaf0ed;
  --surface: #ffffff;
  --surface-2: #f5f8f6;
  --ink: #14201b;
  --muted: #5c6b63;
  --line: #e2e9e5;

  --danger: #c0341d;
  --danger-bg: #fdecea;
  --info: #1457d6;

  --r: 20px;
  --r-sm: 13px;
  --sh-1: 0 1px 3px rgba(16, 40, 30, .08), 0 1px 2px rgba(16, 40, 30, .04);
  --sh-2: 0 10px 30px rgba(16, 40, 30, .14);
  --sh-fab: 0 8px 22px rgba(15, 81, 50, .42);

  --maxw: 560px;
}

* { box-sizing: border-box; }
/* El atributo hidden SIEMPRE gana (evita que una clase con display:* lo pise). */
[hidden] { display: none !important; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; }

/* Íconos SVG (estilo línea, heredan el color del texto) */
.ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; flex: none; display: inline-block; vertical-align: middle; }
.ico-sm { width: 18px; height: 18px; }
.ico-lg { width: 30px; height: 30px; }
.ico-xl { width: 40px; height: 40px; }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.55; letter-spacing: .1px;
}
h1, h2 { margin: 0; line-height: 1.25; }
:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; border-radius: 6px; }

.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 8px; top: 8px; background: var(--green-900); color: #fff; padding: .6rem 1rem; border-radius: 8px; z-index: 60; }

/* ----- Toast ----- */
.toast {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%);
  background: var(--green-900); color: #fff; padding: .8rem 1.2rem; border-radius: 999px;
  box-shadow: var(--sh-2); z-index: 80; font-weight: 600; max-width: 92vw; text-align: center;
}
.toast.error { background: var(--danger); }

/* ============================ AUTH ============================ */
.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 1.2rem;
  background: radial-gradient(120% 80% at 50% -10%, #16794f 0%, #0f5132 55%, #0b3d27 100%);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border-radius: 24px;
  padding: 1.8rem 1.5rem 1.6rem; box-shadow: var(--sh-2); text-align: center;
}
.auth-logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 20px; display: grid; place-items: center;
  background: linear-gradient(135deg, #28b675, #15724a); color: #fff; box-shadow: var(--sh-1); }
.auth-title { font-size: 1.5rem; margin-top: .2rem; }
.auth-sub { color: var(--muted); margin: .3rem 0 1.2rem; }

/* ----- Segmented control ----- */
.segmented {
  display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px; margin-bottom: 1rem;
}
.seg {
  flex: 1; min-height: 46px; border: 0; background: transparent; color: var(--muted);
  font-size: 1rem; font-weight: 700; border-radius: 999px; cursor: pointer; transition: .18s;
}
.seg.is-active { background: var(--green-700); color: #fff; box-shadow: var(--sh-1); }
.seg-grande .seg { min-height: 52px; font-size: 1.05rem; }

/* ----- Formularios ----- */
.form { text-align: left; }
.field { margin-bottom: .9rem; display: flex; flex-direction: column; }
label { font-weight: 650; margin-bottom: .35rem; font-size: .98rem; }
.opt { color: var(--muted); font-weight: 500; }
input, select {
  min-height: 52px; font-size: 1.05rem; padding: .6rem .85rem; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s; width: 100%;
}
input:focus, select:focus { border-color: var(--green-500); box-shadow: 0 0 0 4px var(--green-050); outline: none; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235c6b63' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8rem center; padding-right: 2.4rem; }

.monto-wrap { position: relative; display: flex; align-items: center; }
.monto-wrap .moneda { position: absolute; left: .9rem; font-size: 1.3rem; font-weight: 700; color: var(--muted); }
.monto-wrap input { padding-left: 2.1rem; font-size: 1.5rem; font-weight: 700; }

/* ----- Botones ----- */
.btn {
  min-height: 52px; padding: .7rem 1.3rem; font-size: 1.05rem; font-weight: 750;
  border: 0; border-radius: 14px; cursor: pointer; transition: transform .08s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px) scale(.995); }
.btn-block { width: 100%; margin-top: .5rem; }
.btn-primary { background: var(--green-700); color: #fff; box-shadow: var(--sh-1); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost2 { background: var(--surface-2); color: var(--ink); border: 1.5px solid var(--line); }
.btn-soft { background: var(--green-050); color: var(--green-900); border: 0; border-radius: 999px; min-height: 40px; padding: 0 1rem; font-weight: 700; cursor: pointer; }
.icon-btn { background: rgba(255,255,255,.16); color: #fff; border: 0; width: 42px; height: 42px; border-radius: 12px; font-size: 1.2rem; cursor: pointer; }

/* ============================ APPBAR ============================ */
.appbar {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(135deg, #15724a, #0f5132); color: #fff;
  padding: calc(env(safe-area-inset-top) + .7rem) 0 .7rem;
}
.appbar-in { max-width: var(--maxw); margin: 0 auto; padding: 0 1rem; display: flex; align-items: center; gap: .7rem; }
.appbar-logo { font-size: 1.5rem; }
.appbar-text { display: flex; flex-direction: column; line-height: 1.15; margin-right: auto; }
.appbar-title { font-weight: 800; font-size: 1.1rem; }
.appbar-sub { font-size: .82rem; opacity: .85; }

/* ============================ PAGES ============================ */
main { max-width: var(--maxw); margin: 0 auto; padding: 1rem 1rem calc(110px + env(safe-area-inset-bottom)); }
.page { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ----- Hero ----- */
.hero {
  background: linear-gradient(135deg, #1f9d63, #15724a 70%); color: #fff;
  border-radius: var(--r); padding: 1.3rem 1.3rem 1.4rem; box-shadow: var(--sh-2); margin-bottom: 1rem;
}
.hero-label { font-size: .9rem; opacity: .9; }
.hero-amount { display: block; font-size: 2.4rem; font-weight: 850; letter-spacing: -.5px; margin-top: .1rem; }
.hero-chips { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-top: 1.1rem; }
.chip { background: rgba(255,255,255,.16); border-radius: 14px; padding: .6rem .8rem; display: flex; align-items: center; gap: .6rem; }
.chip-ico { font-size: 1.2rem; width: 30px; height: 30px; display: grid; place-items: center; background: rgba(255,255,255,.2); border-radius: 9px; }
.chip-text { display: flex; flex-direction: column; line-height: 1.15; }
.chip-text small { font-size: .78rem; opacity: .9; }
.chip-text strong { font-size: 1.05rem; }

/* ----- Cards ----- */
.card { background: var(--surface); border-radius: var(--r); padding: 1.1rem 1.15rem; box-shadow: var(--sh-1); margin-bottom: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .7rem; }
.card-head h2 { font-size: 1.18rem; }

/* ----- Ranking ----- */
.ranking, .list { list-style: none; margin: 0; padding: 0; }
.ranking li { margin-bottom: .85rem; }
.ranking-top { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .3rem; font-weight: 600; }
.ranking-top strong { white-space: nowrap; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #1f9d63, #15724a); border-radius: 99px; transition: width .5s ease; }

/* ----- Saldos / lista ----- */
.row { display: flex; align-items: center; gap: .8rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.2rem; background: var(--green-050); flex: none; }
.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 650; }
.row-sub { font-size: .85rem; color: var(--muted); }
.row-amount { font-weight: 800; white-space: nowrap; }
.row-amount.neg { color: var(--danger); }
.row-amount.pos { color: var(--green-700); }
.row-ico.out { background: var(--danger-bg); color: var(--danger); }
.row-ico.in { background: var(--green-050); color: var(--green-700); }

.vacio { color: var(--muted); text-align: center; padding: 1rem .5rem; font-style: italic; }

/* ============================ BOTTOM NAV + FAB ============================ */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 14px rgba(16,40,30,.06);
}
.nav-item {
  flex: 1; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: .5rem 0;
  font-size: .74rem; font-weight: 650; min-height: 62px;
}
.nav-item .ico { width: 25px; height: 25px; }
.nav-item.is-active { color: var(--green-700); }
.nav-item.is-active .ico { stroke-width: 2.4; }

.fab {
  position: fixed; right: max(1rem, calc(50% - var(--maxw)/2 + 1rem));
  bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 45;
  width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(135deg, #28b675, #15724a); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: var(--sh-fab); transition: transform .12s;
}
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(.96); }

/* ============================ MODAL / SHEET ============================ */
.overlay { position: fixed; inset: 0; background: rgba(13, 30, 22, .5); z-index: 50; animation: fade .2s; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: var(--maxw); z-index: 55;
  background: var(--surface); border-radius: 26px 26px 0 0; padding: .6rem 1.15rem calc(1.2rem + env(safe-area-inset-bottom));
  box-shadow: var(--sh-2); max-height: 92dvh; overflow-y: auto; animation: slideup .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.sheet-grip { width: 44px; height: 5px; border-radius: 99px; background: var(--line); margin: .2rem auto .7rem; }
#sheet-title { font-size: 1.25rem; text-align: center; margin-bottom: .9rem; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: .7rem; margin-top: 1rem; }

/* ----- OCR ----- */
#ocr-zona { margin-bottom: 1rem; }
.ocr-btn {
  width: 100%; min-height: 56px; border: 2px dashed var(--green-500); background: var(--green-050);
  color: var(--green-900); border-radius: 14px; font-size: 1.02rem; font-weight: 750; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: .5rem;
}
.ocr-btn:hover { background: #dcefe6; }
.ocr-btn.cargando { opacity: .7; cursor: progress; }
.ocr-estado { margin: .6rem 0 0; padding: .6rem .8rem; border-radius: 10px; background: var(--surface-2); font-size: .92rem; }
.ocr-estado.ok { background: var(--green-050); color: var(--green-900); }
.ocr-estado.err { background: var(--danger-bg); color: var(--danger); }

/* ----- Categorías ----- */
.inline-form { background: var(--surface-2); border-radius: var(--r-sm); padding: 1rem; margin-bottom: 1rem; }
.cat-list .row-ico { background: var(--surface-2); }
.cat-tag { font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }

.appbar-logo { display: inline-grid; place-items: center; }
.chip-ico .ico { width: 20px; height: 20px; }

/* Sub-solapas de reportes */
.seg-3 { margin-bottom: 1rem; }
.seg-3 .seg { min-height: 48px; }

/* Acciones (cuentas) */
.acciones { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.btn-sm { min-height: 46px; font-size: .95rem; padding: .4rem .6rem; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: .7rem; }

/* Botones soft con ícono */
.btn-soft { display: inline-flex; align-items: center; gap: .35rem; }

/* Reportes */
.report h3 { font-size: 1.15rem; margin: 0 0 .2rem; }
.report .rep-sub { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
.rep-block { margin-bottom: 1.1rem; }
.rep-block h4 { font-size: .95rem; text-transform: uppercase; letter-spacing: .4px; color: var(--green-700); margin: 0 0 .4rem; }
.rep-row { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.rep-row:last-child { border-bottom: 0; }
.rep-total { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem .7rem; margin-top: .3rem;
  background: var(--surface-2); border-radius: 10px; font-weight: 800; }
.rep-grande { font-size: 1.5rem; font-weight: 850; }
.rep-pos { color: var(--green-700); } .rep-neg { color: var(--danger); }
.rep-ecuacion { display: flex; align-items: center; gap: .5rem; margin-top: .8rem; padding: .6rem .8rem; border-radius: 10px; font-weight: 650; }
.rep-ecuacion.ok { background: var(--green-050); color: var(--green-900); }
.rep-ecuacion.no { background: var(--danger-bg); color: var(--danger); }
.rep-foot { margin-top: 1rem; }

/* Botón cerrar del modal */
.sheet-x { position: absolute; top: .7rem; right: .8rem; background: var(--surface-2); color: var(--ink); }

/* Botón peligro (borrar) */
.btn-danger { background: var(--danger-bg); color: var(--danger); display: inline-flex; align-items: center; justify-content: center; gap: .4rem; margin-top: .7rem; }
.btn-danger:hover { filter: brightness(.97); }

/* Totales (presupuesto) */
.totales { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-top: 1rem; }
.total { border-radius: 14px; padding: .7rem .5rem; text-align: center; border: 1px solid var(--line); }
.total-rotulo { display: block; font-size: .8rem; color: var(--muted); }
.total strong { font-size: 1.05rem; }
.total-in { background: var(--green-050); }
.total-out { background: var(--danger-bg); }
.total-bal { background: #eef2fb; }
.mes-input { width: auto; min-height: 42px; font-size: .95rem; padding: .3rem .6rem; }

/* Presupuesto: items con barra semáforo */
.pres-item { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.pres-item:last-child { border-bottom: 0; }
.pres-top { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .4rem; }
.pres-top .pres-name { font-weight: 650; }
.pres-nums { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.estado-ok { background: linear-gradient(90deg, #28b675, #15724a) !important; }
.estado-alerta { background: linear-gradient(90deg, #f4b740, #e08a00) !important; }
.estado-excedido { background: linear-gradient(90deg, #e8654b, #c0341d) !important; }
.estado-sin { background: var(--muted) !important; }

/* Reservas */
.res-total { color: var(--green-700); font-size: 1.15rem; }
.res-actions { display: flex; gap: .5rem; margin-top: .6rem; }
.btn-mini { flex: 1; min-height: 42px; border-radius: 10px; border: 0; cursor: pointer; font-weight: 700;
  font-size: .92rem; background: var(--green-700); color: #fff; }
.btn-mini.ghost { background: var(--surface-2); color: var(--ink); border: 1.5px solid var(--line); }

/* Filas de movimiento: tocables para editar */
.row.tappable { cursor: pointer; }
.row.tappable:hover { background: var(--surface-2); border-radius: 10px; }
.row .row-edit { color: var(--muted); margin-left: .3rem; }

/* ----- Desktop ----- */
@media (min-width: 640px) {
  html { font-size: 18px; }
  :root { --maxw: 640px; }
  .bottomnav { border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
