/**
 * Comprehensive Animation System
 * Smooth, modern animations throughout the ticket system
 */

/* ============================================
   PAGE LOAD ANIMATIONS
   ============================================ */

/* Fade in page on load */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInFromRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInFromBottom {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleInBounce {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

/* Page load animation */
body.dashboard-page {
    animation: fadeIn 0.4s ease-out;
}

.dashboard-wrapper {
    animation: fadeIn 0.5s ease-out;
}

.dashboard-header {
    animation: slideInFromTop 0.5s ease-out;
}

@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dashboard-sidebar {
    animation: slideInFromLeft 0.5s ease-out;
}

.dashboard-content {
    animation: fadeInUp 0.6s ease-out;
}

/* ============================================
   BUTTON ANIMATIONS
   ============================================ */

.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    box-shadow: 0 2px 8px rgba(74, 108, 247, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(74, 108, 247, 0.4);
}

.btn-secondary:hover {
    transform: translateY(-1px);
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Button loading state */
.btn.loading {
    pointer-events: none;
    opacity: 0.7;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    margin: auto;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============================================
   CARD ANIMATIONS
   ============================================ */

.card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(74, 108, 247, 0.15);
}

.category-card {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

.category-card:hover::before {
    left: 100%;
}

.category-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 24px rgba(74, 108, 247, 0.25);
}

.category-card:active {
    transform: translateY(-2px) scale(1.01);
}

/* ============================================
   TICKET ITEM ANIMATIONS
   ============================================ */

.ticket-item {
    animation: fadeInUp 0.4s ease-out backwards;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Staggered animation for ticket list */
.ticket-list .ticket-item:nth-child(1) { animation-delay: 0.05s; }
.ticket-list .ticket-item:nth-child(2) { animation-delay: 0.1s; }
.ticket-list .ticket-item:nth-child(3) { animation-delay: 0.15s; }
.ticket-list .ticket-item:nth-child(4) { animation-delay: 0.2s; }
.ticket-list .ticket-item:nth-child(5) { animation-delay: 0.25s; }
.ticket-list .ticket-item:nth-child(n+6) { animation-delay: 0.3s; }

.ticket-item:hover {
    transform: translateX(6px) translateY(-2px);
    box-shadow: 0 4px 16px rgba(74, 108, 247, 0.2);
}

.ticket-item:active {
    transform: translateX(4px) translateY(-1px);
}

/* ============================================
   MODAL ANIMATIONS
   ============================================ */

.modal {
    animation: fadeIn 0.2s ease-out;
    backdrop-filter: blur(4px);
}

.modal-content {
    animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.showing .modal-content {
    animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.hiding .modal-content {
    animation: scaleOut 0.2s ease-in forwards;
}

@keyframes scaleOut {
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* ============================================
   MESSAGE ANIMATIONS
   ============================================ */

.message {
    animation: messageSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.message-own {
    animation: messageSlideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.message-other {
    animation: messageSlideInLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes messageSlideInRight {
    from {
        opacity: 0;
        transform: translateX(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes messageSlideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.message-content {
    transition: all 0.2s ease;
}

.message:hover .message-content {
    transform: scale(1.01);
}

/* ============================================
   NOTIFICATION ANIMATIONS
   ============================================ */

.notifications-dropdown-content {
    animation: slideDownBounce 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes slideDownBounce {
    0% {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    50% {
        transform: translateY(5px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.notification-item {
    animation: slideInFromRight 0.3s ease-out backwards;
}

.notification-item:nth-child(1) { animation-delay: 0.05s; }
.notification-item:nth-child(2) { animation-delay: 0.1s; }
.notification-item:nth-child(3) { animation-delay: 0.15s; }
.notification-item:nth-child(4) { animation-delay: 0.2s; }
.notification-item:nth-child(5) { animation-delay: 0.25s; }
.notification-item:nth-child(n+6) { animation-delay: 0.3s; }

.notification-badge {
    animation: badgePulse 0.6s ease-out;
}

@keyframes badgePulse {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* ============================================
   INPUT ANIMATIONS
   ============================================ */

input[type="text"],
input[type="email"],
input[type="url"],
input[type="number"],
textarea,
select {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

input:focus,
textarea:focus,
select:focus {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 108, 247, 0.15);
}

/* Input label animation */
.input-group {
    position: relative;
}

.input-group label {
    transition: all 0.3s ease;
}

.input-group:focus-within label {
    color: var(--accent);
    transform: translateY(-2px);
}

/* ============================================
   SIDEBAR ANIMATIONS
   ============================================ */

@media (max-width: 768px) {
    .dashboard-sidebar {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .dashboard-sidebar.mobile-open {
        animation: slideInFromLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .sidebar-overlay {
        animation: fadeIn 0.3s ease-out;
    }
    
    .sidebar-overlay.active {
        animation: fadeIn 0.3s ease-out;
    }
}

/* ============================================
   AVATAR ANIMATIONS
   ============================================ */

.user-avatar {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.user-avatar:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(74, 108, 247, 0.4);
}

.user-avatar::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(45deg, var(--accent), var(--primary));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.user-avatar:hover::after {
    opacity: 1;
    animation: rotate 3s linear infinite;
}

@keyframes rotate {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   LOADING STATES
   ============================================ */

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.loading-skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 0%, var(--bg-tertiary) 50%, var(--bg-secondary) 100%);
    background-size: 2000px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

/* ============================================
   WELCOME SCREEN ANIMATIONS
   ============================================ */

.welcome-screen {
    animation: fadeInUp 0.8s ease-out;
}

.welcome-screen i {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.welcome-screen h2 {
    animation: fadeInUp 0.8s ease-out 0.2s backwards;
}

.welcome-screen p {
    animation: fadeInUp 0.8s ease-out 0.4s backwards;
}

.welcome-screen .btn {
    animation: fadeInUp 0.8s ease-out 0.6s backwards;
}

/* ============================================
   SMOOTH SCROLLING
   ============================================ */

html {
    scroll-behavior: smooth;
}

/* ============================================
   ICON ANIMATIONS
   ============================================ */

.fas, .far, .fab {
    transition: transform 0.3s ease;
}

.btn:hover .fas,
.btn:hover .far,
.btn:hover .fab {
    transform: scale(1.1);
}

/* Rotating icon on hover */
.btn:hover .fa-spinner,
.btn:hover .fa-sync {
    animation: spin 1s linear infinite;
}

/* ============================================
   STATUS BADGE ANIMATIONS
   ============================================ */

.ticket-status-badge {
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.ticket-status-badge::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.ticket-status-badge:hover::before {
    left: 100%;
}

/* ============================================
   FILTER ANIMATIONS
   ============================================ */

.filter-group {
    animation: fadeInUp 0.4s ease-out backwards;
}

.filter-group:nth-child(1) { animation-delay: 0.1s; }
.filter-group:nth-child(2) { animation-delay: 0.2s; }
.filter-group:nth-child(3) { animation-delay: 0.3s; }

select {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

select:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(74, 108, 247, 0.1);
}

/* ============================================
   EMPTY STATE ANIMATIONS
   ============================================ */

.empty-state {
    animation: fadeInUp 0.6s ease-out;
}

.empty-state i {
    animation: float 3s ease-in-out infinite;
}

/* ============================================
   ATTACHMENT ANIMATIONS
   ============================================ */

.attachment-preview-item {
    animation: slideInFromBottom 0.3s ease-out backwards;
}

.attachment-preview-item:nth-child(1) { animation-delay: 0.05s; }
.attachment-preview-item:nth-child(2) { animation-delay: 0.1s; }
.attachment-preview-item:nth-child(3) { animation-delay: 0.15s; }
.attachment-preview-item:nth-child(n+4) { animation-delay: 0.2s; }

.attachment-preview-item:hover {
    transform: translateY(-2px) scale(1.02);
}

/* ============================================
   IMAGE MODAL ANIMATIONS
   ============================================ */

.image-modal {
    animation: fadeIn 0.3s ease-out;
}

.image-modal-backdrop {
    animation: fadeIn 0.3s ease-out;
}

.image-modal-content {
    animation: scaleInBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.image-modal-image {
    transition: transform 0.3s ease;
}

.image-modal-image:hover {
    transform: scale(1.02);
}

/* ============================================
   NAVBAR MENU ANIMATIONS
   ============================================ */

.navbar-menu {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.navbar-menu.active {
    animation: slideDownBounce 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.navbar-menu .btn,
.navbar-menu a {
    animation: fadeInUp 0.3s ease-out backwards;
}

.navbar-menu.active .btn:nth-child(1),
.navbar-menu.active a:nth-child(1) { animation-delay: 0.05s; }
.navbar-menu.active .btn:nth-child(2),
.navbar-menu.active a:nth-child(2) { animation-delay: 0.1s; }
.navbar-menu.active .btn:nth-child(3),
.navbar-menu.active a:nth-child(3) { animation-delay: 0.15s; }
.navbar-menu.active .btn:nth-child(4),
.navbar-menu.active a:nth-child(4) { animation-delay: 0.2s; }
.navbar-menu.active .btn:nth-child(5),
.navbar-menu.active a:nth-child(5) { animation-delay: 0.25s; }
.navbar-menu.active .btn:nth-child(n+6),
.navbar-menu.active a:nth-child(n+6) { animation-delay: 0.3s; }

/* ============================================
   TICKET VIEW ANIMATIONS
   ============================================ */

.ticket-view {
    animation: fadeInUp 0.5s ease-out;
}

.ticket-header {
    animation: slideInFromTop 0.4s ease-out;
}

.ticket-info {
    animation: fadeInUp 0.4s ease-out 0.1s backwards;
}

.ticket-messages {
    animation: fadeInUp 0.4s ease-out 0.2s backwards;
}

.message-input {
    animation: fadeInUp 0.4s ease-out 0.3s backwards;
}

/* ============================================
   UTILITY ANIMATIONS
   ============================================ */

/* Fade in animation utility */
.animate-fade-in {
    animation: fadeIn 0.5s ease-out;
}

.animate-fade-in-up {
    animation: fadeInUp 0.5s ease-out;
}

.animate-slide-in-left {
    animation: slideInFromLeft 0.5s ease-out;
}

.animate-slide-in-right {
    animation: slideInFromRight 0.5s ease-out;
}

.animate-scale-in {
    animation: scaleIn 0.3s ease-out;
}

/* ============================================
   REDUCE MOTION (ACCESSIBILITY)
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
