/**
 * UI/UX Enhancements - Subtle animations and micro-interactions
 * Performance-friendly, mobile-first approach
 */

/* ========================================
   1. CSS Variables & Base Transitions
   ======================================== */
:root {
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-smooth: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

/* 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;
    }
}

/* ========================================
   2. Page & Content Transitions
   ======================================== */
.content-area,
.main-content > * {
    animation: fadeSlideIn 0.3s ease-out;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Staggered animations for lists */
.stagger-fade > * {
    opacity: 0;
    animation: fadeSlideIn 0.4s ease-out forwards;
}

.stagger-fade > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-fade > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-fade > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-fade > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-fade > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-fade > *:nth-child(6) { animation-delay: 0.3s; }

/* ========================================
   3. Button & Link Interactions
   ======================================== */
.btn {
    transition: all var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shadow-sm);
}

/* Primary button pulse effect on focus */
.btn-primary:focus,
.btn-success:focus {
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
}

.btn-success:focus {
    box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.25);
}

/* Ripple effect for buttons */
.btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease, opacity 0.4s ease;
    opacity: 0;
}

.btn:active::after {
    width: 200px;
    height: 200px;
    opacity: 0;
}

/* Links with smooth underline animation */
a:not(.btn):not(.nav-link):not(.sidebar-link):not(.card):not(.list-group-item) {
    position: relative;
    transition: color var(--transition-fast);
}

/* ========================================
   4. Card Enhancements
   ======================================== */
.card {
    transition: all var(--transition-smooth);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.card.hover-lift:hover,
.card.hover-up:hover,
.hover-up:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.card.hover-scale:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
}

.card.hover-glow:hover {
    box-shadow: 0 0 20px rgba(13, 110, 253, 0.15);
}

/* Stat cards with icon animation */
.stat-card {
    transition: all var(--transition-smooth);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card:hover .stat-card-icon {
    transform: scale(1.1);
}

.stat-card-icon {
    transition: transform var(--transition-bounce);
}

/* ========================================
   5. Form Elements
   ======================================== */
.form-control,
.form-select {
    transition: border-color var(--transition-fast), 
                box-shadow var(--transition-fast),
                background-color var(--transition-fast);
}

.form-control:focus,
.form-select:focus {
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* Input group animations */
.input-group .form-control:focus {
    z-index: 3;
}

/* Floating labels enhancement */
.form-floating > label {
    transition: all var(--transition-smooth);
}

/* Checkbox and radio with subtle bounce */
.form-check-input {
    transition: all var(--transition-fast);
}

.form-check-input:checked {
    animation: checkBounce 0.3s ease;
}

@keyframes checkBounce {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ========================================
   6. Table Enhancements
   ======================================== */
.table tbody tr {
    transition: background-color var(--transition-fast);
}

.table-hover tbody tr:hover {
    background-color: rgba(13, 110, 253, 0.04);
}

.table tbody tr td {
    transition: all var(--transition-fast);
}

/* ========================================
   7. Navigation & Sidebar
   ======================================== */
.sidebar-link {
    transition: all var(--transition-smooth);
    position: relative;
}

.sidebar-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: var(--sidebar-active, #0d6efd);
    border-radius: 0 2px 2px 0;
    transition: height var(--transition-smooth);
}

.sidebar-link.active::before,
.sidebar-link:hover::before {
    height: 60%;
}

.sidebar-link:hover .bi {
    transform: scale(1.1);
}

.sidebar-link .bi {
    transition: transform var(--transition-bounce);
}

/* ========================================
   8. Badge & Alert Animations
   ======================================== */
.badge {
    transition: all var(--transition-fast);
}

.badge:hover {
    transform: scale(1.05);
}

/* Notification badge pulse */
.badge-pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Alert slide-in */
.alert {
    animation: alertSlide 0.3s ease-out;
}

@keyframes alertSlide {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   9. Modal Enhancements
   ======================================== */
.modal.fade .modal-dialog {
    transition: transform 0.25s ease-out, opacity 0.25s ease-out;
    transform: translateY(-20px) scale(0.95);
}

.modal.show .modal-dialog {
    transform: translateY(0) scale(1);
}

.modal-content {
    animation: modalPop 0.25s ease-out;
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ========================================
   10. Dropdown Enhancements
   ======================================== */
.dropdown-menu {
    animation: dropdownFade 0.2s ease-out;
    transform-origin: top center;
}

@keyframes dropdownFade {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.dropdown-item {
    transition: all var(--transition-fast);
}

.dropdown-item:hover {
    transform: translateX(4px);
}

/* ========================================
   11. List Group Enhancements
   ======================================== */
.list-group-item {
    transition: all var(--transition-fast);
}

.list-group-item:hover {
    background-color: rgba(13, 110, 253, 0.04);
}

.list-group-item-action:active {
    transform: scale(0.99);
}

/* ========================================
   12. Loading States
   ======================================== */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Spinner enhancement */
.spinner-border {
    animation: spinner-border 0.65s linear infinite;
}

/* Button loading state */
.btn.loading {
    pointer-events: none;
    opacity: 0.7;
}

.btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    margin-left: 8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spinner-border 0.65s linear infinite;
    display: inline-block;
    vertical-align: middle;
}

/* ========================================
   13. Tooltip Enhancements
   ======================================== */
.tooltip {
    animation: tooltipFade 0.15s ease-out;
}

@keyframes tooltipFade {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ========================================
   14. Progress Bar Animations
   ======================================== */
.progress-bar {
    transition: width 0.6s ease;
}

.progress-bar-animated {
    animation: progress-bar-stripes 1s linear infinite;
}

/* ========================================
   15. Toast Notifications
   ======================================== */
.toast {
    animation: toastSlide 0.3s ease-out;
}

@keyframes toastSlide {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   16. Image Enhancements
   ======================================== */
.img-hover-zoom {
    overflow: hidden;
}

.img-hover-zoom img {
    transition: transform 0.4s ease;
}

.img-hover-zoom:hover img {
    transform: scale(1.05);
}

/* Lazy loaded images */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded,
img[loading="lazy"]:not([data-src]) {
    opacity: 1;
}

/* ========================================
   17. Scroll Enhancements
   ======================================== */
html {
    scroll-behavior: smooth;
}

/* Scrollbar styling (webkit) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* ========================================
   18. Mobile Touch Feedback
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    .btn:active,
    .card:active,
    .list-group-item:active {
        opacity: 0.8;
    }
    
    /* Disable hover effects on touch devices */
    .card.hover-lift:hover,
    .card.hover-up:hover,
    .hover-up:hover {
        transform: none;
    }
    
    /* Touch-friendly tap targets */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Active state for touch */
    .btn:active {
        transform: scale(0.96);
    }
}

/* Touch device swipe hint animation */
.swipe-hint {
    animation: swipeHint 2s ease-in-out infinite;
}

@keyframes swipeHint {
    0%, 100% { transform: translateX(0); opacity: 1; }
    50% { transform: translateX(-10px); opacity: 0.5; }
}

/* ========================================
   19. Focus States (Accessibility)
   ======================================== */
:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
}

/* ========================================
   20. Utility Animation Classes
   ======================================== */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slide-down {
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.scale-in {
    animation: scaleIn 0.2s ease-out;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Bounce animation for attention */
.bounce {
    animation: bounce 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Shake animation for errors */
.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* ========================================
   21. Breadcrumb Enhancements
   ======================================== */
.breadcrumb-item + .breadcrumb-item::before {
    transition: transform var(--transition-fast);
}

.breadcrumb-item a {
    transition: color var(--transition-fast);
}

.breadcrumb-item a:hover {
    color: var(--primary-color, #0d6efd);
}

/* ========================================
   22. Accordion Enhancements
   ======================================== */
.accordion-button {
    transition: all var(--transition-smooth);
}

.accordion-button:not(.collapsed) {
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.125);
}

.accordion-button::after {
    transition: transform 0.25s ease;
}

.accordion-collapse {
    transition: height 0.3s ease;
}

/* ========================================
   23. Mobile-First Utilities
   ======================================== */

/* Mobile-optimized touch targets */
.touch-target {
    min-width: 44px;
    min-height: 44px;
}

/* Mobile card improvements */
@media (max-width: 767.98px) {
    .card {
        border-radius: 0.5rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-header,
    .card-footer {
        padding: 0.75rem 1rem;
    }
    
    /* Stack buttons on mobile */
    .btn-group-mobile {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group-mobile .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .btn-group-mobile .btn:last-child {
        margin-bottom: 0;
    }
    
    /* Mobile table improvements */
    .table-mobile td,
    .table-mobile th {
        padding: 0.625rem 0.5rem;
        font-size: 0.875rem;
    }
    
    /* Hide columns on mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Full width on mobile */
    .full-mobile {
        width: 100% !important;
    }
    
    /* Mobile spacing adjustments */
    .mb-mobile-3 {
        margin-bottom: 1rem !important;
    }
    
    .py-mobile-2 {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }
    
    /* Mobile text sizes */
    .fs-mobile-sm {
        font-size: 0.875rem !important;
    }
    
    .fs-mobile-xs {
        font-size: 0.75rem !important;
    }
    
    /* Mobile form improvements */
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    .input-group .form-control,
    .input-group .form-select,
    .input-group .btn {
        min-height: 44px;
    }
    
    /* Modal adjustments for mobile */
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-content {
        border-radius: 0.75rem;
    }
    
    /* Bottom sheet modal for mobile */
    .modal-bottom-sheet .modal-dialog {
        margin: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        transform: translateY(100%);
        max-width: 100%;
    }
    
    .modal-bottom-sheet.show .modal-dialog {
        transform: translateY(0);
    }
    
    .modal-bottom-sheet .modal-content {
        border-radius: 1rem 1rem 0 0;
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* Tablet improvements */
@media (min-width: 768px) and (max-width: 991.98px) {
    .card-body {
        padding: 1.125rem;
    }
    
    /* Show on tablet only */
    .show-tablet {
        display: block !important;
    }
}

/* Desktop improvements */
@media (min-width: 992px) {
    /* Show only on desktop */
    .show-desktop {
        display: block !important;
    }
    
    .hide-desktop {
        display: none !important;
    }
}

/* Horizontal scrollable container for mobile */
.scroll-x-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.scroll-x-mobile::-webkit-scrollbar {
    display: none;
}

/* Mobile-friendly stat cards */
@media (max-width: 575.98px) {
    .stat-card {
        padding: 0.875rem;
    }
    
    .stat-card-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    .stat-card h3,
    .stat-card .h3 {
        font-size: 1.25rem;
    }
    
    .stat-card small,
    .stat-card .small {
        font-size: 0.75rem;
    }
}

/* Pull to refresh indicator styling */
.ptr-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    color: #6c757d;
}

.ptr-indicator .spinner-border {
    width: 1.5rem;
    height: 1.5rem;
}

/* Safe area padding for notched devices */
.safe-area-padding {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
}

/* ========================================
   24. Empty States
   ======================================== */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #6c757d;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #495057;
}

.empty-state-text {
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 575.98px) {
    .empty-state {
        padding: 2rem 1rem;
    }
    
    .empty-state-icon {
        font-size: 2.5rem;
    }
    
    .empty-state-title {
        font-size: 1rem;
    }
}
