/**
 * Mobile Optimization Styles
 * 
 * Features:
 * - Touch-friendly buttons (44px min size)
 * - Bottom navigation bar for mobile
 * - Optimized forms for mobile input
 * - Responsive typography
 * - Mobile-first media queries
 */

/* ========================================
   TOUCH-FRIENDLY UI ELEMENTS
   ======================================== */

/* Minimum touch target size (44px as per Apple guidelines) */
.btn, 
.nav-link,
.form-check-input,
.dropdown-item,
.page-link {
    min-height: 44px;
    min-width: 44px;
}

/* Larger touch targets for small buttons */
.btn-sm {
    min-height: 36px;
    min-width: 36px;
    padding: 0.5rem 0.75rem;
}

/* Touch-friendly form inputs */
.form-control,
.form-select {
    min-height: 48px;
    font-size: 16px; /* Prevents iOS zoom on focus */
}

/* Larger touch area for checkboxes and radios */
.form-check-input {
    width: 22px;
    height: 22px;
    margin-top: 0.15em;
}

.form-check-label {
    padding-left: 0.5rem;
    min-height: 44px;
    display: flex;
    align-items: center;
}

/* Touch-friendly cards */
.card {
    touch-action: manipulation;
}

.card-body {
    padding: 1.25rem;
}

/* Touch feedback */
@media (hover: none) {
    .btn:active,
    .nav-link:active,
    .card:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }
}

/* ========================================
   MOBILE NAVIGATION (Bottom Bar)
   ======================================== */

/* Hide bottom nav on desktop */
.mobile-bottom-nav {
    display: none;
}

/* Show bottom nav on mobile */
@media (max-width: 991.98px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: linear-gradient(180deg, #1e293b, #0f172a);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        z-index: 1030;
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .mobile-bottom-nav .nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #94a3b8;
        text-decoration: none;
        font-size: 0.75rem;
        padding: 0.5rem;
        transition: all 0.2s;
        min-height: 64px;
    }
    
    .mobile-bottom-nav .nav-item i {
        font-size: 1.5rem;
        margin-bottom: 0.25rem;
    }
    
    .mobile-bottom-nav .nav-item.active {
        color: #60a5fa;
    }
    
    .mobile-bottom-nav .nav-item:active {
        background: rgba(255, 255, 255, 0.1);
    }
    
    /* Add padding to main content for bottom nav */
    body {
        padding-bottom: calc(64px + env(safe-area-inset-bottom));
    }
    
    /* Adjust sidebar for mobile */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 280px;
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    /* Main content full width on mobile */
    .main-content {
        margin-left: 0;
    }
    
    /* Topbar adjustments */
    .topbar {
        padding: 0.75rem 1rem;
    }
    
    .topbar h1 {
        font-size: 1.25rem;
    }
}

/* ========================================
   MOBILE-FIRST FORMS
   ======================================== */

/* Mobile form optimizations */
@media (max-width: 767.98px) {
    /* Stack form elements */
    .form-row {
        flex-direction: column;
    }
    
    .form-row > .col,
    .form-row > [class*="col-"] {
        padding-left: 0;
        padding-right: 0;
    }
    
    /* Full-width buttons on mobile */
    .btn-mobile-block {
        display: block;
        width: 100%;
        min-height: 48px;
    }
    
    /* Stack flex buttons vertically */
    .d-flex.flex-column.flex-sm-row.gap-2 {
        flex-direction: column !important;
    }
    
    .d-flex.flex-column.flex-sm-row.gap-2 .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .d-flex.flex-column.flex-sm-row.gap-2 .btn:last-child {
        margin-bottom: 0;
    }
    
    /* Larger input text */
    input, select, textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    /* Touch-friendly select dropdowns */
    .form-select {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        padding-right: 2.5rem;
    }
    
    /* Larger spacing between form groups */
    .mb-3 {
        margin-bottom: 1.25rem !important;
    }
    
    /* Mobile-optimized date picker */
    input[type="date"],
    input[type="datetime-local"] {
        min-height: 48px;
    }
}

/* ========================================
   MOBILE TYPOGRAPHY
   ======================================== */

@media (max-width: 767.98px) {
    html {
        font-size: 14px;
    }
    
    h1, .h1 { font-size: 1.5rem; }
    h2, .h2 { font-size: 1.25rem; }
    h3, .h3 { font-size: 1.125rem; }
    h4, .h4 { font-size: 1rem; }
    
    .display-4 {
        font-size: 1.75rem;
    }
}

/* ========================================
   MOBILE TABLES
   ======================================== */

/* Responsive tables for mobile */
@media (max-width: 767.98px) {
    .table-responsive-stack {
        display: block;
    }
    
    .table-responsive-stack thead {
        display: none;
    }
    
    .table-responsive-stack tbody,
    .table-responsive-stack tr,
    .table-responsive-stack td {
        display: block;
        width: 100%;
    }
    
    .table-responsive-stack tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 0.5rem;
        padding: 1rem;
    }
    
    .table-responsive-stack td {
        border: none;
        padding: 0.5rem 0;
        text-align: left !important;
    }
    
    .table-responsive-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        display: block;
        color: var(--text-secondary);
        font-size: 0.875rem;
        margin-bottom: 0.25rem;
    }
    
    /* Regular table responsive */
    .table-responsive {
        border: 0;
    }
    
    .table-responsive .table {
        font-size: 0.875rem;
    }
    
    .table-responsive .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
}

/* ========================================
   MOBILE CARDS
   ======================================== */

@media (max-width: 767.98px) {
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-header {
        padding: 1rem;
    }
    
    /* Card actions always visible on mobile */
    .card-actions {
        opacity: 1 !important;
    }
}

/* ========================================
   MOBILE MODALS
   ======================================== */

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }
    
    .modal-content {
        border-radius: 0;
        border: 0;
        min-height: 100%;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin-left: 0 !important;
        margin-bottom: 0.5rem;
    }
    
    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }
}

/* ========================================
   MOBILE DASHBOARD
   ======================================== */

@media (max-width: 767.98px) {
    .dashboard-stats .col-6 {
        margin-bottom: 1rem;
    }
    
    .dashboard-stats .card {
        margin-bottom: 0;
    }
    
    .chart-container {
        height: 250px !important;
    }
}

/* ========================================
   PULL-TO-REFRESH
   ======================================== */

.pull-to-refresh {
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.pull-to-refresh-spinner {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    opacity: 0;
    transition: opacity 0.2s;
}

.pull-to-refresh.pulling .pull-to-refresh-spinner {
    opacity: 1;
}

/* ========================================
   MOBILE GESTURES
   ======================================== */

/* Swipe actions for list items */
.swipe-item {
    position: relative;
    overflow: hidden;
}

.swipe-item-content {
    transition: transform 0.3s ease;
}

.swipe-item-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.swipe-item.swiped .swipe-item-content {
    transform: translateX(-80px);
}

.swipe-item.swiped .swipe-item-actions {
    transform: translateX(0);
}

/* ========================================
   DARK MODE MOBILE ADJUSTMENTS
   ======================================== */

@media (max-width: 991.98px) {
    [data-theme="dark"] .mobile-bottom-nav {
        background: linear-gradient(180deg, #0f172a, #020617);
        border-top-color: rgba(255, 255, 255, 0.05);
    }
}

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

@supports (padding-top: env(safe-area-inset-top)) {
    @media (max-width: 991.98px) {
        .mobile-bottom-nav {
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
            padding-bottom: env(safe-area-inset-bottom);
        }
        
        body {
            padding-bottom: calc(64px + env(safe-area-inset-bottom));
        }
    }
}

/* ========================================
   IMAGE OPTIMIZATION
   ======================================== */

/* Lazy load image placeholder */
img.lazy-load {
    opacity: 0;
    transition: opacity 0.3s ease;
    background-color: var(--bg-hover);
}

img.lazy-load.loaded {
    opacity: 1;
}

/* Responsive images */
.img-responsive {
    max-width: 100%;
    height: auto;
}

/* Mobile image optimization */
@media (max-width: 767.98px) {
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Smaller images on mobile */
    .img-mobile-sm {
        max-width: 100px;
    }
    
    .img-mobile-md {
        max-width: 200px;
    }
}

/* ========================================
   VIEWPORT HEIGHT FIX (Mobile Browsers)
   ======================================== */

@supports (height: 100dvh) {
    .sidebar,
    .mobile-bottom-nav {
        height: 100dvh;
    }
}

/* ========================================
   HAPTIC FEEDBACK (iOS)
   ======================================== */

@media (hover: none) {
    .btn:active,
    .nav-link:active {
        -webkit-tap-highlight-color: transparent;
    }
}
