:root {
  --papel: #f1f5f3;
  --hoja: #ffffff;
  --tinta: #1d3557;
  --tinta-2: #2b4a73;
  --texto: #18222f;
  --suave: #5b6878;
  --linea: #d3dcd7;
  --verde: #2a7a57;
  --verde-claro: #d8ece2;
  --rojo: #a93b38;
  --rojo-claro: #f6dedd;
  --radio: 10px;
  --fuente: "Segoe UI", system-ui, -apple-system, "Roboto", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --papel: #121a24;
    --hoja: #1a2431;
    --tinta: #0e1824;
    --tinta-2: #25405f;
    --texto: #e6ecf2;
    --suave: #9aa8b8;
    --linea: #2c3a4b;
    --verde: #5cc394;
    --verde-claro: #1d3a2e;
    --rojo: #f08a86;
    --rojo-claro: #3d2222;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--papel);
  color: var(--texto);
  font: 16px/1.5 var(--fuente);
  font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
main { max-width: 38rem; margin: 0 auto; padding: 1rem 1rem 3rem; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 2rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1.5rem 0 .5rem; }
a { color: var(--tinta-2); }
@media (prefers-color-scheme: dark) { a { color: #9cc1ea; } }
:focus-visible { outline: 3px solid #f2b134; outline-offset: 2px; }
.sub { color: var(--suave); margin: 0 0 1rem; }
.visual-oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Barra superior */
.barra {
  position: sticky; top: 0; z-index: 5;
  background: var(--tinta); color: #fff;
  padding: calc(.6rem + env(safe-area-inset-top, 0px)) 1rem .6rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.marca { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.barra nav { display: flex; gap: .25rem; flex-wrap: wrap; margin-left: auto; }
.barra nav a {
  color: #d6e2f0; text-decoration: none; padding: .35rem .6rem; border-radius: 6px; font-size: .95rem;
}
.barra nav a[aria-current="page"] { background: rgba(255,255,255,.14); color: #fff; }

/* Formulario de apunte: el importe es la pieza protagonista */
.apunte { margin-bottom: 2rem; }
.importe {
  display: flex; align-items: baseline;
  background: var(--tinta); color: #fff;
  border-radius: var(--radio);
  padding: .75rem 1.25rem;
  margin-bottom: 1rem;
}
.importe input {
  flex: 1; min-width: 0;
  background: transparent; border: 0; color: #fff;
  font: 700 3.2rem/1.1 var(--fuente);
  font-variant-numeric: tabular-nums;
  text-align: right; letter-spacing: -.02em;
  padding: 0;
}
.importe input::placeholder { color: rgba(255,255,255,.35); }
.importe input:focus { outline: none; }
.importe:focus-within { box-shadow: 0 0 0 3px #f2b134; }
.euro { font-size: 2rem; margin-left: .5rem; color: rgba(255,255,255,.7); }

.chips { border: 0; padding: 0; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.chips legend { font-weight: 600; margin-bottom: .5rem; padding: 0; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chips span {
  display: inline-block; padding: .45rem .8rem;
  border: 1px solid var(--linea); border-radius: 999px;
  background: var(--hoja); font-size: .93rem; cursor: pointer;
}
.chips input:checked + span { background: var(--verde); border-color: var(--verde); color: #fff; }
@media (prefers-color-scheme: dark) { .chips input:checked + span { color: #0c1a13; } }
.chips input:focus-visible + span { outline: 3px solid #f2b134; outline-offset: 2px; }

.fila { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.crece { flex: 1 1 12rem; }
.fila > .campo { flex: 1 1 10rem; }
.campo { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.campo > span { font-size: .9rem; color: var(--suave); }
input, select, button { font: inherit; }
.campo input, .campo select, .acciones input {
  padding: .6rem .7rem; border: 1px solid var(--linea); border-radius: 8px;
  background: var(--hoja); color: var(--texto); min-height: 2.75rem;
}

button, .boton-principal, .boton-secundario, .boton-peligro { cursor: pointer; }
.boton-principal {
  width: 100%; padding: .85rem; border: 0; border-radius: var(--radio);
  background: var(--verde); color: #fff; font-weight: 700; font-size: 1.05rem;
}
@media (prefers-color-scheme: dark) { .boton-principal { color: #0c1a13; } }
.boton-principal:active { transform: translateY(1px); }
.boton-secundario {
  display: inline-block; padding: .55rem .9rem; border-radius: 8px;
  border: 1px solid var(--linea); background: var(--hoja); color: var(--texto);
  text-decoration: none; min-height: 2.75rem; line-height: 1.6;
}
.boton-peligro {
  margin-top: 1rem; width: 100%; padding: .75rem; border-radius: var(--radio);
  border: 1px solid var(--rojo); background: transparent; color: var(--rojo); font-weight: 600;
}
.enlace { background: none; border: 0; color: var(--tinta-2); text-decoration: underline; padding: .25rem; }
@media (prefers-color-scheme: dark) { .enlace { color: #9cc1ea; } }

/* Avisos */
.aviso { padding: .7rem .9rem; border-radius: 8px; margin: 0 0 .75rem; }
.aviso-ok { background: var(--verde-claro); }
.aviso-error { background: var(--rojo-claro); color: var(--rojo); }

/* Mes */
.mes-cabecera { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.mes-cabecera h1 { margin: 0; text-align: center; flex: 1; }
.flecha {
  width: 2.75rem; height: 2.75rem; display: grid; place-items: center;
  font-size: 1.8rem; text-decoration: none; border-radius: 50%; color: var(--texto);
}
a.flecha:hover { background: var(--hoja); }
.total {
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 2px solid var(--texto); padding: .75rem 0 .4rem; margin: .5rem 0 1rem;
}
.total span { color: var(--suave); }
.total strong { font-size: 1.8rem; }

.barras { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.barras li {
  display: grid; grid-template-columns: 1fr auto; gap: .1rem .75rem; margin-bottom: .55rem; font-size: .95rem;
}
.barras-importe { text-align: right; }
.barras-pista { grid-column: 1 / -1; height: 6px; background: var(--linea); border-radius: 3px; overflow: hidden; }
.barras-pista span { display: block; height: 100%; background: var(--verde); }

.lista { list-style: none; padding: 0; margin: 0; }
.dia {
  color: var(--suave); font-size: .85rem; font-weight: 600;
  padding: 1rem 0 .3rem; border-bottom: 1px solid var(--linea);
}
.gasto a {
  display: grid; grid-template-columns: 1fr auto; gap: 0 1rem;
  padding: .65rem 0; border-bottom: 1px solid var(--linea);
  color: inherit; text-decoration: none;
}
.gasto a:hover .gasto-cat { text-decoration: underline; }
.gasto-imp { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 600; }
.gasto-det { color: var(--suave); font-size: .9rem; overflow-wrap: anywhere; }
.vacio { color: var(--suave); padding: 1.5rem 0; }
.volver { text-decoration: none; }

.filtro { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin: 1rem 0 0; }
.filtro .campo { margin: 0; min-width: 10rem; }

/* Acceso */
.acceso { max-width: 22rem; margin: 12vh auto 0; }
.acceso h1 { font-size: 2.4rem; }

/* Ajustes */
.bloque { margin-bottom: 2.5rem; }
.tabla { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.tabla th, .tabla td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--linea); vertical-align: top; }
.tabla th { font-size: .85rem; color: var(--suave); font-weight: 600; }
.acciones { min-width: 12rem; }
.acciones details summary { cursor: pointer; color: var(--tinta-2); }
.acciones form { display: flex; gap: .4rem; margin-top: .4rem; flex-wrap: wrap; }
.acciones input { flex: 1; min-width: 8rem; }
.inactivo { opacity: .5; }
.cat-lista { list-style: none; padding: 0; margin: 0 0 1rem; }
.cat-lista li { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--linea); padding: .3rem 0; }
.cat-lista small, td small { color: var(--suave); }
.alta { border-top: 1px solid var(--linea); margin-top: 1rem; }

@media (max-width: 420px) {
  .importe input { font-size: 2.6rem; }
  .barra nav a { padding: .3rem .45rem; font-size: .9rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Pagos */
.pendiente {
  display: grid; grid-template-columns: 1fr auto; gap: 0 1rem; align-items: baseline;
  padding: .75rem 1rem; margin-bottom: 1rem; border-radius: var(--radio);
  background: var(--hoja); border: 1px solid var(--linea); color: inherit; text-decoration: none;
}
.pendiente strong { font-size: 1.3rem; }
.pendiente small { grid-column: 1 / -1; color: var(--suave); }
.gasto-imp small {
  display: block; font-size: .72rem; font-weight: 600; color: var(--verde); text-align: right;
}
.pagado .gasto-cat, .pagado .gasto-det { color: var(--suave); }
.tarjeta-saldo {
  background: var(--hoja); border: 1px solid var(--linea); border-radius: var(--radio);
  padding: 1rem 1rem 1.1rem; margin-bottom: 1rem;
}
.tarjeta-saldo.al-dia { background: transparent; }
.tarjeta-saldo h2 { margin: 0; }
.saldo-cabecera { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.saldo-cabecera strong { font-size: 1.6rem; }
.al-dia .saldo-cabecera strong { color: var(--suave); font-size: 1.2rem; }
.tarjeta-saldo .sub { margin: .25rem 0 .9rem; }
.tarjeta-saldo .boton-principal { display: block; text-align: center; text-decoration: none; }
.alerta { color: var(--rojo); }
.detalle-gastos { margin-bottom: 1.5rem; }
.detalle-gastos summary { cursor: pointer; color: var(--tinta-2); padding: .4rem 0; }
.tabla-gastos { display: table; font-size: .93rem; }
.tabla-gastos td:first-child { white-space: nowrap; color: var(--suave); width: 1%; }
.num { text-align: right !important; white-space: nowrap; }
.campo textarea {
  padding: .6rem .7rem; border: 1px solid var(--linea); border-radius: 8px;
  background: var(--hoja); color: var(--texto); font: inherit; resize: vertical;
}
.casilla { display: flex; gap: .6rem; align-items: flex-start; margin: .25rem 0 1rem; }
.casilla input { width: 1.25rem; height: 1.25rem; margin-top: .15rem; accent-color: var(--verde); }
.nota { margin: 0 0 1.25rem; padding: .75rem 1rem; background: var(--verde-claro); border-radius: 8px; white-space: pre-line; }
.ficha { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 1rem 0; }
.ficha dt { color: var(--suave); }
.ficha dd { margin: 0; }
.acciones form, td details form { display: flex; gap: .4rem; margin-top: .4rem; flex-wrap: wrap; }
td details input {
  flex: 1; min-width: 10rem; padding: .5rem .6rem; border: 1px solid var(--linea); border-radius: 8px;
  background: var(--hoja); color: var(--texto); min-height: 2.5rem;
}
td details summary { cursor: pointer; color: var(--tinta-2); overflow-wrap: anywhere; }
button:disabled { opacity: .5; cursor: not-allowed; }
