/* ====================================================
   ANIMATIONS.CSS - HIỆU ỨNG ĐỘNG CHO TOÀN BỘ ỨNG DỤNG
   ==================================================== */

/* ===== 1. KEYFRAMES DEFINITIONS - ĐỊNH NGHĨA ANIMATION ===== */

/* Fade In Down - Xuất hiện từ trên xuống */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Fade In Up - Xuất hiện từ dưới lên */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Fade In - Xuất hiện dần dần */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Fade Out - Biến mất dần dần */
@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Slide In From Left - Trượt vào từ trái */
@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Slide In From Right - Trượt vào từ phải */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Slide Out Right - Trượt ra bên phải */
@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

/* Scale In - Phóng to từ nhỏ */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Scale Out - Thu nhỏ đi */
@keyframes scaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

/* Bounce In - Nảy vào */
@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

/* Shake - Rung lắc (khi lỗi) */
@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-10px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(10px);
    }
}

/* Pulse - Nhấp nháy */
@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* Rotate - Xoay 360 độ */
@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Wiggle - Lắc lư */
@keyframes wiggle {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-5deg);
    }
    75% {
        transform: rotate(5deg);
    }
}

/* Float - Bay lên xuống */
@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Glow - Phát sáng */
@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 5px var(--color-primary);
    }
    50% {
        box-shadow: 0 0 20px var(--color-primary), 0 0 30px var(--color-primary);
    }
}

/* Flip In - Lật vào */
@keyframes flipIn {
    from {
        transform: perspective(400px) rotateY(90deg);
        opacity: 0;
    }
    to {
        transform: perspective(400px) rotateY(0deg);
        opacity: 1;
    }
}

/* Slide Down - Trượt xuống (cho dropdown) */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Zoom In - Phóng to nhanh */
@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale3d(0.3, 0.3, 0.3);
    }
    50% {
        opacity: 1;
    }
}

/* Progress Bar - Thanh tiến trình */
@keyframes progress {
    from {
        width: 0%;
    }
    to {
        width: 100%;
    }
}

/* ===== 2. APPLY ANIMATIONS - ÁP DỤNG CHO CÁC THÀNH PHẦN ===== */

/* Header Animation */
.main-header {
    animation: fadeInDown 0.8s ease both;
}

/* Stats Animation - Mỗi item delay khác nhau */
.stat-item:nth-child(1) {
    animation: fadeInUp 0.6s ease 0.1s both;
}

.stat-item:nth-child(2) {
    animation: fadeInUp 0.6s ease 0.2s both;
}

.stat-item:nth-child(3) {
    animation: fadeInUp 0.6s ease 0.3s both;
}

.stat-item:nth-child(4) {
    animation: fadeInUp 0.6s ease 0.4s both;
}

/* Form Section Animation */
.add-patient-section {
    animation: fadeInUp 0.8s ease 0.3s both;
}

/* Control Panel Animation */
.control-panel {
    animation: fadeInUp 0.6s ease 0.5s both;
}

/* Patients Board Animation */
.patients-board {
    animation: fadeIn 1s ease 0.6s both;
}

/* Column Animation - Mỗi cột delay khác nhau */
.column:nth-child(1) {
    animation: slideInLeft 0.6s ease 0.7s both;
}

.column:nth-child(2) {
    animation: fadeInUp 0.6s ease 0.8s both;
}

.column:nth-child(3) {
    animation: slideInRight 0.6s ease 0.9s both;
}

/* Patient Card Animation */
.patient-card {
    animation: scaleIn 0.4s ease both;
}

/* Patient Card Hover Effect */
.patient-card:hover {
    animation: pulse 0.5s ease;
}

/* Empty State Animation */
.empty-state {
    animation: fadeIn 0.5s ease;
}

.empty-icon {
    animation: float 3s ease-in-out infinite;
}

/* Button Hover Effects */
.btn-add:hover,
.btn-next:hover,
.btn-delete:hover,
.btn-control:hover {
    animation: pulse 0.3s ease;
}

/* Form Input Focus Animation */
.form-group input:focus,
.form-group textarea:focus {
    animation: glow 0.3s ease;
}

/* Modal Animations */
.modal {
    animation: fadeIn 0.3s ease;
}

.modal-content {
    animation: scaleIn 0.3s ease;
}

/* Toast Animations */
.toast {
    animation: slideInRight 0.4s ease;
}

.toast.toast-removing {
    animation: slideOutRight 0.3s ease forwards;
}

/* Footer Animation */
.main-footer {
    animation: fadeInUp 0.6s ease 1s both;
}

/* ===== 3. LOADING ANIMATIONS - HIỆU ỨNG LOADING ===== */

/* Spinner - Vòng xoay loading */
@keyframes spinner {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.loading-spinner {
    border: 3px solid var(--color-border-light);
    border-top: 3px solid var(--color-primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spinner 0.8s linear infinite;
}

/* Dots Loading - 3 chấm nhảy */
@keyframes dotBounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

.loading-dots {
    display: inline-flex;
    gap: 5px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--color-primary);
    border-radius: 50%;
    animation: dotBounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

/* Skeleton Loading - Placeholder animation */
@keyframes skeleton {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--color-bg-light) 0px,
        var(--color-bg-lighter) 40px,
        var(--color-bg-light) 80px
    );
    background-size: 200px 100%;
    animation: skeleton 1.5s infinite;
}

/* ===== 4. INTERACTION ANIMATIONS - HIỆU ỨNG TƯƠNG TÁC ===== */

/* Click Effect - Hiệu ứng khi click */
@keyframes clickEffect {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}

button:active {
    animation: clickEffect 0.2s ease;
}

/* Success Check Animation */
@keyframes successCheck {
    0% {
        transform: scale(0) rotate(45deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(45deg);
        opacity: 1;
    }
    100% {
        transform: scale(1) rotate(45deg);
        opacity: 1;
    }
}

.success-check {
    animation: successCheck 0.5s ease;
}

/* Error Animation */
.form-error {
    animation: shake 0.5s ease;
}

/* Count Number Animation */
@keyframes countUp {
    from {
        transform: translateY(10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.count {
    animation: countUp 0.3s ease;
}

/* Badge Bounce - Hiệu ứng badge mới */
@keyframes badgeBounce {
    0%, 100% {
        transform: scale(1);
    }
    10%, 20% {
        transform: scale(0.9) rotate(-3deg);
    }
    30%, 50%, 70%, 90% {
        transform: scale(1.1) rotate(3deg);
    }
    40%, 60%, 80% {
        transform: scale(1.1) rotate(-3deg);
    }
}

.badge-new {
    animation: badgeBounce 0.8s ease;
}

/* ===== 5. UTILITY ANIMATION CLASSES ===== */

/* Classes có thể dùng trực tiếp trong JavaScript */

.animate-fade-in {
    animation: fadeIn 0.5s ease;
}

.animate-fade-out {
    animation: fadeOut 0.5s ease;
}

.animate-slide-in-left {
    animation: slideInLeft 0.5s ease;
}

.animate-slide-in-right {
    animation: slideInRight 0.5s ease;
}

.animate-slide-out-right {
    animation: slideOutRight 0.3s ease forwards;
}

.animate-scale-in {
    animation: scaleIn 0.3s ease;
}

.animate-scale-out {
    animation: scaleOut 0.3s ease forwards;
}

.animate-bounce-in {
    animation: bounceIn 0.6s ease;
}

.animate-shake {
    animation: shake 0.5s ease;
}

.animate-pulse {
    animation: pulse 1s ease infinite;
}

.animate-wiggle {
    animation: wiggle 0.5s ease;
}

.animate-glow {
    animation: glow 2s ease infinite;
}

.animate-float {
    animation: float 3s ease-in-out infinite;
}

/* ===== 6. PERFORMANCE OPTIMIZATION ===== */

/* Tối ưu performance cho animations */
.patient-card,
.btn,
.modal-content,
.toast {
    will-change: transform, opacity;
}

/* Reduce motion cho người dùng có vấn đề về vestibular */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== 7. CUSTOM TIMING FUNCTIONS ===== */

/* Các timing function đặc biệt */
:root {
    --ease-in-out-back: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
    --ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);
}

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

/* ===== 8. PRINT ANIMATIONS - TẮT KHI IN ===== */

@media print {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}