/* Mobile Excellence - Mobile-First Responsive CSS */
/* Optimized for touch interactions and mobile performance */

/* Root Variables for Mobile */
:root {
    /* Touch target sizes */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    --touch-target-large: 56px;
    
    /* Mobile-optimized spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    
    /* Thumb-zone optimized margins */
    --thumb-reach-top: 60px;
    --thumb-reach-bottom: 80px;
    --thumb-reach-side: 20px;
    
    /* Animation durations */
    --animation-fast: 150ms;
    --animation-normal: 300ms;
    --animation-slow: 500ms;
    
    /* Safe area insets for modern devices */
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-right: env(safe-area-inset-right);
    --safe-area-bottom: env(safe-area-inset-bottom);
    --safe-area-left: env(safe-area-inset-left);
}

/* Base Mobile Styles */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

html {
    /* Prevent zoom on input focus */
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    /* Optimize for mobile viewport */
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* Mobile-First Typography */
body {
    font-size: 16px;
    line-height: 1.5;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
}

/* Touch-Optimized Buttons */
.btn, 
button,
[role="button"] {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    padding: 12px 20px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    overflow: hidden;
}

/* Ripple Effect for Touch Feedback */
.ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripple-animation 600ms ease-out;
    background-color: rgba(255, 255, 255, 0.3);
}

@keyframes ripple-animation {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Pull-to-Refresh Indicator */
#pull-to-refresh-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-50px) scale(0.5);
    z-index: 9999;
    background: white;
    border-radius: 50%;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    pointer-events: none;
}

#pull-to-refresh-indicator .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #ddd;
    border-top-color: var(--bs-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 8px;
}

#pull-to-refresh-indicator .spinner.active {
    animation-duration: 0.5s;
}

#pull-to-refresh-indicator .text {
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
}

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

body.pulling-to-refresh {
    overflow-y: hidden;
}

/* Mobile Context Menu */
.mobile-context-menu {
    position: fixed;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 8px 0;
    min-width: 200px;
    z-index: 10000;
    animation: context-menu-appear 200ms ease-out;
}

@keyframes context-menu-appear {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.mobile-context-menu .menu-item {
    padding: 12px 20px;
    cursor: pointer;
    transition: background-color 150ms ease;
    font-size: 16px;
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
}

.mobile-context-menu .menu-item:active {
    background-color: #f0f0f0;
}

/* Swipeable Elements */
[data-swipeable] {
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.swipe-action-left,
.swipe-action-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.swipe-action-left {
    left: 0;
    background-color: #dc3545;
}

.swipe-action-right {
    right: 0;
    background-color: #28a745;
}

/* Touch-Optimized Forms */
input,
textarea,
select {
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: var(--touch-target-min);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #ddd;
    width: 100%;
    -webkit-appearance: none;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.1);
}

/* Thumb-Zone Optimization */
.bottom-navigation {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    padding-bottom: var(--safe-area-bottom);
    z-index: 1000;
}

.bottom-navigation .nav-item {
    flex: 1;
    text-align: center;
    padding: 12px 0;
    min-height: var(--touch-target-comfortable);
}

/* One-Handed Mode */
body.one-handed-mode {
    padding-top: 60px;
}

body.one-handed-mode .dashboard-content {
    max-width: 90%;
    margin: 0 auto;
    transform: scale(0.9);
    transform-origin: top center;
}

body.one-handed-mode.one-handed-left .fab-container {
    left: var(--thumb-reach-side);
    right: auto;
}

body.one-handed-mode.one-handed-right .fab-container {
    right: var(--thumb-reach-side);
    left: auto;
}

/* Mobile-Optimized Cards */
.card {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    margin-bottom: var(--space-md);
    contain: layout style paint;
    will-change: transform;
}

.card.touch-active {
    transform: scale(0.98);
    transition: transform 150ms ease;
}

/* Virtual Scrolling Container */
[data-virtual-scroll] {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

[data-virtual-scroll] > * {
    position: absolute;
    width: 100%;
}

/* Lazy Loading States */
img[data-src] {
    opacity: 0;
    transition: opacity 300ms ease;
}

img.loading {
    filter: blur(5px);
}

img.loaded {
    opacity: 1;
    filter: none;
}

/* Mobile Performance Classes */
body.reduce-motion * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

body.simple-animations * {
    animation-timing-function: linear !important;
    transition-timing-function: linear !important;
}

/* Gesture Hints Overlay */
#gesture-hints-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fade-in 300ms ease;
}

.gesture-hints-container {
    background: white;
    border-radius: 16px;
    padding: 24px;
    max-width: 90%;
    text-align: center;
}

.hint-item {
    display: flex;
    align-items: center;
    margin: 16px 0;
    font-size: 16px;
}

.gesture-icon {
    width: 48px;
    height: 48px;
    margin-right: 16px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

/* Mobile-First Media Queries */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
    .container {
        padding-left: var(--space-lg);
        padding-right: var(--space-lg);
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
    :root {
        --touch-target-min: 40px;
        --touch-target-comfortable: 44px;
    }
    
    body {
        font-size: 18px;
    }
    
    .bottom-navigation {
        display: none;
    }
    
    body.one-handed-mode .dashboard-content {
        transform: none;
        max-width: 100%;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    [data-swipeable] {
        transition: none;
    }
    
    .mobile-context-menu {
        display: none;
    }
}

/* Offline Mode Styles */
body.offline::before {
    content: "You're offline";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff9800;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 14px;
    z-index: 9999;
}

/* Loading States */
body.loading::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

/* Focus Visible for Keyboard Navigation */
*:focus-visible {
    outline: 3px solid var(--bs-primary);
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .card {
        border: 2px solid currentColor;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) and (prefers-color-scheme: light) {
    :root {
        --bg-primary: #121212;
        --bg-secondary: #1e1e1e;
        --text-primary: #ffffff;
        --text-secondary: #aaaaaa;
    }
    
    body {
        background-color: var(--bg-primary);
        color: var(--text-primary);
    }
    
    .card {
        background-color: var(--bg-secondary);
        border-color: #333;
    }
}

/* Utility Classes */
.touch-none { touch-action: none; }
.touch-pan-x { touch-action: pan-x; }
.touch-pan-y { touch-action: pan-y; }
.user-select-none { user-select: none; -webkit-user-select: none; }
.will-change-transform { will-change: transform; }
.contain-layout { contain: layout; }
.contain-paint { contain: paint; }
.contain-strict { contain: strict; }