/* Estilos de Cronos. Los colores y tamanos salen de tokens.css (generado desde DESIGN.md):
   aqui solo se usa var(--...), nunca un color escrito a mano. */
:root {
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: 2rem;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: var(--step-0) / 1.5 var(--font);
  background: var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: var(--space-sm); top: -4rem; z-index: 100; padding: var(--space-sm) var(--space-md); background: var(--accent); color: var(--accent-text); border-radius: var(--radius); font-weight: 700; }
.skip:focus { top: var(--space-sm); }

/* ===== Estructura: contenido + menu ===== */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.content { flex: 1; padding: 1.25rem var(--space-md) 1.5rem; }
.content:focus { outline: none; }
.view { max-width: 760px; margin: 0 auto; }
h1, h2, h3 { font-weight: 700; }
h1 { font-size: var(--step-2); line-height: 1.15; margin: 0 0 var(--space-xs); }
h2 { font-size: var(--step-1); line-height: 1.25; margin: var(--space-lg) 0 0.6rem; }
[hidden] { display: none !important; }
.sub { color: var(--muted); margin: 0 0 var(--space-md); }
.num { font-variant-numeric: tabular-nums; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: var(--space-xs); min-height: 44px; color: var(--accent); font-weight: 700; text-decoration: none; margin-bottom: var(--space-xs); }

/* El menu va primero en el HTML (orden de teclado = orden visual en escritorio); en celular se muestra abajo. */
.nav { order: 1; position: sticky; bottom: 0; z-index: 20; display: flex; border-top: 1px solid var(--line); background: var(--surface); padding: var(--space-xs) var(--space-xs) calc(var(--space-xs) + env(safe-area-inset-bottom)); }
.nav .brand, .nav .side-new, .nav .w { display: none; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; color: var(--muted); font-size: 0.8rem; text-decoration: none; border-radius: var(--radius); }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.nav .fab[aria-current="page"] { color: var(--accent-text); }
.nav .fab { flex: none; width: 56px; height: 56px; margin: -14px var(--space-xs) 0; border-radius: 50%; background: var(--accent); color: var(--accent-text); border: 4px solid var(--bg); box-shadow: 0 var(--key-h) 0 var(--key); }
@media (min-width: 700px) {
  .shell { display: grid; grid-template-columns: 240px 1fr; }
  .nav { position: sticky; top: 0; height: 100dvh; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--line); padding: var(--space-md) 0.75rem; gap: var(--space-xs); order: 0; }
  .nav .m, .nav .fab { display: none; }
  .nav .w { display: flex; }
  .nav .brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: var(--step-1); padding: var(--space-xs) 0.5rem var(--space-md); }
  .nav .brand svg { width: 34px; height: 34px; color: var(--accent); }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 0.75rem; padding: 0 0.75rem; font-size: var(--step-0); }
  .nav a[aria-current="page"] { background: var(--soft); }
  .nav .logout { margin-top: auto; }
  .nav .logout button { width: 100%; min-height: 56px; display: flex; align-items: center; gap: 0.75rem; padding: 0 0.75rem; border: 0; background: none; color: var(--muted); border-radius: var(--radius); font-size: var(--step-0); text-align: left; }
  .nav .logout button:hover { background: var(--soft); color: var(--text); }
  .nav .side-new { display: flex; justify-content: center; gap: var(--space-sm); min-height: 60px; background: var(--accent); color: var(--accent-text); border: 1.5px solid var(--accent); margin-bottom: var(--space-md); font-weight: 700; font-size: var(--step-1); }
  .nav .side-new svg { width: 24px; height: 24px; }
  .content { padding: 2rem; }
  .cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; align-items: start; }
}
/* Dos columnas (formulario y resultado) solo cuando caben: con el menu lateral, a 768 px la tabla se desbordaba. */
@media (min-width: 1100px) { .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* ===== Piezas ===== */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-md); }
.stack > * + * { margin-top: 0.75rem; }
.big { font-size: var(--step-3); font-weight: 700; line-height: 1.1; }
.amounts { display: flex; flex-wrap: wrap; gap: 0.15rem var(--space-md); }
.amounts .a { font-weight: 700; font-size: var(--step-1); }
.amounts .zero { color: var(--muted); font-weight: 400; }
.label { font-size: var(--step--1); color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 0.3rem; font-size: var(--step--1); padding: 0.1rem 0.6rem; border-radius: var(--radius); background: var(--soft); color: var(--text); }
.badge svg.i { width: 16px; height: 16px; }
.badge.warn { background: transparent; border: 1px solid var(--warn); color: var(--warn); }
.due { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0.2rem 0.5rem; padding: 0.4rem 0.75rem; border-radius: var(--radius); background: var(--soft); border: 1.5px solid var(--accent); font-weight: 700; margin-bottom: var(--space-sm); }
.due svg.i { width: 20px; height: 20px; }
.due.urgent { background: var(--warn); color: var(--warn-text); border-color: var(--warn); }
.dot { display: inline-block; flex: none; align-self: center; width: 0.8rem; height: 0.8rem; border-radius: 50%; margin-right: 0.45rem; background: var(--accent); }
.cardrow { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.cardrow header { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem var(--space-md); border-bottom: 1px solid var(--line); font-weight: 700; }
.cardrow header small { font-weight: 400; color: var(--muted); }
.cardrow .part { padding: 0.8rem var(--space-md); }
.cardrow .part + .part { border-top: 1px solid var(--line); }

.gap-top { margin-top: 0.6rem; }
.no-gap { margin: 0.4rem 0 0; }
progress { appearance: none; -webkit-appearance: none; display: block; width: 100%; height: 8px; margin-top: 0.5rem; border: 0; border-radius: 99px; background: var(--line); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.dot.c-teal { background: var(--card-teal); } .dot.c-blue { background: var(--card-blue); } .dot.c-amber { background: var(--card-amber); } .dot.c-rose { background: var(--card-rose); }
.dot.c-violet { background: var(--card-violet); } .dot.c-green { background: var(--card-green); } .dot.c-slate { background: var(--card-slate); } .dot.c-orange { background: var(--card-orange); }
.nowrap { white-space: nowrap; }
.row-actions { display: flex; flex: none; }
.sub-info { flex: 1; min-width: 0; }
.sub-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-sm); }
.sub-head b { overflow-wrap: anywhere; }
.sub-head .num { font-weight: 700; white-space: nowrap; }
.label svg.i, .seg label > span svg.i { width: 1rem; height: 1rem; margin-right: 0.45rem; vertical-align: -0.2em; }
.top + .stack { margin-top: var(--space-md); }
.inline { display: inline; margin: 0; }
.form-narrow { max-width: 520px; }
.form-narrow .cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.panel > .top { flex-wrap: nowrap; align-items: center; }
.notice { display: flex; align-items: center; gap: var(--space-sm); margin: var(--space-md) 0; padding: 0.6rem var(--space-md); border: 1.5px solid var(--accent); background: var(--soft); border-radius: var(--radius); font-weight: 700; }
.m-only { display: inline-flex; }
@media (min-width: 700px) { .m-only { display: none; } }

/* Relieve de tecla (D31): solo lo conserva el «+» redondo del celular. Los botones con texto usan el relleno deslizante (D33). */
:root { --key-h: 4px; --key: color-mix(in srgb, var(--accent), black 52%); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-sm); min-height: 48px; padding: 0 1.25rem; border-radius: var(--radius); border: 1.5px solid var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 700; text-decoration: none; --fill: color-mix(in srgb, var(--accent), black 30%); }
.btn.ghost { background: transparent; color: var(--accent); --fill: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); --fill: var(--danger); }
/* Relleno deslizante (D33): una capa de color detras del texto, escondida a la izquierda; entra al pasar el mouse o presionar. */
.btn, .nav .side-new { position: relative; overflow: hidden; isolation: isolate; }
.nav .side-new { --fill: color-mix(in srgb, var(--accent), black 30%); }
.btn::before, .nav .side-new::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--fill); transform: scaleX(0); transform-origin: left; }
@media (prefers-reduced-motion: no-preference) {
  .btn::before, .nav .side-new::before { transition: transform 0.22s ease, background-color 0.12s ease; }
}
.btn.block { width: 100%; }
.btn.small { min-height: 44px; padding: 0 var(--space-md); }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; color: var(--muted); border-radius: var(--radius); text-decoration: none; }
.link-row { display: flex; align-items: center; gap: 0.75rem; width: 100%; min-height: 64px; padding: 0.5rem var(--space-md); text-align: left; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: var(--space-sm); }
.link-row b, .link-row .label { display: block; }
.link-row .grow { flex: 1; }

.field { display: block; }
.field > span, .field > legend { display: block; font-size: var(--step--1); color: var(--muted); margin-bottom: 0.3rem; }
input[type="text"], input[type="password"], input[inputmode], select { width: 100%; min-height: 48px; padding: 0 0.9rem; border-radius: var(--radius); border: 1.5px solid var(--muted); background: var(--surface); color: var(--text); }
.amount-in { font-size: var(--step-3); font-weight: 700; min-height: 64px; }
fieldset.field { border: 0; padding: 0; margin: 0; }
.stack > fieldset.field { margin-top: 0.75rem; }
.seg { display: flex; flex-wrap: wrap; gap: var(--space-sm); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg label > span { display: flex; align-items: center; min-height: 48px; padding: 0 var(--space-md); border: 1.5px solid var(--muted); border-radius: var(--radius); background: var(--surface); }
.seg input:checked + span { border-color: var(--accent); background: var(--soft); font-weight: 700; box-shadow: inset 0 0 0 1px var(--accent); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.err { color: var(--danger); font-size: var(--step--1); margin: 0.3rem 0 0; }
.hint { color: var(--muted); font-size: var(--step--1); margin: 0.3rem 0 0; }

.day { font-size: var(--step--1); color: var(--muted); margin: 1.25rem 0 var(--space-xs); font-weight: 400; }
.exp { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: var(--space-xs) var(--space-sm); padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.exp .n { font-weight: 600; }
.exp .m { grid-column: 1; color: var(--muted); font-size: var(--step--1); }
.exp .amt { grid-row: 1 / 3; grid-column: 2; font-weight: 700; text-align: right; }
.exp .act { grid-row: 1 / 3; grid-column: 3; display: flex; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin: var(--space-sm) 0; }
.chips a { display: flex; align-items: center; min-height: 44px; padding: 0 var(--space-md); border: 1.5px solid var(--muted); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; }
.chips a[aria-current="page"] { border-color: var(--accent); background: var(--soft); font-weight: 700; box-shadow: inset 0 0 0 1px var(--accent); }
.exp-deleted { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); padding: 0.4rem 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.exp .m .dot { margin-right: 0.35rem; }
.more { text-align: center; padding: var(--space-md) 0; }
.more p { margin: 0.4rem 0 0; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login .panel { width: min(360px, 100%); text-align: center; }
.login .field { text-align: left; }
.login h1, .login .sub { margin: 0; }
.login .logo { width: 64px; height: 64px; color: var(--accent); }
.empty { text-align: center; padding: 2rem var(--space-md); }
.empty svg.i { width: 40px; height: 40px; color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: var(--space-sm) 0.6rem var(--space-sm) 1.1rem; border-radius: var(--radius); max-width: min(92vw, 440px); z-index: 50; display: flex; align-items: center; gap: 0.75rem; }
.toast button, .toast a { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; min-height: 44px; padding: 0 0.75rem; display: inline-flex; align-items: center; }
@media (min-width: 700px) { .toast { bottom: 1.25rem; } }
@media (prefers-reduced-motion: no-preference) {
  .view { animation: in 0.18s ease-out; }
  @keyframes in { from { opacity: 0; transform: translateY(4px); } }
}

/* ===== Registro por ciclos ===== */
details.cyc { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); margin-bottom: var(--space-sm); }
details.cyc summary { list-style: none; cursor: pointer; padding: 0.8rem var(--space-md); display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-xs) var(--space-md); min-height: 56px; border-radius: var(--radius); }
details.cyc summary::-webkit-details-marker { display: none; }
details.cyc[open] summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
details.cyc .when b, details.cyc .when .label { display: block; }
details.cyc .right { display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-xs); }
details.cyc .inner { padding: 0 var(--space-md) var(--space-xs); }
.subrow { display: grid; grid-template-columns: 4rem 1fr auto; gap: var(--space-sm); padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.subrow:last-child { border-bottom: 0; }
.subrow .d { color: var(--muted); }
.subrow .r { font-weight: 700; text-align: right; }
.chart { display: block; width: 100%; max-width: 460px; height: auto; margin: var(--space-xs) 0; }
.chart .bar { fill: var(--accent); }
.chart .bar-label { fill: var(--muted); font-size: 11px; }
@media (max-width: 480px) { details.cyc .right { align-items: flex-start; width: 100%; } }

/* ===== Estados de interaccion (D29) =====
   Hover solo con mouse; presionado en todo; cargando (htmx) y deshabilitado atenuan.
   Los tonos se derivan de los tokens con color-mix: no hay colores nuevos. Sin sombras. */
@media (prefers-reduced-motion: no-preference) {
  .btn, .icon-btn, .seg label > span, .chips a, .nav a, .nav .logout button, .link-row, .back,
  details.cyc summary, .toast button, .toast a, .chev {
    transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  }
}
svg.i.chev { width: 1rem; height: 1rem; margin-left: 0.4rem; vertical-align: -0.15em; color: var(--muted); }
details.cyc[open] .chev { transform: rotate(90deg); }

@media (hover: hover) {
  /* D31: el «+» redondo es una tecla: sube 2 px y su sombra crece. */
  .nav .fab:hover { transform: translateY(-2px); box-shadow: 0 calc(var(--key-h) + 2px) 0 var(--key); filter: brightness(1.12); }
  /* D33: el color entra de izquierda a derecha; el texto cambia de color para mantener el contraste. */
  .btn:hover::before, .nav .side-new:hover::before { transform: scaleX(1); }
  .btn.ghost:hover { color: var(--accent-text); }
  .btn.danger:hover { color: var(--bg); }
  .icon-btn:hover { background: var(--soft); color: var(--text); }
  .seg label:hover > span, .chips a:hover { border-color: var(--accent); background: var(--soft); }
  .nav a:not(.fab):not(.side-new):not([aria-current="page"]):hover { background: var(--soft); color: var(--text); }
  .link-row:hover, details.cyc summary:hover { background: var(--soft); }
  .link-row:hover { border-color: var(--accent); }
  .back:hover { text-decoration: underline; text-underline-offset: 3px; }
  .toast button:hover, .toast a:hover { background: color-mix(in srgb, currentColor 18%, transparent); }
  a:not([class]):hover { text-decoration-thickness: 2px; }
}

.seg label:active > span, .chips a:active { transform: translateY(1px); }
/* D31: al presionar, el «+» se hunde por completo y su sombra desaparece. D33: los botones con texto bajan 2 px y el relleno se oscurece. */
.nav .fab:active { transform: translateY(var(--key-h)); box-shadow: 0 0 0 var(--key); filter: none; }
.btn:active, .nav .side-new:active { transform: translateY(2px); filter: none; }
.btn:active::before, .nav .side-new:active::before { transform: scaleX(1); background: color-mix(in srgb, var(--fill), black 22%); }
.btn.ghost:active { color: var(--accent-text); }
.btn.danger:active { color: var(--bg); }
.nav .fab:active {
  background: color-mix(in srgb, var(--accent), var(--text) 20%);
  border-color: color-mix(in srgb, var(--accent), var(--text) 20%);
}
.icon-btn:active, .nav .logout button:active { background: color-mix(in srgb, var(--text) 14%, transparent); }
.chips a:active, .nav a:not(.fab):not(.side-new):active, .link-row:active, details.cyc summary:active {
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
}
.seg label:active > span { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.back:active, .toast button:active, .toast a:active { opacity: 0.7; }

/* Cargando: htmx pone .htmx-request en el elemento que hizo la peticion (el formulario o el enlace). */
.htmx-request .btn, .htmx-request .icon-btn, .btn.htmx-request, .icon-btn.htmx-request { opacity: 0.6; pointer-events: none; cursor: progress; }
/* Cargando: el boton se queda presionado (D33). */
.htmx-request .btn, .btn.htmx-request { transform: translateY(2px); }
/* Deshabilitado: plano, sin relieve */
.btn:disabled, .btn[aria-disabled="true"], .icon-btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; transform: none; box-shadow: none; filter: none; }

/* ===== Simulador (D18, D19) =====
   "Sin interes" lleva siempre el fondo alt-soft (solo se usa para eso, DESIGN.md). */
.plans { border-collapse: collapse; width: 100%; }
.plans th, .plans td { padding: 0.55rem 0.4rem; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
@media (max-width: 480px) { .plans { font-size: var(--step--1); } }
.plans tbody tr:last-child th, .plans tbody tr:last-child td { border-bottom: 0; }
.plans th[scope="row"] { text-align: left; font-weight: 400; color: var(--muted); }
.plans thead th { font-size: var(--step--1); }
.plans .alt { background: var(--alt-soft); }
.flush, .sub.flush { margin: 0; }
.err-list { margin: 0.3rem 0 0; padding-left: 1.2rem; }
.err-list .err { margin: 0.15rem 0; }
.quick { display: flex; flex-wrap: wrap; gap: var(--space-sm); }
.quick[hidden] { display: none; }
.quick .btn { min-width: 48px; }
.sim-item .top { align-items: center; flex-wrap: nowrap; }
.sim-name { overflow-wrap: anywhere; }
.blocks { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-sm); margin-top: var(--space-sm); }
.blk { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-sm) 0.75rem; }
.blk.alt { background: var(--alt-soft); border-color: transparent; }
.blk h3 { font-size: var(--step--1); margin: 0 0 var(--space-xs); color: var(--muted); font-weight: 700; }
.blk dl { margin: 0; }
.blk dl > div { display: flex; justify-content: space-between; gap: var(--space-sm); }
.blk dt { color: var(--muted); }
.blk dd { margin: 0; font-weight: 700; }
.sim-actions { display: flex; justify-content: flex-end; margin-top: var(--space-sm); }
.sim-deleted { margin-bottom: var(--space-sm); }
