/* ========================================
   ANIMACIONES Y MEJORAS VISUALES - GastoClaro v3.0
   ======================================== */

/* ========================================
   1. ANIMACIONES DE ENTRADA PARA TRANSACCIONES
   ======================================== */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.transaction-item {
    animation: slideInUp 0.3s ease-out backwards;
}

.transaction-item:nth-child(1) { animation-delay: 0s; }
.transaction-item:nth-child(2) { animation-delay: 0.03s; }
.transaction-item:nth-child(3) { animation-delay: 0.06s; }
.transaction-item:nth-child(4) { animation-delay: 0.09s; }
.transaction-item:nth-child(5) { animation-delay: 0.12s; }
.transaction-item:nth-child(6) { animation-delay: 0.15s; }
.transaction-item:nth-child(7) { animation-delay: 0.18s; }
.transaction-item:nth-child(8) { animation-delay: 0.21s; }
.transaction-item:nth-child(9) { animation-delay: 0.24s; }
.transaction-item:nth-child(10) { animation-delay: 0.27s; }

/* ========================================
   2. HOVER EFFECTS MEJORADOS EN TARJETAS DE BALANCE
   ======================================== */
.balance-item {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
    position: relative;
    overflow: hidden;
}

.balance-item::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.balance-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.balance-item:hover::before {
    width: 300px;
    height: 300px;
}

.balance-item.income:hover {
    box-shadow: 0 12px 24px rgba(134, 239, 172, 0.4);
    border-color: rgba(187, 247, 208, 1);
}

.balance-item.expense:hover {
    box-shadow: 0 12px 24px rgba(248, 113, 113, 0.4);
    border-color: rgba(252, 165, 165, 1);
}

.balance-item.warning:hover {
    box-shadow: 0 12px 24px rgba(251, 113, 133, 0.4);
    border-color: rgba(253, 164, 175, 1);
}

.balance-item.success:hover {
    box-shadow: 0 12px 24px rgba(52, 211, 153, 0.4);
    border-color: rgba(110, 231, 183, 1);
}

.balance-item .amount {
    transition: all 0.3s ease;
}

.balance-item:hover .amount {
    transform: scale(1.02);
    filter: brightness(1.1);
}

/* ========================================
   3. ANIMACIÓN COUNTING UP EN BALANCE
   ======================================== */
@keyframes countUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.balance-amount,
.balance-item .amount {
    animation: countUp 0.5s ease-out;
}

/* Efecto de pulso cuando cambia el valor */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.balance-amount.updating,
.balance-item .amount.updating {
    animation: pulse 0.4s ease-in-out;
}

/* ========================================
   4. MEJORAS EN BOTONES - RIPPLE EFFECT
   ======================================== */
.btn-primary,
.btn-secondary,
.add-btn,
.btn-icon,
.swipe-action-btn {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary::after,
.btn-secondary::after,
.add-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-primary:active::after,
.btn-secondary:active::after,
.add-btn:active::after {
    width: 300px;
    height: 300px;
    transition: width 0s, height 0s;
}

.btn-primary:hover,
.add-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(34, 197, 94, 0.25);
}

.btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
}

.btn-icon:hover {
    transform: scale(1.08);
}

/* Micro-animación en iconos SVG */
.btn-icon svg {
    transition: all 0.2s ease;
}

.btn-icon:hover svg {
    transform: scale(1.1);
}

/* ========================================
   5. SKELETON LOADERS
   ======================================== */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.1) 25%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.1) 75%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
    border-radius: var(--radius-md);
}

.skeleton-transaction {
    height: 80px;
    margin-bottom: 12px;
}

.skeleton-card {
    height: 120px;
    margin-bottom: 16px;
}

/* ========================================
   6. ANIMACIÓN EN BARRAS DE PROGRESO
   ======================================== */
@keyframes fillProgress {
    from {
        width: 0;
    }
}

.goal-progress-fill,
.loan-progress-fill,
.budget-progress .progress-fill {
    animation: fillProgress 1.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Pulso en objetivos casi completos */
@keyframes progressPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
    }
}

.goal-progress-fill.near-complete {
    animation: fillProgress 1.5s cubic-bezier(0.4, 0, 0.2, 1) forwards,
               progressPulse 2s infinite 1.5s;
}

/* Badge de progreso */
.progress-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    animation: fadeIn 0.3s ease-out;
}

.progress-badge.almost-there {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
    animation: fadeIn 0.3s ease-out, pulse 2s infinite;
}

.progress-badge.completed {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

/* ========================================
   7. TOAST NOTIFICATIONS MEJORADAS
   ======================================== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(400px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(400px);
    }
}

.toast {
    background: white;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 400px;
    pointer-events: auto;
    animation: slideInRight 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 4px solid;
}

.toast.hiding {
    animation: slideOutRight 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
}

.toast-success {
    border-left-color: #22c55e;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(255, 255, 255, 1));
}

.toast-error {
    border-left-color: #ef4444;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(255, 255, 255, 1));
}

.toast-info {
    border-left-color: #3b82f6;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(255, 255, 255, 1));
}

.toast-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.toast-message {
    font-size: 13px;
    color: var(--text-secondary);
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.toast-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* ========================================
   8. MICRO-INTERACCIONES EN CALENDARIO
   ======================================== */
.calendar-day {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.calendar-day:hover {
    transform: scale(1.15);
    z-index: 10;
}

.calendar-day.has-transactions:hover {
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

/* Preview tooltip del día */
.day-preview {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: var(--bg-primary);
    padding: 12px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.calendar-day:hover .day-preview {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

.day-preview-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.day-preview-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.day-preview-stat {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary);
}

.day-preview-stat .income {
    color: var(--income-color);
}

.day-preview-stat .expense {
    color: var(--expense-color);
}

/* Indicador de días con muchos movimientos */
.calendar-day.busy::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 6px;
    height: 6px;
    background: #f59e0b;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

/* ========================================
   ANIMACIONES ADICIONALES DE ENTRADA
   ======================================== */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.balance-card,
.daily-summary {
    animation: scaleIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.goal-card,
.loan-item {
    animation: slideInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.goal-card:nth-child(1) { animation-delay: 0.1s; }
.goal-card:nth-child(2) { animation-delay: 0.2s; }
.goal-card:nth-child(3) { animation-delay: 0.3s; }

/* ========================================
   CONFETTI PARA OBJETIVOS COMPLETADOS
   ======================================== */
@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    background: #22c55e;
    pointer-events: none;
    z-index: 9999;
    animation: confetti-fall 3s linear forwards;
}

.confetti:nth-child(2n) { background: #3b82f6; }
.confetti:nth-child(3n) { background: #f59e0b; }
.confetti:nth-child(4n) { background: #ef4444; }
.confetti:nth-child(5n) { background: #8b5cf6; }

/* ========================================
   TRANSICIONES SUAVES GLOBALES
   ======================================== */
.modal {
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    animation: scaleIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Animación de carga para filtros */
.filters-section select,
.filters-section input {
    transition: all 0.3s ease;
}

.filters-section select:focus,
.filters-section input:focus {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.2);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    .toast-container {
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: auto;
        max-width: 100%;
    }

    .day-preview {
        display: none;
    }
}
