/**
 * ============================================
 * MSHUB MOBILE APP OPTIMIZATION CSS
 * ============================================
 * Optimizări complete pentru experiență de aplicație mobilă
 * Suport pentru toate device-urile: 320px - 2560px+
 * Touch gestures, PWA support, responsive design
 */

/* ========================================
   1. ROOT VARIABLES & BASE STYLES
   ======================================== */
:root {
    /* Touch targets - minimum 44px pentru Apple HIG */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    
    /* Spacing mobile-optimized */
    --mobile-spacing-xs: 8px;
    --mobile-spacing-sm: 12px;
    --mobile-spacing-md: 16px;
    --mobile-spacing-lg: 24px;
    --mobile-spacing-xl: 32px;
    
    /* Font sizes responsive */
    --mobile-font-xs: 12px;
    --mobile-font-sm: 14px;
    --mobile-font-base: 16px;
    --mobile-font-lg: 18px;
    --mobile-font-xl: 20px;
    --mobile-font-2xl: 24px;
    
    /* Z-index layers */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
}

/* ========================================
   2. TOUCH OPTIMIZATION
   ======================================== */

/* Remove tap highlight color */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Smooth scrolling for all devices */
html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Touch-friendly buttons and links */
button,
a,
.btn,
.clickable,
[role="button"] {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    touch-action: manipulation;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

/* Active state feedback for touch */
button:active,
a:active,
.btn:active,
.clickable:active {
    opacity: 0.7;
    transform: scale(0.98);
    transition: all 0.1s ease;
}

/* ========================================
   3. MOBILE VIEWPORT OPTIMIZATION
   ======================================== */

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .navbar,
    .sidebar,
    .footer {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    
    .modal-content {
        margin-left: max(0px, env(safe-area-inset-left));
        margin-right: max(0px, env(safe-area-inset-right));
    }
}

/* Fix for iOS address bar resizing */
.mobile-vh-fix {
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* ========================================
   4. RESPONSIVE BREAKPOINTS
   ======================================== */

/* Extra small devices (phones, less than 576px) */
@media (max-width: 575.98px) {
    body {
        font-size: var(--mobile-font-base);
    }
    
    .container,
    .container-fluid {
        padding-left: var(--mobile-spacing-md);
        padding-right: var(--mobile-spacing-md);
    }
    
    h1 { font-size: 24px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }
    h5 { font-size: 14px !important; }
    h6 { font-size: 12px !important; }
    
    /* Stack cards vertically */
    .row > [class*='col-'] {
        margin-bottom: var(--mobile-spacing-md);
    }
}

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .container {
        max-width: 540px;
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) {
    .container {
        max-width: 720px;
    }
}

/* ========================================
   5. TOUCH GESTURES & INTERACTIONS
   ======================================== */

/* Swipeable elements */
.swipeable {
    touch-action: pan-y;
    cursor: grab;
}

.swipeable:active {
    cursor: grabbing;
}

/* Pull to refresh indicator */
.ptr-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    transition: transform 0.3s ease;
    z-index: var(--z-fixed);
}

.ptr-indicator.visible {
    transform: translateX(-50%) translateY(0);
}

/* Horizontal scroll containers */
.scroll-x {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}

.scroll-x::-webkit-scrollbar {
    display: none;
}

.scroll-x > * {
    scroll-snap-align: start;
}

/* ========================================
   6. MOBILE MODALS OPTIMIZATION
   ======================================== */

@media (max-width: 767.98px) {
    /* Full-screen modals on mobile */
    .modal-fullscreen-mobile {
        max-width: 100%;
        margin: 0;
        height: 100%;
        border-radius: 0 !important;
    }
    
    .modal-fullscreen-mobile .modal-content {
        height: 100%;
        border-radius: 0 !important;
        border: none;
    }
    
    /* Bottom sheet style modals */
    .modal-bottom-sheet {
        margin: auto 0 0 0;
        max-height: 90vh;
    }
    
    .modal-bottom-sheet .modal-content {
        border-radius: 20px 20px 0 0 !important;
    }
    
    /* Modal headers mobile */
    .modal-header {
        padding: var(--mobile-spacing-md);
    }
    
    .modal-body {
        padding: var(--mobile-spacing-md);
    }
    
    .modal-footer {
        padding: var(--mobile-spacing-md);
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: var(--mobile-spacing-xs) 0;
    }
}

/* ========================================
   7. MOBILE FORMS OPTIMIZATION
   ======================================== */

@media (max-width: 767.98px) {
    /* Touch-friendly form controls */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    textarea,
    select {
        min-height: var(--touch-target-comfortable);
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 12px 16px;
    }
    
    /* Labels */
    .form-label {
        font-size: var(--mobile-font-sm);
        margin-bottom: var(--mobile-spacing-xs);
    }
    
    /* Form groups spacing */
    .form-group,
    .mb-3 {
        margin-bottom: var(--mobile-spacing-md) !important;
    }
    
    /* Checkboxes and radios */
    .form-check-input {
        width: 24px;
        height: 24px;
        margin-top: 0;
    }
    
    .form-check-label {
        padding-left: var(--mobile-spacing-xs);
        line-height: 24px;
    }
}

/* ========================================
   8. MOBILE TABLES OPTIMIZATION
   ======================================== */

@media (max-width: 767.98px) {
    /* Responsive table wrapper */
    .table-responsive-mobile {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: var(--mobile-spacing-md);
    }
    
    /* Card-style tables for mobile */
    .table-mobile-cards {
        border: none;
    }
    
    .table-mobile-cards thead {
        display: none;
    }
    
    .table-mobile-cards tbody tr {
        display: block;
        margin-bottom: var(--mobile-spacing-md);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 12px;
        padding: var(--mobile-spacing-md);
        background: rgba(255, 255, 255, 0.05);
    }
    
    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        padding: var(--mobile-spacing-xs) 0;
        border: none;
    }
    
    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: var(--mobile-spacing-md);
    }
}

/* ========================================
   9. MOBILE NAVIGATION OPTIMIZATION
   ======================================== */

@media (max-width: 991.98px) {
    /* Mobile sidebar */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        transition: left 0.3s ease;
        z-index: var(--z-fixed);
    }
    
    .sidebar.active {
        left: 0;
    }
    
    /* Mobile navigation overlay */
    .mobile-nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: calc(var(--z-fixed) - 1);
    }
    
    .mobile-nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    /* Bottom navigation bar */
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: rgba(0, 0, 0, 0.95);
        backdrop-filter: blur(20px);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: var(--z-sticky);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        height: 100%;
        color: rgba(255, 255, 255, 0.6);
        text-decoration: none;
        transition: color 0.2s ease;
    }
    
    .bottom-nav-item:active {
        background: rgba(255, 255, 255, 0.05);
    }
    
    .bottom-nav-item.active {
        color: #ff6b23;
    }
    
    .bottom-nav-item i {
        font-size: 20px;
        margin-bottom: 4px;
    }
    
    .bottom-nav-item span {
        font-size: 11px;
    }
}

/* ========================================
   10. MOBILE CARDS & CONTENT
   ======================================== */

@media (max-width: 767.98px) {
    /* Glass cards mobile */
    .glass-container,
    .card {
        margin-bottom: var(--mobile-spacing-md);
        border-radius: 16px;
    }
    
    .card-body {
        padding: var(--mobile-spacing-md);
    }
    
    /* Grid layouts */
    .row {
        margin-left: calc(-1 * var(--mobile-spacing-xs));
        margin-right: calc(-1 * var(--mobile-spacing-xs));
    }
    
    .row > [class*='col-'] {
        padding-left: var(--mobile-spacing-xs);
        padding-right: var(--mobile-spacing-xs);
    }
}

/* ========================================
   11. MOBILE BUTTONS & ACTIONS
   ======================================== */

@media (max-width: 767.98px) {
    /* Full-width buttons */
    .btn-mobile-full {
        width: 100%;
        margin-bottom: var(--mobile-spacing-xs);
    }
    
    /* Button groups */
    .btn-group {
        display: flex;
        flex-direction: column;
    }
    
    .btn-group .btn {
        margin-bottom: var(--mobile-spacing-xs);
        border-radius: 12px !important;
    }
    
    /* Floating action button */
    .fab {
        position: fixed;
        bottom: 80px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, #ff6b23 0%, #ff8c42 100%);
        box-shadow: 0 4px 20px rgba(255, 107, 35, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        font-size: 24px;
        z-index: var(--z-sticky);
        transition: all 0.3s ease;
    }
    
    .fab:active {
        transform: scale(0.9);
    }
}

/* ========================================
   12. LANDSCAPE ORIENTATION
   ======================================== */

@media (max-width: 767.98px) and (orientation: landscape) {
    /* Optimize for landscape mode */
    .modal-dialog {
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .navbar,
    .bottom-nav {
        height: 48px;
    }
    
    /* Reduce vertical spacing in landscape */
    .container,
    .container-fluid {
        padding-top: var(--mobile-spacing-sm);
        padding-bottom: var(--mobile-spacing-sm);
    }
}

/* ========================================
   13. IMAGES & MEDIA MOBILE
   ======================================== */

@media (max-width: 767.98px) {
    /* Responsive images */
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Lazy loading optimization */
    img[loading="lazy"] {
        background: rgba(255, 255, 255, 0.05);
    }
    
    /* Video responsive */
    video {
        max-width: 100%;
        height: auto;
    }
    
    /* Image galleries */
    .image-gallery {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: var(--mobile-spacing-xs);
    }
}

/* ========================================
   14. MOBILE NOTIFICATIONS & TOASTS
   ======================================== */

@media (max-width: 767.98px) {
    .toast,
    .alert {
        border-radius: 12px;
        margin: var(--mobile-spacing-md);
    }
    
    /* Toast container */
    .toast-container {
        position: fixed;
        top: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 40px);
        max-width: 400px;
        z-index: var(--z-tooltip);
    }
}

/* ========================================
   15. PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* GPU acceleration for animations */
.animated,
.transition,
.modal,
.sidebar,
.dropdown-menu {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* 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;
        scroll-behavior: auto !important;
    }
}

/* ========================================
   16. DARK MODE MOBILE OPTIMIZATION
   ======================================== */

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
    
    /* Better contrast for mobile OLED screens */
    body {
        background-color: #000000;
    }
    
    .glass-container,
    .card {
        background: rgba(255, 255, 255, 0.05);
        border-color: rgba(255, 255, 255, 0.1);
    }
}

/* ========================================
   17. MOBILE-SPECIFIC UTILITIES
   ======================================== */

/* Hide on mobile */
@media (max-width: 767.98px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 767.98px) {
    .show-mobile {
        display: block !important;
    }
}

/* Mobile text alignment */
@media (max-width: 767.98px) {
    .text-mobile-center {
        text-align: center !important;
    }
    
    .text-mobile-left {
        text-align: left !important;
    }
}

/* Mobile padding utilities */
@media (max-width: 767.98px) {
    .p-mobile-0 { padding: 0 !important; }
    .p-mobile-1 { padding: var(--mobile-spacing-xs) !important; }
    .p-mobile-2 { padding: var(--mobile-spacing-sm) !important; }
    .p-mobile-3 { padding: var(--mobile-spacing-md) !important; }
    .p-mobile-4 { padding: var(--mobile-spacing-lg) !important; }
}

/* ========================================
   18. PRINT STYLES (MOBILE DEVICES)
   ======================================== */

@media print {
    .no-print,
    .sidebar,
    .navbar,
    .bottom-nav,
    .fab {
        display: none !important;
    }
    
    body {
        background: white;
        color: black;
    }
}

/* ========================================
   19. FOLDABLE & DUAL SCREEN SUPPORT
   ======================================== */

@media (horizontal-viewport-segments: 2) {
    .dual-screen-layout {
        display: grid;
        grid-template-columns: env(viewport-segment-width 0 0) env(viewport-segment-width 1 0);
        gap: env(viewport-segment-right 0 0);
    }
}

/* ========================================
   20. ACCESSIBILITY MOBILE
   ======================================== */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid #ff6b23;
    outline-offset: 2px;
}

/* Screen reader only */
.sr-only-mobile {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn,
    .card,
    .form-control {
        border: 2px solid currentColor;
    }
}

/* ========================================
   END OF MOBILE OPTIMIZATION CSS
   ======================================== */
