/**
 * Q-MAK Utilities & Animation Library
 * Comprehensive reusable components for enhanced UI/UX
 * Phase 1: Critical UX Improvements
 */

/* ========== GLOBAL RESETS & BASE STYLES ========== */
* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family-base);
    line-height: var(--line-height-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== KEYFRAME ANIMATIONS ========== */

/* Fade Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

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

/* Scale Animations */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

/* Slide Animations */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideDown {
    from {
        max-height: 0;
        opacity: 0;
    }
    to {
        max-height: 500px;
        opacity: 1;
    }
}

/* Loading & Skeleton Animations */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
        animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
    }
    50% {
        transform: translateY(-25%);
        animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
    }
}

/* Progress Animations */
@keyframes progressIndeterminate {
    0% {
        left: -35%;
        right: 100%;
    }
    60% {
        left: 100%;
        right: -90%;
    }
    100% {
        left: 100%;
        right: -90%;
    }
}

/* Success Checkmark Animation */
@keyframes checkmark {
    0% {
        stroke-dashoffset: 100;
    }
    100% {
        stroke-dashoffset: 0;
    }
}

/* Confetti Animation */
@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Shake Animation (for errors) */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

/* Ripple Effect */
@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* ========== LOADING STATES ========== */

/* Spinner Loader */
.loader-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--accent-600);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loader-spinner--sm {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.loader-spinner--lg {
    width: 60px;
    height: 60px;
    border-width: 6px;
}

/* Dots Loader */
.loader-dots {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.loader-dots__dot {
    width: 12px;
    height: 12px;
    background-color: var(--accent-600);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loader-dots__dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loader-dots__dot:nth-child(2) {
    animation-delay: -0.16s;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 4px;
    background-color: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
}

.progress-bar__fill {
    height: 100%;
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

.progress-bar--indeterminate .progress-bar__fill {
    position: absolute;
    animation: progressIndeterminate 1.5s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
}

/* ========== SKELETON SCREENS ========== */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--gray-100) 0%,
        var(--gray-200) 20%,
        var(--gray-100) 40%,
        var(--gray-100) 100%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s linear infinite;
    border-radius: var(--radius-md);
}

.skeleton--text {
    height: 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-sm);
}

.skeleton--title {
    height: 2rem;
    width: 60%;
    margin-bottom: 1rem;
}

.skeleton--avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton--card {
    height: 200px;
    border-radius: var(--radius-lg);
}

/* ========== UTILITY CLASSES ========== */

/* Animation Classes */
.animate-fadeIn {
    animation: fadeIn var(--duration-normal) var(--ease-out);
}

.animate-fadeInUp {
    animation: fadeInUp var(--duration-normal) var(--ease-out);
}

.animate-fadeInDown {
    animation: fadeInDown var(--duration-normal) var(--ease-out);
}

.animate-scaleIn {
    animation: scaleIn var(--duration-normal) var(--ease-out);
}

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.animate-spin {
    animation: spin 1s linear infinite;
}

.animate-bounce {
    animation: bounce 1s infinite;
}

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

/* Hover Effects */
.hover-lift {
    transition: transform var(--duration-normal) var(--ease-out);
}

.hover-lift:hover {
    transform: translateY(-4px);
}

.hover-scale {
    transition: transform var(--duration-fast) var(--ease-out);
}

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

.hover-glow {
    transition: box-shadow var(--duration-normal) var(--ease-out);
}

.hover-glow:hover {
    box-shadow: var(--shadow-accent);
}

/* Glassmorphism */
.glass {
    background: var(--glass-light);
    backdrop-filter: blur(var(--blur-md));
    -webkit-backdrop-filter: blur(var(--blur-md));
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.glass-dark {
    background: var(--glass-dark);
    backdrop-filter: blur(var(--blur-md));
    -webkit-backdrop-filter: blur(var(--blur-md));
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Gradient Backgrounds */
.bg-gradient-primary {
    background: var(--gradient-primary);
}

.bg-gradient-accent {
    background: var(--gradient-accent);
}

.bg-gradient-success {
    background: var(--gradient-success);
}

.bg-gradient-warning {
    background: var(--gradient-warning);
}

.bg-gradient-danger {
    background: var(--gradient-danger);
}

/* Gradient Text */
.text-gradient {
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: var(--font-weight-bold);
}

/* Focus Styles for Accessibility */
.focus-ring:focus {
    outline: 3px solid rgba(37, 99, 235, 0.5);
    outline-offset: 2px;
}

.focus-ring-inset:focus {
    outline: 3px solid rgba(37, 99, 235, 0.5);
    outline-offset: -2px;
}

/* ========== BADGE COMPONENTS ========== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
    line-height: 1;
}

.badge--primary {
    background-color: var(--accent-100, #dbeafe);
    color: var(--accent-700);
}

.badge--success {
    background-color: #dcfce7;
    color: var(--success-700);
}

.badge--warning {
    background-color: #fed7aa;
    color: var(--warning-700);
}

.badge--danger {
    background-color: #fee2e2;
    color: var(--danger-700);
}

.badge--info {
    background-color: #cffafe;
    color: var(--info-600);
}

.badge--pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ========== TOAST NOTIFICATIONS ========== */

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    min-width: 300px;
    max-width: 500px;
    padding: 1rem 1.5rem;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-notification);
    animation: slideInRight 0.3s var(--ease-out);
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: 4px solid;
}

.toast--success {
    border-left-color: var(--success-600);
}

.toast--error {
    border-left-color: var(--danger-600);
}

.toast--warning {
    border-left-color: var(--warning-600);
}

.toast--info {
    border-left-color: var(--info-600);
}

.toast--exit {
    animation: slideInRight 0.3s var(--ease-out) reverse;
}

/* ========== MODAL ENHANCEMENTS ========== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: var(--z-modal-backdrop);
    animation: fadeIn 0.2s var(--ease-out);
}

.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    z-index: var(--z-modal);
    max-height: 90vh;
    overflow-y: auto;
    animation: scaleIn 0.3s var(--ease-out);
}

/* ========== EMPTY STATES ========== */

.empty-state {
    text-align: center;
    padding: var(--spacing-12) var(--spacing-6);
    color: var(--primary-500);
}

.empty-state__icon {
    font-size: 4rem;
    color: var(--gray-300);
    margin-bottom: var(--spacing-4);
}

.empty-state__title {
    font-size: var(--text-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--primary-700);
    margin-bottom: var(--spacing-2);
}

.empty-state__description {
    font-size: var(--text-sm);
    color: var(--primary-500);
    margin-bottom: var(--spacing-6);
}

/* ========== CARD ENHANCEMENTS ========== */

.card-enhanced {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    padding: var(--spacing-6);
    transition: all var(--duration-normal) var(--ease-out);
    border: 1px solid var(--gray-200);
}

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

.card-enhanced--interactive {
    cursor: pointer;
}

.card-enhanced--interactive:active {
    transform: translateY(0);
}

/* ========== BUTTON ENHANCEMENTS ========== */

.btn-enhanced {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

.btn-enhanced::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.btn-enhanced:hover::before {
    transform: translateX(0);
}

/* Ripple effect container */
.btn-ripple {
    position: relative;
    overflow: hidden;
}

.ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: scale(0);
    animation: ripple 0.6s ease-out;
    pointer-events: none;
}

/* ========== ACCESSIBILITY UTILITIES ========== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent-600);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: var(--z-max);
}

.skip-link:focus {
    top: 0;
}

/* ========== RESPONSIVE UTILITIES ========== */

@media (max-width: 768px) {
    .touch-target {
        min-height: var(--touch-target-comfortable);
        min-width: var(--touch-target-comfortable);
    }
    
    .toast {
        top: auto;
        bottom: 80px;
        right: 20px;
        left: 20px;
        min-width: auto;
    }
}

/* ========== STATUS INDICATORS ========== */

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot--online {
    background-color: var(--success-500);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.status-dot--offline {
    background-color: var(--gray-400);
}

.status-dot--busy {
    background-color: var(--danger-500);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.status-dot--pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* ========== DIVIDERS ========== */

.divider {
    height: 1px;
    background: var(--gray-200);
    margin: var(--spacing-6) 0;
}

.divider--gradient {
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--gray-300) 50%,
        transparent 100%
    );
}

/* ========== SCROLL BEHAVIOR ========== */

.scroll-smooth {
    scroll-behavior: smooth;
}

.scrollbar-hidden {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hidden::-webkit-scrollbar {
    display: none;
}

/* Custom Scrollbar */
.scrollbar-custom::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.scrollbar-custom::-webkit-scrollbar-track {
    background: var(--gray-50);
    border-radius: var(--radius-lg);
}

.scrollbar-custom::-webkit-scrollbar-thumb {
    background: var(--gradient-accent);
    border-radius: var(--radius-lg);
    border: 2px solid var(--gray-50);
}

.scrollbar-custom::-webkit-scrollbar-thumb:hover {
    background: var(--accent-700);
}

/* ========== PRINT STYLES ========== */

@media print {
    .no-print {
        display: none !important;
    }
}
