/* Libreta: una cartilla de ahorro con tinta verde y sello violeta. */
:root {
  color-scheme: light;
  --papel: #EDF3EF; --hoja: #F8FBF9; --hundido: #DFE9E3; --linea: #CBDAD2;
  --tinta: #12302A; --tinta2: #3F5951; --tinta3: #566D65;
  --sello: #5A35B0; --sobre-sello: #FFFFFF; --sello-suave: #E6DFF6;
  --ingreso: #0B6B4F; --alerta: #B3261E; --alerta-suave: #F8E1DE;
  --s-ing: #0F8A64; --s-gas: #5A35B0; --s-neutra: #8A9C95; --tram: #5A35B01F;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "New York", ui-serif, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  --tabs: 62px;
}
@media (prefers-color-scheme: dark) { :root[data-tema="auto"] { color-scheme: dark;
  --papel: #0E1F1B; --hoja: #162B26; --hundido: #1E3630; --linea: #2A463E;
  --tinta: #E6F0EB; --tinta2: #B9CCC4; --tinta3: #9DB2A9;
  --sello: #B9A2FF; --sobre-sello: #1C1140; --sello-suave: #2C2550;
  --ingreso: #6FDCB3; --alerta: #FF9A90; --alerta-suave: #43211F;
  --s-ing: #2FA37C; --s-gas: #9176E8; --s-neutra: #71877E; --tram: #B9A2FF24; } }
:root[data-tema="oscuro"] { color-scheme: dark;
  --papel: #0E1F1B; --hoja: #162B26; --hundido: #1E3630; --linea: #2A463E;
  --tinta: #E6F0EB; --tinta2: #B9CCC4; --tinta3: #9DB2A9;
  --sello: #B9A2FF; --sobre-sello: #1C1140; --sello-suave: #2C2550;
  --ingreso: #6FDCB3; --alerta: #FF9A90; --alerta-suave: #43211F;
  --s-ing: #2FA37C; --s-gas: #9176E8; --s-neutra: #71877E; --tram: #B9A2FF24; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--papel); }
body { margin: 0; background: var(--papel); color: var(--tinta); font: 16px/1.4 var(--sans); -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
h1, h2, h3, p, ul, figure, fieldset { margin: 0; padding: 0; border: 0; }
ul { list-style: none; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; text-align: inherit; }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 2px solid var(--sello); outline-offset: 2px; }
[hidden] { display: none !important; }
small { font-size: 13px; color: var(--tinta3); }
.suave { color: var(--tinta3); font-size: 14px; }
.rojo { color: var(--alerta) !important; }

.vista { max-width: 760px; margin: auto; padding: calc(env(safe-area-inset-top) + 8px) max(18px, env(safe-area-inset-right)) calc(var(--tabs) + env(safe-area-inset-bottom) + 34px) max(18px, env(safe-area-inset-left)); }
.tit-vista, .nav-mes h1 { font: 600 24px/1.2 var(--serif); }
.tit-vista { padding: 10px 0 14px; }
.nav-mes { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.nav-mes button { width: 44px; height: 44px; font-size: 28px; line-height: 1; text-align: center; color: var(--sello); }

/* Portada */
.portada { position: relative; isolation: isolate; margin: 6px -18px 8px; padding: 26px 18px 22px; overflow: hidden; border-block: 1px solid var(--linea); background: var(--hoja); }
.portada::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--sello); opacity: .17; -webkit-mask: url(guilloche.svg) center / cover no-repeat; mask: url(guilloche.svg) center / cover no-repeat; }
.frase { font: 400 clamp(25px, 7.3vw, 34px)/1.24 var(--serif); max-width: 22em; font-variant-numeric: lining-nums; text-wrap: pretty; }
.frase b { font-weight: 700; white-space: nowrap; }
.saldo-linea { margin-top: 14px; font-size: 14px; color: var(--tinta2); }
.saldo-linea b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.nota { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin: 6px 0; padding: 11px 13px; background: var(--sello-suave); border-radius: 10px; font-size: 14px; }
.nota .btn-txt { flex: none; }

/* Widgets */
.widgets { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 28px; }
@media (min-width: 680px) { .widgets { grid-template-columns: repeat(2, minmax(0, 1fr)); } .widget.completo { grid-column: 1 / -1; } .portada { margin-inline: 0; border-radius: 6px; border: 1px solid var(--linea); } }
.widget { padding: 20px 0 22px; border-bottom: 1px solid var(--linea); min-height: 74px; min-width: 0; }
.widget h2 { font: 600 19px/1.25 var(--serif); margin-bottom: 12px; }
.editar-inicio { display: block; margin: 20px auto 0; }
.w-fila { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; align-items: baseline; width: 100%; }
.w-fila > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-fila > :last-child { flex: none; font-variant-numeric: tabular-nums; }
.w-cat { padding: 6px 0; }
.w-cat .barra { margin-top: 5px; }
.w-total { border-top: 1px solid var(--linea); margin-top: 5px; padding-top: 9px; font-weight: 600; }
.w-pie { margin-top: 8px; color: var(--tinta3); font-size: 13px; }
.w-enlace { margin-top: 8px; color: var(--sello); font-weight: 600; font-size: 15px; min-height: 36px; }

.barra { display: block; height: 6px; background: var(--hundido); border-radius: 3px; overflow: hidden; }
.barra i { display: block; height: 100%; background: var(--s-gas); border-radius: 3px; }
.barra.pasado i { background: var(--alerta); }
.medidor { position: relative; display: block; margin: 8px 0 6px; }
.medidor em { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--tinta); }

/* Gráficos */
.graf { outline-offset: 4px; }
.graf svg { display: block; width: 100%; max-height: 240px; touch-action: pan-y; overflow: visible; }
.g-lectura { min-height: 20px; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--tinta); margin-bottom: 4px; }
.g-leyenda { display: flex; gap: 16px; font-size: 13px; color: var(--tinta2); margin-bottom: 6px; }
.g-leyenda span { display: inline-flex; gap: 6px; align-items: center; }
.g-leyenda i { width: 14px; height: 3px; border-radius: 2px; background: var(--c); }
.g-leyenda i.disc { background: repeating-linear-gradient(90deg, var(--c) 0 4px, transparent 4px 7px); }
.m-gas { --c: var(--s-gas); } .m-ing { --c: var(--s-ing); } .m-neu { --c: var(--s-neutra); }
.g-rejilla { stroke: var(--linea); stroke-width: 1; }
.g-cero { stroke: var(--tinta3); stroke-width: 1; }
.g-eje { fill: var(--tinta3); font: 10.5px var(--sans); }
.g-guia { stroke: var(--tinta3); stroke-width: 1; stroke-dasharray: 2 3; }
.b-gas { fill: var(--s-gas); } .b-ing { fill: var(--s-ing); }
[class^="l-"] { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.l-gas { stroke: var(--s-gas); } .l-ing { stroke: var(--s-ing); } .l-neu { stroke: var(--s-neutra); }
path.disc { stroke-dasharray: 4 5; }
.p-gas { fill: var(--s-gas); stroke: var(--papel); stroke-width: 2; } .p-ing { fill: var(--s-ing); stroke: var(--papel); stroke-width: 2; } .p-neu { fill: var(--s-neutra); stroke: var(--papel); stroke-width: 2; }
.g-tabla { margin-top: 6px; font-size: 13px; color: var(--tinta3); }
.g-tabla summary { cursor: pointer; padding: 6px 0; }
.g-tabla table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; color: var(--tinta2); }
.g-tabla th, .g-tabla td { padding: 4px 0; text-align: right; font-weight: 400; border-bottom: 1px solid var(--linea); }
.g-tabla th:first-child { text-align: left; }

/* Libreta */
.busca input, .campo input, .campo select, .reg-concepto input, .reg-nota input { width: 100%; height: 44px; padding: 0 12px; font-size: 16px; background: var(--hoja); border: 1px solid var(--linea); border-radius: 9px; appearance: none; -webkit-appearance: none; }
.filtros { display: flex; gap: 6px; margin: 8px 0 4px; align-items: center; overflow-x: auto; scrollbar-width: none; }
.filtros select { flex: 1 1 0; min-width: 0; height: 36px; font-size: 14px; padding: 0 8px; background: var(--hundido); border: 0; border-radius: 8px; appearance: none; -webkit-appearance: none; }
.filtros .btn-txt { flex: none; padding-left: 6px; }
.dia { margin-top: 16px; }
.dia h2 { display: flex; justify-content: space-between; font: 600 14px/1.3 var(--sans); color: var(--tinta2); padding-bottom: 6px; border-bottom: 1.5px solid var(--tinta); font-variant-numeric: tabular-nums; }
.apunte { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 56px; padding: 8px 0; border-bottom: 1px solid var(--linea); }
.apunte.marcado { background: var(--sello-suave); }
.ico { flex: none; width: 30px; text-align: center; font-size: 20px; }
.marcado .ico { color: var(--sello); font-weight: 700; }
.ap-txt { flex: 1; min-width: 0; display: grid; }
.ap-txt b, .ap-txt small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ap-txt b { font-weight: 500; }
.ap-imp { flex: none; font-variant-numeric: tabular-nums; font-weight: 500; }
.ap-imp.ingreso { color: var(--ingreso); }
.ap-imp.transferencia { color: var(--tinta3); }
.libro { margin-bottom: 18px; border-top: 1.5px solid var(--tinta); }
.barra-sel { position: fixed; z-index: 5; left: 0; right: 0; bottom: calc(var(--tabs) + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: center; padding: 8px 18px; background: var(--hoja); border-top: 1px solid var(--linea); }
.barra-sel span { flex: 1; font-size: 14px; }
.vacio { padding: 40px 12px; text-align: center; }
.vacio h3 { font: 600 20px var(--serif); margin-bottom: 6px; }
.vacio p { color: var(--tinta3); max-width: 30ch; margin: auto; }

/* Plan */
.seg { display: flex; padding: 3px; margin-bottom: 14px; background: var(--hundido); border-radius: 10px; }
.seg button { flex: 1; min-height: 38px; text-align: center; font-size: 14px; border-radius: 8px; color: var(--tinta2); }
.seg [aria-checked="true"] { background: var(--hoja); color: var(--tinta); font-weight: 600; }
.plan-mes { margin-bottom: 8px; }
.piezas { margin-bottom: 18px; border-top: 1.5px solid var(--tinta); }
.pieza, .piezas > li > .pieza { display: block; width: 100%; padding: 13px 0; }
.piezas > li { border-bottom: 1px solid var(--linea); }
.piezas > li.pieza { padding-bottom: 13px; }
.pieza-ed { display: block; width: 100%; }
.pieza-c { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.pieza-c b { font-weight: 600; }

/* Ajustes */
.grupo { margin-bottom: 26px; }
.grupo h2, .sub { font: 600 18px var(--serif); margin-bottom: 8px; }
.sub { margin-top: 14px; font-size: 16px; }
.grupo > .suave { margin-bottom: 6px; }
.ajuste { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 8px 0; border-bottom: 1px solid var(--linea); }
.ajuste span { display: grid; min-width: 0; } .ajuste b { font-weight: 500; }
.ajuste i { font-style: normal; color: var(--tinta3); font-size: 20px; }
.campo.fila-campo { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 10px 0 0; }
.campo.fila-campo label { margin: 0; flex: 0 1 auto; font-size: 16px; color: inherit; }
.campo.fila-campo select { width: auto; min-width: 0; flex: 0 1 170px; }

/* Botones */
.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; background: var(--hundido); text-align: center; font-weight: 600; font-size: 15px; }
.btn.prim { background: var(--sello); color: var(--sobre-sello); }
.btn.peligro { background: var(--alerta); color: var(--hoja); }
.btn.peligro-suave { background: var(--alerta-suave); color: var(--alerta); }
.btn.ancho { display: block; width: 100%; }
.btn.peque { min-height: 36px; font-size: 14px; padding: 0 12px; }
.btn-txt { min-height: 36px; color: var(--sello); font-weight: 600; font-size: 15px; }
.fila-btn { display: flex; gap: 10px; margin-top: 16px; } .fila-btn .btn { flex: 1; }

/* Barra inferior */
.tabs { position: fixed; z-index: 6; inset: auto 0 0; display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--tabs) + env(safe-area-inset-bottom)); padding: 0 max(6px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left)); background: var(--hoja); border-top: 1px solid var(--linea); }
.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--tinta3); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs [aria-current] { color: var(--sello); font-weight: 600; }
.tabs .tab-nuevo { align-self: center; justify-self: center; width: 52px; height: 46px; border-radius: 12px; background: var(--sello); color: var(--sobre-sello); transform: rotate(-3deg); }
.tab-nuevo svg { stroke-width: 2.4; }

/* Hojas */
dialog.hoja { width: 100%; max-width: 560px; max-height: 94dvh; margin: auto auto 0; padding: 0; border: 0; color: var(--tinta); background: var(--papel); border-radius: 18px 18px 0 0; overflow: auto; overscroll-behavior: contain; }
dialog.hoja::backdrop { background: #06120F99; }
.hoja-in { padding: 14px 18px calc(env(safe-area-inset-bottom) + 16px); }
.hoja-cab { position: sticky; top: -14px; z-index: 2; display: flex; align-items: center; gap: 14px; margin: -14px -18px 10px; padding: 12px 18px 8px; background: var(--papel); }
.hoja-cab h2 { flex: 1; font: 600 20px var(--serif); }
.hoja-intro { color: var(--tinta2); font-size: 14px; margin-bottom: 12px; }
.conf-tit { font: 600 21px/1.25 var(--serif); } .conf-txt { margin-top: 8px; color: var(--tinta2); }
.campo { display: block; margin-bottom: 12px; }
.campo label, .campo legend { display: block; padding: 0; margin-bottom: 4px; font-size: 13px; color: var(--tinta2); }
.campo select { padding-right: 26px; }
.campo small { display: block; margin-top: 3px; }
.campo-check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.campo-check input { width: 20px; height: 20px; accent-color: var(--sello); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: block; padding: 7px 10px; font-size: 14px; border-radius: 8px; background: var(--hundido); }
.chip input:checked + span { background: var(--sello); color: var(--sobre-sello); }
.chip input:focus-visible + span { outline: 2px solid var(--sello); outline-offset: 2px; }
.error { margin: 8px 0; padding: 8px 10px; font-size: 14px; color: var(--alerta); background: var(--alerta-suave); border-radius: 8px; }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.imp-res { padding: 10px 0; font-size: 15px; }
.imp-prev { margin-top: 6px; font-size: 13px; color: var(--tinta2); }
.imp-prev li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.imp-prev span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-prev span:last-child { flex: none; }
.lista-w li, .lista-simple li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--linea); }
.lista-simple small { display: block; }
.w-sw { display: flex; gap: 10px; align-items: center; flex: 1; min-width: 0; }
.w-sw input { flex: none; width: 21px; height: 21px; accent-color: var(--sello); }
.w-sw span { display: grid; } .w-sw b { font-weight: 500; }
.w-orden { display: flex; gap: 4px; flex: none; }
.w-orden button { width: 38px; height: 38px; text-align: center; border-radius: 8px; background: var(--hundido); }
.lista-aj { margin-bottom: 14px; }

/* Registro */
.registro .hoja-in { display: flex; flex-direction: column; gap: 9px; }
.registro .hoja-cab, .registro .seg { margin-bottom: 0; }
.imp-grande { display: block; text-align: center; font: 600 clamp(36px, 11vw, 46px)/1.1 var(--serif); font-variant-numeric: lining-nums tabular-nums; padding: 2px 0; }
.imp-grande[data-tipo="ingreso"] { color: var(--ingreso); }
.sugerencias { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.sugerencias button { flex: none; margin-top: 6px; padding: 5px 10px; font-size: 14px; background: var(--hundido); border-radius: 7px; }
.sugerencias:empty { display: none; }
.cats { display: grid; grid-auto-flow: column; grid-template-rows: repeat(2, auto); grid-auto-columns: max-content; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-inline: -18px; padding-inline: 18px; }
.cats.abierta { display: flex; flex-wrap: wrap; margin: 0; padding: 0; }
.cats button { display: flex; gap: 6px; align-items: center; min-height: 36px; padding: 0 10px; font-size: 14px; border-radius: 8px; background: var(--hundido); }
.cats [aria-checked="true"] { background: var(--sello); color: var(--sobre-sello); font-weight: 600; }
.reg-fila { display: flex; gap: 8px; }
.reg-fila label { flex: 1 1 0; min-width: 0; font-size: 12px; color: var(--tinta3); }
.reg-fila span { display: block; margin-bottom: 2px; }
.reg-fila select, .reg-fila input { display: block; width: 100%; height: 38px; padding: 0 8px; font-size: 16px; color: var(--tinta); background: var(--hoja); border: 1px solid var(--linea); border-radius: 8px; appearance: none; -webkit-appearance: none; }
.reg-nota summary { font-size: 14px; color: var(--tinta3); cursor: pointer; }
.reg-nota input { margin-top: 6px; }
.teclado { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.teclado button { height: clamp(42px, 6.4dvh, 54px); text-align: center; font: 500 23px var(--serif); font-variant-numeric: lining-nums; background: var(--hoja); border-radius: 9px; }
.teclado button:active { background: var(--hundido); }

/* Aviso y sello */
.aviso { position: fixed; z-index: 30; left: 14px; right: 14px; bottom: calc(var(--tabs) + env(safe-area-inset-bottom) + 12px); max-width: 480px; margin: auto; display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 14px; color: var(--papel); background: var(--tinta); border-radius: 10px; font-size: 15px; }
.aviso button { flex: none; font-weight: 700; color: inherit; text-decoration: underline; }
.sello { position: fixed; z-index: 40; top: 38%; left: 50%; display: grid; justify-items: center; padding: 10px 24px 8px; color: var(--sello); border: 3px solid currentColor; outline: 1px solid currentColor; outline-offset: 3px; border-radius: 9px; background: color-mix(in srgb, var(--papel) 82%, transparent); pointer-events: none; font-family: var(--serif); animation: sellar 1050ms cubic-bezier(.2, .9, .3, 1) both; }
.sello b { font-size: 34px; line-height: 1.05; }
.sello span { font-size: 15px; }
@keyframes sellar {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-3deg) scale(2.1); }
  16% { opacity: 1; transform: translate(-50%, -50%) rotate(-9deg) scale(.96); }
  23%, 72% { opacity: 1; transform: translate(-50%, -50%) rotate(-9deg) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(-9deg) scale(1); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
