/**
 * Mobile Responsive Styles
 * Embassy REIT MIS
 * Optimized for touch devices and small screens
 */

/* =============================================
   GENERAL MOBILE IMPROVEMENTS
   ============================================= */

/* Larger touch targets */
@media (max-width: 768px) {
    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }

    .btn-sm {
        min-height: 38px;
        padding: 8px 12px;
    }

    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    /* Better spacing */
    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    /* Page title adjustments */
    .page-title-box {
        padding: 10px 0;
    }

    .page-title {
        font-size: 1.1rem;
    }

    .breadcrumb {
        display: none;
    }

    /* Stats cards - 2 per row on mobile */
    .col-xl-3.col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Smaller stat numbers on mobile */
    .card h3 {
        font-size: 1.3rem;
    }

    /* Hide less important columns on mobile */
    .hide-mobile {
        display: none !important;
    }
}

/* Extra small devices */
@media (max-width: 576px) {
    /* Stats cards - 1 per row on very small screens */
    .col-xl-3.col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Full width buttons */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .btn-group-mobile .btn {
        width: 100%;
    }

    /* Reduce padding */
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }

    .content-page {
        margin-left: 0 !important;
    }

    /* Page title */
    .page-title-main {
        font-size: 1rem;
    }
}

/* =============================================
   SIGNATURE PAD - TOUCH OPTIMIZED
   ============================================= */

.signature-canvas {
    touch-action: none; /* Critical for touch devices */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

@media (max-width: 768px) {
    .signature-canvas {
        width: 100% !important;
        height: 180px !important;
        border: 2px dashed #007bff;
        background: #fafafa;
    }

    /* Make signature section full width on mobile */
    .signature-section-mobile {
        flex-direction: column;
    }

    .signature-section-mobile > div {
        width: 100% !important;
        margin-bottom: 1rem;
    }

    /* Larger clear button */
    #btn-clear-signature {
        width: 100%;
        margin-top: 8px;
    }
}

/* Visual feedback for touch */
.signature-canvas:active {
    border-color: #28a745;
}

/* =============================================
   TABLES - MOBILE RESPONSIVE
   ============================================= */

@media (max-width: 768px) {
    /* Horizontal scroll wrapper */
    .table-responsive {
        border: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Card-style table on mobile */
    .table-mobile-cards {
        border: 0;
    }

    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        padding: 12px;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }

    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: 0;
        border-bottom: 1px solid #f0f0f0;
    }

    .table-mobile-cards tbody td:last-child {
        border-bottom: 0;
    }

    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6c757d;
        font-size: 0.85rem;
        flex: 0 0 40%;
    }

    /* Swipe indicator */
    .swipe-hint {
        text-align: center;
        color: #999;
        font-size: 0.8rem;
        padding: 8px;
        display: none;
    }

    .table-responsive + .swipe-hint {
        display: block;
    }
}

/* =============================================
   MODALS - MOBILE OPTIMIZED
   ============================================= */

@media (max-width: 768px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        min-height: 100vh;
    }

    .modal-content {
        border: 0;
        border-radius: 0;
        min-height: 100vh;
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 10;
        border-bottom: 1px solid #dee2e6;
    }

    .modal-body {
        padding: 1rem;
        padding-bottom: 100px; /* Space for footer */
    }

    .modal-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid #dee2e6;
        padding: 1rem;
        z-index: 10;
    }

    .modal-footer .btn {
        flex: 1;
    }

    /* Large modal title */
    .modal-title {
        font-size: 1.1rem;
    }

    /* Close button larger */
    .btn-close {
        width: 44px;
        height: 44px;
        padding: 12px;
    }
}

/* Modal for specific dialogs (not fullscreen) */
@media (max-width: 768px) {
    .modal-dialog.modal-sm-mobile {
        margin: 20px;
        max-width: calc(100% - 40px);
        min-height: auto;
    }

    .modal-dialog.modal-sm-mobile .modal-content {
        min-height: auto;
        border-radius: 12px;
    }

    .modal-dialog.modal-sm-mobile .modal-footer {
        position: relative;
    }
}

/* =============================================
   PHOTO UPLOAD - TOUCH FRIENDLY
   ============================================= */

@media (max-width: 768px) {
    .photo-upload-area {
        border: 2px dashed #dee2e6;
        border-radius: 12px;
        padding: 20px;
        text-align: center;
        background: #f8f9fa;
    }

    .photo-upload-area input[type="file"] {
        position: absolute;
        width: 100%;
        height: 100%;
        opacity: 0;
        cursor: pointer;
    }

    .photo-preview-item {
        width: 100px !important;
        height: 100px !important;
    }

    .photo-preview-item .remove-photo {
        width: 28px !important;
        height: 28px !important;
        font-size: 16px !important;
    }
}

/* =============================================
   PRODUCT GRID - MOBILE
   ============================================= */

@media (max-width: 768px) {
    .product-grid .col-xl-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .product-card {
        margin-bottom: 1rem;
    }

    .product-card img {
        height: 120px;
    }
}

@media (max-width: 576px) {
    .product-grid .col-xl-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* =============================================
   NAVIGATION - MOBILE
   ============================================= */

@media (max-width: 768px) {
    /* Better hamburger menu */
    .button-menu-mobile {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .button-menu-mobile i {
        font-size: 24px;
    }

    /* Sidebar overlay */
    .left-side-menu {
        z-index: 1050;
    }

    /* Better topbar */
    .topnav-menu-left {
        padding-left: 10px;
    }
}

/* =============================================
   DELIVERY/ORDER DETAIL - MOBILE
   ============================================= */

@media (max-width: 768px) {
    /* Product cell with image */
    .product-cell {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 8px !important;
    }

    .product-thumb {
        width: 60px !important;
        height: 60px !important;
    }

    /* Line items table adjustments */
    .line-items-mobile td {
        padding: 8px 4px;
        font-size: 0.85rem;
    }

    /* Status badges */
    .badge {
        font-size: 0.7rem;
        padding: 4px 8px;
    }

    /* Delivery items in modal */
    #new-delivery-items input,
    #new-delivery-items select {
        width: 70px !important;
        font-size: 14px;
    }
}

/* =============================================
   PRINT PAGES - MOBILE
   ============================================= */

@media (max-width: 768px) {
    .print-btn {
        position: relative;
        top: auto;
        right: auto;
        width: 100%;
        margin-bottom: 1rem;
    }
}

/* =============================================
   FLOATING ACTION BUTTON (FAB)
   ============================================= */

.fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #007bff;
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    z-index: 1000;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fab:hover,
.fab:active {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

@media (max-width: 768px) {
    .fab {
        display: flex;
    }
}

/* =============================================
   UTILITY CLASSES
   ============================================= */

/* Show only on mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }

    .show-mobile-flex {
        display: flex !important;
    }

    .show-mobile-inline {
        display: inline-block !important;
    }
}

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Text adjustments */
@media (max-width: 768px) {
    .text-truncate-mobile {
        max-width: 150px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* =============================================
   TOUCH FEEDBACK
   ============================================= */

@media (hover: none) {
    .btn:active,
    .card:active,
    tr:active {
        opacity: 0.8;
        transform: scale(0.98);
    }

    /* Remove hover effects on touch devices */
    .btn:hover {
        transform: none;
    }
}

/* =============================================
   SAFE AREA (for notched phones)
   ============================================= */

@supports (padding: max(0px)) {
    .content-page {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    .modal-footer {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
