/* Mobile and Small Screen Fixes for Tailor Shop Management */

/* ===== GENERAL MOBILE IMPROVEMENTS ===== */

/* Ensure proper viewport behavior */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== NAVIGATION FIXES ===== */

/* Mobile navbar improvements */
@media (max-width: 991px) {
    /* Navbar container */
    .navbar {
        padding: 0.5rem 1rem;
    }
    
    .navbar .container {
        padding: 0;
    }
    
    /* Brand */
    .navbar-brand {
        font-size: 1.1rem;
        padding: 0.5rem 0;
    }
    
    /* Toggler button */
    .navbar-toggler {
        padding: 0.5rem 0.75rem;
        font-size: 1rem;
        border: 1px solid rgba(255, 255, 255, 0.5);
    }
    
    .navbar-toggler:focus {
        box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.25);
    }
    
    /* Hide desktop menu completely */
    .navbar-collapse.d-none.d-lg-flex {
        display: none !important;
    }
}

/* ===== OFFCANVAS SIDEBAR IMPROVEMENTS ===== */

/* Offcanvas width and positioning */
.offcanvas.offcanvas-mobile {
    width: 85vw !important;
    max-width: 320px !important;
    z-index: 1045 !important;
}

/* Ensure offcanvas is hidden by default */
.offcanvas.offcanvas-mobile:not(.show) {
    visibility: hidden !important;
    transform: translateX(-100%) !important;
}

.offcanvas.offcanvas-mobile.show {
    visibility: visible !important;
    transform: translateX(0) !important;
}

/* RTL: Offcanvas from right */
html[dir="rtl"] .offcanvas.offcanvas-mobile {
    right: 0 !important;
    left: auto !important;
}

html[dir="rtl"] .offcanvas.offcanvas-mobile:not(.show) {
    transform: translateX(100%) !important;
}

html[dir="rtl"] .offcanvas.offcanvas-mobile.show {
    transform: translateX(0) !important;
}

/* LTR: Offcanvas from left */
html:not([dir="rtl"]) .offcanvas.offcanvas-mobile {
    left: 0 !important;
    right: auto !important;
}

html:not([dir="rtl"]) .offcanvas.offcanvas-mobile:not(.show) {
    transform: translateX(-100%) !important;
}

html:not([dir="rtl"]) .offcanvas.offcanvas-mobile.show {
    transform: translateX(0) !important;
}

/* Offcanvas backdrop */
.offcanvas-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
}

.offcanvas-backdrop.fade {
    opacity: 0;
}

.offcanvas-backdrop.show {
    opacity: 1;
}

/* Offcanvas header */
.offcanvas-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.offcanvas-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-close-white {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Offcanvas body */
.offcanvas-body {
    padding: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Prevent body scroll when offcanvas is open */
body.offcanvas-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* Mobile nav links */
.mobile-nav-link {
    display: block !important;
    padding: 0.75rem 1rem !important;
    color: rgba(255, 255, 255, 0.95) !important;
    text-decoration: none !important;
    border-radius: 0.5rem !important;
    transition: all 0.2s ease !important;
    font-size: 0.95rem !important;
    font-weight: 500 !important;
}

.mobile-nav-link:hover,
.mobile-nav-link:focus {
    background-color: rgba(255, 255, 255, 0.15) !important;
    color: white !important;
}

.mobile-nav-link i {
    margin-left: 0.5rem;
    font-size: 1.1rem;
}

html[dir="rtl"] .mobile-nav-link i {
    margin-left: 0;
    margin-right: 0.5rem;
}

/* Dropdown in offcanvas */
.offcanvas-body .dropdown {
    position: relative;
}

.offcanvas-body .nav-item.dropdown {
    margin-bottom: 0.25rem;
}

.offcanvas-body .dropdown-toggle {
    width: 100%;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

html[dir="ltr"] .offcanvas-body .dropdown-toggle {
    text-align: left;
}

.offcanvas-body .dropdown-toggle::after {
    margin-left: auto;
    transition: transform 0.2s ease;
}

html[dir="rtl"] .offcanvas-body .dropdown-toggle::after {
    margin-left: 0;
    margin-right: auto;
}

.offcanvas-body .dropdown.show .dropdown-toggle::after {
    transform: rotate(180deg);
}

.offcanvas-body .dropdown-menu {
    position: static !important;
    float: none !important;
    width: 100% !important;
    background-color: rgba(0, 0, 0, 0.2) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 0.5rem !important;
    margin: 0.5rem 0 !important;
    padding: 0.5rem !important;
    display: none !important;
    transform: none !important;
    box-shadow: none !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.offcanvas-body .dropdown-menu.show {
    display: block !important;
}

.offcanvas-body .dropdown-item {
    padding: 0.65rem 1rem !important;
    font-size: 0.9rem !important;
    border-radius: 0.375rem !important;
    color: rgba(255, 255, 255, 0.9) !important;
    background: transparent !important;
    white-space: normal !important;
    word-wrap: break-word !important;
}

.offcanvas-body .dropdown-item:hover,
.offcanvas-body .dropdown-item:focus {
    background-color: rgba(255, 255, 255, 0.15) !important;
    color: white !important;
}

.offcanvas-body .dropdown-header {
    font-size: 0.8rem !important;
    padding: 0.5rem 1rem !important;
    color: rgba(255, 255, 255, 0.6) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    font-weight: 600 !important;
}

.offcanvas-body .dropdown-divider {
    border-color: rgba(255, 255, 255, 0.15) !important;
    margin: 0.5rem 0 !important;
}

/* ===== FLOATING MENU BUTTON ===== */

/* Hide floating button on mobile */
@media (max-width: 991px) {
    .floating-menu-btn {
        display: none !important;
    }
}

/* Adjust floating button position on desktop */
@media (min-width: 992px) {
    .floating-menu-btn {
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    html[dir="rtl"] .floating-menu-btn {
        right: 20px;
        left: auto;
    }
}

/* ===== CONTENT AREA IMPROVEMENTS ===== */

/* Container padding on mobile */
@media (max-width: 767px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    /* Page headers */
    h1 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }
    
    h2 {
        font-size: 1.35rem;
    }
    
    h3 {
        font-size: 1.2rem;
    }
    
    /* Cards */
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-header {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

/* ===== FORM IMPROVEMENTS ===== */

@media (max-width: 767px) {
    /* Form controls */
    .form-control,
    .form-select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 0.625rem 0.75rem;
    }
    
    .form-label {
        font-size: 0.95rem;
        margin-bottom: 0.375rem;
    }
    
    /* Form groups */
    .mb-3 {
        margin-bottom: 1rem !important;
    }
    
    /* Button groups */
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn-group .btn {
        width: 100%;
        margin: 0 !important;
    }
    
    /* Action buttons */
    .d-flex.gap-2 {
        flex-direction: column;
        gap: 0.5rem !important;
    }
    
    .d-flex.gap-2 .btn {
        width: 100%;
    }
}

/* ===== TABLE IMPROVEMENTS ===== */

@media (max-width: 767px) {
    /* Table responsive wrapper */
    .table-responsive {
        border-radius: 0.5rem;
        margin-bottom: 1rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Table styling */
    .table {
        font-size: 0.85rem;
        min-width: 600px; /* Ensures horizontal scroll */
    }
    
    .table th,
    .table td {
        padding: 0.5rem;
        white-space: nowrap;
    }
    
    .table thead th {
        font-size: 0.8rem;
        position: sticky;
        top: 0;
        background-color: #f8f9fa;
        z-index: 10;
    }
    
    /* Action buttons in tables */
    .table .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .table .btn-group-sm .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    /* Cut order actions - make them stack vertically on mobile */
    .cut-order-actions {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.25rem !important;
        min-width: 120px !important;
    }
    
    .cut-order-actions .btn {
        width: 100% !important;
        margin: 0 !important;
        font-size: 0.75rem !important;
        padding: 0.375rem 0.5rem !important;
        white-space: nowrap !important;
    }
    
    .cut-order-actions form {
        width: 100% !important;
        margin: 0 !important;
    }
    
    .cut-order-actions form .btn {
        width: 100% !important;
    }
    
    /* Hide button text on very small screens, show only icons */
    @media (max-width: 400px) {
        .cut-order-actions .btn {
            font-size: 0 !important;
            padding: 0.5rem !important;
        }
        
        .cut-order-actions .btn i {
            font-size: 1rem !important;
            margin: 0 !important;
        }
    }
}

/* ===== MODAL IMPROVEMENTS ===== */

@media (max-width: 767px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0 !important;
    }
}

/* ===== PAGINATION IMPROVEMENTS ===== */

@media (max-width: 767px) {
    .pagination {
        font-size: 0.875rem;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .pagination .page-link {
        padding: 0.375rem 0.625rem;
    }
    
    /* Hide some pagination items on very small screens */
    @media (max-width: 400px) {
        .pagination .page-item:not(.active):not(:first-child):not(:last-child):not(.disabled) {
            display: none;
        }
    }
}

/* ===== BADGE AND ALERT IMPROVEMENTS ===== */

@media (max-width: 767px) {
    .badge {
        font-size: 0.7rem;
        padding: 0.25em 0.5em;
    }
    
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
}

/* ===== DASHBOARD IMPROVEMENTS ===== */

@media (max-width: 767px) {
    .dashboard-card {
        margin-bottom: 1rem;
    }
    
    .dashboard-card .card-body {
        padding: 1.25rem;
    }
    
    /* Dashboard stats */
    .row.g-4 {
        gap: 1rem !important;
    }
    
    .col-md-3,
    .col-md-4,
    .col-md-6 {
        width: 100%;
        padding-left: 0;
        padding-right: 0;
    }
}

/* ===== SELECT2 MOBILE IMPROVEMENTS ===== */

@media (max-width: 767px) {
    .select2-container--bootstrap-5 .select2-selection {
        font-size: 16px !important;
        min-height: 42px !important;
    }
    
    .select2-container--bootstrap-5 .select2-dropdown {
        font-size: 16px !important;
    }
    
    .select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
        font-size: 16px !important;
        padding: 0.625rem 0.75rem !important;
    }
    
    .select2-container--bootstrap-5 .select2-results__option {
        padding: 0.75rem 1rem !important;
    }
}

/* ===== EXPENSES PAGES MOBILE FIXES ===== */

@media (max-width: 767px) {
    /* Expenses list */
    .expense-form-container {
        padding: 0.75rem;
    }
    
    .form-card {
        padding: 1.25rem;
    }
    
    .field-with-button {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .field-with-button .form-select {
        width: 100%;
    }
    
    .btn-add-inline {
        width: 100%;
    }
    
    /* Expenses report */
    .report-container {
        padding: 0.75rem;
    }
    
    .filter-card {
        padding: 1rem;
    }
    
    .filter-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .filter-actions {
        flex-direction: column;
    }
    
    .filter-actions .btn {
        width: 100%;
    }
    
    .expenses-table {
        font-size: 0.85rem;
    }
    
    .expenses-table th,
    .expenses-table td {
        padding: 0.5rem 0.375rem;
    }
}

/* ===== UTILITY CLASSES FOR MOBILE ===== */

/* Hide on mobile */
@media (max-width: 767px) {
    .d-mobile-none {
        display: none !important;
    }
}

/* Show only on mobile */
.d-mobile-block {
    display: none !important;
}

@media (max-width: 767px) {
    .d-mobile-block {
        display: block !important;
    }
}

/* Full width on mobile */
@media (max-width: 767px) {
    .w-mobile-100 {
        width: 100% !important;
    }
}

/* ===== TOUCH IMPROVEMENTS ===== */

/* Larger touch targets */
@media (max-width: 767px) and (hover: none) {
    .btn,
    .nav-link,
    .dropdown-item,
    .page-link {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover,
    .nav-link:hover,
    .dropdown-item:hover {
        transform: none;
    }
}

/* ===== LANDSCAPE MODE FIXES ===== */

@media (max-width: 767px) and (orientation: landscape) {
    /* Reduce navbar height in landscape */
    .navbar {
        padding: 0.25rem 1rem;
    }
    
    .navbar-brand {
        font-size: 1rem;
    }
    
    /* Reduce offcanvas width in landscape */
    .offcanvas.offcanvas-mobile {
        width: 70vw !important;
        max-width: 280px !important;
    }
}

/* ===== VERY SMALL SCREENS (< 400px) ===== */

@media (max-width: 400px) {
    body {
        font-size: 14px;
    }
    
    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    h1 {
        font-size: 1.35rem;
    }
    
    .btn {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    .table {
        font-size: 0.75rem;
    }
    
    .form-control,
    .form-select {
        font-size: 14px !important;
    }
    
    /* Make tables more compact */
    .table th,
    .table td {
        padding: 0.375rem 0.25rem !important;
    }
    
    /* Stack badges vertically */
    .badge {
        display: block !important;
        margin: 0.125rem 0 !important;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0d6efd;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 9999;
}

.skip-to-content:focus {
    top: 0;
}

/* ===== PRINT FIXES ===== */

@media print {
    /* Hide mobile-specific elements */
    .navbar-toggler,
    .offcanvas,
    .floating-menu-btn,
    .offcanvas-backdrop {
        display: none !important;
    }
    
    /* Reset mobile styles for print */
    .container {
        max-width: 100% !important;
        padding: 0 !important;
    }
    
    .table {
        font-size: 10px !important;
    }
}


/* ===== CUT ORDER CARD MOBILE FIXES ===== */

@media (max-width: 767px) {
    /* Card container */
    .cut-order-card {
        padding: 10px !important;
        margin: 10px !important;
        max-width: 100% !important;
    }
    
    /* Card title row */
    .card-title-row {
        flex-direction: column !important;
        align-items: center !important;
        min-height: auto !important;
        gap: 10px !important;
    }
    
    .card-title-center {
        position: static !important;
        transform: none !important;
        font-size: 1.2rem !important;
        margin-bottom: 10px !important;
    }
    
    /* Info table wrapper */
    .info-table-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin-bottom: 15px !important;
    }
    
    /* Info table */
    .info-table {
        font-size: 0.85rem !important;
        min-width: 100% !important;
    }
    
    .info-table td {
        padding: 6px 4px !important;
        font-size: 0.8rem !important;
    }
    
    .info-table .info-label {
        min-width: 80px !important;
        font-size: 0.75rem !important;
    }
    
    .info-table .info-value {
        min-width: 80px !important;
        font-size: 0.8rem !important;
        word-break: break-word !important;
        white-space: normal !important;
    }
    
    /* Logo section */
    .logo-section {
        transform: scale(0.8) !important;
    }
    
    /* Grid for measurements */
    .grid-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .grid-header,
    .grid-row {
        font-size: 0.75rem !important;
    }
    
    .grid-cell {
        padding: 4px 2px !important;
        min-width: 60px !important;
    }
}

@media (max-width: 400px) {
    .cut-order-card {
        padding: 5px !important;
        margin: 5px !important;
    }
    
    .card-title-center {
        font-size: 1rem !important;
    }
    
    .info-table {
        font-size: 0.75rem !important;
    }
    
    .info-table td {
        padding: 4px 2px !important;
        font-size: 0.7rem !important;
    }
    
    .info-table .info-label {
        min-width: 60px !important;
        font-size: 0.7rem !important;
    }
}

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

@media (max-width: 767px) {
    /* Dashboard title */
    .row h1 {
        font-size: 1.5rem !important;
        text-align: center !important;
    }
    
    /* Financial stats cards */
    .col-md-3 {
        width: 100% !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    
    .col-md-3 .card {
        margin-bottom: 1rem !important;
    }
    
    .col-md-3 .card-body {
        padding: 1.25rem !important;
    }
    
    /* Card content layout */
    .col-md-3 .card-body .d-flex {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 0.5rem !important;
    }
    
    .col-md-3 .card-body .d-flex > div {
        width: 100% !important;
        text-align: center !important;
    }
    
    .col-md-3 .card-body h6 {
        font-size: 0.9rem !important;
        margin-bottom: 0.5rem !important;
        text-align: center !important;
    }
    
    .col-md-3 .card-body h3 {
        font-size: 1.75rem !important;
        text-align: center !important;
        margin-bottom: 0.5rem !important;
    }
    
    .col-md-3 .card-body small {
        font-size: 0.8rem !important;
        text-align: center !important;
        display: block !important;
    }
    
    /* Icon positioning */
    .col-md-3 .card-body i.display-4 {
        font-size: 2.5rem !important;
        opacity: 0.15 !important;
        margin-top: 0.5rem !important;
    }
    
    /* Subscription alerts */
    .alert .d-flex {
        flex-direction: column !important;
        gap: 1rem !important;
        text-align: center !important;
    }
    
    .alert .btn {
        width: 100% !important;
    }
    
    /* Notifications card */
    .card-header .d-flex {
        flex-direction: column !important;
        gap: 0.5rem !important;
        text-align: center !important;
    }
    
    .card-header .btn {
        width: 100% !important;
    }
}

@media (max-width: 400px) {
    .col-md-3 .card-body h3 {
        font-size: 1.5rem !important;
    }
    
    .col-md-3 .card-body h6 {
        font-size: 0.85rem !important;
    }
    
    .col-md-3 .card-body i.display-4 {
        font-size: 2rem !important;
    }
}

/* ===== DASHBOARD SECTION HEADERS ===== */

@media (max-width: 767px) {
    .row h4 {
        font-size: 1.25rem !important;
        text-align: center !important;
        margin-bottom: 1.5rem !important;
    }
    
    /* Recent activities section */
    .col-md-6,
    .col-md-4 {
        width: 100% !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        margin-bottom: 1rem !important;
    }
    
    /* Dashboard cards */
    .dashboard-card {
        margin-bottom: 1rem !important;
    }
    
    .dashboard-card .card-body {
        padding: 1rem !important;
    }
    
    .dashboard-card h5 {
        font-size: 1.1rem !important;
        text-align: center !important;
    }
    
    .dashboard-card p {
        font-size: 0.9rem !important;
        text-align: center !important;
    }
    
    .dashboard-card .btn {
        width: 100% !important;
        margin-top: 0.5rem !important;
    }
}


/* ===== CUT ORDER VIEW PAGE MOBILE FIXES ===== */

@media (max-width: 767px) {
    /* Prevent horizontal scroll - CRITICAL FIX */
    body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    .container,
    .container-fluid {
        overflow-x: hidden !important;
        max-width: 100% !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100% !important;
    }
    
    .col-md-8,
    .col-md-4,
    .col-12 {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
        max-width: 100% !important;
    }
    
    /* Cards */
    .card {
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    .card-body {
        padding: 0.75rem !important;
        overflow-x: hidden !important;
        max-width: 100% !important;
    }
    
    /* Page header */
    .cut-orders-view .d-flex.align-items-center {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    .cut-orders-view h1 {
        font-size: 1.5rem !important;
        word-break: break-word !important;
        max-width: 100% !important;
    }
    
    /* Button groups */
    .card-header {
        overflow-x: hidden !important;
        max-width: 100% !important;
    }
    
    .card-header .btn-group {
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .card-header .btn-group .btn {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0.25rem 0 !important;
        border-radius: 0.375rem !important;
        white-space: normal !important;
        word-break: break-word !important;
    }
    
    /* Info sections */
    .info-section {
        padding: 0.75rem !important;
        margin-bottom: 1rem !important;
        overflow-x: hidden !important;
        max-width: 100% !important;
    }
    
    .section-header {
        font-size: 0.9rem !important;
        margin-bottom: 0.5rem !important;
        word-break: break-word !important;
        max-width: 100% !important;
    }
    
    /* Tables in info sections */
    .info-section table {
        display: block !important;
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        table-layout: fixed !important;
    }
    
    .info-section table tbody {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .info-section table tr {
        display: flex !important;
        flex-wrap: wrap !important;
        margin-bottom: 0.75rem !important;
        padding-bottom: 0.75rem !important;
        border-bottom: 1px solid #e9ecef !important;
        max-width: 100% !important;
    }
    
    .info-section table tr:last-child {
        border-bottom: none !important;
    }
    
    .info-section table td {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.25rem 0.5rem !important;
        text-align: right !important;
        white-space: normal !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        box-sizing: border-box !important;
    }
    
    /* Label and value styling */
    .info-section table td .text-muted {
        display: block !important;
        font-weight: 600 !important;
        margin-bottom: 0.25rem !important;
        color: #6c757d !important;
        word-break: break-word !important;
        max-width: 100% !important;
    }
    
    .info-section table td strong,
    .info-section table td .badge {
        display: inline-block !important;
        font-size: 1rem !important;
        word-break: break-word !important;
        max-width: 100% !important;
    }
    
    /* Financial information - special styling */
    .info-section table td .fs-5 {
        font-size: 1.25rem !important;
        word-break: break-word !important;
    }
    
    .info-section table td .badge.fs-5 {
        font-size: 1.1rem !important;
        padding: 0.5rem 1rem !important;
        max-width: 100% !important;
        white-space: normal !important;
    }
    
    /* Related work orders section */
    .shadow-sm {
        overflow-x: hidden !important;
        max-width: 100% !important;
    }
    
    /* Related work orders table */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    .table-responsive table {
        min-width: 600px !important;
        max-width: none !important;
    }
    
    .table-responsive table th,
    .table-responsive table td {
        padding: 0.5rem 0.25rem !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
    }
    
    .table-responsive .btn-sm {
        font-size: 0.75rem !important;
        padding: 0.25rem 0.5rem !important;
        white-space: nowrap !important;
    }
    
    /* Field rows */
    .field-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.25rem !important;
        margin-bottom: 0.75rem !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    .field-row .text-muted {
        font-weight: 600 !important;
        margin-bottom: 0.25rem !important;
        word-break: break-word !important;
        max-width: 100% !important;
    }
    
    .field-row strong,
    .field-row span:not(.text-muted),
    .field-row a {
        width: 100% !important;
        max-width: 100% !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }
    
    /* Links */
    a {
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }
}

@media (max-width: 400px) {
    .info-section {
        padding: 0.5rem !important;
    }
    
    .section-header {
        font-size: 0.85rem !important;
    }
    
    .info-section table td {
        padding: 0.25rem !important;
        font-size: 0.85rem !important;
    }
    
    .info-section table td .fs-5 {
        font-size: 1.1rem !important;
    }
    
    .info-section table td .badge.fs-5 {
        font-size: 0.95rem !important;
        padding: 0.375rem 0.75rem !important;
    }
}

/* ===== CUT ORDER VIEW - CARD HEADER RESPONSIVE ===== */

@media (max-width: 767px) {
    .card-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
    }
    
    .card-header h5 {
        text-align: center !important;
        margin-bottom: 0.5rem !important;
    }
    
    .card-header .d-flex {
        flex-direction: column !important;
    }
    
    .card-header .btn-group-sm {
        flex-direction: column !important;
        width: 100% !important;
    }
    
    .card-header .btn-group-sm .btn {
        width: 100% !importantant;
        margin: 0.25rem 0 !important;
        border-radius: 0.375rem !important;
    }
}
        margin: 0.25rem 0 !important;
        border-radius: 0.375rem !important;
    }
}

/* ===== CUT ORDER VIEW - FIX HORIZONTAL SCROLL ===== */

@media (max-width: 767px) {
    /* CRITICAL: Remove white-space: nowrap from all table cells */
    .info-section table td {
        white-space: normal !important;
        word-wrap: break-word !important;
        word-break: break-word !important;
    }
    
    /* Remove fixed widths from table cells */
    .info-section table td[style*="width"] {
        width: auto !important;
        max-width: none !important;
    }
    
    /* Force tables to be responsive */
    .info-section table {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    .info-section table tbody {
        display: block !important;
        width: 100% !important;
    }
    
    .info-section table tr {
        display: block !important;
        width: 100% !important;
        margin-bottom: 1rem !important;
        padding-bottom: 1rem !important;
        border-bottom: 1px solid #e9ecef !important;
    }
    
    .info-section table tr:last-child {
        border-bottom: none !important;
    }
    
    .info-section table td {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.5rem 0 !important;
        text-align: right !important;
        box-sizing: border-box !important;
    }
    
    /* Labels styling */
    .info-section table td .text-muted {
        display: block !important;
        font-weight: 600 !important;
        margin-bottom: 0.25rem !important;
        color: #6c757d !important;
    }
    
    /* Values styling */
    .info-section table td strong,
    .info-section table td span:not(.text-muted),
    .info-section table td .badge {
        display: inline-block !important;
        word-break: break-word !important;
        max-width: 100% !important;
    }
    
    /* Ensure all content respects container width */
    * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Override any inline styles that might cause overflow */
    [style*="white-space: nowrap"] {
        white-space: normal !important;
    }
    
    [style*="width:"] {
        width: auto !important;
    }
}

@media (max-width: 400px) {
    .info-section table td {
        padding: 0.375rem 0 !important;
        font-size: 0.9rem !important;
    }
}


/* ===== EXTERNAL PROCESSING PAGE MOBILE FIXES ===== */

@media (max-width: 767px) {
    /* Workshops Filter Section */
    .card-header .row.g-2 .col-12 {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }
    
    .card-header .row.g-2 .input-group {
        width: 100% !important;
    }
    
    .card-header .row.g-2 input[type="text"] {
        width: 100% !important;
    }
    
    /* Work Orders Filter Section - Stack vertically on mobile */
    .card-header .row.g-2 .col-12.col-md-4,
    .card-header .row.g-2 .col-12.col-md-3,
    .card-header .row.g-2 .col-12.col-md-2 {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Statistics Cards */
    .row.mb-4 .col-md-4 {
        width: 100% !important;
        margin-bottom: 1rem !important;
    }
    
    /* Tab Navigation */
    .nav-tabs {
        flex-wrap: wrap !important;
    }
    
    .nav-tabs .nav-item {
        flex: 1 1 auto !important;
        min-width: 100px !important;
    }
    
    .nav-tabs .nav-link {
        font-size: 0.85rem !important;
        padding: 0.5rem 0.25rem !important;
        text-align: center !important;
    }
    
    /* Table Actions */
    .table td[width="150"],
    .table td[width="280"],
    .table td[width="100"] {
        width: auto !important;
        min-width: 120px !important;
    }
    
    /* Button Groups in Tables */
    .table .btn-group {
        flex-direction: column !important;
        gap: 0.25rem !important;
    }
    
    .table .btn-group .btn {
        width: 100% !important;
        margin: 0 !important;
    }
}

/* Desktop - Ensure proper alignment and spacing */
@media (min-width: 768px) {
    /* Work Orders Filters - Compact Layout */
    #work-orders-pane .card-header .row.g-2 {
        justify-content: flex-start !important;
    }
    
    #work-orders-pane .card-header .col-md-4 {
        flex: 0 0 auto !important;
        width: 33.33% !important;
    }
    
    #work-orders-pane .card-header .col-md-3 {
        flex: 0 0 auto !important;
        width: 25% !important;
    }
    
    #work-orders-pane .card-header .col-md-2 {
        flex: 0 0 auto !important;
        width: 16.66% !important;
    }
}

@media (max-width: 400px) {
    .nav-tabs .nav-link {
        font-size: 0.75rem !important;
        padding: 0.5rem 0.15rem !important;
    }
    
    .nav-tabs .nav-link i {
        display: block !important;
        margin-bottom: 0.25rem !important;
    }
}
