:root {
  --bg: #ffffff;
  --surface: #f4f7f5;
  --ink: #15201b;
  --muted: #5a6761;
  --line: #e1e7e3;
  --accent: #10705a;
  --accent-soft: #e4f2ed;
  --warn: #9a5b00;
  --warn-soft: #fbf1e1;
  --bad: #a3322a;
  --bad-soft: #fbe9e7;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --gutter: 16px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { font-family: var(--font-display); margin: 0; line-height: 1.12; text-wrap: balance; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.eyebrow { font-family: var(--font-mono); font-size: 0.76rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.gris { color: var(--muted); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.error { color: var(--bad); font-size: 0.9rem; min-height: 1.35em; }

.vista {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  display: grid;
  gap: 20px;
}

/* Clave */
.clave { display: grid; gap: 8px; padding-top: 12vh; }
.clave img { border-radius: 14px; margin-bottom: 8px; }
.clave h1 { font-size: 2.2rem; }
.clave .gris { margin-bottom: 12px; }
label { font-weight: 500; }
input:not([type="radio"]) {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font-size: 16px; /* 16px evita el zoom de iOS al enfocar */
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:not([type="radio"]):focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.primario {
  min-height: 52px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  font-size: 1.05rem;
}
.primario:active { filter: brightness(0.92); }
.primario:disabled { opacity: 0.6; }
.enlace { background: none; border: 0; color: var(--accent); min-height: 44px; padding: 0 4px; text-decoration: underline; text-underline-offset: 2px; }

/* Semana */
.tope { display: grid; gap: 6px; }
.semana-nav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; }
.flecha {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 99px;
  background: none;
  color: var(--ink);
  font-size: 1.3rem;
  text-decoration: none;
}
.flecha:active { background: var(--surface); }
.flecha:disabled { color: var(--line); cursor: default; }
.total { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; padding-top: 6px; }
.total.neg { color: var(--bad); }
.aviso { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 0.92rem; }

.sobres { display: grid; gap: 14px; }
.env { display: grid; gap: 6px; }
.env-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.env-row span:first-child { font-weight: 500; }
.env-row .num { color: var(--muted); font-size: 0.9rem; }
.env.neg .env-row span { color: var(--bad); }
.meter { height: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.meter div { height: 100%; background: var(--accent); border-radius: 99px; transition: width 300ms ease; }
.env.neg .meter { border-color: var(--bad); background: var(--bad-soft); }

section > .eyebrow { margin-bottom: 4px; padding-top: 12px; border-top: 1px dashed var(--line); }
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; min-height: 60px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lista .que { min-width: 0; }
.lista .que b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista .que small { color: var(--muted); font-size: 0.84rem; }
.lista .der { display: flex; align-items: center; gap: 4px; }
.lista .num { font-size: 1rem; }
.lista button { min-height: 44px; min-width: 44px; padding: 0 8px; border: 0; background: none; color: var(--muted); font-size: 0.9rem; border-radius: 8px; }
.lista button:active { background: var(--surface); }
.lista .si { color: var(--bad); font-weight: 600; }
.lista .confirma { display: flex; justify-content: flex-end; align-items: center; gap: 4px; color: var(--bad); font-size: 0.9rem; }
.lista .vacia { color: var(--muted); display: block; }
.etiqueta { font-size: 0.7rem; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.04em; background: var(--warn-soft); color: var(--warn); border-radius: 99px; padding: 3px 8px; white-space: nowrap; }

.pie { text-align: center; padding-top: 4px; }
.pie a { display: inline-block; padding: 12px 4px; }

.fab {
  position: fixed;
  right: max(20px, calc(env(safe-area-inset-right) + 12px));
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  width: 60px; height: 60px;
  border: 0; border-radius: 99px;
  background: var(--accent);
  color: var(--bg);
  font-size: 2rem; font-weight: 500; line-height: 1;
  box-shadow: 0 6px 18px rgba(16, 112, 90, 0.35);
}
.fab:active { transform: scale(0.95); }

/* Hoja de nuevo gasto */
.hoja {
  width: 100%; max-width: 480px;
  max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--bg);
  color: var(--ink);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.hoja[open] { animation: sube 220ms ease-out; }
.hoja::backdrop { background: rgba(21, 32, 27, 0.4); }
@keyframes sube { from { transform: translateY(40px); opacity: 0; } }
.hoja form { display: grid; gap: 8px; padding: 8px max(var(--gutter), env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left)); }
.hoja-tope { display: flex; justify-content: space-between; align-items: center; }
.hoja-tope h2 { font-size: 1.3rem; }
.monto { font-family: var(--font-display); font-size: 2rem !important; font-weight: 700; min-height: 60px !important; }
fieldset { border: 0; margin: 4px 0 0; padding: 0; min-width: 0; }
legend { font-weight: 500; padding: 0; margin-bottom: 8px; }
.opciones { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.opciones label { position: relative; }
.opciones input { position: absolute; opacity: 0; inset: 0; margin: 0; pointer-events: none; }
.opciones span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 10px;
  font-weight: 500; font-size: 0.95rem; line-height: 1.2;
}
.opciones input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.opciones input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.hoja .primario { margin-top: 12px; }

/* Atajo */
.pasos { margin: 0; padding-left: 1.3em; display: grid; gap: 14px; }
.pasos ul { margin: 6px 0 0; padding-left: 1.1em; }
code { font-family: var(--font-mono); font-size: 0.9em; background: var(--surface); padding: 1px 5px; border-radius: 4px; }
.copiar { display: grid; gap: 8px; margin-top: 8px; }
#v-atajo .total { font-size: 1.6rem; }
.copiar input { font-family: var(--font-mono); font-size: 16px; background: var(--surface); }
.copiar button { justify-self: start; min-height: 48px; padding: 0 14px; border: 1px solid var(--accent); border-radius: 10px; background: var(--bg); color: var(--accent); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .meter div { transition: none; }
  .hoja[open] { animation: none; }
}
