/* Gastos Casa — hoja de estilos base
   Mobile-first desde 360px. Escritorio como mejora progresiva. */

/* ── Tokens ─────────────────────────────────────────────────────────── */

:root {
  color-scheme: light dark;

  --brand-500: #12a882;
  --brand-600: #0a6e52;
  --brand-050: #e4f5ef;

  --income: #0e8f6b;
  --expense: #d1553f;
  --savings: #5b6cf9;

  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-sunken: #eceff0;
  --border: #e0e5e4;
  --text: #101d19;
  --text-muted: #5f716b;
  --shadow: 0 1px 2px rgba(16, 29, 25, .06), 0 8px 24px -16px rgba(16, 29, 25, .35);

  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;

  --gap: 12px;
  --page-x: 18px;
  --tabbar-h: 62px;

  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-500: #2bc79c;
    --brand-600: #0f8f6d;
    --brand-050: #14322a;

    --income: #3ecfa4;
    --expense: #f0806b;
    --savings: #8c97ff;

    --bg: #0e1512;
    --surface: #18211d;
    --surface-sunken: #131b18;
    --border: #26322d;
    --text: #eaf2ee;
    --text-muted: #93a49d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

/* ── Reset ──────────────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  /* Evita el rebote horizontal y el zoom por doble toque en móvil. */
  overflow-x: hidden;
  touch-action: manipulation;
}

h1, h2, h3, p, ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 10;
  padding: 12px 16px;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: 8px;
  top: 8px;
}

/* ── Layout ─────────────────────────────────────────────────────────── */

.app {
  width: min(100%, 640px);
  margin-inline: auto;
  padding:
    calc(20px + env(safe-area-inset-top))
    calc(var(--page-x) + env(safe-area-inset-right))
    calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom))
    calc(var(--page-x) + env(safe-area-inset-left));
}

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.view[hidden] {
  display: none;
}

.view-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.view-eyebrow {
  font-size: .8125rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.view-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.block__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 6px;
}

.block__title {
  font-size: 1.0625rem;
  font-weight: 650;
}

/* ── Selector de mes ────────────────────────────────────────────────── */

.month-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.month-picker__step {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 999px;
  color: var(--text-muted);
  transition: background-color .15s ease, color .15s ease;
}

.month-picker__step:hover {
  background: var(--surface-sunken);
  color: var(--text);
}

.month-picker__step svg {
  width: 22px;
  height: 22px;
}

.month-picker__label {
  flex: 1 1 auto;
  text-align: center;
  font-size: 1.0625rem;
  font-weight: 650;
}

/* ── Tarjeta de balance ─────────────────────────────────────────────── */

.balance-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 22px 20px;
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, var(--brand-500), var(--brand-600));
  color: #fff;
  box-shadow: var(--shadow);
}

.balance-card--savings {
  background: linear-gradient(160deg, #6f7dfb, #3b45c9);
}

.balance-card__label {
  font-size: .875rem;
  font-weight: 600;
  opacity: .85;
}

.balance-card__amount {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}

.balance-card__hint {
  font-size: .8125rem;
  opacity: .75;
}

/* ── KPIs ───────────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
}

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.kpi-card__label {
  font-size: .875rem;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-card__amount {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.kpi-card--income .kpi-card__amount {
  color: var(--income);
}

.kpi-card--expense .kpi-card__amount {
  color: var(--expense);
}

/* ── Principal (Resumen: Piso y Ahorro del mes) ────────────────────── */

.principal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
}

.principal-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.principal-card--link {
  cursor: pointer;
}

.principal-card__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.principal-card__icon {
  font-size: 1rem;
}

.principal-card__amount {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.principal-card__amount[data-negative] {
  color: var(--expense);
}

.principal-card__hint {
  font-size: .75rem;
  color: var(--text-muted);
}

/* ── Barra de progreso ──────────────────────────────────────────────── */

/*
 * `<progress>` nativo y no un div con `width` puesto por JS: la CSP del
 * proyecto es `style-src 'self'` sin `unsafe-inline` (ver public/_headers),
 * y eso bloquea tanto el atributo `style=""` como cualquier mutación vía
 * `element.style.*` desde JS. El elemento `<progress>` no tiene ese problema
 * porque su relleno se controla con los atributos `value`/`max`, ajenos a
 * `style-src`. Se estiliza con los pseudo-elementos propietarios de cada
 * motor: no hay una forma estándar única todavía.
 */
.progress {
  display: block;
  width: 100%;
  height: 6px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-sunken);
}

.progress::-webkit-progress-bar {
  background: var(--surface-sunken);
  border-radius: 999px;
}

.progress::-webkit-progress-value {
  background: var(--savings);
  border-radius: 999px;
  transition: width .2s ease;
}

.progress::-moz-progress-bar {
  background: var(--savings);
  border-radius: 999px;
}

.progress--lg {
  height: 10px;
}

/* ── Carpetas de gasto ──────────────────────────────────────────────── */

.folder-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
}

@media (min-width: 480px) {
  .folder-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.folder {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 116px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.folder__icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  font-size: 1.35rem;
  background: var(--brand-050);
  border-radius: var(--radius-sm);
}

.folder__name {
  margin-top: auto;
  font-size: .9375rem;
  font-weight: 600;
  line-height: 1.2;
}

.folder__amount {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Fondos de ahorro ───────────────────────────────────────────────── */

.fund-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.fund-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.fund-card__icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  font-size: 1.25rem;
  background: var(--surface-sunken);
  border-radius: 999px;
}

.fund-card__body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.fund-card__name {
  font-weight: 600;
}

.fund-card__meta {
  font-size: .8125rem;
  color: var(--text-muted);
}

.fund-card__amount {
  flex: 0 0 auto;
  font-size: 1.0625rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── Fondo por meses ────────────────────────────────────────────────── */

.month-list {
  display: flex;
  flex-direction: column;
}

.month-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}

.month-row:last-child {
  border-bottom: 0;
}

.month-row__label {
  font-weight: 600;
}

.month-row__net {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.month-row__net[data-negative] {
  color: var(--expense);
}

/* ── Estado vacío ───────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 20px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.empty-state__icon {
  font-size: 1.75rem;
}

.empty-state__title {
  font-weight: 650;
}

.empty-state__text {
  font-size: .875rem;
  color: var(--text-muted);
  max-width: 34ch;
}

/* ── Navegación inferior ────────────────────────────────────────────── */

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: min(100%, 640px);
  margin-inline: auto;
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  /* La primera declaración es el respaldo: si el navegador no entiende
     color-mix, descarta la segunda y la barra sigue siendo opaca. */
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 50px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: color .15s ease, background-color .15s ease;
}

.tab__icon {
  width: 24px;
  height: 24px;
}

.tab__label {
  max-width: 100%;
  overflow: hidden;
  font-size: .75rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab[aria-current="page"] {
  color: var(--brand-600);
  background: var(--brand-050);
}

@media (prefers-color-scheme: dark) {
  .tab[aria-current="page"] {
    color: var(--brand-500);
  }
}

/* ── Arranque ───────────────────────────────────────────────────────── */

/* Visible mientras `/api/me` decide entre login y aplicación, para no
   enseñar una pantalla que después se sustituye. */
.boot {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  color: var(--text-muted);
}

.boot[hidden],
.app[hidden],
.tabbar[hidden],
.auth[hidden] {
  display: none;
}

.boot__label {
  font-size: .9375rem;
}

/* ── Login ──────────────────────────────────────────────────────────── */

.auth {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(var(--page-x) + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(var(--page-x) + env(safe-area-inset-left));
}

.auth__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(100%, 400px);
  padding: 28px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.auth__logo {
  border-radius: 16px;
  margin-bottom: 6px;
}

.auth__title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.auth__subtitle {
  font-size: .9375rem;
  color: var(--text-muted);
  text-align: center;
}

.auth__form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  margin-top: 18px;
}

.auth__error {
  padding: 10px 12px;
  font-size: .875rem;
  color: var(--expense);
  background: color-mix(in srgb, var(--expense) 12%, transparent);
  border-radius: var(--radius-sm);
}

.auth__error[hidden] {
  display: none;
}

/* ── Formularios ────────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field__input {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 14px;
  font: inherit;
  /* 16px evita que iOS haga zoom al enfocar el campo. */
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.field__input:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 1px;
}

.button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 12px 18px;
  font-weight: 650;
  color: #fff;
  background: var(--brand-600);
  border-radius: var(--radius-sm);
  transition: opacity .15s ease;
}

.button:disabled {
  opacity: .6;
  cursor: progress;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.icon-button:hover {
  color: var(--text);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.view-header--split {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ── Paneles de la pestaña Gastos ───────────────────────────────────── */

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel[hidden] {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-header__body {
  min-width: 0;
}

.panel-header__title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.panel-header__meta {
  font-size: .875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.balance-card--expenses {
  background: linear-gradient(160deg, #e8705c, #b93f2c);
}

/* La carpeta de Recibos se distingue: no lleva a una lista de gastos sino a
   la checklist mensual. */
.folder--bills {
  border-color: color-mix(in srgb, var(--brand-500) 45%, var(--border));
}

/* Las carpetas pasan a ser botones al conectarse con datos. */
button.folder {
  width: 100%;
  text-align: left;
  transition: transform .12s ease;
}

button.folder:active {
  transform: scale(.98);
}

/* ── Chips de filtro ────────────────────────────────────────────────── */

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip-row[hidden] {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 8px 14px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.chip[aria-pressed="true"] {
  color: #fff;
  background: var(--brand-600);
  border-color: var(--brand-600);
}

/* ── Lista de movimientos ───────────────────────────────────────────── */

.movement-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.movement {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 12px 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.movement:active {
  background: var(--surface-sunken);
}

.movement__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.movement__title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.movement__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: .8125rem;
  color: var(--text-muted);
}

.movement__amount {
  flex: 0 0 auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tag {
  padding: 2px 8px;
  font-size: .6875rem;
  font-weight: 650;
  border-radius: 999px;
}

.tag--discretionary {
  color: var(--expense);
  background: color-mix(in srgb, var(--expense) 14%, transparent);
}

.tag--bill {
  color: var(--brand-600);
  background: var(--brand-050);
}

/* ── Recibos ────────────────────────────────────────────────────────── */

.bill-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
}

.bill-summary__pending {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.bill-summary__amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bill-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bill {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 12px 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.bill:active {
  background: var(--surface-sunken);
}

.bill__mark {
  flex: 0 0 auto;
  width: 26px;
  font-size: 1.05rem;
  text-align: center;
  color: var(--text-muted);
}

.bill__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.bill__name {
  font-weight: 600;
}

.bill__meta {
  font-size: .8125rem;
  color: var(--text-muted);
}

.bill__amount {
  flex: 0 0 auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bill--completed .bill__amount {
  color: var(--income);
}

.bill--skipped .bill__name,
.bill--skipped .bill__amount {
  color: var(--text-muted);
  text-decoration: line-through;
}

/* ── Botón flotante ─────────────────────────────────────────────────── */

.fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 14px 20px;
  font-weight: 650;
  color: #fff;
  background: var(--brand-600);
  border-radius: 999px;
  box-shadow: 0 6px 20px -6px rgba(0, 0, 0, .45);
}

.fab[hidden] {
  display: none;
}

.fab__icon {
  width: 20px;
  height: 20px;
  stroke-width: 2.4;
}

/* En pantallas anchas el botón acompaña al contenido en lugar de pegarse
   al borde de la ventana. */
@media (min-width: 700px) {
  .fab {
    right: calc(50% - 320px + 18px);
  }
}

/* ── Hoja inferior ──────────────────────────────────────────────────── */

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: min(100%, 640px);
  max-width: 100%;
  max-height: 92dvh;
  margin: 0 auto;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
}

.sheet::backdrop,
.dialog::backdrop {
  background: rgba(0, 0, 0, .5);
}

.sheet__inner {
  display: flex;
  flex-direction: column;
  max-height: 92dvh;
}

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 8px;
}

.sheet__title {
  font-size: 1.25rem;
  font-weight: 700;
}

.sheet__body {
  overflow-y: auto;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
}

.sheet__form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sheet__error {
  padding: 10px 12px;
  font-size: .875rem;
  color: var(--expense);
  background: color-mix(in srgb, var(--expense) 12%, transparent);
  border-radius: var(--radius-sm);
}

.sheet__error[hidden] {
  display: none;
}

/* ── Campo de importe ───────────────────────────────────────────────── */

.amount-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.amount-field__label {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.amount-field__row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.amount-input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: none;
  border: 0;
  outline: none;
}

.amount-field__currency {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-muted);
}

/* ── Selector visual de categoría ───────────────────────────────────── */

.picker-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 76px;
  padding: 10px 6px;
  font-size: .75rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.picker__icon {
  font-size: 1.25rem;
}

.picker__name {
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.picker[aria-pressed="true"] {
  color: var(--text);
  background: var(--brand-050);
  border-color: var(--brand-500);
}

/* ── Interruptor ────────────────────────────────────────────────────── */

.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.switch__body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

.switch__title {
  font-weight: 600;
}

.switch__hint {
  font-size: .8125rem;
  color: var(--text-muted);
}

/* El input real se mantiene accesible (foco y teclado) pero invisible: lo
   que se ve es `.switch__track`. */
.switch__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch__track {
  flex: 0 0 auto;
  position: relative;
  width: 50px;
  height: 30px;
  background: var(--border);
  border-radius: 999px;
  transition: background-color .15s ease;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  background: #fff;
  border-radius: 999px;
  transition: transform .15s ease;
}

.switch__input:checked ~ .switch__track {
  background: var(--brand-600);
}

.switch__input:checked ~ .switch__track::after {
  transform: translateX(20px);
}

.switch__input:focus-visible ~ .switch__track {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
}

/* ── Histórico de un recibo ─────────────────────────────────────────── */

.history__list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: .875rem;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
}

.history__month {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.history__amount {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ── Confirmación ───────────────────────────────────────────────────── */

.dialog {
  width: min(100% - 32px, 380px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-radius: var(--radius-lg);
}

.dialog__inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px;
}

.dialog__title {
  font-size: 1.125rem;
  font-weight: 700;
}

.dialog__text {
  font-size: .9375rem;
  color: var(--text-muted);
}

.dialog__actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.dialog__actions .button {
  flex: 1 1 0;
}

/* ── Variantes de botón ─────────────────────────────────────────────── */

.button--ghost {
  color: var(--text);
  background: var(--surface-sunken);
}

.button--danger {
  background: var(--expense);
}

.button--danger-ghost {
  color: var(--expense);
  background: color-mix(in srgb, var(--expense) 12%, transparent);
}

/* ── Avisos ─────────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 76px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(100% - 32px, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  font-size: .9375rem;
  font-weight: 600;
  color: #fff;
  background: #1d2b26;
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, .6);
  animation: toast-in .18s ease;
  pointer-events: auto;
}

.toast--error {
  background: var(--expense);
}

.toast__message {
  flex: 1 1 auto;
}

.toast__action {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 8px;
  font-weight: 750;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Estados ────────────────────────────────────────────────────────── */

.state {
  padding: 20px 4px;
  font-size: .9375rem;
  color: var(--text-muted);
  text-align: center;
}

.empty-state--error {
  border-color: color-mix(in srgb, var(--expense) 40%, var(--border));
}

.empty-state .button {
  margin-top: 10px;
}

/* ── Resumen: tarjetas clicables ────────────────────────────────────── */

/* Ingresos es la única KPI clicable: abre su detalle. Gastos ya tiene
   pestaña propia, así que su tarjeta se queda como escaparate. */
button.kpi-card {
  width: 100%;
  text-align: left;
  transition: transform .12s ease;
}

button.kpi-card:active {
  transform: scale(.98);
}

/* ── Aviso de ahorro del mes ────────────────────────────────────────── */

.savings-hint {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 12px 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}

.savings-hint:active {
  transform: scale(.98);
}

.savings-hint__icon {
  flex: 0 0 auto;
  font-size: 1.375rem;
}

.savings-hint__body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.savings-hint__label {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text-muted);
}

.savings-hint__amount {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--savings);
  font-variant-numeric: tabular-nums;
}

/* ── Fila genérica de estadística (desglose de gastos en Resumen) ──── */

.category-row-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.category-row:active {
  background: var(--surface-sunken);
}

.category-row__icon {
  flex: 0 0 auto;
  font-size: 1.0625rem;
}

.category-row__name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: .9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-row__amount {
  flex: 0 0 auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.discretionary-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
  font-size: .8125rem;
  color: var(--text-muted);
}

.discretionary-line strong {
  color: var(--expense);
  font-variant-numeric: tabular-nums;
}

/* ── Fondos de ahorro: fila clicable ────────────────────────────────── */

button.fund-card {
  width: 100%;
  text-align: left;
  transition: transform .12s ease;
}

button.fund-card:active {
  transform: scale(.98);
}

.fund-card__target {
  font-size: .8125rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* El detalle de un fondo reutiliza panel-header, con un botón extra a la
   derecha: que el cuerpo crezca es lo que empuja ese botón al borde. */
.panel-header__body {
  flex: 1 1 auto;
}

.fund-detail__amount {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* Vive dentro de `.balance-card--savings` (fondo en degradado), así que no
   se toca el color: hereda el blanco translúcido de `.balance-card__hint`
   en vez del gris apagado que se usaría sobre una superficie plana. */
.fund-detail__target {
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}

.fund-detail__progress-label {
  font-size: .8125rem;
  font-weight: 650;
  color: var(--savings);
}

/* ── Toggle aportar / retirar ───────────────────────────────────────── */

.movement-type {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.movement-type__option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  font-weight: 650;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.movement-type__option[aria-pressed="true"][data-type="contribution"] {
  color: var(--income);
  background: color-mix(in srgb, var(--income) 14%, transparent);
  border-color: var(--income);
}

.movement-type__option[aria-pressed="true"][data-type="withdrawal"] {
  color: var(--expense);
  background: color-mix(in srgb, var(--expense) 14%, transparent);
  border-color: var(--expense);
}

.movement-type__note {
  margin-top: -2px;
  font-size: .8125rem;
  color: var(--text-muted);
}

/* ── Ghost link (nuevo fondo) ───────────────────────────────────────── */

.ghost-link {
  align-self: flex-start;
  padding: 8px 2px;
  font-size: .875rem;
  font-weight: 650;
  color: var(--brand-600);
}

@media (prefers-color-scheme: dark) {
  .ghost-link {
    color: var(--brand-500);
  }
}

/* ── Dashboard ──────────────────────────────────────────────────────── */

.dashboard-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bar__head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.bar__icon {
  flex: 0 0 auto;
  font-size: 1rem;
}

.bar__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  font-size: .9375rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar__value {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: .9375rem;
  font-variant-numeric: tabular-nums;
}

.bar__value[data-negative] {
  color: var(--expense);
}

/* Barra más alta que la del progreso de un fondo, y recoloreada: por defecto
   (gastos) el relleno es el color de gasto; el dataset de ahorro lo cambia. */
.bar__track.progress {
  height: 14px;
}

.bar__track.progress::-webkit-progress-value {
  background: var(--expense);
}

.bar__track.progress::-moz-progress-bar {
  background: var(--expense);
}

.bar-chart--savings .bar__track.progress::-webkit-progress-value {
  background: var(--savings);
}

.bar-chart--savings .bar__track.progress::-moz-progress-bar {
  background: var(--savings);
}

/* ── Lista de la compra ─────────────────────────────────────────────── */

/* El alta queda accesible aunque la lista sea larga. El desplegable de
   coincidencias es absoluto para no mover la lista con cada tecla. */
.shop-composer {
  position: sticky;
  top: calc(8px + env(safe-area-inset-top));
  z-index: 4;
  padding-block: 4px;
  background: var(--bg);
}

.shop-add {
  display: flex;
  gap: 8px;
}

.shop-add__input {
  flex: 1 1 auto;
  min-width: 0;
}

.shop-add__quantity {
  flex: 0 0 74px;
  width: 74px;
  padding-inline: 8px;
  text-align: center;
}

.shop-add__submit {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  color: #fff;
  background: var(--brand-600);
  border-radius: var(--radius-sm);
}

.shop-add__submit svg {
  width: 22px;
  height: 22px;
}

.shop-add__submit:disabled {
  opacity: .6;
  cursor: progress;
}

[data-shopping-refresh].is-loading svg {
  animation: shop-spin .8s linear infinite;
}

@keyframes shop-spin {
  to { transform: rotate(360deg); }
}

/* Coincidencias entre los tachados. Cuelga del campo, así que va pegada a él
   y con el mismo ancho. */
.shop-suggestions {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: calc(var(--tap) + 8px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 6px 6px;
  max-height: min(44dvh, 330px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.shop-suggestions[hidden] {
  display: none;
}

.shop-suggestions__label {
  padding: 0 10px 4px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.shop-suggestions__list {
  display: flex;
  flex-direction: column;
}

.shop-suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  text-align: left;
  border-radius: var(--radius-sm);
}

.shop-suggestion:active {
  background: var(--surface-sunken);
}

.shop-suggestion__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shop-suggestion__hint {
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--brand-600);
  font-size: .75rem;
}

.shop-suggestion__quantity {
  flex: 0 0 auto;
  padding: 2px 6px;
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border-radius: 999px;
}

@media (prefers-color-scheme: dark) {
  .shop-suggestion__hint {
    color: var(--brand-500);
  }
}

/* Filas de la lista. */
.shop-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shop-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.shop-item__toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 54px;
  padding: 10px 4px 10px 14px;
  text-align: left;
}

.shop-item__toggle:disabled,
.shop-item__action:disabled {
  cursor: progress;
}

/* Casilla dibujada con el borde de la propia marca: al tachar se rellena. */
.shop-item__mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  font-size: .875rem;
  font-weight: 700;
  line-height: 1;
  color: transparent;
  border: 2px solid var(--border);
  border-radius: 999px;
}

.shop-item__name {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.shop-item__content {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.shop-item__quantity {
  flex: 0 0 auto;
  padding: 2px 7px;
  font-size: .75rem;
  font-weight: 650;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border-radius: 999px;
}

.shop-item__saving {
  flex-basis: 100%;
  font-size: .6875rem;
  color: var(--text-muted);
}

.shop-item--done {
  background: var(--surface-sunken);
}

.shop-item--done .shop-item__mark {
  color: #fff;
  background: var(--brand-600);
  border-color: var(--brand-600);
}

.shop-item--done .shop-item__name {
  color: var(--text-muted);
  text-decoration: line-through;
}

.shop-item__actions {
  display: flex;
  flex: 0 0 auto;
}

.shop-item__action {
  flex: 0 0 auto;
  width: var(--tap);
  min-height: var(--tap);
  line-height: 1;
  color: var(--text-muted);
}

.shop-item__edit {
  font-size: 1.125rem;
}

.shop-item__delete {
  font-size: 1.375rem;
  border-radius: var(--radius-md);
}

.shop-item__delete:active {
  color: var(--expense);
}

.shop-item--busy {
  opacity: .68;
}

.shop-item--highlight {
  animation: shop-highlight 1.1s ease;
}

@keyframes shop-highlight {
  0%, 100% { box-shadow: none; }
  35% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-500) 35%, transparent); }
}

.shop-limit-warning {
  padding: 10px 12px;
  font-size: .8125rem;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
}

.app-version {
  padding-top: 4px;
  font-size: .6875rem;
  color: var(--text-muted);
  text-align: center;
}

/* Contador junto al título de "Pendientes" y "Tachados". */
.block__meta {
  font-size: .875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

/* Mantenimiento, no la acción principal de la pantalla: discreta hasta que se
   toca, igual que la × de cada fila. Del aviso se encarga la confirmación. */
.ghost-link--danger {
  color: var(--text-muted);
}

.ghost-link--danger:active {
  color: var(--expense);
}
