:root {
  --brand:        #10b981;
  --brand-dark:   #0f766e;
  --brand-darker: #115e59;
  --brand-light:  #d1fae5;
  --brand-lighter:#ecfdf5;
  --ink:      #0f172a;
  --muted:    #64748b;
  --bg:       #f1f5f9;
  --card:     #ffffff;
  --line:     rgba(15,23,42,.08);
  --field:    #ffffff;
  --field-bg: #f1f5f9;
  --ok:       #16a34a;
  --warn:     #f59e0b;
  --danger:   #ef4444;
  --info:     #0ea5e9;
  --radius:   18px;
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 10px 25px rgba(15,23,42,.08);
  --shadow-lg: 0 24px 55px rgba(15,23,42,.16);
}

/* ---- Modo oscuro ---- */
:root[data-theme="dark"] {
  --brand-light:  #164e42;
  --brand-lighter:#12312b;
  --ink:      #e2e8f0;
  --muted:    #94a3b8;
  --bg:       #0b1120;
  --card:     #131c2e;
  --line:     rgba(255,255,255,.09);
  --field:    #1c2740;
  --field-bg: #1c2740;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 10px 25px rgba(0,0,0,.45);
  --shadow-lg: 0 24px 55px rgba(0,0,0,.55);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-light:  #164e42;
    --brand-lighter:#12312b;
    --ink:      #e2e8f0;
    --muted:    #94a3b8;
    --bg:       #0b1120;
    --card:     #131c2e;
    --line:     rgba(255,255,255,.09);
    --field:    #1c2740;
    --field-bg: #1c2740;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
    --shadow-md: 0 10px 25px rgba(0,0,0,.45);
    --shadow-lg: 0 24px 55px rgba(0,0,0,.55);
  }
}
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select,
:root[data-theme="dark"] .input-group-text,
:root[data-theme="dark"] .list-group-item,
:root[data-theme="dark"] .table {
  background-color: var(--card); color: var(--ink); border-color: var(--line);
}
:root[data-theme="dark"] .btn-light { background: var(--field); border-color: var(--line); color: var(--ink); }
:root[data-theme="dark"] .btn-outline-secondary { color: var(--ink); border-color: var(--line); }
:root[data-theme="dark"] .bar-track { background: rgba(255,255,255,.09); }
:root[data-theme="dark"] .table > :not(caption) > * > * { background-color: transparent; color: var(--ink); }
:root[data-theme="dark"] .modal-content, :root[data-theme="dark"] .dropdown-menu { background: var(--card); color: var(--ink); }
:root[data-theme="dark"] .text-bg-light { background: var(--field) !important; color: var(--ink) !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .card,
  :root:not([data-theme="light"]) .form-control,
  :root:not([data-theme="light"]) .form-select,
  :root:not([data-theme="light"]) .input-group-text,
  :root:not([data-theme="light"]) .table { background-color: var(--card); color: var(--ink); border-color: var(--line); }
  :root:not([data-theme="light"]) .btn-light { background: var(--field); border-color: var(--line); color: var(--ink); }
  :root:not([data-theme="light"]) .bar-track { background: rgba(255,255,255,.09); }
}

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: clip; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition-duration: .01ms !important; animation-duration: .01ms !important; } }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;   /* 'clip' (no 'hidden') para no romper position: sticky del navbar */
}
main.container-xl { flex: 1 0 auto; width: 100%; min-width: 0; }
.site-footer { flex-shrink: 0; background: var(--card); }
h1,h2,h3,h4,h5,h6,.navbar-brand { font-family: 'Sora','Inter',sans-serif; font-weight: 700; letter-spacing: -.01em; }
h1,h2,h3,h4 { text-wrap: balance; }
img, svg, canvas { max-width: 100%; }

a { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand-darker); }
.text-primary { color: var(--brand-dark) !important; }
.text-money-in  { color: var(--ok); }
.text-money-out { color: var(--danger); }
.text-muted { color: var(--muted) !important; }

.nav-icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 1.1rem; text-decoration: none; border: 0; background: transparent; position: relative; }
.nav-icon-btn:hover { background: rgba(255,255,255,.14); color: #fff; }

/* ---------- Navbar ---------- */
.app-nav {
  background: linear-gradient(100deg, var(--brand-darker), var(--brand-dark) 55%, var(--brand));
  position: sticky; top: 0; z-index: 1035;
  box-shadow: var(--shadow-sm);
}
.brand-badge {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: rgba(255,255,255,.16); color: #fff; font-weight: 800;
}
.app-nav .nav-link { font-weight: 500; border-radius: 9px; transition: background .15s; padding: .5rem .8rem; }
.app-nav .nav-link:hover, .app-nav .nav-link.active { background: rgba(255,255,255,.14); color: #fff; }
.app-nav .dropdown-menu { box-shadow: var(--shadow-md); border: 0; border-radius: 14px; }

/* ---------- Botones ---------- */
.btn { border-radius: 12px; font-weight: 600; transition: transform .12s, box-shadow .15s, filter .15s, background .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-primary:hover, .btn-primary:focus { background: var(--brand-darker); border-color: var(--brand-darker); color: #fff; box-shadow: 0 6px 18px rgba(15,118,110,.28); }
.btn-outline-primary { color: var(--brand-dark); border-color: var(--brand-dark); border-width: 1.5px; }
.btn-outline-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-outline-secondary { border-color: var(--line); color: var(--muted); }
.btn-outline-secondary:hover { background: var(--field-bg); border-color: var(--line); color: var(--ink); }
.btn-success { background: var(--ok); border-color: var(--ok); }
.btn-gradient { background: linear-gradient(120deg, var(--brand-dark), var(--brand)); border: 0; color: #fff; }
.btn-gradient:hover { color: #fff; box-shadow: var(--shadow-md); filter: brightness(1.05); }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: none; }
.card-body { padding: 1.1rem 1.15rem; }
.card-header { background: transparent; font-weight: 700; border-bottom: 1px solid var(--line); }
/* Título de sección dentro de una tarjeta */
.card-body > h6:first-child,
.card-body > .fw-bold:first-child { font-size: .98rem; font-weight: 700; letter-spacing: -.01em; margin-bottom: .95rem; }

/* ---------- Formularios (estilo app: campos "rellenos") ---------- */
.form-control, .form-select {
  border-radius: 12px; padding: .68rem .9rem;
  background: var(--field-bg); border: 1px solid transparent; color: var(--ink);
}
.form-control::placeholder { color: var(--muted); opacity: .75; }
.form-control:focus, .form-select:focus {
  background: var(--card); border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(16,185,129,.14); color: var(--ink);
}
.form-control:disabled, .form-control[readonly] { background: var(--field-bg); opacity: .7; }
.form-label { font-weight: 600; font-size: .86rem; color: var(--ink); margin-bottom: .35rem; }
.form-text { color: var(--muted); font-size: .8rem; }
.form-check-input { border-color: var(--line); }
.form-check-input:checked { background-color: var(--brand-dark); border-color: var(--brand-dark); }
.form-check-input:focus { box-shadow: 0 0 0 3px rgba(16,185,129,.14); border-color: var(--brand); }
.form-control-color { padding: .3rem; border-radius: 12px; background: var(--field-bg); border-color: transparent; }
input[type="date"].form-control::-webkit-calendar-picker-indicator { opacity: .55; }

/* ---------- input-group unido y limpio ---------- */
.input-group { flex-wrap: nowrap; }
.input-group > .form-control, .input-group > .form-select { min-width: 0; }
.input-group-text {
  background: var(--field-bg); border: 1px solid transparent; color: var(--muted); font-weight: 600;
}
.input-group:focus-within .input-group-text { border-color: transparent; }
.input-group > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) { margin-left: 0; }
.input-group > .btn { border-radius: 0 12px 12px 0; }

.badge.text-bg-primary { background: var(--brand-dark) !important; }

/* ---------- Campo de archivo (recibo / foto) ---------- */
input[type="file"].form-control {
  padding: 0; overflow: hidden; color: var(--muted); font-size: .86rem;
  border: 1.5px dashed var(--line); background: var(--card);
  display: flex; align-items: center; min-height: 46px;
}
input[type="file"].form-control::file-selector-button {
  align-self: stretch; margin: 0 .85rem 0 0; padding: 0 1rem;
  border: 0; border-right: 1px solid var(--line);
  background: var(--brand-lighter); color: var(--brand-dark);
  font: inherit; font-weight: 700; font-size: .85rem; cursor: pointer; transition: background .15s;
}
input[type="file"].form-control::file-selector-button:hover { background: var(--brand-light); }
input[type="file"].form-control:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(16,185,129,.14); }

/* ---------- Checkboxes / switches (más grandes, tipo app) ---------- */
.form-check { padding-left: 0; display: flex; align-items: flex-start; gap: .7rem; min-height: 1.5rem; margin-bottom: .55rem; }
.form-check .form-check-input {
  float: none; margin: .1rem 0 0 0; flex: 0 0 auto;
  width: 1.3rem; height: 1.3rem; border-radius: 8px; border: 1.6px solid var(--line);
  background-color: var(--field-bg); cursor: pointer; transition: background-color .15s, border-color .15s;
}
.form-check .form-check-input:checked { background-color: var(--brand-dark); border-color: var(--brand-dark); }
.form-check .form-check-label { cursor: pointer; font-size: .93rem; line-height: 1.45; color: var(--ink); }
.form-switch { padding-left: 0; }
.form-switch .form-check-input { width: 2.6rem; height: 1.5rem; border-radius: 999px; margin-top: 0; }
.form-switch .form-check-input:checked { background-color: var(--brand-dark); border-color: var(--brand-dark); }

/* ---------- Control segmentado (Ingreso / Gasto / Transferencia) ---------- */
.btn-group[role="group"].w-100 {
  background: var(--field-bg); border-radius: 13px; padding: 4px; gap: 4px;
}
.btn-group[role="group"].w-100 > .btn {
  border: 0 !important; border-radius: 9px !important; font-weight: 600; font-size: .9rem;
  background: transparent; color: var(--muted); box-shadow: none;
}
.btn-group[role="group"].w-100 > .btn:hover { color: var(--ink); background: rgba(15,23,42,.04); }
.btn-group[role="group"].w-100 > .btn.active,
.btn-group[role="group"].w-100 > .btn-success,
.btn-group[role="group"].w-100 > .btn-danger,
.btn-group[role="group"].w-100 > .btn-primary {
  background: var(--card) !important; color: var(--ink) !important; box-shadow: var(--shadow-sm);
}
.btn-group[role="group"].w-100 > .btn-success.active, .btn-group[role="group"].w-100 > .btn-outline-success.active { color: var(--ok) !important; }
.btn-group[role="group"].w-100 > .btn-danger.active, .btn-group[role="group"].w-100 > .btn-outline-danger.active { color: var(--danger) !important; }

/* ---------- Tablas: lista limpia, no rejilla de datos ---------- */
.table { --bs-table-bg: transparent; color: var(--ink); margin-bottom: 0; }
.table > thead th {
  border: 0; border-bottom: 1px solid var(--line);
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; padding: .35rem .55rem .55rem;
}
.table > tbody td, .table > tbody th {
  border: 0; border-top: 1px solid var(--line);
  padding: .72rem .55rem; vertical-align: middle; font-variant-numeric: tabular-nums;
}
.table > tbody tr:first-child td, .table > tbody tr:first-child th { border-top: 0; }
.table > thead + tbody tr:first-child td { border-top: 1px solid var(--line); }
.table > tbody td:last-child, .table > thead th:last-child { text-align: right; white-space: nowrap; }
.table.table-sm > :not(caption) > * > * { padding: .5rem .5rem; }
.table tr:hover > * { background: var(--field-bg); }

/* ---------- Stat cards (panel) ---------- */
.stat-card { border-radius: var(--radius); color: #fff; border: 0; overflow: hidden; position: relative; }
.stat-card .card-body { position: relative; z-index: 1; padding: 1.1rem 1.2rem; }
.stat-card .lbl { font-size: .8rem; opacity: .9; font-weight: 600; }
.stat-card .num { font-family: 'Sora',sans-serif; font-size: 1.7rem; font-weight: 800; line-height: 1.15; }
.stat-card .sub { font-size: .78rem; opacity: .82; }
.stat-card::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 140px; height: 140px;
  background: radial-gradient(circle, rgba(255,255,255,.18), transparent 70%);
}
.grad-in    { background: linear-gradient(135deg, #059669, #34d399); }
.grad-out   { background: linear-gradient(135deg, #e11d48, #fb7185); }
.grad-net   { background: linear-gradient(135deg, #0f766e, #14b8a6); }
.grad-worth { background: linear-gradient(135deg, #4338ca, #818cf8); }
.grad-gold  { background: linear-gradient(135deg, #d97706, #fbbf24); color: #422006; }

/* ---------- Barras de progreso de presupuesto ---------- */
.bar-track { background: #e9eef5; border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 999px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.bar-fill.lvl-success { background: var(--ok); }
.bar-fill.lvl-info    { background: var(--info); }
.bar-fill.lvl-warning { background: var(--warn); }
.bar-fill.lvl-danger  { background: var(--danger); }

.cat-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.cat-ico {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  color: #fff; font-size: 1.05rem; flex: 0 0 auto;
}

/* ---------- Anillo de salud financiera ---------- */
.health-ring { --val: 0; width: 128px; height: 128px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--brand) calc(var(--val)*1%), #e9eef5 0);
}
.health-ring .inner { width: 98px; height: 98px; border-radius: 50%; background: var(--card); display: grid; place-items: center; text-align: center; }
.health-ring .score { font-family: 'Sora',sans-serif; font-size: 1.8rem; font-weight: 800; line-height: 1; }

/* ---------- Lista de movimientos ---------- */
.mov-row { display: flex; align-items: center; gap: .85rem; padding: .7rem .2rem; border-bottom: 1px solid #eef2f7; }
.mov-row:last-child { border-bottom: 0; }
.mov-row .desc { font-weight: 600; }
.mov-row .meta { font-size: .8rem; color: var(--muted); }
.mov-amount { font-family: 'Sora',sans-serif; font-weight: 700; white-space: nowrap; }

.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--brand-lighter); color: var(--brand-darker);
  border-radius: 999px; padding: .24rem .66rem; font-size: .76rem; font-weight: 700; white-space: nowrap;
}
.chip.soft { background: var(--field-bg); color: var(--muted); }

/* ---------- Encabezado de página ---------- */
main.container-xl > h3:first-child,
main.container-xl > h3.mb-1,
main.container-xl > h3.mb-3 { font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: .35rem; }
main.container-xl > h3 + p.text-muted,
main.container-xl > p.text-muted:nth-child(2) {
  font-size: .88rem; line-height: 1.5; color: var(--muted);
  max-width: 62ch; margin-bottom: 1.1rem;
}

/* ---------- Subtítulo/ayuda dentro de una tarjeta ---------- */
.card-body > .small.text-muted, .card-body > p.text-muted {
  font-size: .84rem; line-height: 1.5; margin-bottom: .9rem;
}

/* ---------- Mini-tarjetas de resumen (fila de 3) ---------- */
.card .card-body.py-2.text-center { padding: .85rem .6rem; }
.card .card-body.py-2.text-center .small.text-muted,
.card .card-body.py-2.text-center .text-muted:first-child {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; margin-bottom: .15rem;
}
.card .card-body.py-2.text-center .fw-bold {
  font-family: 'Sora', sans-serif; font-weight: 800; letter-spacing: -.02em; font-size: 1.2rem; line-height: 1.1;
}

/* ---------- Filas "etiqueta ⋯ valor" dentro de tarjetas ---------- */
.card-body > .d-flex.justify-content-between:not(:last-child) { padding-bottom: .55rem; }
.card-body .list-plain > * {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.card-body .list-plain > *:first-child { border-top: 0; }

/* ---------- Barras de progreso ---------- */
.bar-track { background: var(--field-bg); border-radius: 999px; height: 8px; }

/* ---------- Empty states más compactos ---------- */
.empty { text-align: center; padding: 1.75rem 1rem; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.empty i { font-size: 2rem; color: var(--brand); display: block; margin-bottom: .5rem; opacity: .85; }

/* ---------- Grupos de acciones rápidas (fila de botones + campo) ---------- */
.action-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.action-row > .btn, .action-row > form > .btn { flex: 1 1 auto; }
.d-grid > .btn { width: 100%; }

/* Botón "+" / icono que acompaña a un campo: que iguale la altura, no un bloque enorme */
.col-1 > .btn, .col-2 > .btn, [class*="col-"].d-grid > .btn { min-width: 44px; padding-inline: .6rem; }

/* ---------- Quick add (barra lenguaje natural) ---------- */
.quick-add { background: linear-gradient(120deg, var(--brand-darker), var(--brand)); border-radius: var(--radius); color: #fff; }
.quick-add input {
  border: 0; background: rgba(255,255,255,.16); color: #fff; border-radius: 11px;
}
.quick-add input::placeholder { color: rgba(255,255,255,.75); }
.quick-add input:focus { background: rgba(255,255,255,.25); box-shadow: none; color: #fff; }

/* ---------- Auth ---------- */
body.page-auth { background: var(--card); }
body.page-auth main.container-xl { padding: 0 !important; max-width: 100%; display: flex; flex-direction: column; }
.auth-card { display: contents; }   /* el wrapper heredado no cuenta para el layout */

.auth-wrap {
  flex: 1; min-height: 100dvh; width: 100%;
  max-width: 400px; margin: 0 auto;
  display: flex; flex-direction: column; justify-content: center;
  padding: calc(3.5rem + env(safe-area-inset-top)) 1.6rem calc(2rem + env(safe-area-inset-bottom));
}

.auth-back {
  position: fixed; left: .9rem; top: calc(.9rem + env(safe-area-inset-top)); z-index: 5;
  display: inline-flex; align-items: center; gap: .2rem;
  color: var(--muted); font-size: .88rem; font-weight: 600;
  padding: .4rem .5rem;
}
.auth-back:hover { color: var(--ink); }

.auth-top { text-align: center; margin-bottom: 2rem; }
.auth-logo {
  width: 66px; height: 66px; border-radius: 18px; margin: 0 auto 1.3rem;
  display: grid; place-items: center; overflow: hidden;
  background: #fff; border: 1px solid var(--line);
  box-shadow: 0 12px 26px rgba(15,23,42,.12);
}
.auth-logo img { width: 100%; height: 100%; object-fit: contain; }
.auth-top h1 {
  font-family: 'Sora', system-ui, sans-serif; font-weight: 800;
  font-size: 1.6rem; letter-spacing: -.02em; margin: 0 0 .35rem; color: var(--ink);
}
.auth-top p { color: var(--muted); margin: 0; font-size: .95rem; }

.auth-field { margin-bottom: 1.05rem; }
.auth-field > label {
  display: block; font-size: .82rem; font-weight: 600;
  color: var(--ink); margin-bottom: .45rem;
}
.auth-field .box { position: relative; }
.auth-field .form-control, .auth-field .form-select {
  height: 52px; border-radius: 14px; font-size: 1rem;
  padding: 0 1rem; background: var(--field-bg);
  border: 1.5px solid transparent; color: var(--ink);
}
.auth-field .form-control::placeholder { color: var(--muted); opacity: .8; }
.auth-field .form-control:focus, .auth-field .form-select:focus {
  background: var(--card); border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(16,185,129,.15);
}
.auth-field .box:has(.pw-toggle) .form-control { padding-right: 3rem; }
.auth-field .pw-toggle {
  position: absolute; right: .4rem; top: 50%; transform: translateY(-50%);
  width: 42px; height: 42px; border: 0; background: transparent;
  color: var(--muted); font-size: 1.1rem; border-radius: 10px;
}
.auth-field .pw-toggle:hover { color: var(--ink); }
.auth-field .hint { font-size: .78rem; color: var(--muted); }

.auth-btn {
  width: 100%; height: 54px; border-radius: 14px;
  font-weight: 700; font-size: 1.05rem; margin-top: .7rem;
}
.auth-alt { text-align: center; color: var(--muted); font-size: .93rem; margin-top: 1.7rem; }
.auth-alt a { font-weight: 700; }
.auth-wrap .alert { border-radius: 12px; }

@media (min-width: 600px) {
  .auth-wrap {
    max-width: 400px; justify-content: center; min-height: 100dvh;
    padding-top: 2rem;
  }
}

/* ---------- Confirmación (modal propio) ---------- */
.confirm-overlay { position: fixed; inset: 0; z-index: 1090; display: none; align-items: center; justify-content: center; background: rgba(15,23,42,.55); padding: 1.2rem; }
.confirm-overlay.open { display: flex; }
.confirm-box { background: #fff; border-radius: 16px; max-width: 400px; width: 100%; padding: 1.4rem; box-shadow: var(--shadow-lg); }
.confirm-msg { margin: 0 0 1.1rem; }
.confirm-actions { display: flex; gap: .6rem; justify-content: flex-end; }
.confirm-actions .btn { min-width: 96px; }

/* ---------- Toasts / logros ---------- */
.toast-stack { position: fixed; right: 12px; bottom: 12px; z-index: 1085; display: flex; flex-direction: column; gap: 8px; max-width: min(360px,92vw); }
@media (max-width: 991.98px) { .toast-stack { bottom: 78px; } }
.mini-toast { display: flex; gap: .6rem; align-items: flex-start; background: #fff; border-left: 4px solid var(--brand); border-radius: 12px; padding: .75rem .85rem; font-size: .88rem; box-shadow: var(--shadow-md); animation: tin .28s ease; }
.mini-toast.leave { animation: tout .4s ease forwards; }
@keyframes tin { from { opacity: 0; transform: translateY(12px); } }
@keyframes tout { to { opacity: 0; transform: translateX(20px); } }

/* ---------- Reveal ---------- */
.reveal { opacity: 0; transform: translateY(16px); transition: opacity .5s ease, transform .5s ease; }
.reveal.in { opacity: 1; transform: none; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty i { font-size: 2.5rem; color: var(--brand); display: block; margin-bottom: .5rem; }

/* ---------- Bottom nav (móvil) ---------- */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040; display: flex; justify-content: space-around; align-items: stretch; background: #fff; border-top: 1px solid rgba(15,23,42,.08); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 20px rgba(15,23,42,.06); }
.bottom-nav .bn-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px 2px; color: var(--muted); font-size: .68rem; font-weight: 600; min-height: 58px; }
.bottom-nav .bn-item i { font-size: 1.3rem; }
.bottom-nav .bn-item.active { color: var(--brand-dark); }
.bottom-nav .bn-add {
  flex: 0 0 54px; align-self: center;
  width: 54px; height: 54px; min-height: 0; aspect-ratio: 1;
  margin: -18px .15rem 0; padding: 0; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand)); color: #fff;
  display: grid; place-items: center; box-shadow: 0 8px 20px rgba(16,185,129,.4);
}
.bottom-nav .bn-add i { font-size: 1.5rem; line-height: 1; }
.bottom-nav .bn-add span { display: none; }   /* el "+" no lleva etiqueta de texto */

/* ============================================================
   MÓVIL  (una tableta angosta y todos los teléfonos)
   ========================================================== */
@media (max-width: 991.98px) {
  main.container-xl { padding: .8rem 12px 1rem; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .site-footer { display: none; }

  /* ---- Escala tipográfica coherente ---- */
  h1, .h1 { font-size: 1.45rem; }
  h2, .h2 { font-size: 1.28rem; }
  h3, .h3 { font-size: 1.18rem; margin-bottom: .85rem; }
  h4, .h4 { font-size: 1.08rem; }
  h5, .h5 { font-size: 1rem; }
  h6, .h6 { font-size: .92rem; }
  .display-1,.display-2,.display-3,.display-4 { font-size: 2.1rem; }
  .display-5 { font-size: 1.9rem; }
  .display-6 { font-size: 1.6rem; }
  .fs-1 { font-size: 1.5rem !important; }
  .fs-2 { font-size: 1.32rem !important; }
  .fs-3 { font-size: 1.18rem !important; }
  .fs-4 { font-size: 1.06rem !important; }
  .fs-5 { font-size: .98rem !important; }
  .lead { font-size: 1rem; }
  .small, small { font-size: .82rem; }

  /* ---- Ritmo de espaciado más compacto ---- */
  .card { border-radius: 14px; }
  .card-body { padding: .9rem; }
  .card + .card, .card.mb-3, .card.mb-4 { margin-bottom: .9rem; }
  .mb-4 { margin-bottom: 1rem !important; }
  .mt-4 { margin-top: 1rem !important; }
  .my-4 { margin-top: 1rem !important; margin-bottom: 1rem !important; }
  .py-4 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
  .p-4 { padding: 1rem !important; }
  .g-4 { --bs-gutter-x: .9rem; --bs-gutter-y: .9rem; }
  .g-3 { --bs-gutter-x: .7rem; --bs-gutter-y: .7rem; }
  .row { --bs-gutter-x: .8rem; }

  /* ---- Nada dentro de una tarjeta debe desbordar / cortarse ---- */
  .card, .card-body { min-width: 0; }
  .card [class*="col-"], .row > [class*="col-"] { min-width: 0; }
  .form-control, .form-select, .input-group { min-width: 0; max-width: 100%; }

  /* ---- Formularios: 16px evita el zoom automático de iOS ---- */
  .form-control, .form-select { font-size: 16px; min-height: 46px; border-radius: 12px; padding-left: .75rem; padding-right: .75rem; }
  .form-control-sm, .form-select-sm { min-height: 40px; font-size: 15px; padding-left: .6rem; padding-right: .6rem; }
  textarea.form-control { min-height: 88px; }
  .input-group-text { font-size: 15px; padding-inline: .6rem; }
  .form-label { font-size: .84rem; font-weight: 600; margin-bottom: .3rem; }
  .form-control-color { min-height: 46px; }

  /* ---- input-group: se mantiene en una línea; el campo encoge, no se parte ---- */
  .input-group { flex-wrap: nowrap; }
  .input-group > .form-control, .input-group > .form-select { min-width: 0; }
  .input-group > .btn { flex: 0 0 auto; white-space: nowrap; }

  /* ---- Botones táctiles (mínimo 44px) ---- */
  .btn { min-height: 44px; border-radius: 12px; padding-inline: .9rem;
         display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
         min-width: 0; max-width: 100%; }
  .btn-sm { min-height: 38px; padding-inline: .7rem; border-radius: 10px; }
  .btn-lg { min-height: 52px; }
  .d-grid > .btn, .btn.w-100 { width: 100%; }
  .btn-group .btn { flex: 1; }
  /* botones dentro de columnas angostas de una grilla: padding chico y texto que no rompe */
  [class*="col-"] .btn, [class*="col-"] .btn-sm { padding-inline: .5rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* ---- Barra superior ---- */
  .app-nav { padding: .15rem .5rem; }
  .app-nav .container-xl { padding-inline: .5rem; }
  .navbar-brand { font-size: 1.05rem; gap: .45rem; }
  .navbar-brand img { width: 24px; height: 24px; }
  .nav-icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 1.15rem; }
  .nav-dot { position: absolute; top: 2px; right: 0; background: var(--danger); color: #fff; font-size: .6rem; font-weight: 700; min-width: 16px; height: 16px; border-radius: 999px; display: grid; place-items: center; border: 2px solid var(--brand-dark); }

  /* ---- Menú plegable (hoja desplegable) ---- */
  .app-nav .navbar-collapse {
    position: absolute; left: 8px; right: 8px; top: calc(100% + 6px);
    background: var(--card); color: var(--ink);
    border: 1px solid var(--line); border-radius: 18px;
    box-shadow: var(--shadow-lg);
    padding: .5rem; max-height: 82vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
    z-index: 1041;
  }
  .mobile-account {
    display: flex; align-items: center; gap: .7rem; padding: .75rem;
    margin-bottom: .35rem; background: var(--brand-lighter); border-radius: 13px;
  }
  .mobile-account .fw-semibold { color: var(--ink); }

  /* items principales */
  .app-nav .navbar-nav { gap: 1px; }
  .app-nav .navbar-nav .nav-link {
    color: var(--ink); padding: .8rem .8rem; border-radius: 11px;
    display: flex; align-items: center; gap: .8rem; font-size: .95rem; font-weight: 500;
  }
  .app-nav .navbar-nav .nav-link.active, .app-nav .navbar-nav .nav-link:hover {
    background: var(--brand-lighter); color: var(--brand-darker); font-weight: 600;
  }
  .app-nav .navbar-nav .nav-link > i:first-child {
    color: var(--brand-dark); width: 22px; text-align: center; font-size: 1.1rem; flex: none;
  }

  /* "Más" pasa a ser un encabezado de sección, no un desplegable */
  .app-nav .nav-item.dropdown > .dropdown-toggle {
    pointer-events: none;
    padding: 1rem .8rem .35rem; margin-top: .2rem;
    font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
    color: var(--muted); background: transparent !important;
  }
  .app-nav .nav-item.dropdown > .dropdown-toggle::after { display: none; }
  .app-nav .nav-item.dropdown > .dropdown-toggle > i { display: none; }

  .app-nav .dropdown-menu {
    position: static !important; display: block !important; float: none;
    inset: auto !important; transform: none !important;
    width: 100%; border: 0; box-shadow: none; padding: 0; margin: 0; background: transparent;
  }
  .app-nav .dropdown-menu .dropdown-item {
    color: var(--ink); padding: .72rem .8rem; border-radius: 11px;
    display: flex; align-items: center; gap: .8rem; font-size: .92rem;
    white-space: normal;
  }
  .app-nav .dropdown-menu .dropdown-item > i:first-child {
    color: var(--brand-dark); width: 22px; text-align: center; font-size: 1.05rem; flex: none;
  }
  .app-nav .dropdown-menu .dropdown-item.active,
  .app-nav .dropdown-menu .dropdown-item:hover {
    background: var(--brand-lighter); color: var(--brand-darker); font-weight: 600;
  }
  .app-nav .dropdown-divider {
    display: block; border-top: 1px solid var(--line); opacity: 1; margin: .45rem .5rem;
  }

  .mobile-logout { border-top: 1px solid var(--line); margin-top: .4rem; padding-top: .35rem; }
  .mobile-logout .nav-link { color: var(--ink); padding: .8rem .8rem; display: flex; align-items: center; gap: .8rem; border-radius: 11px; }
  .mobile-logout .nav-link.text-danger { color: var(--danger) !important; }
  .mobile-logout .nav-link.text-danger i { color: var(--danger); }

  /* ---- Tarjetas de estadística del panel ---- */
  .stat-card .card-body { padding: .8rem .85rem; }
  .stat-card .lbl { font-size: .72rem; }
  .stat-card .num { font-size: 1.3rem; }
  .stat-card .sub { font-size: .7rem; }
  .stat-card::after { width: 100px; height: 100px; right: -24px; top: -24px; }

  /* ---- Listas de movimientos y filas ---- */
  .mov-row { padding: .6rem .1rem; gap: .7rem; }
  .mov-row .desc, .mov-row .fw-semibold { font-size: .92rem; }
  .mov-row .meta { font-size: .76rem; }
  .mov-amount { font-size: .95rem; }
  .cat-ico { width: 36px; height: 36px; font-size: 1rem; border-radius: 10px; }

  /* ---- Tablas ---- */
  .table-responsive { -webkit-overflow-scrolling: touch; }
  table.table { font-size: .84rem; width: 100%; }
  .table > thead th { padding: .3rem .35rem .45rem; font-size: .62rem; }
  .table > :not(caption) > * > * { padding: .6rem .35rem; }
  .table > tbody td:first-child { padding-left: 0; }
  .table > tbody td:last-child { padding-right: 0; }
  .table-sm > :not(caption) > * > * { padding: .45rem .3rem; }
  .table tr:hover > * { background: transparent; }

  /* ---- Anillo de salud ---- */
  .health-ring { width: 110px; height: 110px; }
  .health-ring .inner { width: 84px; height: 84px; }
  .health-ring .score { font-size: 1.5rem; }

  /* ---- XP / racha / gamificación ---- */
  .xp-card .card-body { padding: .9rem; }
  .logro-badge { padding: .75rem .4rem; }
  .logro-badge i { font-size: 1.4rem; }
  .logro-badge .t { font-size: .72rem; }

  /* ---- Chips, badges ---- */
  .chip { font-size: .74rem; padding: .2rem .58rem; }
  .badge { font-size: .72rem; }

  /* ---- Grillas que en escritorio son de varias columnas ---- */
  .plantilla-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: .5rem; }

  /* ---- Modales a lo ancho de la pantalla ---- */
  .modal-dialog { margin: .6rem; }
  .modal-content { border-radius: 16px; }
  .modal-body { padding: 1rem; }

  /* ---- Alertas / avisos ---- */
  .alert { border-radius: 12px; padding: .75rem .9rem; font-size: .9rem; }

  /* ---- Dropdowns generales ---- */
  .dropdown-menu { border-radius: 14px; box-shadow: var(--shadow-lg); font-size: .95rem; }
  .dropdown-item { padding: .6rem .9rem; }
}

/* ============================================================
   TELÉFONO ANGOSTO  (≤ 400px)
   ========================================================== */
@media (max-width: 400px) {
  main.container-xl { padding-inline: 10px; }
  .card-body { padding: .8rem; }
  h1, .h1 { font-size: 1.35rem; }
  h3, .h3 { font-size: 1.12rem; }
  .stat-card .num { font-size: 1.18rem; }
  .stat-card .lbl { font-size: .68rem; }
  table.table { font-size: .8rem; }
  .btn { padding-inline: .8rem; }
  .plantilla-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Buscador global ---------- */
.buscador-overlay { position: fixed; inset: 0; z-index: 1095; background: rgba(15,23,42,.55); backdrop-filter: blur(3px); display: flex; align-items: flex-start; justify-content: center; padding: 10vh 1rem 1rem; }
.buscador-box { width: 100%; max-width: 560px; background: var(--card); color: var(--ink); border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden; }
.buscador-input { display: flex; align-items: center; gap: .6rem; padding: .9rem 1rem; border-bottom: 1px solid var(--line); }
.buscador-input i { color: var(--muted); }
.buscador-input input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 1rem; }
.buscador-input kbd { background: var(--field-bg); border-radius: 5px; padding: .1rem .4rem; font-size: .7rem; color: var(--muted); }
.buscador-res { max-height: 55vh; overflow-y: auto; }
.buscador-res .bg-grp { font-size: .7rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: .6rem 1rem .2rem; font-weight: 700; }
.buscador-res .bg-item { display: flex; gap: .7rem; align-items: center; padding: .55rem 1rem; color: var(--ink); }
.buscador-res .bg-item i { color: var(--brand); width: 20px; text-align: center; }
.buscador-res .bg-item:hover, .buscador-res .bg-item.sel { background: var(--brand-lighter); }

/* ---------- XP / nivel ---------- */
.xp-card { background: linear-gradient(120deg, var(--brand-darker), var(--brand)); color: #fff; border: 0; }
.xp-bar { height: 8px; background: rgba(255,255,255,.25); border-radius: 999px; overflow: hidden; }
.xp-bar > span { display: block; height: 100%; background: #fff; border-radius: 999px; transition: width .8s cubic-bezier(.2,.8,.2,1); }
.logro-badge { display: flex; flex-direction: column; align-items: center; gap: .3rem; text-align: center; padding: .9rem .5rem; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.logro-badge.got i { color: var(--brand); }
.logro-badge.locked { opacity: .45; }
.logro-badge i { font-size: 1.6rem; }
.logro-badge .t { font-size: .78rem; font-weight: 700; line-height: 1.2; }

/* ---------- Plantillas rápidas ---------- */
.plantilla-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; }
.plantilla-btn { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); padding: .8rem .6rem; text-align: center; cursor: pointer; transition: transform .12s, box-shadow .15s; }
.plantilla-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.plantilla-btn i { font-size: 1.4rem; display: block; margin-bottom: .3rem; }
.plantilla-btn .m { font-weight: 700; font-family: 'Sora',sans-serif; }
.plantilla-btn .n { font-size: .78rem; color: var(--muted); }

/* ---------- Split rows ---------- */
.split-row { display: flex; gap: .5rem; margin-bottom: .5rem; align-items: center; }

/* ---------- Onboarding ---------- */
.onb-step { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.onb-step:last-child { border-bottom: 0; }
.onb-step .ck { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--line); color: var(--muted); flex: 0 0 auto; }
.onb-step.done .ck { background: var(--ok); border-color: var(--ok); color: #fff; }
.onb-step.done .txt { text-decoration: line-through; color: var(--muted); }

/* ============================================================
   MOVIMIENTO / MICROINTERACCIONES
   ========================================================== */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: no-preference) {

  /* Tarjetas y filas: elevar al pasar el cursor (solo con mouse/trackpad) */
  @media (hover: hover) {
    .card { transition: transform .2s cubic-bezier(.2,.8,.2,1), box-shadow .2s; }
    .stat-card, .xp-card, .quick-add { transition: transform .2s, box-shadow .2s; }
    .card:hover:not(.no-lift) { transform: translateY(-2px); box-shadow: var(--shadow-md); }
    a > .card:hover, .card.lift:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
    .mov-row { transition: background .15s; border-radius: 10px; }
    .mov-row:hover { background: var(--brand-lighter); }
    .list-group-item { transition: background .15s; }
  }

  /* Respuesta táctil al presionar */
  .btn, .plantilla-btn, .logro-badge, .nav-icon-btn, .chip, .bn-item, .bg-item, .dropdown-item {
    transition: transform .12s ease, background .15s ease, box-shadow .15s ease, color .15s ease;
  }
  .btn:active, .plantilla-btn:active, .nav-icon-btn:active, .bn-item:active { transform: scale(.96); }
  .card [role="button"]:active, .cat-ico:active { transform: scale(.94); }

  /* Barras de presupuesto: crecen desde 0 al aparecer */
  .bar-fill, .xp-bar > span, .ld-bar > span { animation: bar-grow .9s cubic-bezier(.2,.8,.2,1) both; }
  @keyframes bar-grow { from { width: 0 !important; } }

  /* Anillo de salud: barre al cargar */
  .health-ring { animation: ring-in 1s ease both; }
  @keyframes ring-in { from { filter: saturate(0); opacity: .4; } }

  /* Brillo decorativo de las stat-cards (solo escritorio, muy lento) */
  @media (hover: hover) and (min-width: 992px) {
    .stat-card::after { animation: blob 10s ease-in-out infinite alternate; }
    @keyframes blob { to { transform: translate(-12px, 10px) scale(1.1); } }
  }

  /* Bottom-nav: el ítem activo late suave al entrar */
  .bottom-nav .bn-item.active i { animation: pop-soft .4s cubic-bezier(.2,.9,.25,1.4) both; }
  @keyframes pop-soft { 0% { transform: scale(.8); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }

  /* Modales / diálogos: aparición */
  .confirm-box { animation: modal-in .26s cubic-bezier(.2,.9,.25,1.1); }
  .modal.show .modal-dialog { animation: modal-in .3s cubic-bezier(.2,.9,.25,1.05); }
  @keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }

  /* Buscador global */
  .buscador-box { animation: modal-in .24s ease; }
}

/* Botón primario: leve pulso de foco */
.btn-primary:focus-visible { box-shadow: 0 0 0 4px rgba(16,185,129,.25); }

@media print {
  .app-nav, .bottom-nav, .site-footer, .no-print, .buscador-overlay, #app-splash, #nav-progress { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  main.container-xl { padding: 0; }
  main.container-xl > * { animation: none !important; }
}

/* ============================================================
 *  Consola de administración
 * ========================================================== */
.adm-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1.1rem; }
.adm-head h3 { margin: 0; font-family: 'Sora', system-ui, sans-serif; letter-spacing: -.02em; }
.adm-head .sub { color: var(--muted); font-size: .84rem; }

.adm-section { margin-top: 1.6rem; }
.adm-section > h6 { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); margin: 0 0 .7rem; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: .85rem .95rem;
  display: flex; flex-direction: column; gap: .15rem; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--kc, var(--brand)); }
.kpi .k-lbl { font-size: .72rem; color: var(--muted); font-weight: 600; }
.kpi .k-num { font-family: 'Sora', system-ui, sans-serif; font-weight: 800; font-size: 1.4rem; line-height: 1.15; color: var(--ink); }
.kpi .k-sub { font-size: .72rem; color: var(--muted); }
.kpi .k-sub a { color: inherit; }

.adm-chart { position: relative; height: 260px; }
.adm-chart.sm { height: 200px; }

.dist { display: flex; flex-direction: column; gap: .55rem; }
.dist-row { display: grid; grid-template-columns: 7.5rem 1fr auto; align-items: center; gap: .6rem; font-size: .82rem; }
.dist-row .d-lbl { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dist-row .d-track { height: 8px; border-radius: 999px; background: var(--field-bg); overflow: hidden; }
.dist-row .d-track > span { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.dist-row .d-val { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }

.adm-list { display: flex; flex-direction: column; }
.adm-list .row-i { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; border-top: 1px solid var(--line); }
.adm-list .row-i:first-child { border-top: 0; }
.adm-list .row-i .grow { min-width: 0; flex: 1; }
.adm-list .row-i .t { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adm-list .row-i .s { font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 575.98px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi .k-num { font-size: 1.2rem; }
  .dist-row { grid-template-columns: 6rem 1fr auto; font-size: .78rem; }
}

/* ============================================================
 *  App nativa de Android (Capacitor) — áreas seguras
 * ========================================================== */
html.is-native .app-nav { padding-top: env(safe-area-inset-top, 0); }
html.is-native .bottom-nav { padding-bottom: calc(.35rem + env(safe-area-inset-bottom, 0)); }
html.is-native .buscador-box { margin-top: env(safe-area-inset-top, 0); }
html.is-native #pwaInstall, html.is-native .pwa-hint { display: none !important; }
