/* =====================================================================
   Mis Apps – Control de Gastos  |  style.css
   ===================================================================== */

/* ── Reset & base ─────────────────────────────────────────────────── */
#mag-app *,
#mag-app *::before,
#mag-app *::after { box-sizing: border-box; }

#mag-app {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    max-width: 980px;
    margin: 0 auto;
    padding: 28px 20px 60px;
    color: #1a1a2e;
    line-height: 1.5;
}

/* ── Login notice ─────────────────────────────────────────────────── */
.mag-login-notice {
    padding: 20px;
    background: #fef9c3;
    border: 1px solid #fde047;
    border-radius: 10px;
    font-size: .95rem;
}

/* ── Header ───────────────────────────────────────────────────────── */
.mag-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
}
.mag-header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.mag-back-link {
    font-size: .8rem;
    color: #94a3b8;
    text-decoration: none;
    transition: color .15s;
}
.mag-back-link:hover { color: #6366f1; }
.mag-header h2 {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 800;
    color: #1a1a2e;
}

/* ── Selector de mes ──────────────────────────────────────────────── */
.mag-mes-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px 18px;
    margin-bottom: 24px;
}
#mag-select-mes {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 600;
    background: #fff;
    color: #1a1a2e;
    cursor: pointer;
    appearance: auto;
}
#mag-select-mes:focus { outline: 2px solid #6366f1; outline-offset: 2px; }

/* ── Secciones ────────────────────────────────────────────────────── */
.mag-seccion {
    background: #fff;
    border-radius: 18px;
    padding: 26px;
    margin-bottom: 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.04);
    border: 1px solid #f1f5f9;
}
.mag-seccion-title {
    margin: 0 0 18px;
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: #94a3b8;
}

/* ── Resumen cards ────────────────────────────────────────────────── */
.mag-resumen-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}
.mag-card {
    border-radius: 14px;
    padding: 20px;
    text-align: center;
}
.mag-card-label {
    display: block;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 8px;
    opacity: .75;
}
.mag-card-value {
    display: block;
    font-size: 1.45rem;
    font-weight: 800;
}
.mag-card--ingreso  { background: #f0fdf4; color: #15803d; }
.mag-card--egreso   { background: #fef2f2; color: #b91c1c; }
.mag-card--balance  { background: #eff6ff; color: #1d4ed8; }
.mag-card--balance.mag-card--balance-pos { background: #f0fdf4; color: #15803d; }
.mag-card--balance.mag-card--balance-neg { background: #fef2f2; color: #b91c1c; }

/* ── Gráfico ──────────────────────────────────────────────────────── */
.mag-chart-wrap {
    position: relative;
    height: 280px;
}

/* ── Grilla movimientos ───────────────────────────────────────────── */
.mag-movimientos-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
}
.mag-col-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    margin-bottom: 4px;
    border-bottom: 2px solid #f1f5f9;
}
.mag-col-head h3 {
    margin: 0;
    font-size: .95rem;
    font-weight: 700;
    color: #1a1a2e;
}

/* ── Items ────────────────────────────────────────────────────────── */
.mag-lista { min-height: 40px; }
.mag-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid #f8fafc;
    gap: 8px;
}
.mag-item:last-child { border-bottom: none; }
.mag-item-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.mag-item-cat {
    font-size: .9rem;
    font-weight: 600;
    color: #1a1a2e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mag-item-desc {
    font-size: .78rem;
    color: #94a3b8;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mag-pin { font-size: .75rem; }
.mag-item-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.mag-item-monto {
    font-size: .95rem;
    font-weight: 700;
    color: #374151;
    white-space: nowrap;
}
.mag-item-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .15s;
}
.mag-item:hover .mag-item-actions { opacity: 1; }
.mag-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 5px;
    font-size: .8rem;
    border-radius: 6px;
    transition: background .15s;
    line-height: 1;
}
.mag-icon-btn:hover { background: #f1f5f9; }
.mag-empty {
    color: #cbd5e1;
    font-size: .88rem;
    text-align: center;
    padding: 24px 0;
    margin: 0;
}

/* ── Botón copiar ─────────────────────────────────────────────────── */
#mag-copiar-wrap {
    text-align: center;
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px dashed #e2e8f0;
}

/* ── Botones ──────────────────────────────────────────────────────── */
.mag-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 9px;
    border: none;
    cursor: pointer;
    font-size: .875rem;
    font-weight: 700;
    transition: all .15s;
    white-space: nowrap;
    line-height: 1;
}
.mag-btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

.mag-btn-primary {
    background: #6366f1;
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,.35);
}
.mag-btn-primary:hover { background: #4f46e5; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(99,102,241,.4); }
.mag-btn-primary:active { transform: translateY(0); }

.mag-btn-outline {
    background: #fff;
    color: #475569;
    border: 1.5px solid #e2e8f0;
}
.mag-btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }

.mag-btn-copiar { width: auto; }

.mag-btn-add {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border: 1.5px dashed #cbd5e1;
    border-radius: 7px;
    background: none;
    color: #64748b;
    font-size: .8rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
    line-height: 1;
}
.mag-btn-add:hover { border-color: #6366f1; color: #6366f1; background: #eef2ff; }
.mag-btn-add:disabled { opacity: .4; cursor: not-allowed; }

/* ── Overlay ──────────────────────────────────────────────────────── */
#mag-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.5);
    backdrop-filter: blur(3px);
    z-index: 9998;
}

/* ── Modales ──────────────────────────────────────────────────────── */
.mag-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
    pointer-events: none;
}
.mag-modal-box {
    background: #fff;
    border-radius: 18px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 24px 64px rgba(0,0,0,.2);
    pointer-events: all;
    animation: mag-pop .2s cubic-bezier(.34,1.56,.64,1);
}
.mag-modal-box--sm { max-width: 360px; }

@keyframes mag-pop {
    from { opacity: 0; transform: scale(.93) translateY(12px); }
    to   { opacity: 1; transform: scale(1)  translateY(0); }
}

.mag-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #f1f5f9;
}
.mag-modal-head h4 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: #1a1a2e;
}
.mag-modal-x {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: #94a3b8;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 6px;
    transition: background .15s;
}
.mag-modal-x:hover { background: #f1f5f9; color: #475569; }

.mag-modal-body { padding: 20px 24px; }

.mag-modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 24px 20px;
    border-top: 1px solid #f1f5f9;
}

/* ── Formulario ───────────────────────────────────────────────────── */
.mag-field { margin-bottom: 16px; }
.mag-field:last-child { margin-bottom: 0; }
.mag-field label {
    display: block;
    font-size: .8rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.mag-field input[type="text"],
.mag-field input[type="number"],
.mag-field select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 9px;
    font-size: .95rem;
    color: #1a1a2e;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
.mag-field input:focus,
.mag-field select:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.mag-field--check label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0;
    font-size: .9rem;
    font-weight: 500;
    color: #374151;
}
.mag-field--check label small {
    display: block;
    font-size: .78rem;
    color: #94a3b8;
    margin-top: 2px;
}
.mag-field--check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    margin-top: 2px;
    cursor: pointer;
    accent-color: #6366f1;
}

/* ── Toast ────────────────────────────────────────────────────────── */
#mag-toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(90px);
    padding: 12px 26px;
    border-radius: 10px;
    font-size: .88rem;
    font-weight: 600;
    z-index: 99999;
    pointer-events: none;
    white-space: nowrap;
    transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s;
    opacity: 0;
    background: #1e293b;
    color: #fff;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#mag-toast.mag-toast--show { transform: translateX(-50%) translateY(0); opacity: 1; }
#mag-toast.mag-toast--ok  { background: #15803d; }
#mag-toast.mag-toast--err { background: #b91c1c; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
    #mag-app { padding: 16px 14px 48px; }
    .mag-header { flex-direction: column; align-items: flex-start; }
    .mag-mes-bar { flex-direction: column; align-items: stretch; }
    .mag-resumen-grid { grid-template-columns: 1fr; }
    .mag-movimientos-grid { grid-template-columns: 1fr; gap: 16px; }
    .mag-chart-wrap { height: 220px; }
    .mag-modal-box { max-width: 100%; }
}
