/* ==========================================
   MOBILE UX ENHANCEMENTS
   Phase 2 M7: Mobile UX & Final Polish
   ========================================== */

/* ==========================================
   TOUCH TARGETS - WCAG 2.5.5 Target Size
   Minimum 44x44px for all interactive elements
   ========================================== */

/* Ensure all clickable elements meet touch target requirements */
@media (pointer: coarse) {
    /* Buttons */
    .mud-button,
    .mud-icon-button,
    .mud-fab,
    button {
        min-height: 44px;
        min-width: 44px;
    }

    /* Form inputs */
    .mud-input,
    .mud-select,
    .mud-autocomplete,
    input,
    select,
    textarea {
        min-height: 44px;
    }

    /* Navigation items */
    .mud-nav-link,
    .mud-list-item,
    .mud-menu-item {
        min-height: 48px;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    /* Chips and badges */
    .mud-chip {
        min-height: 36px;
    }

    /* Table rows */
    .mud-table-row {
        min-height: 48px;
    }

    /* Links with adequate spacing */
    a:not(.mud-button) {
        display: inline-block;
        padding: 8px 4px;
        margin: -8px -4px;
    }
}

/* ==========================================
   MICRO-INTERACTIONS & ANIMATIONS
   Subtle feedback for user actions
   ========================================== */

/* Button press feedback */
.mud-button:active:not(:disabled),
.mud-icon-button:active:not(:disabled),
.mud-fab:active:not(:disabled) {
    transform: scale(0.97);
    transition: transform 0.1s ease;
}

/* Card hover lift effect */
.mud-paper {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

@media (hover: hover) {
    .mud-paper:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    }
}

/* Ripple effect enhancement */
.mud-button .mud-ripple-container,
.mud-icon-button .mud-ripple-container {
    transition: opacity 0.3s ease;
}

/* Loading skeleton shimmer */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.skeleton-shimmer {
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.06) 25%,
        rgba(0, 0, 0, 0.12) 50%,
        rgba(0, 0, 0, 0.06) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* Smooth page transitions */
.page-enter {
    opacity: 0;
    transform: translateY(10px);
}

.page-enter-active {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ==========================================
   FOCUS STATES - Accessibility
   Clear visual focus indicators
   ========================================== */

/* Enhanced focus ring */
:focus-visible {
    outline: 3px solid rgba(0, 180, 216, 0.5);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Focus within for form groups */
.mud-input-control:focus-within {
    box-shadow: 0 0 0 3px rgba(0, 180, 216, 0.2);
    border-radius: 4px;
}

/* Skip focus ring for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* High contrast focus for dark backgrounds */
.mud-appbar :focus-visible,
.mud-drawer :focus-visible {
    outline-color: rgba(255, 255, 255, 0.8);
}

/* ==========================================
   MOBILE NAVIGATION ENHANCEMENTS
   ========================================== */

/* Swipe gesture hints */
.swipe-hint {
    position: relative;
    overflow: hidden;
}

.swipe-hint::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 8px;
    width: 4px;
    height: 40%;
    background: rgba(0, 180, 216, 0.3);
    border-radius: 2px;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.swipe-hint:hover::after {
    opacity: 1;
}

/* Pull-to-refresh indicator */
.ptr-indicator {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    transition: top 0.3s ease;
}

.ptr-indicator.active {
    top: 20px;
}

/* ==========================================
   SAFE AREA INSETS (iPhone X+)
   ========================================== */

/* Bottom navigation with safe area */
.bottom-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

/* App bar with safe area */
.mud-appbar {
    padding-top: env(safe-area-inset-top);
}

/* Content area safe margins */
@media (max-width: 767px) {
    .mud-main-content {
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
    }
}

/* ==========================================
   HAPTIC FEEDBACK VISUAL CUES
   Visual feedback to complement haptics
   ========================================== */

/* Success action */
@keyframes success-pulse {
    0% { box-shadow: 0 0 0 0 rgba(6, 214, 160, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(6, 214, 160, 0); }
    100% { box-shadow: 0 0 0 0 rgba(6, 214, 160, 0); }
}

.success-feedback {
    animation: success-pulse 0.6s ease;
}

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

.error-feedback {
    animation: error-shake 0.5s ease;
}

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

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* Momentum scrolling for touch */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Hide scrollbar on mobile but keep functionality */
@media (max-width: 767px) {
    .hide-scrollbar {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

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

/* ==========================================
   FORM OPTIMIZATIONS
   ========================================== */

/* Prevent zoom on input focus (iOS) */
@media (max-width: 767px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Better input padding for touch */
@media (pointer: coarse) {
    .mud-input-slot {
        padding: 12px 14px;
    }
}

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

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

/* Inline spinner */
.loading-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.loading-inline::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==========================================
   DARK MODE SUPPORT
   ========================================== */

@media (prefers-color-scheme: dark) {
    .loading-skeleton {
        background: linear-gradient(
            90deg,
            #2a2a2a 25%,
            #3a3a3a 50%,
            #2a2a2a 75%
        );
    }

    :focus-visible {
        outline-color: rgba(0, 180, 216, 0.7);
    }
}

/* ==========================================
   HIGH CONTRAST MODE
   ========================================== */

@media (prefers-contrast: high) {
    :focus-visible {
        outline: 3px solid currentColor;
        outline-offset: 3px;
    }

    .mud-button {
        border: 2px solid currentColor;
    }
}

/* ==========================================
   REDUCED MOTION
   ========================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .loading-skeleton {
        animation: none;
        background: #e0e0e0;
    }
}
