/* ============================================================
   ADVANCED UI ANIMATIONS & MICRO INTERACTIONS — v32
   MedAI · Futuristic AI Motion Design
   ============================================================ */

/* ── Keyframe Library ── */
@keyframes fadeInUp    { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeInDown  { from { opacity:0; transform:translateY(-16px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeInLeft  { from { opacity:0; transform:translateX(-20px); } to { opacity:1; transform:translateX(0); } }
@keyframes fadeInRight { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }
@keyframes scaleIn     { from { opacity:0; transform:scale(0.88); } to { opacity:1; transform:scale(1); } }
@keyframes scaleInBounce { 0%{ opacity:0; transform:scale(0.75); } 70%{ transform:scale(1.04); } 100%{ opacity:1; transform:scale(1); } }
@keyframes slideDown   { from { opacity:0; max-height:0; } to { opacity:1; max-height:600px; } }
@keyframes shimmer     { 0%{ background-position:-400px 0; } 100%{ background-position:400px 0; } }
@keyframes ripple      { 0%{ transform:scale(0); opacity:0.5; } 100%{ transform:scale(6); opacity:0; } }
@keyframes glowPulse   { 0%,100%{ box-shadow:0 0 0 0 rgba(108,99,255,0); } 50%{ box-shadow:0 0 18px 4px rgba(108,99,255,0.3); } }
@keyframes floatUp     { 0%,100%{ transform:translateY(0); } 50%{ transform:translateY(-6px); } }
@keyframes spinSlow    { 100%{ transform:rotate(360deg); } }
@keyframes blink       { 0%,100%{ opacity:1; } 50%{ opacity:0; } }
@keyframes barFill     { from{ width:0%; } to{ width:var(--bar-w, 100%); } }
@keyframes countBounce { 0%{ transform:scale(1); } 40%{ transform:scale(1.15); } 100%{ transform:scale(1); } }
@keyframes cardEntrance {
    0%   { opacity:0; transform:translateY(28px) scale(0.96); }
    60%  { opacity:1; transform:translateY(-4px) scale(1.005); }
    100% { opacity:1; transform:translateY(0) scale(1); }
}
@keyframes timelineReveal {
    from { opacity:0; transform:translateX(-12px); max-height:0; }
    to   { opacity:1; transform:translateX(0);     max-height:200px; }
}
@keyframes dotPing {
    0%   { transform:scale(1); opacity:1; }
    75%,100% { transform:scale(2.2); opacity:0; }
}
@keyframes sidebarItemIn {
    from { opacity:0; transform:translateX(-16px); }
    to   { opacity:1; transform:translateX(0); }
}

/* ── Utility animation classes ── */
.anim-fade-up   { animation: fadeInUp    0.45s cubic-bezier(0.16,1,0.3,1) both; }
.anim-fade-down { animation: fadeInDown  0.4s  cubic-bezier(0.16,1,0.3,1) both; }
.anim-fade-left { animation: fadeInLeft  0.4s  cubic-bezier(0.16,1,0.3,1) both; }
.anim-scale-in  { animation: scaleIn     0.35s cubic-bezier(0.16,1,0.3,1) both; }
.anim-scale-bounce { animation: scaleInBounce 0.45s cubic-bezier(0.16,1,0.3,1) both; }
.anim-float     { animation: floatUp 3s ease-in-out infinite; }

/* Stagger delay helpers */
.d-50  { animation-delay: 50ms !important; }
.d-100 { animation-delay: 100ms !important; }
.d-150 { animation-delay: 150ms !important; }
.d-200 { animation-delay: 200ms !important; }
.d-250 { animation-delay: 250ms !important; }
.d-300 { animation-delay: 300ms !important; }
.d-400 { animation-delay: 400ms !important; }
.d-500 { animation-delay: 500ms !important; }

/* ── Intersection Observer triggered ── */
.reveal { opacity:0; transform:translateY(24px); transition:opacity 0.55s cubic-bezier(0.16,1,0.3,1), transform 0.55s cubic-bezier(0.16,1,0.3,1); }
.reveal.in { opacity:1; transform:none; }
.reveal-left  { opacity:0; transform:translateX(-20px); transition:opacity 0.5s ease, transform 0.5s ease; }
.reveal-left.in  { opacity:1; transform:none; }
.reveal-right { opacity:0; transform:translateX(20px); transition:opacity 0.5s ease, transform 0.5s ease; }
.reveal-right.in { opacity:1; transform:none; }
.reveal-scale { opacity:0; transform:scale(0.93); transition:opacity 0.45s ease, transform 0.45s cubic-bezier(0.16,1,0.3,1); }
.reveal-scale.in { opacity:1; transform:scale(1); }

/* ── Skeleton Loading ── */
.skeleton {
    background: linear-gradient(90deg,
        rgba(255,255,255,0.04) 0%,
        rgba(255,255,255,0.10) 40%,
        rgba(255,255,255,0.04) 80%);
    background-size: 400px 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    border-radius: var(--radius-sm);
    color: transparent !important;
    pointer-events: none;
}
[data-theme="light"] .skeleton {
    background: linear-gradient(90deg,
        rgba(0,0,0,0.05) 0%,
        rgba(0,0,0,0.12) 40%,
        rgba(0,0,0,0.05) 80%);
    background-size: 400px 100%;
    animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton-line  { height:14px; margin-bottom:8px; }
.skeleton-title { height:20px; width:60%; margin-bottom:12px; }
.skeleton-card  { height:100px; border-radius:var(--radius-md); }

/* ── Ripple Button Effect ── */
.btn-ripple { position:relative; overflow:hidden; }
.btn-ripple .ripple-wave {
    position:absolute; border-radius:50%;
    background: rgba(255,255,255,0.3);
    width:6px; height:6px;
    margin-left:-3px; margin-top:-3px;
    animation: ripple 0.6s linear forwards;
    pointer-events: none;
}

/* ── Magnetic Button (JS-driven, CSS sets transition) ── */
.btn-magnetic { transition: transform 0.2s cubic-bezier(0.23,1,0.32,1) !important; }

/* ── Dashboard Cards ── */
.stat-card, .case-card, .glass-card {
    transition: transform 0.25s cubic-bezier(0.23,1,0.32,1),
                box-shadow 0.25s ease,
                border-color 0.25s ease !important;
}
.stat-card:hover {
    transform: translateY(-4px) scale(1.012) !important;
    box-shadow: 0 12px 40px rgba(0,0,0,0.35), 0 0 0 1px rgba(108,99,255,0.15) !important;
}
.case-card:hover {
    transform: translateY(-3px) scale(1.008) !important;
    box-shadow: 0 10px 32px rgba(0,0,0,0.3), 0 0 0 1px rgba(108,99,255,0.2) !important;
}

/* ── Sidebar Navigation ── */
.sidebar-nav .nav-item {
    transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease !important;
}
.sidebar-nav .nav-item:hover {
    transform: translateX(3px) !important;
    background: rgba(108,99,255,0.08) !important;
}
.sidebar-nav .nav-item.active {
    animation: glowPulse 2.5s ease infinite;
}
.sidebar-nav .nav-item .nav-icon {
    transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1) !important;
}
.sidebar-nav .nav-item:hover .nav-icon { transform: scale(1.2) !important; }

/* ── Sidebar stagger on load ── */
.sidebar-nav .nav-item { opacity:0; animation: sidebarItemIn 0.4s cubic-bezier(0.16,1,0.3,1) both; }
.sidebar-nav .nav-item:nth-child(1)  { animation-delay: 80ms; }
.sidebar-nav .nav-item:nth-child(2)  { animation-delay: 130ms; }
.sidebar-nav .nav-item:nth-child(3)  { animation-delay: 180ms; }
.sidebar-nav .nav-item:nth-child(4)  { animation-delay: 230ms; }
.sidebar-nav .nav-item:nth-child(5)  { animation-delay: 280ms; }
.sidebar-nav .nav-item:nth-child(6)  { animation-delay: 330ms; }
.sidebar-nav .nav-item:nth-child(7)  { animation-delay: 380ms; }
.sidebar-nav .nav-item:nth-child(8)  { animation-delay: 430ms; }

/* ── Search Bar Focus Animation ── */
.search-container, .rag-search-bar {
    transition: box-shadow 0.25s ease, border-color 0.25s ease, transform 0.2s ease !important;
}
.search-container:focus-within, .rag-search-bar:focus-within {
    transform: scaleX(1.01) !important;
    box-shadow: 0 0 0 3px rgba(108,99,255,0.2), 0 4px 20px rgba(108,99,255,0.1) !important;
}

/* ── Tab Switching ── */
.tab-content { animation: fadeInUp 0.3s cubic-bezier(0.16,1,0.3,1) both; }
.tab-btn {
    transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease, transform 0.15s ease !important;
    position: relative; overflow: hidden;
}
.tab-btn:hover  { transform: translateY(-1px) !important; }
.tab-btn.active::after {
    content: ''; position: absolute; bottom: 0; left: 10%; right: 10%;
    height: 2px; background: var(--gradient-primary); border-radius: 1px;
    animation: fadeInUp 0.25s ease;
}

/* ── Diagnosis / Confidence Cards ── */
.diagnosis-card, .confidence-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease !important;
}
.diagnosis-card:hover { transform: translateX(4px) !important; }

/* Confidence bar fill on enter */
.confidence-bar-fill, .vc-bar, .rag-relevance-fill {
    animation: barFill 0.8s cubic-bezier(0.16,1,0.3,1) both;
}

/* ── AI Timeline Steps ── */
.workflow-step, .step-item, .agent-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease !important;
}
.workflow-step:hover, .step-item:hover { transform: translateX(3px) !important; }
.workflow-step.active-step {
    animation: glowPulse 1.8s ease infinite !important;
}

/* Agent card entrance */
.agent-card { animation: cardEntrance 0.5s cubic-bezier(0.16,1,0.3,1) both; }
.agent-card:nth-child(1) { animation-delay: 0ms; }
.agent-card:nth-child(2) { animation-delay: 80ms; }
.agent-card:nth-child(3) { animation-delay: 160ms; }
.agent-card:nth-child(4) { animation-delay: 240ms; }
.agent-card:nth-child(5) { animation-delay: 320ms; }

/* ── Vital Cards ── */
.vital-card {
    transition: transform 0.2s cubic-bezier(0.23,1,0.32,1),
                box-shadow 0.2s ease, border-color 0.3s ease !important;
}
.vital-card:hover { transform: translateY(-3px) scale(1.02) !important; }

/* ── RAG Knowledge Cards ── */
.rag-card { transition: transform 0.2s ease, box-shadow 0.25s ease, border-color 0.2s ease !important; }
.rag-card:hover { transform: translateY(-2px) !important; }

/* ── Modal Spring Animation ── */
.modal-dialog { animation: scaleInBounce 0.45s cubic-bezier(0.16,1,0.3,1) !important; }

/* ── Glowing Active States ── */
.nav-item.active,
.rag-pill.active,
.auth-role-btn.active {
    animation: glowPulse 2.5s ease infinite;
}

/* ── Button hover lift ── */
.btn:not(.btn-sm):not([disabled]) {
    transition: transform 0.18s cubic-bezier(0.23,1,0.32,1),
                box-shadow 0.18s ease, opacity 0.18s ease !important;
}
.btn:not(.btn-sm):not([disabled]):hover { transform: translateY(-2px) !important; }
.btn:not([disabled]):active { transform: scale(0.96) !important; }

/* ── Typing Cursor Blink ── */
.typing-cursor { animation: blink 0.8s step-end infinite; }

/* ── Activity Dot Ping ── */
.dot-ping {
    position: relative;
}
.dot-ping::after {
    content: ''; position: absolute; inset: 0;
    border-radius: 50%;
    background: inherit;
    animation: dotPing 1.4s cubic-bezier(0,0,0.2,1) infinite;
}

/* ── Number Stat Bounce (when value changes) ── */
.stat-bounce { animation: countBounce 0.35s cubic-bezier(0.16,1,0.3,1); }

/* ── Page entrance ── */
.page.active {
    animation: fadeInUp 0.42s cubic-bezier(0.16,1,0.3,1) !important;
}

/* ── Panel sections stagger ── */
.panel-section {
    animation: fadeInUp 0.4s cubic-bezier(0.16,1,0.3,1) both;
}
.panel-section:nth-child(1) { animation-delay: 0ms; }
.panel-section:nth-child(2) { animation-delay: 60ms; }
.panel-section:nth-child(3) { animation-delay: 120ms; }
.panel-section:nth-child(4) { animation-delay: 180ms; }
.panel-section:nth-child(5) { animation-delay: 240ms; }

/* ── Floating Action Button pulse ── */
.chat-fab, .fab-btn {
    animation: floatUp 3s ease-in-out infinite;
    transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s ease !important;
}
.chat-fab:hover, .fab-btn:hover {
    transform: scale(1.12) translateY(-4px) !important;
    animation-play-state: paused;
}

/* ── Logo spin on hover ── */
.brand-logo:hover svg,
.auth-brand-logo:hover svg { animation: spinSlow 1.2s linear; }

/* ── Input focus glow ── */
.input-wrapper:focus-within {
    animation: none;
    box-shadow: 0 0 0 3px rgba(108,99,255,0.18), 0 2px 12px rgba(108,99,255,0.12) !important;
    border-color: var(--accent-primary) !important;
}

/* ── Reduce motion for accessibility ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
