/**
 * Mobile Responsive CSS for Code-GSM
 * Fixes: viewport, select2, tables, spacing, layout
 */

/* ============================================
   BASE MOBILE FIXES
   ============================================ */

/* Ensure proper box-sizing */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Prevent horizontal scroll */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ============================================
   MOBILE STYLES (screens <= 768px)
   ============================================ */
@media screen and (max-width: 768px) {
    
    /* === HEADER & TOP SPACING === */
    .page-header {
        padding: 10px !important;
        margin: 0 !important;
    }
    
    .page-header-content {
        padding: 5px 10px !important;
    }
    
    .page-title h4 {
        font-size: 16px !important;
        margin: 0 !important;
    }
    
    /* === CONTENT AREA === */
    .content {
        padding: 5px !important;
        margin: 0 !important;
    }
    
    .card {
        margin: 0 !important;
        border-radius: 0 !important;
    }
    
    .card-body {
        padding: 10px !important;
    }
    
    /* === FORM LAYOUT === */
    .form-group.row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    .col-lg-4, .col-lg-8, .col-lg-12,
    .col-md-4, .col-md-8, .col-md-12 {
        padding-left: 5px !important;
        padding-right: 5px !important;
    }
    
    /* Stack columns on mobile */
    .form-group.row > [class*="col-lg-"],
    .form-group.row > [class*="col-md-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 10px;
    }
    
    /* === SELECT2 DROPDOWN FIX === */
    .select2-container {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .select2-container--default .select2-selection--single {
        height: 44px !important;
        padding: 8px 12px !important;
        font-size: 14px !important;
    }
    
    .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 26px !important;
        padding-left: 0 !important;
        font-size: 14px !important;
        white-space: normal !important;
        word-wrap: break-word !important;
    }
    
    .select2-dropdown {
        width: 100% !important;
        max-width: calc(100vw - 20px) !important;
        left: 0 !important;
    }
    
    .select2-results__option {
        padding: 10px 12px !important;
        font-size: 14px !important;
        line-height: 1.4 !important;
        white-space: normal !important;
        word-wrap: break-word !important;
    }
    
    .select2-results__group {
        padding: 8px 12px !important;
        font-size: 13px !important;
        font-weight: 600 !important;
    }
    
    .select2-search--dropdown .select2-search__field {
        padding: 10px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    /* === PACKAGE SECTION === */
    .pkg_section {
        height: auto !important;
        max-height: 400px !important;
        overflow-y: auto !important;
        padding: 10px !important;
    }
    
    .left_package {
        width: 100% !important;
        margin-bottom: 10px !important;
    }
    
    .left_package h5 {
        font-size: 13px !important;
        line-height: 1.3 !important;
    }
    
    /* === SEARCH INPUT === */
    .form-control-lg {
        height: 44px !important;
        font-size: 14px !important;
        padding: 10px 15px !important;
    }
    
    /* === BUTTONS === */
    .btn {
        width: 100% !important;
        padding: 12px 15px !important;
        font-size: 14px !important;
        margin-bottom: 10px !important;
    }
    
    .btn-order {
        width: 100% !important;
        position: relative !important;
        bottom: auto !important;
        right: auto !important;
        float: none !important;
    }
    
    .PlaceOrderBtn {
        position: relative !important;
        bottom: auto !important;
        right: auto !important;
        padding: 10px !important;
        width: 100% !important;
    }
    
    /* === TABLES RESPONSIVE === */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    table.dataTable {
        width: 100% !important;
        display: block !important;
        overflow-x: auto !important;
    }
    
    table.dataTable thead {
        display: none !important;
    }
    
    table.dataTable tbody tr {
        display: block !important;
        margin-bottom: 15px !important;
        border: 1px solid #ddd !important;
        border-radius: 5px !important;
        padding: 10px !important;
    }
    
    table.dataTable tbody td {
        display: block !important;
        text-align: left !important;
        padding: 8px 10px !important;
        border: none !important;
        border-bottom: 1px solid #eee !important;
    }
    
    table.dataTable tbody td:before {
        content: attr(data-label);
        font-weight: 600;
        display: block;
        margin-bottom: 5px;
        color: #666;
        font-size: 12px;
    }
    
    table.dataTable tbody td:last-child {
        border-bottom: none !important;
    }
    
    /* === NAVIGATION / SIDEBAR === */
    .sidebar {
        width: 100% !important;
        position: fixed !important;
        z-index: 1000 !important;
    }
    
    .navbar {
        padding: 5px 10px !important;
    }
    
    .navbar-brand img {
        max-height: 40px !important;
    }
    
    /* === MODAL / POPUP === */
    .modal-dialog {
        margin: 10px !important;
        max-width: calc(100vw - 20px) !important;
    }
    
    .modal-content {
        border-radius: 5px !important;
    }
    
    /* === TYPOGRAPHY === */
    h1 { font-size: 22px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }
    h5 { font-size: 14px !important; }
    
    /* === HIDE UNNECESSARY ELEMENTS ON MOBILE === */
    .hidden-mobile,
    .desktop-only {
        display: none !important;
    }
    
    /* === COLUMNS FIX === */
    .columns {
        -moz-column-width: 100% !important;
        -webkit-column-width: 100% !important;
        column-width: 100% !important;
        column-count: 1 !important;
    }
    
    /* === INPUT FIELDS === */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents iOS zoom */
        width: 100% !important;
    }
    
    /* === FOOTER === */
    footer {
        padding: 10px !important;
        text-align: center !important;
    }
    
    /* === ALERT MESSAGES === */
    .alert {
        padding: 10px !important;
        font-size: 13px !important;
        margin: 5px 0 !important;
    }
    
    /* === DROPDOWN MENUS === */
    .dropdown-menu {
        position: fixed !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-height: 70vh !important;
        overflow-y: auto !important;
    }
    
    .dropdown-item {
        padding: 12px 15px !important;
        white-space: normal !important;
        font-size: 14px !important;
    }
}

/* ============================================
   SMALL MOBILE (screens <= 480px)
   ============================================ */
@media screen and (max-width: 480px) {
    
    .page-title h4 {
        font-size: 14px !important;
    }
    
    .card-body {
        padding: 8px !important;
    }
    
    .select2-results__option {
        padding: 12px 10px !important;
        font-size: 13px !important;
    }
    
    .btn {
        padding: 14px 12px !important;
        font-size: 13px !important;
    }
    
    .pkg_section {
        max-height: 350px !important;
    }
    
    .left_package h5 {
        font-size: 12px !important;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    
    /* Larger touch targets */
    .select2-results__option {
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
    }
    
    .btn {
        min-height: 44px !important;
    }
    
    input, select, textarea {
        min-height: 44px !important;
    }
    
    /* Remove hover effects on touch */
    .select2-results__option:hover {
        background-color: transparent !important;
    }
    
    .select2-results__option:active,
    .select2-results__option.select2-results__option--highlighted {
        background-color: #5897fb !important;
        color: white !important;
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */
@media screen and (max-width: 812px) and (orientation: landscape) {
    
    .pkg_section {
        max-height: 250px !important;
    }
    
    .modal-dialog {
        max-height: 90vh !important;
        overflow-y: auto !important;
    }
}

/* ============================================
   FIX iOS SAFARI
   ============================================ */
@supports (-webkit-touch-callout: none) {
    /* iOS specific fixes */
    body {
        -webkit-text-size-adjust: 100%;
    }
    
    input, textarea, select {
        font-size: 16px !important; /* Prevent zoom on focus */
    }
    
    .select2-search__field {
        font-size: 16px !important;
    }
}
