/* ========================================
   ADVANCED USER EXPERIENCE OPTIMIZATIONS
   ======================================== */

/* Enhanced Loading States */
@media (max-width: 768px) {
    /* Skeleton Loading */
    .skeleton {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: loading 1.5s infinite;
        border-radius: 4px;
    }
    
    @keyframes loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    .skeleton-text {
        height: 0.8rem;
        margin-bottom: 0.3rem;
    }
    
    .skeleton-text.large {
        height: 1.2rem;
    }
    
    .skeleton-text.small {
        height: 0.6rem;
        width: 60%;
    }
    
    .skeleton-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }
    
    .skeleton-card {
        height: 100px;
        border-radius: 8px;
    }
    
    /* Loading Spinners */
    .spinner {
        width: 20px;
        height: 20px;
        border: 2px solid #f3f3f3;
        border-top: 2px solid var(--primary-color);
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }
    
    .spinner-sm {
        width: 16px;
        height: 16px;
        border-width: 1.5px;
    }
    
    .spinner-lg {
        width: 32px;
        height: 32px;
        border-width: 3px;
    }
    
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    /* Progress Indicators */
    .progress-bar {
        height: 4px;
        background: #e0e0e0;
        border-radius: 2px;
        overflow: hidden;
    }
    
    .progress-bar-fill {
        height: 100%;
        background: var(--primary-color);
        border-radius: 2px;
        transition: width 0.3s ease;
    }
    
    .progress-circular {
        width: 40px;
        height: 40px;
        position: relative;
    }
    
    .progress-circular svg {
        transform: rotate(-90deg);
    }
    
    .progress-circular circle {
        fill: none;
        stroke-width: 3;
        stroke-linecap: round;
    }
    
    .progress-circular .background {
        stroke: #e0e0e0;
    }
    
    .progress-circular .progress {
        stroke: var(--primary-color);
        stroke-dasharray: 126;
        stroke-dashoffset: 126;
        transition: stroke-dashoffset 0.3s ease;
    }
}

/* Enhanced Feedback Systems */
@media (max-width: 768px) {
    /* Micro-interactions */
    .btn {
        position: relative;
        overflow: hidden;
    }
    
    .btn::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.3);
        transform: translate(-50%, -50%);
        transition: width 0.6s, height 0.6s;
    }
    
    .btn:active::after {
        width: 300px;
        height: 300px;
    }
    
    /* Hover States */
    .card {
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    
    .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    
    .btn {
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    
    .btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }
    
    /* Focus States */
    .btn:focus,
    .form-control:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
    
    /* Success/Error States */
    .btn.success {
        background: var(--success-color);
        border-color: var(--success-color);
    }
    
    .btn.error {
        background: var(--danger-color);
        border-color: var(--danger-color);
    }
    
    .btn.warning {
        background: var(--warning-color);
        border-color: var(--warning-color);
    }
    
    /* Shake Animation for Errors */
    @keyframes shake {
        0%, 100% { transform: translateX(0); }
        10%, 30%, 50%, 70%, 90% { transform: translateX(-2px); }
        20%, 40%, 60%, 80% { transform: translateX(2px); }
    }
    
    .shake {
        animation: shake 0.5s ease-in-out;
    }
    
    /* Pulse Animation */
    @keyframes pulse {
        0% { transform: scale(1); }
        50% { transform: scale(1.05); }
        100% { transform: scale(1); }
    }
    
    .pulse {
        animation: pulse 2s infinite;
    }
    
    /* Bounce Animation */
    @keyframes bounce {
        0%, 20%, 53%, 80%, 100% { transform: translateY(0); }
        40%, 43% { transform: translateY(-8px); }
        70% { transform: translateY(-4px); }
        90% { transform: translateY(-2px); }
    }
    
    .bounce {
        animation: bounce 1s ease-in-out;
    }
}

/* Enhanced Form UX */
@media (max-width: 768px) {
    /* Floating Labels */
    .form-group.floating-label {
        position: relative;
    }
    
    .form-group.floating-label label {
        position: absolute;
        top: 0.8rem;
        left: 0.8rem;
        background: white;
        padding: 0 0.3rem;
        font-size: 0.8rem;
        color: #666;
        transition: all 0.2s ease;
        pointer-events: none;
    }
    
    .form-group.floating-label .form-control:focus + label,
    .form-group.floating-label .form-control:not(:placeholder-shown) + label {
        top: -0.4rem;
        left: 0.5rem;
        font-size: 0.7rem;
        color: var(--primary-color);
    }
    
    /* Input Validation States */
    .form-control.valid {
        border-color: var(--success-color);
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%232ecc71' d='M10.5 3.5L4.5 9.5L1.5 6.5' stroke='%232ecc71' stroke-width='2' fill='none'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.5rem center;
        background-size: 1rem;
    }
    
    .form-control.invalid {
        border-color: var(--danger-color);
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23e74c3c' d='M6 0L0 6l6 6 6-6z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.5rem center;
        background-size: 1rem;
    }
    
    /* Helper Text */
    .form-helper {
        font-size: 0.7rem;
        color: #666;
        margin-top: 0.25rem;
    }
    
    .form-helper.error {
        color: var(--danger-color);
    }
    
    .form-helper.success {
        color: var(--success-color);
    }
    
    /* Password Strength Indicator */
    .password-strength {
        height: 4px;
        background: #e0e0e0;
        border-radius: 2px;
        margin-top: 0.5rem;
        overflow: hidden;
    }
    
    .password-strength-bar {
        height: 100%;
        transition: width 0.3s ease, background-color 0.3s ease;
    }
    
    .password-strength-bar.weak {
        width: 33%;
        background: var(--danger-color);
    }
    
    .password-strength-bar.medium {
        width: 66%;
        background: var(--warning-color);
    }
    
    .password-strength-bar.strong {
        width: 100%;
        background: var(--success-color);
    }
    
    /* Character Counter */
    .char-counter {
        font-size: 0.7rem;
        color: #666;
        text-align: right;
        margin-top: 0.25rem;
    }
    
    .char-counter.warning {
        color: var(--warning-color);
    }
    
    .char-counter.error {
        color: var(--danger-color);
    }
}

/* Enhanced Navigation UX */
@media (max-width: 768px) {
    /* Smooth Scroll */
    html {
        scroll-behavior: smooth;
    }
    
    /* Sticky Headers */
    .sticky-header {
        position: sticky;
        top: 0;
        z-index: 1000;
        background: white;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    /* Back to Top Button */
    .back-to-top {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 48px;
        height: 48px;
        background: var(--primary-color);
        color: white;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 1000;
    }
    
    .back-to-top.visible {
        opacity: 1;
        visibility: visible;
    }
    
    .back-to-top:hover {
        background: var(--primary-dark);
        transform: translateY(-2px);
    }
    
    /* Breadcrumb Navigation */
    .breadcrumb {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 0.8rem;
        padding: 0.5rem 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .breadcrumb-item {
        white-space: nowrap;
        color: #666;
        text-decoration: none;
    }
    
    .breadcrumb-item.active {
        color: var(--primary-color);
        font-weight: 500;
    }
    
    .breadcrumb-separator {
        color: #999;
        font-size: 0.7rem;
    }
    
    /* Progress Steps */
    .progress-steps {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        margin: 1rem 0;
    }
    
    .progress-step {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.25rem;
        z-index: 1;
    }
    
    .progress-step-circle {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: #e0e0e0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.7rem;
        font-weight: 600;
        color: #666;
        transition: all 0.3s ease;
    }
    
    .progress-step.active .progress-step-circle {
        background: var(--primary-color);
        color: white;
    }
    
    .progress-step.completed .progress-step-circle {
        background: var(--success-color);
        color: white;
    }
    
    .progress-step-label {
        font-size: 0.6rem;
        color: #666;
        text-align: center;
        max-width: 60px;
    }
    
    .progress-line {
        position: absolute;
        top: 12px;
        left: 12px;
        right: 12px;
        height: 2px;
        background: #e0e0e0;
        z-index: 0;
    }
    
    .progress-line-fill {
        height: 100%;
        background: var(--success-color);
        transition: width 0.3s ease;
    }
}

/* Enhanced Content UX */
@media (max-width: 768px) {
    /* Lazy Loading Images */
    img {
        loading: lazy;
        transition: opacity 0.3s ease;
    }
    
    img[data-src] {
        opacity: 0;
    }
    
    img.loaded {
        opacity: 1;
    }
    
    /* Image Placeholders */
    .img-placeholder {
        background: #f0f0f0;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #999;
        font-size: 0.8rem;
    }
    
    /* Expandable Content */
    .expandable {
        max-height: 100px;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .expandable.expanded {
        max-height: 1000px;
    }
    
    .expand-toggle {
        background: none;
        border: none;
        color: var(--primary-color);
        font-size: 0.8rem;
        cursor: pointer;
        padding: 0.5rem 0;
        display: flex;
        align-items: center;
        gap: 0.25rem;
    }
    
    .expand-toggle::after {
        content: "▼";
        transition: transform 0.3s ease;
    }
    
    .expand-toggle.expanded::after {
        transform: rotate(180deg);
    }
    
    /* Tooltips */
    .tooltip {
        position: relative;
        cursor: help;
    }
    
    .tooltip::before {
        content: attr(data-tooltip);
        position: absolute;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%);
        background: #333;
        color: white;
        padding: 0.3rem 0.6rem;
        border-radius: 4px;
        font-size: 0.7rem;
        white-space: nowrap;
        opacity: 0;
        visibility: hidden;
        transition: all 0.2s ease;
        z-index: 1000;
    }
    
    .tooltip:hover::before {
        opacity: 1;
        visibility: visible;
        transform: translateX(-50%) translateY(-4px);
    }
    
    /* Context Menus */
    .context-menu {
        position: fixed;
        background: white;
        border: 1px solid #e0e0e0;
        border-radius: 6px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        padding: 0.25rem 0;
        min-width: 150px;
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transform: scale(0.95);
        transition: all 0.2s ease;
    }
    
    .context-menu.visible {
        opacity: 1;
        visibility: visible;
        transform: scale(1);
    }
    
    .context-menu-item {
        display: block;
        padding: 0.5rem 0.8rem;
        color: #333;
        text-decoration: none;
        font-size: 0.8rem;
        transition: background-color 0.2s ease;
    }
    
    .context-menu-item:hover {
        background: #f5f5f5;
    }
    
    .context-menu-divider {
        height: 1px;
        background: #e0e0e0;
        margin: 0.25rem 0;
    }
}

/* Enhanced Accessibility UX */
@media (max-width: 768px) {
    /* Skip Links */
    .skip-link {
        position: absolute;
        top: -40px;
        left: 0;
        background: var(--primary-color);
        color: white;
        padding: 0.5rem 1rem;
        text-decoration: none;
        border-radius: 0 0 4px 0;
        z-index: 10000;
        transition: top 0.3s ease;
    }
    
    .skip-link:focus {
        top: 0;
    }
    
    /* Focus Indicators */
    *:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
    
    /* High Contrast Mode */
    @media (prefers-contrast: high) {
        .btn {
            border: 2px solid currentColor;
        }
        
        .card {
            border: 2px solid #333;
        }
        
        .form-control {
            border: 2px solid #333;
        }
    }
    
    /* Reduced Motion */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
        
        html {
            scroll-behavior: auto;
        }
    }
    
    /* Screen Reader Only */
    .sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
    
    /* Touch Targets */
    .touch-target {
        min-height: 44px;
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Enhanced Performance UX */
@media (max-width: 768px) {
    /* Optimized Animations */
    .gpu-accelerated {
        transform: translateZ(0);
        will-change: transform;
    }
    
    /* Optimized Scrolling */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Virtual Scrolling Placeholder */
    .virtual-scroll {
        height: 400px;
        overflow-y: auto;
        position: relative;
    }
    
    .virtual-scroll-item {
        position: absolute;
        width: 100%;
        min-height: 60px;
    }
    
    /* Infinite Loading */
    .infinite-loading {
        text-align: center;
        padding: 1rem;
        color: #666;
        font-size: 0.8rem;
    }
    
    .infinite-loading .spinner {
        margin: 0 auto 0.5rem;
    }
    
    /* Pull to Refresh */
    .pull-to-refresh {
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #666;
        font-size: 0.8rem;
        transition: transform 0.3s ease;
    }
    
    .pull-to-refresh.pulling {
        transform: translateY(-20px);
    }
    
    .pull-to-refresh.refreshing {
        transform: translateY(0);
    }
    
    /* Swipe Actions */
    .swipeable {
        position: relative;
        overflow: hidden;
    }
    
    .swipeable-content {
        transform: translateX(0);
        transition: transform 0.3s ease;
    }
    
    .swipeable-actions {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        display: flex;
        align-items: center;
    }
    
    .swipeable-actions .btn {
        height: 100%;
        border-radius: 0;
    }
}

/* Enhanced Error Handling UX */
@media (max-width: 768px) {
    /* Error Boundaries */
    .error-boundary {
        padding: 2rem 1rem;
        text-align: center;
        background: #fff5f5;
        border: 1px solid #feb2b2;
        border-radius: 8px;
        margin: 1rem 0;
    }
    
    .error-boundary h3 {
        color: var(--danger-color);
        margin-bottom: 0.5rem;
    }
    
    .error-boundary p {
        color: #666;
        margin-bottom: 1rem;
    }
    
    .error-boundary .btn {
        background: var(--danger-color);
        color: white;
    }
    
    /* Network Error States */
    .network-error {
        padding: 2rem 1rem;
        text-align: center;
        background: #fff3cd;
        border: 1px solid #ffeaa7;
        border-radius: 8px;
        margin: 1rem 0;
    }
    
    .network-error h3 {
        color: #856404;
        margin-bottom: 0.5rem;
    }
    
    .network-error p {
        color: #856404;
        margin-bottom: 1rem;
    }
    
    .network-error .btn {
        background: #ffc107;
        color: #212529;
    }
    
    /* Retry Mechanism */
    .retry-button {
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 0.5rem 1rem;
        border-radius: 4px;
        font-size: 0.8rem;
        cursor: pointer;
        transition: background-color 0.2s ease;
    }
    
    .retry-button:hover {
        background: var(--primary-dark);
    }
    
    .retry-button:disabled {
        background: #ccc;
        cursor: not-allowed;
    }
    
    .retry-countdown {
        font-size: 0.7rem;
        color: #666;
        margin-left: 0.5rem;
    }
}

/* Enhanced Onboarding UX */
@media (max-width: 768px) {
    /* Tour Overlay */
    .tour-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        z-index: 9999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .tour-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .tour-tooltip {
        position: absolute;
        background: white;
        border-radius: 8px;
        padding: 1rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        max-width: 280px;
        z-index: 10000;
    }
    
    .tour-tooltip h4 {
        margin-bottom: 0.5rem;
        color: #333;
    }
    
    .tour-tooltip p {
        margin-bottom: 1rem;
        color: #666;
        font-size: 0.8rem;
    }
    
    .tour-tooltip .tour-actions {
        display: flex;
        gap: 0.5rem;
        justify-content: flex-end;
    }
    
    .tour-tooltip .tour-actions .btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.6rem;
    }
    
    .tour-highlight {
        position: relative;
        z-index: 9998;
        box-shadow: 0 0 0 4px var(--primary-color);
        border-radius: 4px;
    }
    
    /* Welcome Messages */
    .welcome-banner {
        background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
        color: white;
        padding: 1rem;
        border-radius: 8px;
        margin: 1rem 0;
        text-align: center;
    }
    
    .welcome-banner h3 {
        margin-bottom: 0.5rem;
    }
    
    .welcome-banner p {
        margin-bottom: 1rem;
        opacity: 0.9;
    }
    
    .welcome-banner .btn {
        background: white;
        color: var(--primary-color);
        border: none;
    }
    
    /* Feature Highlights */
    .feature-highlight {
        background: #f0f9ff;
        border: 1px solid #bae6fd;
        border-radius: 8px;
        padding: 1rem;
        margin: 1rem 0;
    }
    
    .feature-highlight h4 {
        color: #0369a1;
        margin-bottom: 0.5rem;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    .feature-highlight p {
        color: #0c4a6e;
        font-size: 0.8rem;
    }
    
    .feature-highlight .btn {
        background: #0369a1;
        color: white;
        border: none;
        margin-top: 0.5rem;
    }
}
