/**
 * Django Messages Styling with Auto-dismiss Animations
 * Supports both LTR and RTL layouts with smooth transitions
 */

/* Base Messages Container */
.messages {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 90%;
    max-width: 500px;
    pointer-events: none; /* Allow clicks through container */
}

/* RTL Layout Adjustments */
.rtl-layout .messages {
    /* Position remains the same for centered layout */
}

/* Individual Alert Styling */
.alert {
    padding: 12px 20px 12px 45px; /* Extra padding for close button */
    margin-bottom: 10px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: auto; /* Re-enable clicks on alerts */
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(-20px);
}

/* RTL Alert Adjustments */
.rtl-layout .alert {
    padding: 12px 45px 12px 20px; /* Swap padding for RTL */
    text-align: right;
}

/* Alert Types */
.alert-success {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.alert-error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert-warning {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
}

.alert-info {
    background-color: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

/* Close Button */
.alert-close {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 20px;
    font-weight: bold;
    color: inherit;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.2s ease;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* RTL Close Button */
.rtl-layout .alert-close {
    right: auto;
    left: 15px;
}

.alert-close:hover {
    opacity: 0.8;
    transform: translateY(-50%) scale(1.1);
}

.alert-close:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.alert-close.show {
    opacity: 0.6;
}

/* Animation Classes */
.alert.fade-in {
    animation: slideInDown 0.5s ease forwards;
}

.alert.fade-out {
    animation: slideOutUp 0.5s ease forwards;
}

.alert.dismissing {
    pointer-events: none;
}

.alert.paused {
    animation-play-state: paused;
}

/* Keyframe Animations */
@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideOutUp {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
        max-height: 100px;
        margin-bottom: 10px;
        padding-top: 12px;
        padding-bottom: 12px;
    }
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
        max-height: 0;
        margin-bottom: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
}

/* Hover Effects */
.alert:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.alert:hover .alert-close {
    opacity: 0.8;
}

/* Progress Bar (Optional Enhancement) */
.alert::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background-color: currentColor;
    opacity: 0.3;
    width: 100%;
    transform-origin: left;
    animation: progressBar 4s linear;
}

.rtl-layout .alert::before {
    transform-origin: right;
}

.alert.paused::before {
    animation-play-state: paused;
}

@keyframes progressBar {
    from {
        transform: scaleX(1);
    }
    to {
        transform: scaleX(0);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .messages {
        top: 60px;
        width: 95%;
        max-width: none;
        padding: 0 10px;
    }
    
    .alert {
        font-size: 13px;
        padding: 10px 35px 10px 15px;
    }
    
    .rtl-layout .alert {
        padding: 10px 15px 10px 35px;
    }
    
    .alert-close {
        right: 10px;
        font-size: 18px;
    }
    
    .rtl-layout .alert-close {
        right: auto;
        left: 10px;
    }
}

@media (max-width: 480px) {
    .messages {
        top: 50px;
    }
    
    .alert {
        font-size: 12px;
        padding: 8px 30px 8px 12px;
        margin-bottom: 8px;
    }
    
    .rtl-layout .alert {
        padding: 8px 12px 8px 30px;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .alert {
        border-width: 2px;
    }
    
    .alert-close {
        opacity: 1;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .alert,
    .alert-close,
    .alert::before {
        animation: none;
        transition: none;
    }
    
    .alert.fade-in {
        opacity: 1;
        transform: translateY(0);
    }
    
    .alert.fade-out {
        opacity: 0;
    }
}