:root {
  color-scheme: light dark;
  --bg: #F6F3EC;
  --surface: #FFFDF8;
  --surface-2: #ECE8DD;
  --ink: #1B2823;
  --muted: #5A6660;
  --line: #DAD5C7;
  --brand: #0F5F4C;
  --on-brand: #FFFDF8;
  --hero: #0F5F4C;
  --on-hero: #F6F3EC;
  --on-hero-muted: #BFD6CD;
  --amber: #F0B042;
  --track: #E3DED0;
  --danger: #A83A29;
  --success: #0F6B4F;
  --shadow: 0 1px 2px rgba(27, 40, 35, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111916;
    --surface: #1A2420;
    --surface-2: #24302B;
    --ink: #EDEFE9;
    --muted: #A5B1AB;
    --line: #2F3C36;
    --brand: #6FD1B3;
    --on-brand: #0B1512;
    --hero: #17463A;
    --on-hero: #F2F5EF;
    --on-hero-muted: #B4CEC4;
    --track: #2F3C36;
    --danger: #F0907D;
    --success: #6FD1B3;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
main:focus { outline: none; }
.money { font-variant-numeric: tabular-nums; }

/* Estructura */
.shell { min-height: 100dvh; }
main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.nav {
  position: fixed;
  z-index: 5;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav-brand { display: none; }
.nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 60px;
  padding: 9px 2px 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.nav a[aria-current="page"] { color: var(--brand); }

@media (min-width: 860px) {
  .shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); }
  .nav {
    position: sticky;
    inset: 0 auto auto 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 24px 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .nav-brand { display: block; padding: 0 12px 16px; font-size: 20px; font-weight: 800; letter-spacing: -.02em; color: var(--brand); }
  .nav a { flex-direction: row; gap: 12px; min-height: 46px; padding: 0 12px; border-radius: 12px; font-size: 15px; }
  .nav a:hover { background: var(--surface-2); }
  .nav a[aria-current="page"] { background: var(--surface-2); }
  main { padding: 40px 32px 56px; width: 100%; }
  .nav[hidden] ~ main { grid-column: 1 / -1; }
}

/* Texto */
.page-title { font-size: 30px; line-height: 1.15; font-weight: 800; letter-spacing: -.025em; }
.section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.section-head h2 { font-size: 19px; font-weight: 750; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); border-color: currentColor; background: transparent; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn.link { border: 0; background: none; padding: 0 4px; color: var(--brand); min-height: 44px; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row > .btn { flex: 1 1 110px; }

/* Resumen del mes */
.hero {
  padding: 22px 20px;
  border-radius: 22px;
  background: var(--hero);
  color: var(--on-hero);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hero .label { font-weight: 600; color: var(--on-hero-muted); }
.hero .figure { font-size: clamp(36px, 11vw, 52px); line-height: 1.1; font-weight: 800; letter-spacing: -.03em; overflow-wrap: anywhere; }
.hero .hint { color: var(--on-hero-muted); font-size: 15px; }
.equation { margin: 14px 0 0; padding: 14px 0 0; border-top: 1px solid rgba(255, 255, 255, .22); display: flex; flex-direction: column; gap: 4px; }
.equation div { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0 16px; }
.equation dt { color: var(--on-hero-muted); font-size: 15px; }
.equation dd { margin: 0; font-weight: 700; font-size: 15px; }

/* Tarjetas */
.card {
  display: block;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
}
a.card:hover, .row-card:hover { border-color: var(--brand); }
.row-card { width: 100%; text-align: left; cursor: pointer; }
.section-title { font-size: 19px; font-weight: 750; letter-spacing: -.01em; }
[data-install]:empty { display: none; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.card-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 12px; }
.card-title { font-weight: 700; overflow-wrap: anywhere; min-width: 0; }
.pct { font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.card-meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 6px; font-size: 14px; color: var(--muted); }
.over { color: var(--danger); font-weight: 650; }
.done { color: var(--success); font-weight: 650; }

.bar { height: 10px; margin-top: 10px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; min-width: 0; border-radius: 99px; background: var(--brand); transition: width .35s ease; }
.bar.is-done > i { background: var(--amber); }
.bar.is-over > i { background: var(--danger); }

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--amber);
  background: color-mix(in srgb, var(--amber) 14%, var(--surface));
}
.notice p { flex: 1 1 240px; font-size: 15px; }

.empty {
  padding: 24px 18px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Detalle de meta */
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; font-weight: 650; color: var(--brand); text-decoration: none; align-self: flex-start; }
.goal-figure { font-size: clamp(34px, 10vw, 46px); font-weight: 800; line-height: 1.1; letter-spacing: -.03em; overflow-wrap: anywhere; }

/* Listas */
.rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); overflow: hidden; }
.rows li + li { border-top: 1px solid var(--line); }
.row {
  width: 100%;
  min-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row:focus-visible { outline-offset: -3px; }
.row-main { min-width: 0; display: flex; flex-direction: column; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.row-amount { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.row-amount.plus { color: var(--success); }

/* Selector de mes */
.month {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 8px;
}
.month strong { text-align: center; font-size: 18px; }
.month strong::first-letter { text-transform: uppercase; }
.icon-btn { width: 46px; height: 46px; padding: 0; font-size: 20px; }

/* Ajustes */
.setting { display: flex; flex-direction: column; gap: 10px; }
.setting h2 { font-size: 17px; font-weight: 700; }

/* Formularios */
.sheet {
  width: min(520px, 100%);
  max-width: 100%;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--ink);
}
.sheet::backdrop { background: rgba(10, 18, 15, .55); }
@media (min-width: 560px) {
  .sheet { margin: auto; border-radius: 22px; width: min(480px, calc(100% - 32px)); }
}
.form { display: flex; flex-direction: column; gap: 16px; padding: 22px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 560px) { .form { padding: 24px; } }
.form h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .field-label { font-weight: 650; font-size: 15px; }
.field .opt { font-weight: 400; color: var(--muted); }
.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--muted);
  border-radius: 12px;
  background: var(--bg);
  font-size: 16px;
}
.help { font-size: 14px; color: var(--muted); }
.error { color: var(--danger); font-weight: 600; font-size: 15px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.seg label { position: relative; display: flex; align-items: center; justify-content: center; min-height: 42px; border-radius: 10px; font-weight: 650; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg label:has(input:checked) { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .18); color: var(--brand); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--amber); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.form-actions .btn { flex: 1 1 120px; }
.form-actions .btn.danger { flex: 1 1 100%; }

/* Bienvenida */
.welcome { min-height: calc(100dvh - 60px); justify-content: center; max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.welcome .mark { width: 64px; height: 64px; border-radius: 16px; }
.welcome h1 { font-size: clamp(34px, 9vw, 44px); line-height: 1.08; font-weight: 800; letter-spacing: -.03em; }
.points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.points li { padding-left: 16px; border-left: 3px solid var(--amber); }
.points strong { display: block; }
.step { font-size: 14px; font-weight: 700; color: var(--muted); }
.welcome .form { padding: 0; }

/* Avisos */
.toast {
  position: fixed;
  z-index: 20;
  left: 16px;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  max-width: 440px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  text-align: center;
}
@media (min-width: 860px) { .toast { bottom: 24px; } }
.noscript { padding: 24px; text-align: center; }

/* Privacidad */
.doc { max-width: 680px; margin: 0 auto; padding: 32px 16px 64px; display: flex; flex-direction: column; gap: 14px; }
.doc h1 { font-size: 32px; font-weight: 800; letter-spacing: -.025em; line-height: 1.15; }
.doc h2 { margin-top: 14px; font-size: 19px; font-weight: 750; }
.doc ul { margin: 0; padding-left: 22px; }
.doc a { color: var(--brand); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
