:root {
    --bg: #fbfbf8;
    --card: #f1f1ed;
    --card-hover: #eaeae4;
    --panel: #ffffff;
    --ink: #111111;
    --muted: #7c7c74;
    --line: #e5e5df;
    --pink: #ff5fc4;
    --yellow: #f2ed4a;
    --peach: #ffc48a;
    --neg: #e0347a;
    --shadow: 0 4px 20px rgba(0, 0, 0, .07);
    --r: 22px;
    --r-sm: 14px;
    --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #121211;
    --card: #1d1d1b;
    --card-hover: #242422;
    --panel: #2a2a27;
    --ink: #f6f6f2;
    --muted: #9b9b93;
    --line: #2e2e2b;
    --neg: #ff7ab0;
    --shadow: 0 4px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: 6.5rem;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    margin: 0;
    font-weight: 800;
    letter-spacing: -.035em;
    line-height: 1.1;
}

p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }

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

.wrap {
    width: min(1180px, calc(100% - 4rem));
    margin-inline: auto;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    padding: .75rem 1.25rem;
    background: var(--ink);
    color: var(--bg);
    border-radius: 0 0 12px 0;
}

.skip-link:focus { left: 0; }

/* ---------- Navegación ---------- */
.nav {
    position: sticky;
    top: 1rem;
    z-index: 55;
    display: flex;
    align-items: center;
    gap: .5rem;
    width: min(1180px, calc(100% - 4rem));
    margin: 1rem auto 0;
    padding: .45rem .45rem .45rem 1rem;
    border-radius: 100px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.nav-brand {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    font-weight: 800;
    font-size: .98rem;
    letter-spacing: -.03em;
}

.nav-brand span {
    font-size: .74rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0;
}

.nav-tools {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-left: auto;
}

.nav-user {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .4rem .9rem;
    border-radius: 100px;
    background: var(--card);
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
}

.nav-user i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--pink);
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: var(--card);
    color: var(--muted);
    font: inherit;
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color .18s, color .18s;
}

.icon-btn:hover {
    background: var(--yellow);
    color: #111;
}

[data-theme="dark"] .icon-btn:hover { background: var(--panel); color: var(--ink); }

.icon-btn svg { width: 17px; height: 17px; }

.icon-btn.is-danger:hover { background: var(--neg); color: #fff; }

/* ---------- Estructura ---------- */
main { padding: 2rem 0 5rem; }

.section { margin-bottom: 1rem; }

.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 2rem;
    margin: 2.25rem 0 1rem;
    padding-inline: .35rem;
}

.eyebrow {
    font-size: .76rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: .3rem;
}

.section-title { font-size: clamp(1.35rem, 2.6vw, 1.8rem); }

.section-note {
    max-width: 44ch;
    font-size: .88rem;
    color: var(--muted);
}

/* ---------- Grilla bento ---------- */
.bento {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: .85rem;
}

.card {
    grid-column: span 12;
    min-width: 0;
    padding: 1.5rem;
    border-radius: var(--r);
    background: var(--card);
}

.card-head {
    display: flex;
    align-items: flex-start;
    gap: .8rem;
    margin-bottom: 1.2rem;
}

.card-head h2 { font-size: 1.1rem; }

.card-note {
    margin-top: .25rem;
    font-size: .85rem;
    color: var(--muted);
}

.card-icon {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 11px;
    background: var(--panel);
    color: var(--ink);
}

.card-icon svg { width: 18px; height: 18px; }

/* ---------- Encabezado ---------- */
.card-intro {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .9rem;
    padding: 2.2rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    align-self: flex-start;
    padding: .35rem .85rem;
    border-radius: 100px;
    background: var(--yellow);
    color: #111;
    font-size: .8rem;
    font-weight: 600;
}

.badge i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #111;
}

.hero-title {
    font-size: clamp(1.9rem, 4.4vw, 2.9rem);
    letter-spacing: -.045em;
}

.hero-title em {
    font-style: normal;
    background: var(--pink);
    color: #fff;
    padding: 0 .25rem;
    border-radius: 10px;
}

.hero-text {
    max-width: 52ch;
    font-size: .94rem;
    color: var(--muted);
}

/* ---------- Métricas ---------- */
.card-stat { display: flex; flex-direction: column; }

.stat-value {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    font-weight: 800;
    letter-spacing: -.05em;
    line-height: 1;
    overflow-wrap: anywhere;
}

.stat-label {
    margin-top: .45rem;
    font-size: .86rem;
    color: var(--muted);
}

.stat-meta {
    margin-top: auto;
    padding-top: .9rem;
    font-size: .78rem;
    color: var(--muted);
}

.card-accent {
    background: var(--yellow);
    color: #111;
}

.card-accent .stat-label,
.card-accent .stat-meta { color: rgba(17, 17, 17, .68); }

.card-accent .card-icon { background: rgba(17, 17, 17, .12); color: #111; }

.is-neg { color: var(--neg); }
.card-accent .is-neg { color: #a3145a; }

/* ---------- Gráficos ---------- */
.chart-box {
    position: relative;
    height: 300px;
    min-width: 0;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-top: 1rem;
}

.chart-legend li {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .3rem .75rem;
    border-radius: 100px;
    background: var(--panel);
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
}

.chart-legend i {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    background: currentColor;
}

/* ---------- Formularios ---------- */
.field { display: block; margin-bottom: .9rem; }

.field-label {
    display: block;
    margin-bottom: .4rem;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .02em;
    color: var(--muted);
}

.input,
.select {
    width: 100%;
    padding: .8rem 1rem;
    border: 1.5px solid transparent;
    border-radius: var(--r-sm);
    background: var(--panel);
    color: var(--ink);
    font: inherit;
    font-size: .95rem;
    font-weight: 600;
    transition: border-color .18s, background-color .18s;
}

.input::placeholder { color: var(--muted); font-weight: 500; }

.input:hover,
.select:hover { border-color: var(--line); }

.input:focus,
.select:focus {
    outline: 0;
    border-color: var(--pink);
}

.select {
    appearance: none;
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237c7c74' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .9rem center;
    background-size: 17px;
    cursor: pointer;
}

.input-money { position: relative; }

.input-money .input { padding-left: 3.2rem; }

.input-money::before {
    content: 'USD';
    position: absolute;
    left: 1rem;
    top: 50%;
    translate: 0 -50%;
    font-size: .8rem;
    font-weight: 700;
    color: var(--muted);
    pointer-events: none;
}

.color-field {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .7rem .55rem 1rem;
    border: 1.5px solid transparent;
    border-radius: var(--r-sm);
    background: var(--panel);
    font-size: .8rem;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
}

.color-field:hover { border-color: var(--line); }

.color-field input[type="color"] {
    width: 42px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: none;
    cursor: pointer;
}

.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 9px; }
.color-field input[type="color"]::-moz-color-swatch { border: 0; border-radius: 9px; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    margin-top: 1.2rem;
}

/* Fila de campos que comparten renglón: input elástico + accesorios fijos. */
.field-row {
    display: flex;
    gap: .5rem;
    margin-top: .4rem;
}

.field-row .input {
    flex: 1;
    min-width: 0;
}

.field-row .btn,
.field-row .color-field { flex: 0 0 auto; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .75rem 1.35rem;
    border: 0;
    border-radius: 100px;
    font: inherit;
    font-size: .9rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color .18s, color .18s;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: var(--pink); color: #fff; }

.btn-ghost { background: var(--panel); color: var(--ink); }
.btn-ghost:hover { background: var(--yellow); color: #111; }

.btn-danger { background: var(--neg); color: #fff; }
.btn-danger:hover { background: var(--ink); color: var(--bg); }

.btn-block { width: 100%; }
.btn-grow { flex: 1; }

.btn-sm {
    padding: .5rem 1rem;
    font-size: .82rem;
}

.btn-sm svg { width: 14px; height: 14px; }

.field-hint {
    display: block;
    margin-top: .5rem;
    font-size: .8rem;
    color: var(--muted);
}

.select:disabled {
    opacity: .55;
    cursor: not-allowed;
}

/* ---------- Avisos ---------- */
.flash-stack {
    display: grid;
    gap: .5rem;
    margin-bottom: 1rem;
}

.flash {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .9rem 1.2rem;
    border-radius: var(--r-sm);
    font-size: .9rem;
    font-weight: 600;
    background: var(--yellow);
    color: #111;
}

.flash.is-error { background: var(--neg); color: #fff; }

.flash svg { flex: 0 0 auto; width: 18px; height: 18px; }

/* ---------- Meses ---------- */
.months { display: grid; gap: .5rem; }

.month {
    border-radius: var(--r-sm);
    background: var(--panel);
    overflow: hidden;
}

.month > summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    cursor: pointer;
    list-style: none;
    transition: background-color .18s;
}

.month > summary::-webkit-details-marker { display: none; }
.month > summary:hover { background: var(--card-hover); }

.month-name { font-size: 1rem; font-weight: 700; }

.month-count { font-size: .78rem; color: var(--muted); }

.month-total {
    margin-left: auto;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -.03em;
    white-space: nowrap;
}

.month-chevron {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--card);
    color: var(--muted);
    transition: rotate .2s;
}

.month[open] .month-chevron { rotate: 180deg; }

.month-chevron svg { width: 15px; height: 15px; }

.month-body { padding: 0 1.25rem 1rem; }

.entry {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .8rem 0;
    border-top: 1px solid var(--line);
}

.entry-dot {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.entry-name { font-size: .92rem; font-weight: 700; }

.entry-amount {
    margin-left: auto;
    font-size: .95rem;
    font-weight: 700;
    white-space: nowrap;
}

.entry-actions { display: flex; gap: .3rem; }

.mini-btn {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
    transition: background-color .18s, color .18s;
}

.mini-btn:hover { background: var(--ink); color: var(--bg); }
.mini-btn.is-danger:hover { background: var(--neg); color: #fff; }
.mini-btn svg { width: 15px; height: 15px; }

/* ---------- Proyectos ---------- */
.project-add { margin-bottom: 1.1rem; }

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: .6rem;
}

.project {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .7rem .8rem;
    border-radius: var(--r-sm);
    background: var(--panel);
}

.project-swatch {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 10px;
}

.project-body { min-width: 0; }

.project-name {
    font-size: .95rem;
    font-weight: 700;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.project-meta { font-size: .78rem; color: var(--muted); }

.project-actions {
    display: flex;
    align-items: center;
    gap: .3rem;
    margin-left: auto;
}

.project.is-archived { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }

.project.is-archived .project-swatch { opacity: .45; }

.project.is-archived .project-name { color: var(--muted); }

/* Archivados */
.archived {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}

.archived > summary {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .35rem 0;
    cursor: pointer;
    list-style: none;
    font-size: .84rem;
    font-weight: 700;
    color: var(--muted);
}

.archived > summary::-webkit-details-marker { display: none; }

.archived > summary:hover { color: var(--ink); }

.archived > summary svg { width: 16px; height: 16px; }

.archived > summary .month-chevron {
    width: 24px;
    height: 24px;
    margin-left: auto;
}

.archived[open] > summary .month-chevron { rotate: 180deg; }

.archived .project-grid { margin-top: .8rem; }

/* ---------- Vacío ---------- */
.empty {
    padding: 2.5rem 1.5rem;
    border: 1.5px dashed var(--line);
    border-radius: var(--r-sm);
    text-align: center;
    font-size: .9rem;
    color: var(--muted);
}

/* ---------- Modales ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.modal.is-open { display: flex; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 17, 17, .55);
    backdrop-filter: blur(3px);
    border: 0;
    padding: 0;
    cursor: pointer;
}

.modal-panel {
    position: relative;
    width: min(430px, 100%);
    max-height: calc(100dvh - 2.5rem);
    overflow-y: auto;
    padding: 1.75rem;
    border-radius: var(--r);
    background: var(--bg);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .25);
}

.modal-panel h2 { font-size: 1.35rem; margin-top: .35rem; }

.modal-meta { margin-top: .4rem; font-size: .86rem; color: var(--muted); }

.modal-form { margin-top: 1.4rem; }

/* ---------- Acceso ---------- */
.login {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: 1.5rem;
}

.login-card {
    width: min(420px, 100%);
    padding: 2.25rem;
    border-radius: var(--r);
    background: var(--card);
}

.login-mark {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin-bottom: 1.4rem;
    border-radius: 16px;
    background: var(--yellow);
    color: #111;
}

.login-mark svg { width: 24px; height: 24px; }

.login-card h1 { font-size: 1.9rem; }

.login-card .hero-text { margin-top: .5rem; }

.login-form { margin-top: 1.6rem; }

.login-form .btn-block { margin-top: 1.2rem; }

.login-card .flash { margin-top: 1.4rem; }

.color-field-block {
    width: 100%;
    justify-content: space-between;
}

.login-back {
    margin-top: 1.5rem;
    text-align: center;
    font-size: .84rem;
    color: var(--muted);
}

.login-back a {
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.login-back a:hover { color: var(--ink); }

/* ---------- Acceso rápido móvil ---------- */
.fab {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 50;
    display: none;
    align-items: center;
    gap: .5rem;
    padding: .9rem 1.4rem;
    border-radius: 100px;
    background: var(--ink);
    color: var(--bg);
    font-size: .9rem;
    font-weight: 700;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

.fab svg { width: 17px; height: 17px; }

/* ---------- Escritorio ---------- */
@media (min-width: 900px) {
    .card-intro { grid-column: span 6; grid-row: span 2; }
    .card-stat { grid-column: span 3; }
    .card-chart { grid-column: span 6; }
    .card-form { grid-column: span 5; }
    .card-form-wide { grid-column: span 7; }
}

@media (min-width: 620px) and (max-width: 899px) {
    .card-stat { grid-column: span 6; }
}

@media (max-width: 899px) {
    .wrap,
    .nav { width: calc(100% - 2rem); }

    .nav {
        top: .75rem;
        margin-top: .75rem;
        padding-left: .9rem;
    }

    .nav-brand span { display: none; }

    .nav-user {
        max-width: 8.5rem;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    main { padding-bottom: 6.5rem; }

    .card { padding: 1.25rem; }

    .card-intro { padding: 1.6rem; }

    .section-head {
        flex-direction: column;
        align-items: flex-start;
        gap: .5rem;
    }

    .chart-box { height: 240px; }

    .month > summary { padding: .9rem 1rem; flex-wrap: wrap; }

    .month > summary .month-chevron { margin-left: auto; }

    .month-total { width: 100%; margin-left: 0; order: 3; }

    .month-body { padding: 0 1rem .75rem; }

    .entry { flex-wrap: wrap; gap: .5rem .75rem; }

    .entry-amount { margin-left: auto; }

    .entry-actions { width: 100%; justify-content: flex-end; }

    .fab { display: inline-flex; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *,
    *::before,
    *::after {
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
    }
}
