/* Control de Gastos — estilo Neumorfismo accesible (contraste AA) */
:root {
    --bg: #e6e9ef;
    --texto: #1f2937;
    --texto-suave: #475569;
    --sombra-clara: #ffffff;
    --sombra-oscura: #bfc6d4;
    --primario: #3451c7;
    --primario-osc: #283fa0;
    --ok: #1f7a3a;
    --aviso: #8a5a00;
    --peligro: #b42323;
    --radio: 18px;
    --elev: 7px 7px 15px var(--sombra-oscura), -7px -7px 15px var(--sombra-clara);
    --elev-sm: 4px 4px 9px var(--sombra-oscura), -4px -4px 9px var(--sombra-clara);
    --hundido: inset 4px 4px 8px var(--sombra-oscura), inset -4px -4px 8px var(--sombra-clara);
    --ancho-sidebar: 270px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    background: var(--bg);
    color: var(--texto);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
h1, .h1 { font-size: clamp(1.4rem, 1.1rem + 1.2vw, 1.9rem); font-weight: 700; }
h2, .h2 { font-size: 1.2rem; font-weight: 650; }
h3, .h3 { font-size: 1.05rem; font-weight: 650; }
.text-muted, .text-secondary, .form-text { color: var(--texto-suave) !important; }
a { color: var(--primario); }
a:hover { color: var(--primario-osc); }

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

/* ---------- Estructura ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--ancho-sidebar);
    flex-shrink: 0;
    background: var(--bg);
    padding: 1.25rem 1rem;
    box-shadow: 6px 0 14px rgba(160, 170, 190, .25);
}
.sidebar .offcanvas-body { display: flex; flex-direction: column; padding: 0; }
.sidebar .marca { font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; gap: .6rem; color: var(--texto); text-decoration: none; padding: .25rem .5rem 1rem; }
.sidebar .marca .logo {
    width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
    color: var(--primario); box-shadow: var(--elev-sm); font-size: 1.25rem;
}
.nav-grupo { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--texto-suave); font-weight: 700; margin: 1.1rem .75rem .35rem; }
.sidebar .nav-link {
    color: var(--texto); border-radius: 12px; padding: .55rem .85rem; display: flex; align-items: center; gap: .65rem; font-weight: 500;
    min-height: 44px;
}
.sidebar .nav-link:hover { box-shadow: var(--elev-sm); color: var(--primario-osc); }
.sidebar .nav-link.active { box-shadow: var(--hundido); color: var(--primario-osc); font-weight: 700; }
.contenido { flex: 1; min-width: 0; padding: 1.25rem; }
.topbar { display: none; }
.contenedor { max-width: 1280px; margin: 0 auto; }

@media (max-width: 991.98px) {
    .app { display: block; }
    .topbar {
        display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem 1rem;
        position: sticky; top: 0; z-index: 1020; background: var(--bg); box-shadow: 0 4px 12px rgba(160, 170, 190, .35);
    }
    .sidebar { width: 290px; background: var(--bg); box-shadow: none; padding: 1rem; }
    .contenido { padding: 1rem; }
}

/* ---------- Componentes neumorficos ---------- */
.neu-card { background: var(--bg); border-radius: var(--radio); box-shadow: var(--elev); padding: 1.25rem; border: 0; }
.neu-card.sm { box-shadow: var(--elev-sm); padding: 1rem; }
.neu-inset { background: var(--bg); border-radius: 14px; box-shadow: var(--hundido); padding: .75rem 1rem; }

.btn { border-radius: 12px; font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 0; }
.neu-btn, .btn-neu { background: var(--bg); color: var(--texto); box-shadow: var(--elev-sm); }
.neu-btn:hover, .btn-neu:hover { color: var(--primario-osc); background: var(--bg); box-shadow: 2px 2px 5px var(--sombra-oscura), -2px -2px 5px var(--sombra-clara); }
.neu-btn:active, .btn-neu:active { box-shadow: var(--hundido); }
.neu-btn-primary { background: var(--primario); color: #fff; box-shadow: 4px 4px 10px rgba(52, 81, 199, .35), -4px -4px 9px var(--sombra-clara); }
.neu-btn-primary:hover { background: var(--primario-osc); color: #fff; }
.neu-btn-danger { background: var(--bg); color: var(--peligro); box-shadow: var(--elev-sm); }
.neu-btn-danger:hover { background: var(--peligro); color: #fff; }
.btn-sm { min-height: 38px; padding: .3rem .75rem; font-size: .9rem; }
.btn-icono { width: 44px; padding: 0; }

.form-label { font-weight: 600; margin-bottom: .35rem; }
.form-control, .form-select, .input-group-text {
    background: var(--bg); color: var(--texto); border: 0; border-radius: 12px; min-height: 46px;
    box-shadow: var(--hundido);
}
.input-group-text { box-shadow: none; padding-inline: .9rem; color: var(--texto-suave); }
.input-group > .form-control { border-radius: 12px !important; }
.input-group > .input-group-text + .form-control { margin-left: 0; }
.form-control:focus, .form-select:focus { background: var(--bg); color: var(--texto); box-shadow: var(--hundido), 0 0 0 3px rgba(52, 81, 199, .55); }
.form-control::placeholder { color: #64748b; }
.form-control.is-invalid, .form-select.is-invalid { box-shadow: var(--hundido), 0 0 0 2px var(--peligro); background-image: none; }
.invalid-feedback { color: var(--peligro); font-weight: 600; }
.form-check-input { width: 1.4em; height: 1.4em; background-color: var(--bg); border: 0; box-shadow: var(--hundido); }
.form-check-input:checked { background-color: var(--primario); }
input[type="color"].form-control { padding: .3rem; width: 100%; height: 46px; }

/* ---------- Tablas ---------- */
.tabla { width: 100%; border-collapse: separate; border-spacing: 0 .5rem; margin: 0; }
.tabla thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--texto-suave); font-weight: 700; padding: .4rem .85rem; border: 0; white-space: nowrap; background: transparent; }
.tabla tbody td { padding: .8rem .85rem; background: var(--bg); vertical-align: middle; border: 0; }
.tabla tbody tr { box-shadow: var(--elev-sm); }
.tabla tbody td:first-child { border-radius: 12px 0 0 12px; }
.tabla tbody td:last-child { border-radius: 0 12px 12px 0; }
.tabla .acciones { white-space: nowrap; text-align: right; }

@media (max-width: 767.98px) {
    .tabla thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .tabla, .tabla tbody, .tabla tr, .tabla td { display: block; width: 100%; }
    .tabla tbody tr { margin-bottom: 1rem; border-radius: 14px; padding: .4rem 0; background: var(--bg); }
    .tabla tbody td { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 1rem; text-align: right !important; border-radius: 0 !important; }
    .tabla tbody td::before { content: attr(data-label); font-weight: 700; color: var(--texto-suave); text-align: left; flex-shrink: 0; }
    .tabla tbody td.acciones { justify-content: flex-end; flex-wrap: wrap; padding-top: .7rem; }
    .tabla tbody td.acciones::before { content: none; }
}

/* ---------- KPIs, progreso, badges ---------- */
.kpi { display: flex; flex-direction: column; gap: .15rem; height: 100%; }
.kpi .etiqueta { font-size: .85rem; font-weight: 600; color: var(--texto-suave); display: flex; align-items: center; gap: .4rem; }
.kpi .valor { font-size: clamp(1.35rem, 1rem + 1.1vw, 1.8rem); font-weight: 800; line-height: 1.15; word-break: break-word; }
.kpi .nota { font-size: .85rem; color: var(--texto-suave); }
.valor-ok { color: var(--ok); }
.valor-mal { color: var(--peligro); }
.valor-aviso { color: var(--aviso); }

.neu-progress { height: 16px; border-radius: 10px; box-shadow: var(--hundido); background: var(--bg); overflow: hidden; }
.neu-progress > span { display: block; height: 100%; border-radius: 10px; background: var(--primario); transition: width .4s; }
.neu-progress.ok > span { background: var(--ok); }
.neu-progress.aviso > span { background: #d98b00; }
.neu-progress.peligro > span { background: var(--peligro); }

.etiqueta-neu { display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .65rem; border-radius: 20px; font-size: .82rem; font-weight: 600; box-shadow: var(--elev-sm); }
.punto { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.estado-ok { color: var(--ok); } .estado-riesgo, .estado-vencida { color: var(--peligro); } .estado-lograda { color: var(--primario); }

.grafica { position: relative; height: 280px; }
.grafica.alta { height: 320px; }

.alerta-neu { border-radius: 14px; padding: .85rem 1.1rem; box-shadow: var(--hundido); display: flex; gap: .75rem; align-items: flex-start; }
.alerta-neu.peligro { color: #7f1d1d; border-left: 5px solid var(--peligro); }
.alerta-neu.aviso { color: #6b4500; border-left: 5px solid #d98b00; }
.alerta-neu.info { color: #1e3a8a; border-left: 5px solid var(--primario); }

.lista-simple { list-style: none; padding: 0; margin: 0; }
.lista-simple li { padding: .65rem 0; border-bottom: 1px solid rgba(100, 116, 139, .2); }
.lista-simple li:last-child { border-bottom: 0; }

.vacio { text-align: center; padding: 2rem 1rem; color: var(--texto-suave); }
.vacio i { font-size: 2.2rem; display: block; margin-bottom: .5rem; }

/* ---------- Autenticacion ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.auth-card { width: 100%; max-width: 440px; }

.skip-link { position: absolute; left: -999px; top: .5rem; background: var(--primario); color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 3000; }
.skip-link:focus { left: .5rem; color: #fff; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print {
    .sidebar, .topbar, .no-imprimir { display: none !important; }
    .neu-card { box-shadow: none; border: 1px solid #ccc; }
}
