/* Animations và Effects */

/* 1. Animation cho biểu đồ (fade-in, grow) */
.chart-animate {
    animation: chartFadeIn 1.5s cubic-bezier(.25,.46,.45,.94);
}

@keyframes chartFadeIn {
    0% { 
        opacity: 0; 
        transform: scale(0.95) translateY(20px); 
    }
    100% { 
        opacity: 1; 
        transform: scale(1) translateY(0); 
    }
}

/* 2. Hiệu ứng hover cho card tổng quan - tối ưu để tránh nháy */
#summaryContainer .card {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    will-change: transform, box-shadow;
}

#summaryContainer .card:hover {
    box-shadow: 0 8px 32px rgba(80,0,120,0.18);
    transform: translateY(-2px) scale(1.02);
    border-color: #d53f8c;
}

/* 3. Highlight min/max: giảm animation để tránh nháy */
.highlight-min {
    color: #3498db;
    font-weight: bold;
    animation: minPulse 2s infinite alternate;
}

.highlight-max {
    color: #e74c3c;
    font-weight: bold;
    animation: maxPulse 2s infinite alternate;
}

@keyframes minPulse {
    0% { text-shadow: 0 0 0 #3498db; }
    100% { text-shadow: 0 0 4px #3498db; }
}

@keyframes maxPulse {
    0% { text-shadow: 0 0 0 #e74c3c; }
    100% { text-shadow: 0 0 4px #e74c3c; }
}

/* 4. Tối ưu canvas để tránh nháy khi hover */
canvas {
    transition: none !important;
    will-change: auto;
    image-rendering: auto;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Tối ưu container của biểu đồ */
.chart-container {
    will-change: auto;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Ngăn chặn flicker khi hover chart */
#monthlyChart, #dailyChart {
    transition: none !important;
    image-rendering: auto;
}

/* 5. Tooltip nâng cao cho card tổng quan */
.summary-tooltip {
    position: relative;
    cursor: pointer;
}

.summary-tooltip .tooltiptext {
    visibility: hidden;
    width: 180px;
    background: #222b;
    color: #fff;
    text-align: left;
    border-radius: 8px;
    padding: 8px;
    position: absolute;
    z-index: 10;
    bottom: 120%;
    left: 50%;
    margin-left: -90px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.85rem;
    box-shadow: 0 2px 8px #0005;
}

.summary-tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}

/* 6. Icon trend động (SVG) và sparkline nhỏ bên cạnh số liệu */
.trend-icon {
    display: inline-block;
    vertical-align: middle;
    margin-left: 4px;
    width: 22px;
    height: 22px;
    transition: transform 0.3s;
}

.trend-up {
    color: #22c55e;
    animation: trendBounceUp 1s infinite alternate;
}

.trend-down {
    color: #ef4444;
    animation: trendBounceDown 1s infinite alternate;
}

.trend-flat {
    color: #f59e42;
}

@keyframes trendBounceUp {
    0% { transform: translateY(0); }
    100% { transform: translateY(-5px) scale(1.15); }
}

@keyframes trendBounceDown {
    0% { transform: translateY(0); }
    100% { transform: translateY(5px) scale(1.15); }
}

.sparkline {
    display: inline-block;
    height: 18px;
    width: 60px;
    margin-left: 6px;
    vertical-align: middle;
}

/* Badge nổi bật cho trend mạnh */
.trend-badge {
    display: inline-block;
    background: linear-gradient(90deg,#f43f5e,#f59e42);
    color: #fff;
    font-size: 0.7rem;
    border-radius: 8px;
    padding: 2px 8px;
    margin-left: 6px;
    font-weight: bold;
    animation: badgePulse 1.2s infinite alternate;
}

@keyframes badgePulse {
    0% { box-shadow: 0 0 0 #f43f5e; }
    100% { box-shadow: 0 0 8px #f43f5e; }
}

/* Tooltip nâng cao cho số liệu tổng quan */
.main-tooltip {
    position: relative;
    cursor: pointer;
}

.main-tooltip .main-tooltiptext {
    visibility: hidden;
    width: 180px;
    background: #222b;
    color: #fff;
    text-align: left;
    border-radius: 8px;
    padding: 8px;
    position: absolute;
    z-index: 10;
    bottom: 120%;
    left: 50%;
    margin-left: -90px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.85rem;
    box-shadow: 0 2px 8px #0005;
}

.main-tooltip:hover .main-tooltiptext {
    visibility: visible;
    opacity: 1;
}

/* Micro-interaction: số liệu phóng to nhẹ khi hover */
.counter-up:hover {
    transform: scale(1.08);
    color: #e961ab;
    transition: transform 0.2s, color 0.2s;
}

/* Ripple effect for button */
.btn {
    position: relative;
    overflow: hidden;
}

.ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripple 0.6s linear;
    background: rgba(255,255,255,0.5);
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Loader spinner */
.loader {
    border: 4px solid #e0e0e0;
    border-top: 4px solid #e961ab;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
    display: none;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
