/* Mobile Optimizations for Reno Tile Solutions */
/* Optimized for low-end devices and slow connections */

/* === Improved Touch Targets (Apple/Google Standards) === */
@media (max-width: 768px) {
    /* Larger touch targets for mobile - 44x44px minimum */
    .btn, button, a.btn, .btn-sm {
        min-height: 44px !important;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 16px;
        line-height: 1.5;
        border-radius: 6px;
        font-weight: 500;
    }
    
    /* Extra padding for icon buttons */
    .btn-icon {
        padding: 12px;
    }
    
    /* Better form inputs for mobile - Prevents iOS zoom */
    .form-control, .form-select, input, select, textarea {
        min-height: 44px !important;
        font-size: 16px !important; /* CRITICAL: Prevents zoom on iOS */
        padding: 12px 14px;
        border-radius: 6px;
        line-height: 1.5;
        -webkit-appearance: none; /* Remove iOS default styling */
        appearance: none;
    }
    
    /* Select dropdowns */
    select.form-control {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        padding-right: 40px;
    }
    
    /* Checkboxes and radios - larger touch targets */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 22px;
        min-height: 22px;
        margin: 4px;
    }
    
    /* Labels for checkboxes/radios */
    label {
        padding: 8px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    /* Better table display */
    .table-responsive {
        border: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        font-size: 14px;
        min-width: 600px;
    }
    
    .table th, .table td {
        padding: 8px 6px;
        white-space: nowrap;
    }
    
    /* Stack cards on mobile */
    .card {
        margin-bottom: 15px;
    }
    
    /* Better spacing for action buttons */
    .btn-group-vertical .btn {
        width: 100%;
        margin-bottom: 5px;
    }
    
    /* Modal improvements */
    .modal-dialog {
        margin: 10px;
    }
    
    .modal-content {
        border-radius: 8px;
    }
    
    /* Better navbar for mobile */
    .navbar-nav .nav-link {
        padding: 12px 15px;
        font-size: 16px;
    }
    
    /* Info boxes responsive */
    .info-box {
        min-height: 80px;
        margin-bottom: 15px;
    }
    
    .info-box-icon {
        width: 70px;
    }
    
    .info-box-content {
        margin-left: 80px;
    }
    
    .info-box-number {
        font-size: 20px;
    }
    
    /* Dashboard charts */
    canvas {
        max-height: 250px !important;
    }
    
    /* Sidebar improvements */
    .sidebar {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Breadcrumb improvements */
    .breadcrumb {
        font-size: 13px;
        padding: 8px 12px;
    }
    
    /* DataTables mobile view */
    .dataTables_wrapper {
        font-size: 14px;
    }
    
    .dataTables_filter input {
        width: 100% !important;
        margin-top: 5px;
    }
    
    /* Better pagination */
    .pagination {
        flex-wrap: wrap;
    }
    
    .page-link {
        padding: 8px 12px;
        font-size: 14px;
    }
}

/* === Extra Small Devices === */
@media (max-width: 576px) {
    /* Stack all columns */
    .col-sm-6, .col-md-4, .col-md-6, .col-md-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Reduce padding */
    .content-wrapper {
        padding: 10px !important;
    }
    
    .card-body {
        padding: 12px;
    }
    
    /* Smaller headings */
    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    h4 { font-size: 16px; }
    
    /* Action buttons full width */
    .btn-block-mobile {
        display: block;
        width: 100%;
        margin-bottom: 8px;
    }
    
    /* Hide less important columns in tables */
    .table .d-none-mobile {
        display: none !important;
    }
    
    /* Better form layout */
    .form-group {
        margin-bottom: 12px;
    }
    
    .form-horizontal .col-sm-2,
    .form-horizontal .col-sm-3,
    .form-horizontal .col-sm-10,
    .form-horizontal .col-sm-9 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-left: 0 !important;
    }
}

/* === POS Specific Mobile Optimizations === */
@media (max-width: 768px) {
    /* Stack POS layout vertically on mobile */
    .pos-container {
        flex-direction: column;
    }
    
    .pos-products-section {
        width: 100% !important;
        margin-bottom: 15px;
    }
    
    .pos-cart-section {
        width: 100% !important;
        position: sticky;
        top: 0;
        z-index: 100;
        background: white;
    }
    
    /* Larger product cards for touch */
    .product-card {
        min-height: 120px;
        margin-bottom: 12px;
        cursor: pointer;
        transition: transform 0.1s ease, box-shadow 0.1s ease;
        border: 2px solid transparent;
    }
    
    .product-card:active {
        transform: scale(0.98);
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
        border-color: #007bff;
    }
    
    .product-card .product-name {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 6px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    
    .product-card .product-price {
        font-size: 18px;
        font-weight: bold;
        color: #28a745;
    }
    
    .product-card .product-stock {
        font-size: 12px;
        padding: 4px 8px;
    }
    
    .product-card .product-img {
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .product-card .product-img img {
        max-height: 100%;
        max-width: 100%;
        object-fit: contain;
    }
    
    /* Better barcode input */
    #barcode-input {
        font-size: 18px !important;
        letter-spacing: 1px;
        font-family: monospace;
    }
    
    /* Cart items */
    .cart-item {
        padding: 12px;
        border-bottom: 1px solid #eee;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .cart-item .item-name {
        flex: 1;
        font-size: 15px;
        font-weight: 500;
    }
    
    .cart-item .item-quantity {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .cart-item .item-quantity button {
        min-width: 36px;
        min-height: 36px;
        padding: 8px;
        font-size: 16px;
    }
    
    .cart-item .item-quantity input {
        width: 50px;
        text-align: center;
        font-size: 16px !important;
        padding: 6px;
    }
    
    .cart-item .item-price {
        font-size: 16px;
        font-weight: bold;
        min-width: 70px;
        text-align: right;
    }
    
    .cart-item .item-remove {
        min-width: 36px;
        min-height: 36px;
        padding: 8px;
    }
    
    /* Cart summary - sticky at bottom */
    .cart-summary {
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 2px solid #dee2e6;
        padding: 15px;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
        z-index: 101;
    }
    
    .cart-total {
        font-size: 24px;
        font-weight: bold;
        margin-bottom: 12px;
        text-align: center;
    }
    
    /* Checkout button - large and prominent */
    #checkout-btn {
        width: 100%;
        min-height: 56px !important;
        font-size: 20px;
        font-weight: bold;
        background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
        border: none;
        box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
    }
    
    #checkout-btn:active {
        transform: scale(0.98);
    }
    
    /* Product grid - 2 columns on mobile */
    .products-container .col-6 {
        padding-left: 6px;
        padding-right: 6px;
    }
    
    /* Search input */
    #product-search {
        font-size: 16px !important;
        min-height: 44px;
    }
    
    /* Category filter */
    #category-filter {
        font-size: 16px !important;
        min-height: 44px;
        background-color: #fff;
    }
}

/* === Landscape Mode Optimizations === */
@media (max-width: 768px) and (orientation: landscape) {
    .content-wrapper {
        padding: 8px !important;
    }
    
    .card {
        margin-bottom: 10px;
    }
    
    .info-box {
        min-height: 60px;
    }
}

/* === Sticky Footer for Mobile === */
@media (max-width: 768px) {
    .mobile-action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 10px;
        border-top: 1px solid #ddd;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 1000;
    }
    
    .mobile-action-bar .btn {
        margin: 0 5px;
    }
}

/* === Quick Action Buttons === */
@media (max-width: 768px) {
    .mobile-quick-actions {
        position: fixed;
        bottom: 80px;
        right: 20px;
        z-index: 999;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .mobile-quick-actions .btn-float {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 6px 16px rgba(0,0,0,0.3);
        font-size: 24px;
        border: none;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
        cursor: pointer;
    }

    .mobile-quick-actions .btn-float:active {
        transform: scale(0.9);
        box-shadow: 0 3px 8px rgba(0,0,0,0.3);
    }

    .mobile-quick-actions .btn-float.btn-primary {
        background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
        color: white;
    }

    .mobile-quick-actions .btn-float.btn-success {
        background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
        color: white;
    }

    .mobile-quick-actions .btn-float.btn-info {
        background: linear-gradient(135deg, #17a2b8 0%, #117a8b 100%);
        color: white;
    }

    .mobile-quick-actions .btn-float.btn-warning {
        background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%);
        color: #212529;
    }

    /* Tooltip for quick actions */
    .btn-float[data-tooltip] {
        position: relative;
    }

    .btn-float[data-tooltip]:before {
        content: attr(data-tooltip);
        position: absolute;
        right: 70px;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(0, 0, 0, 0.85);
        color: white;
        padding: 8px 12px;
        border-radius: 6px;
        font-size: 14px;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        z-index: 1000;
    }

    .btn-float[data-tooltip]:hover:before,
    .btn-float[data-tooltip]:active:before {
        opacity: 1;
    }

    /* Hide quick actions on desktop */
}

@media (min-width: 769px) {
    .mobile-quick-actions {
        display: none;
    }
}

/* === Loading States === */
.mobile-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
}

/* === Offline Indicator === */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #dc3545;
    color: white;
    padding: 8px;
    text-align: center;
    z-index: 10000;
    display: none;
}

.offline-indicator.show {
    display: block;
}

/* === Pull to Refresh Indicator === */
.pull-to-refresh {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    transition: top 0.3s ease;
}

.pull-to-refresh.active {
    top: 10px;
}

/* === Improve Select2 on Mobile === */
@media (max-width: 768px) {
    .select2-container--default .select2-selection--single {
        height: 44px !important;
        padding: 6px 12px;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 32px;
        font-size: 16px;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__arrow {
        height: 42px;
    }
}

/* === Safe Area for iPhone X and newer === */
@supports (padding: max(0px)) {
    .content-wrapper {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
    
    .mobile-action-bar {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* === Dark Mode Support (Optional) === */
@media (prefers-color-scheme: dark) {
    /* Can be enabled if needed */
}

/* === Accessibility Improvements === */
@media (max-width: 768px) {
    /* Ensure sufficient contrast */
    .btn-primary {
        background-color: #007bff;
        border-color: #007bff;
    }
    
    /* Focus states for keyboard navigation */
    button:focus,
    a:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid #007bff;
        outline-offset: 2px;
    }
}
