/* =========================================================================
   Gestor de Finanzas del Hogar — hoja de estilos
   Minimalista, moderno, colorido, con microanimaciones.
   ========================================================================= */

/* ---- Paleta y variables ---- */
:root {
    --violet:      #6c5ce7;
    --violet-600:  #5a4bd4;
    --violet-050:  #efecff;
    --mint:        #00b894;
    --mint-050:    #e2fbf3;
    --coral:       #ff6b6b;
    --coral-050:   #ffecec;
    --amber:       #ffb020;
    --amber-050:   #fff5e0;
    --sky:         #0984e3;

    --ink:         #1e2235;
    --ink-soft:    #4b5066;
    --muted:       #8a90a6;
    --line:        #e8eaf2;
    --bg:          #f5f6fb;
    --surface:     #ffffff;
    --surface-2:   #fbfbff;

    --radius:      18px;
    --radius-sm:   12px;
    --radius-pill: 999px;

    --shadow-sm:   0 2px 8px rgba(30, 34, 53, 0.06);
    --shadow-md:   0 10px 30px rgba(30, 34, 53, 0.08);
    --shadow-lg:   0 20px 55px rgba(30, 34, 53, 0.16);
    --shadow-glow: 0 12px 32px rgba(108, 92, 231, 0.35);

    --ease:        cubic-bezier(0.22, 0.61, 0.36, 1);
    --ease-back:   cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Alto real del topbar, medido por JS (app.js) para que el encabezado
       de la tabla se pegue justo debajo y no quede tapado. */
    --topbar-h: 64px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
            Helvetica, Arial, sans-serif;
}

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

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

body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(1200px 600px at 100% -10%, rgba(108, 92, 231, 0.10), transparent 60%),
        radial-gradient(1000px 500px at -10% 110%, rgba(0, 184, 148, 0.10), transparent 55%),
        var(--bg);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
ul { margin: 0; padding: 0; list-style: none; }

.icon { width: 1.25em; height: 1.25em; display: inline-block; vertical-align: middle; }

/* =========================================================================
   Botones
   ========================================================================= */
.btn {
    --btn-bg: var(--violet);
    --btn-fg: #fff;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    background: var(--btn-bg);
    color: var(--btn-fg);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.7rem 1.15rem;
    border-radius: var(--radius-pill);
    transition: transform 0.18s var(--ease-back), box-shadow 0.2s var(--ease),
                background 0.2s var(--ease), filter 0.2s var(--ease);
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-glow); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:focus-visible { outline: 3px solid rgba(108, 92, 231, 0.4); outline-offset: 2px; }
.btn .icon { width: 1.1em; height: 1.1em; }

.btn--primary { --btn-bg: linear-gradient(135deg, var(--violet), #8b7cff); }
.btn--ingreso { --btn-bg: linear-gradient(135deg, var(--mint), #34e0b0); }
.btn--egreso  { --btn-bg: linear-gradient(135deg, var(--coral), #ff9f6b); }
.btn--sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

.dash__actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.btn--ghost {
    --btn-bg: transparent;
    --btn-fg: var(--ink-soft);
    box-shadow: inset 0 0 0 1.5px var(--line);
}
.btn--ghost:hover {
    box-shadow: inset 0 0 0 1.5px var(--violet);
    color: var(--violet);
    background: var(--violet-050);
}
.btn--danger { color: var(--coral); }
.btn--danger:hover {
    box-shadow: inset 0 0 0 1.5px var(--coral);
    color: var(--coral);
    background: var(--coral-050);
}
.btn--delete {
    --btn-bg: linear-gradient(135deg, var(--coral), #ff8a73);
    --btn-fg: #fff;
}
.btn--delete:hover { box-shadow: 0 12px 28px rgba(255, 107, 107, 0.28); }
.btn:disabled {
    cursor: wait;
    filter: saturate(0.7);
    opacity: 0.72;
    transform: none;
}

/* =========================================================================
   Topbar / navegación
   ========================================================================= */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line);
}
.topbar__inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0.8rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 800; }
.brand__mark {
    display: grid;
    place-items: center;
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--violet), #8b7cff);
    color: #fff;
    font-size: 1.2rem;
    box-shadow: var(--shadow-glow);
}
.brand__text { font-size: 1.05rem; letter-spacing: -0.01em; }
.brand__text em { font-style: normal; color: var(--muted); font-weight: 600; }

.mainnav { display: flex; gap: 0.35rem; margin-left: 0.5rem; }
.mainnav__link {
    position: relative;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-pill);
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 0.95rem;
    transition: color 0.2s, background 0.2s;
}
.mainnav__link:hover { color: var(--violet); background: var(--violet-050); }
.mainnav__link.is-active { color: var(--violet); background: var(--violet-050); }

.topbar__user { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.user-chip { display: flex; align-items: center; gap: 0.5rem; }
.user-chip__avatar {
    display: grid;
    place-items: center;
    width: 2rem; height: 2rem;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--mint), #34e0b0);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
}
.user-chip__name { font-weight: 600; font-size: 0.9rem; color: var(--ink-soft); }
.logout-form { margin: 0; }

/* =========================================================================
   Layout principal
   ========================================================================= */
.app-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.75rem 1.25rem 4rem;
}

.page-title { font-size: 1.6rem; letter-spacing: -0.02em; }
.page-subtitle { color: var(--muted); margin: 0.35rem 0 0; font-size: 0.95rem; }

/* =========================================================================
   Flash messages
   ========================================================================= */
.flash-stack {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
}
.flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.92rem;
    box-shadow: var(--shadow-sm);
    animation: flash-in 0.4s var(--ease-back) both;
}
.flash--success { background: var(--mint-050); color: #0a7a63; }
.flash--error   { background: var(--coral-050); color: #c0392b; }
.flash__close {
    border: none; background: none; font-size: 1.3rem; line-height: 1;
    color: inherit; opacity: 0.6; transition: opacity 0.2s;
}
.flash__close:hover { opacity: 1; }
@keyframes flash-in {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   Dashboard
   ========================================================================= */

/* Panel flotante: navegación de meses + alta rápida, siempre a mano
   mientras se hace scroll por la tabla. */
.dash__head {
    position: fixed;
    right: max(1.25rem);
    bottom: max(1.25rem, env(safe-area-inset-bottom));
    z-index: 70;
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas:
        "year year"
        "month month"
        "income expense";
    align-items: center;
    gap: 0.55rem;
    width: max-content;
    max-width: min(360px, calc(100vw - 2rem));
    padding: 0.65rem;
    border: 1px solid rgba(232, 234, 242, 0.9);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 18px 48px rgba(30, 34, 53, 0.18);
    backdrop-filter: saturate(180%) blur(16px);
    animation: toolbar-in 0.4s var(--ease-back) both;
}
@keyframes toolbar-in {
    from { opacity: 0; transform: translateY(18px) scale(0.94); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Deja espacio para que el panel flotante no tape el final de la tabla. */
.dash { padding-bottom: 8.5rem; }

.year-picker {
    grid-area: year;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}
.year-picker__nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 2.1rem;
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius-pill);
    background: rgba(239, 236, 255, 0.72);
    color: var(--violet);
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s, transform 0.2s var(--ease-back);
}
.year-picker__nav svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}
.year-picker__nav:hover {
    background: var(--violet);
    color: #fff;
    transform: translateY(-1px);
}

.month-picker {
    grid-area: month;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: rgba(245, 246, 251, 0.95);
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    padding: 0.3rem;
}
.month-picker__nav {
    display: grid;
    place-items: center;
    width: 2.3rem; height: 2.3rem;
    border-radius: 50%;
    color: var(--ink-soft);
    transition: background 0.2s, color 0.2s, transform 0.2s var(--ease-back);
}
.month-picker__nav svg { width: 1.2rem; height: 1.2rem; }
.month-picker__nav:hover { background: var(--violet-050); color: var(--violet); transform: scale(1.1); }
.month-picker__label { position: relative; padding: 0 0.6rem; text-align: center; min-width: 9.5rem; }
.month-picker__name { font-weight: 700; font-size: 1rem; }
.month-picker__jump {
    position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.month-picker__jump input { width: 100%; height: 100%; border: none; background: none; cursor: pointer; }
.dash__actions {
    display: contents;
}
.dash__actions .btn {
    min-height: 2.85rem;
    justify-content: center;
    white-space: nowrap;
    box-shadow: 0 10px 24px rgba(30, 34, 53, 0.12);
}
.dash__actions .btn--ingreso { grid-area: income; }
.dash__actions .btn--egreso { grid-area: expense; }

/* Tarjetas resumen */
.cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.35rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform 0.28s var(--ease), box-shadow 0.28s var(--ease);
}
.card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    background: var(--accent, var(--violet));
    transition: width 0.28s var(--ease);
}
.card:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); }
.card:hover::before { width: 8px; }
.card__icon {
    display: grid;
    place-items: center;
    width: 3rem; height: 3rem;
    border-radius: 14px;
    background: var(--accent-050, var(--violet-050));
    color: var(--accent, var(--violet));
    flex-shrink: 0;
}
.card__icon .icon { width: 1.5rem; height: 1.5rem; }
.card__body { display: flex; flex-direction: column; }
.card__label { color: var(--muted); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.card__amount { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.card--ingreso { --accent: var(--mint); --accent-050: var(--mint-050); }
.card--egreso  { --accent: var(--coral); --accent-050: var(--coral-050); }
.card--margen  { --accent: var(--violet); --accent-050: var(--violet-050); }
.card--margen.is-negative { --accent: var(--coral); --accent-050: var(--coral-050); }
.card--margen.is-negative .card__amount { color: var(--coral); }

/* Tarjeta diezmo */
.tithe {
    position: relative;
    margin-bottom: 1.5rem;
    padding: 1.6rem 1.75rem;
    border-radius: var(--radius);
    color: #fff;
    background: linear-gradient(135deg, var(--violet) 0%, #8b7cff 55%, var(--sky) 130%);
    box-shadow: var(--shadow-glow);
    overflow: hidden;
}
.tithe__deco {
    position: absolute;
    right: -1.5rem; bottom: -2.5rem;
    opacity: 0.14;
    pointer-events: none;
}
.tithe__deco-icon { width: 11rem; height: 11rem; }
.tithe__content { position: relative; z-index: 1; }
.tithe__header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1.1rem; }
.tithe__header .icon { width: 1.4rem; height: 1.4rem; }
.tithe__title { font-size: 1.15rem; font-weight: 700; }
.tithe__grid { display: flex; flex-wrap: wrap; gap: 2.5rem; align-items: flex-end; }
.tithe__label { display: block; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.85; font-weight: 600; margin-bottom: 0.15rem; }
.tithe__base { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tithe__amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.amount--lg { font-size: 2.4rem; letter-spacing: -0.03em; }
.tithe__note { margin: 1rem 0 0; font-size: 0.85rem; opacity: 0.85; }

/* =========================================================================
   Lista de movimientos
   ========================================================================= */
.movs {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.35rem 1.5rem 0.75rem;
}
.movs__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}
.movs__title { font-size: 1.2rem; }
.movs__filters { display: flex; gap: 0.4rem; }
.chip {
    border: none;
    background: var(--bg);
    color: var(--ink-soft);
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-size: 0.85rem;
    transition: background 0.2s, color 0.2s, transform 0.15s var(--ease-back);
}
.chip:hover { transform: translateY(-1px); }
.chip.is-active { background: var(--violet); color: #fff; }

.mov-list { display: flex; flex-direction: column; }
.mov {
    display: grid;
    grid-template-columns: auto 1fr auto auto auto;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 0.35rem;
    border-bottom: 1px solid var(--line);
    transition: background 0.2s var(--ease);
    animation: mov-in 0.4s var(--ease-back) both;
}
.mov:last-child { border-bottom: none; }
.mov:hover { background: var(--surface-2); }
.mov.is-removing { animation: mov-out 0.35s var(--ease) forwards; }

@keyframes mov-in {
    from { opacity: 0; transform: translateY(-8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes mov-out {
    to { opacity: 0; transform: translateX(24px); height: 0; padding: 0; margin: 0; }
}

.mov__icon {
    display: grid;
    place-items: center;
    width: 2.6rem; height: 2.6rem;
    border-radius: 12px;
    color: var(--cat-color, var(--violet));
    background: color-mix(in srgb, var(--cat-color, var(--violet)) 14%, white);
    flex-shrink: 0;
}
.mov__icon .icon { width: 1.35rem; height: 1.35rem; }
.mov__main { display: flex; flex-direction: column; min-width: 0; }
.mov__cat { font-weight: 700; font-size: 0.98rem; }
.mov__desc { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov__date { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.mov__amount { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mov__amount--ingreso { color: var(--mint); }
.mov__amount--egreso  { color: var(--coral); }

.mov__actions { display: flex; gap: 0.25rem; opacity: 0; transition: opacity 0.2s; }
.mov:hover .mov__actions, .mov:focus-within .mov__actions { opacity: 1; }
.mov__delete-form { margin: 0; }
.mov__btn {
    display: grid;
    place-items: center;
    width: 2rem; height: 2rem;
    border: none; background: none;
    border-radius: 8px;
    color: var(--muted);
    transition: background 0.2s, color 0.2s, transform 0.15s var(--ease-back);
}
.mov__btn svg { width: 1.05rem; height: 1.05rem; }
.mov__edit:hover { background: var(--violet-050); color: var(--violet); transform: scale(1.12); }
.mov__delete:hover { background: var(--coral-050); color: var(--coral); transform: scale(1.12); }

.mov.is-hidden { display: none; }

.mov-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}
.mov-empty__icon { width: 3rem; height: 3rem; opacity: 0.4; margin-bottom: 0.75rem; }
.mov-empty p { font-weight: 700; color: var(--ink-soft); margin: 0 0 0.25rem; }
.mov-empty span { font-size: 0.9rem; }

/* =========================================================================
   Tabla matriz anual
   ========================================================================= */
.matrix-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 0.5rem 0.5rem 0.25rem;
    animation: flash-in 0.35s var(--ease) both;
}
.matrix-wrap { overflow-x: auto; border-radius: var(--radius); }

.matrix {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-variant-numeric: tabular-nums;
    min-width: 1080px;
    table-layout: fixed;
}

/* Encabezado de columnas (meses): pegado justo debajo del header del sitio. */
.matrix thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--surface);
    padding: 0.55rem 0.5rem;
    text-align: right;
    font-size: 0.72rem;
    color: var(--muted);
    border-bottom: 2px solid var(--line);
    white-space: nowrap;
}
.matrix__corner {
    left: 0;
    z-index: 4 !important;
    text-align: left !important;
    width: 250px;
    min-width: 250px;
    max-width: 250px;
    font-weight: 700;
    color: var(--ink-soft) !important;
}
.matrix__mth { min-width: 68px; }
.matrix__mth-abbr { display: block; font-weight: 800; color: var(--ink); font-size: 0.78rem; letter-spacing: 0.02em; }
.matrix__mth-year { display: block; font-size: 0.64rem; }
.matrix__mth.is-current .matrix__mth-abbr { color: var(--violet); }
.matrix__mth.is-current {
    background: var(--violet-050);
    box-shadow: inset 0 -3px 0 var(--violet);
}

/* Celdas */
.matrix__name,
.matrix__val { padding: 0.48rem 0.5rem; border-bottom: 1px solid var(--line); }
.matrix__name {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
    text-align: left;
    width: 250px;
    min-width: 250px;
    max-width: 250px;
    font-weight: 600;
    white-space: normal;
    line-height: 1.2;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 0.42rem;
    overflow: hidden;
}
.matrix__val { text-align: right; white-space: nowrap; font-weight: 600; font-size: 0.78rem; }
.matrix__val.is-zero { color: var(--line); font-weight: 400; }

.matrix__dot {
    display: grid;
    place-items: center;
    width: 1.35rem; height: 1.35rem;
    border-radius: 7px;
    flex-shrink: 0;
    color: var(--cat-color, var(--violet));
    background: color-mix(in srgb, var(--cat-color, var(--violet)) 15%, white);
}
.matrix__dot .icon { width: 0.84rem; height: 0.84rem; }

/* Filas de categoría */
.matrix__row--cat:hover .matrix__name,
.matrix__row--cat:hover .matrix__val { background: var(--surface-2); }

.matrix__val.is-clickable { cursor: pointer; border-radius: 6px; transition: background 0.15s, color 0.15s; }
.matrix__val.is-clickable:hover { background: var(--violet-050); color: var(--violet); }
.matrix__val.is-clickable:focus-visible { outline: 2px solid var(--violet); outline-offset: -2px; }
.matrix__val.is-settled {
    color: #126b58;
    background:
        linear-gradient(90deg, rgba(0, 184, 148, 0.12), rgba(0, 184, 148, 0.04));
    box-shadow: 0 0 1px rgba(0, 184, 148, 0.55) inset;
}
.matrix__val.is-egreso.is-settled {
    color: #a33a35;
    background:
        linear-gradient(90deg, rgba(255, 107, 107, 0.14), rgba(255, 107, 107, 0.05));
    box-shadow: 0 0 1px rgba(255, 107, 107, 0.55) inset;
}

/* Filas destacadas: margen y totales */
.matrix__row--margen .matrix__name,
.matrix__row--margen .matrix__val {
    background: linear-gradient(90deg, var(--violet), #7d6ef0);
    color: #fff;
    font-weight: 800;
    font-size: 0.84rem;
    border-bottom: none;
    padding-top: 0.58rem;
    padding-bottom: 0.58rem;
}
.matrix__row--margen .matrix__val.is-neg { color: #ffd0d0; }
.matrix__row--margen .matrix__name { border-radius: 10px 0 0 10px; }

.matrix__row--total .matrix__name,
.matrix__row--total .matrix__val {
    font-weight: 800;
    border-bottom: 2px solid var(--line);
}
.matrix__row--ingresos .matrix__name,
.matrix__row--ingresos .matrix__val { background: var(--mint-050); color: #0a7a63; }
.matrix__row--egresos .matrix__name,
.matrix__row--egresos .matrix__val { background: var(--coral-050); color: #c0392b; }

/* Deja aire antes de cada bloque de totales */
.matrix__row--total .matrix__name,
.matrix__row--total .matrix__val { padding-top: 0.55rem; padding-bottom: 0.55rem; }

.matrix__row--cash-spacer .matrix__name,
.matrix__row--cash-spacer .matrix__val {
    height: 0.8rem;
    padding: 0;
    border-bottom: none;
    background: var(--surface);
}
.matrix__row--cash .matrix__name,
.matrix__row--cash .matrix__val {
    background: #f4f7fb;
    color: var(--ink-soft);
    font-weight: 800;
    border-top: 1px solid var(--line);
}
.matrix__row--cash .matrix__val.is-neg { color: #c0392b; }
.matrix__row--cash .matrix__val.is-pos { color: #276b58; }

.matrix-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 2.5rem 1rem 1rem;
    color: var(--muted);
}
.matrix-empty__icon { width: 2.6rem; height: 2.6rem; opacity: 0.4; margin-bottom: 0.6rem; }
.matrix-empty p { font-weight: 700; color: var(--ink-soft); margin: 0 0 0.2rem; }
.matrix-empty span { font-size: 0.88rem; }

.matrix-hint {
    margin: 0.6rem 0.4rem 0.4rem;
    font-size: 0.8rem;
    color: var(--muted);
    text-align: right;
}

/* Detalle de celda */
.detail-list { display: flex; flex-direction: column; gap: 0.5rem; }
.detail-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border-left: 4px solid var(--line);
}
.detail-item--ingreso { border-left-color: var(--mint); }
.detail-item--egreso  { border-left-color: var(--coral); }
.detail-item__main { display: flex; flex-direction: column; min-width: 0; }
.detail-item__desc { font-weight: 600; }
.detail-item__nodesc { color: var(--muted); font-weight: 400; font-style: italic; }
.detail-item__date { color: var(--muted); font-size: 0.82rem; }
.detail-item__amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.detail-item--ingreso .detail-item__amount { color: var(--mint); }
.detail-item--egreso .detail-item__amount  { color: var(--coral); }
.detail-item__actions { display: flex; gap: 0.2rem; }

/* =========================================================================
   Formularios y modal
   ========================================================================= */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 1rem;
}
.modal[hidden] { display: none; }
.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(20, 22, 38, 0.45);
    backdrop-filter: blur(3px);
    animation: fade-in 0.25s var(--ease) both;
}
.modal__dialog {
    position: relative;
    width: min(520px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    animation: modal-in 0.35s var(--ease-back) both;
}
.modal__dialog--sm { width: min(420px, 100%); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.modal__title { font-size: 1.25rem; }
.modal__copy {
    margin: -0.35rem 0 0;
    color: var(--ink-soft);
    font-size: 0.94rem;
}
.modal__close {
    border: none; background: none; font-size: 1.6rem; line-height: 1;
    color: var(--muted); width: 2rem; height: 2rem; border-radius: 8px;
    transition: background 0.2s, color 0.2s;
}
.modal__close:hover { background: var(--bg); color: var(--ink); }

.form__row { margin-bottom: 1rem; }
.form__row--2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form__field { display: flex; flex-direction: column; gap: 0.4rem; }
.form__label { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }
.form__label em { font-style: normal; color: var(--muted); font-weight: 500; }

input[type="text"], input[type="number"], input[type="date"], input[type="month"], select {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--ink);
    background: var(--surface-2);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--violet);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.12);
}

.input-money { position: relative; display: flex; align-items: center; }
.input-money__prefix {
    position: absolute; left: 0.85rem; color: var(--muted); font-weight: 700; pointer-events: none;
}
.input-money input { padding-left: 1.8rem; font-weight: 700; }

input[type="color"] {
    width: 100%; height: 2.7rem; padding: 0.2rem; border: 1.5px solid var(--line);
    border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer;
}

.form__actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.5rem; }
.form__actions--split {
    justify-content: space-between;
    align-items: center;
}
.form__actions-main {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-left: auto;
}
.form__error {
    margin: 0.25rem 0 0;
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius-sm);
    background: var(--coral-050);
    color: #b8322a;
    font-size: 0.88rem;
    font-weight: 700;
}
.recurrence {
    display: grid;
    gap: 0.85rem;
    padding: 0.9rem;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.recurrence__months {
    max-width: 13rem;
    margin-left: 3.55rem;
}
.btn[hidden],
.form__field[hidden],
.recurrence[hidden] {
    display: none !important;
}

/* Toggle tipo ingreso/egreso */
.type-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    background: var(--bg);
    padding: 0.35rem;
    border-radius: var(--radius-pill);
    margin-bottom: 1.1rem;
}
.type-toggle__opt {
    position: relative;
    text-align: center;
    padding: 0.6rem;
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.2s, background 0.25s var(--ease), box-shadow 0.2s;
}
.type-toggle__opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.type-toggle__opt--ingreso:has(input:checked) { background: var(--mint); color: #fff; box-shadow: var(--shadow-sm); }
.type-toggle__opt--egreso:has(input:checked)  { background: var(--coral); color: #fff; box-shadow: var(--shadow-sm); }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 0.65rem; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
    position: relative;
    width: 2.9rem; height: 1.6rem;
    background: var(--line);
    border-radius: var(--radius-pill);
    transition: background 0.25s var(--ease);
    flex-shrink: 0;
}
.switch__thumb {
    position: absolute;
    top: 0.2rem; left: 0.2rem;
    width: 1.2rem; height: 1.2rem;
    background: #fff;
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: transform 0.28s var(--ease-back);
}
.switch input:checked + .switch__track { background: var(--mint); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(1.3rem); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.18); }
.switch__label { font-weight: 600; font-size: 0.92rem; color: var(--ink-soft); }

/* Grid de iconos */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr)); gap: 0.5rem; }
.icon-grid__opt { position: relative; cursor: pointer; }
.icon-grid__opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.icon-grid__box {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--line);
    color: var(--ink-soft);
    background: var(--surface-2);
    transition: border-color 0.2s, color 0.2s, transform 0.15s var(--ease-back), background 0.2s;
}
.icon-grid__box .icon { width: 1.35rem; height: 1.35rem; }
.icon-grid__opt:hover .icon-grid__box { transform: translateY(-2px); border-color: var(--violet); color: var(--violet); }
.icon-grid__opt input:checked + .icon-grid__box {
    border-color: var(--violet); color: var(--violet); background: var(--violet-050);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

/* =========================================================================
   Categorías
   ========================================================================= */
.cats__head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.75rem;
}
.cats__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.cat-group {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.35rem 1.5rem;
}
.cat-group__title {
    font-size: 1.05rem;
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 2px solid var(--line);
}
.cat-group__empty { color: var(--muted); font-size: 0.9rem; }
.cat-list { display: flex; flex-direction: column; gap: 0.3rem; }
.cat {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.65rem 0.4rem;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}
.cat:hover { background: var(--surface-2); }
.cat.is-inactive { opacity: 0.55; }
.cat__icon {
    display: grid; place-items: center;
    width: 2.4rem; height: 2.4rem;
    border-radius: 11px;
    color: var(--cat-color, var(--violet));
    background: color-mix(in srgb, var(--cat-color, var(--violet)) 14%, white);
    flex-shrink: 0;
}
.cat__icon .icon { width: 1.25rem; height: 1.25rem; }
.cat__name { flex: 1; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.cat__badge {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-pill);
    background: var(--amber-050);
    color: #b5750a;
}
.cat__badge--muted { background: var(--bg); color: var(--muted); }
.cat__actions { display: flex; gap: 0.3rem; opacity: 0; transition: opacity 0.2s; }
.cat:hover .cat__actions, .cat:focus-within .cat__actions { opacity: 1; }
.cat__actions form { margin: 0; }

/* =========================================================================
   Login
   ========================================================================= */
.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1.5rem;
}
.login-shell { width: min(410px, 100%); }
.login-card {
    position: relative;
    background: var(--surface);
    border-radius: 26px;
    padding: 2.75rem 2.25rem 2.25rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
    overflow: hidden;
    animation: modal-in 0.5s var(--ease-back) both;
}
.login-card__glow {
    position: absolute;
    top: -60%; left: 50%;
    width: 130%; aspect-ratio: 1;
    transform: translateX(-50%);
    background: radial-gradient(circle, rgba(108, 92, 231, 0.18), transparent 62%);
    pointer-events: none;
}
.login-brand { position: relative; margin-bottom: 2rem; }
.login-brand__mark {
    display: inline-grid;
    place-items: center;
    width: 4rem; height: 4rem;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--violet), #8b7cff);
    color: #fff;
    font-size: 2rem;
    box-shadow: var(--shadow-glow);
    margin-bottom: 1rem;
    animation: float 4s ease-in-out infinite;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}
.login-brand__title { font-size: 1.5rem; letter-spacing: -0.02em; }
.login-brand__subtitle { color: var(--muted); margin: 0.5rem 0 0; font-size: 0.95rem; }

.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-pill);
    background: #fff;
    color: #3c4043;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: inset 0 0 0 1.5px var(--line), var(--shadow-sm);
    transition: transform 0.2s var(--ease-back), box-shadow 0.25s var(--ease);
    margin-top: 0.5rem;
}
.google-btn:hover {
    transform: translateY(-2px);
    box-shadow: inset 0 0 0 1.5px var(--violet), var(--shadow-md);
}
.google-btn__icon { display: grid; place-items: center; }
.login-note { margin: 1.25rem 0 0; font-size: 0.82rem; color: var(--muted); }
.login-page .flash { text-align: left; margin-bottom: 1rem; }

/* =========================================================================
   Error pages
   ========================================================================= */
.error-page { text-align: center; padding: 5rem 1rem; }
.error-page__code {
    font-size: 5rem; font-weight: 900; letter-spacing: -0.04em;
    background: linear-gradient(135deg, var(--violet), var(--sky));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    margin-bottom: 0.5rem;
}
.error-page__msg { color: var(--ink-soft); font-size: 1.15rem; margin-bottom: 1.5rem; }

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 780px) {
    .cards { grid-template-columns: 1fr; }
    .cats__grid { grid-template-columns: 1fr; }
    .mainnav { order: 3; width: 100%; justify-content: center; }
    .topbar__inner { flex-wrap: wrap; }
    .user-chip__name { display: none; }
    .tithe__grid { gap: 1.5rem; }
    .amount--lg { font-size: 2rem; }
}
@media (max-width: 520px) {
    .mov { grid-template-columns: auto 1fr auto; grid-template-areas: "icon main amount" "icon date actions"; row-gap: 0.25rem; }
    .mov__icon { grid-area: icon; }
    .mov__main { grid-area: main; }
    .mov__amount { grid-area: amount; text-align: right; }
    .mov__date { grid-area: date; }
    .mov__actions { grid-area: actions; opacity: 1; justify-content: flex-end; }
    .form__row--2 { grid-template-columns: 1fr; }
    .dash { padding-bottom: 10rem; }
    .dash__head {
        right: 0.75rem;
        bottom: max(0.75rem, env(safe-area-inset-bottom));
        grid-template-columns: 1fr 1fr;
        width: calc(100vw - 1.5rem);
        max-width: 100%;
        padding: 0.55rem;
        border-radius: 16px;
    }
    .month-picker__label { min-width: 0; flex: 1; }
    .month-picker__name { font-size: 0.9rem; }
    .dash__actions .btn {
        min-width: 0;
        padding: 0.68rem 0.75rem;
        font-size: 0.9rem;
    }
    .recurrence__months {
        max-width: none;
        margin-left: 0;
    }
}

/* Accesibilidad: respeta reduce motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
