/* ============================================
   Responsive Width & Overflow Control
   Ensures pages fit viewport width
   ============================================ */

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

/* Wrapper should not exceed viewport */
#wrapper {
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
    display: flex;
}

/* Content page should fit within viewport */
.content-page {
    flex: 1;
    min-width: 0; /* Allows flex item to shrink below its content size */
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Content container with proper constraints */
.content {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Container fluid should respect viewport */
.container-fluid {
    max-width: 100%;
    width: 100%;
    padding-left: 15px;
    padding-right: 15px;
    box-sizing: border-box;
    margin-left: auto;
    margin-right: auto;
}

/* Ensure rows don't cause overflow */
.row {
    margin-left: -15px;
    margin-right: -15px;
    max-width: 100%;
    box-sizing: border-box;
}

.row > * {
    padding-left: 15px;
    padding-right: 15px;
    box-sizing: border-box;
}

/* Tables should be responsive */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: block;
}

.table-responsive > .table {
    width: 100%;
    margin-bottom: 0;
    min-width: 600px; /* Minimum width for readability */
}

/* Regular tables should also be contained */
.table {
    max-width: 100%;
    table-layout: auto;
    word-wrap: break-word;
}

/* Cards should not exceed container */
.card {
    max-width: 100%;
    box-sizing: border-box;
}

/* Form controls should fit */
.form-control,
.form-control-modern,
select.form-control {
    max-width: 100%;
    box-sizing: border-box;
}

/* Input groups should be contained */
.input-group {
    max-width: 100%;
    box-sizing: border-box;
}

/* Old header/menu - hidden with new sidebar layout */
.navbar-custom-modern,
.horizontal-menu-bar {
    display: none !important;
}

/* Fix for Bootstrap columns */
[class*="col-"] {
    box-sizing: border-box;
}

/* Prevent images from causing overflow */
img {
    max-width: 100%;
    height: auto;
}

/* Ensure buttons and badges don't break layout */
.btn, .badge {
    white-space: nowrap;
    box-sizing: border-box;
}

/* Text should wrap properly */
p, span, div, td, th {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Long text in table cells - only apply ellipsis when not in responsive wrapper */
.table-responsive .table td,
.table-responsive .table th {
    max-width: none;
    white-space: normal;
    word-wrap: break-word;
}

/* For tables not in responsive wrapper, limit cell width */
.table:not(.table-responsive .table) td,
.table:not(.table-responsive .table) th {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table td.long-text, .table th.long-text {
    max-width: none;
    white-space: normal;
    word-wrap: break-word;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .row {
        margin-left: -10px;
        margin-right: -10px;
    }
    
    .row > * {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .content-page {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }
    
    .table-responsive > .table {
        min-width: 500px;
    }
}

@media (max-width: 576px) {
    .container-fluid {
        padding-left: 8px;
        padding-right: 8px;
    }
    
    .row {
        margin-left: -8px;
        margin-right: -8px;
    }
    
    .row > * {
        padding-left: 8px;
        padding-right: 8px;
    }
    
    .table-responsive > .table {
        min-width: 400px;
        font-size: 12px;
    }
    
    .table td, .table th {
        padding: 8px 4px;
        font-size: 12px;
    }
}

/* Fix for specific page elements */
.page-title-box {
    max-width: 100%;
    box-sizing: border-box;
}

/* Ensure filters and search bars fit */
.card-body .row {
    max-width: 100%;
}

/* Fix for view_stock.php table specifically */
#medicationTableBody,
#supplyTableBody {
    max-width: 100%;
}

/* Prevent fixed width elements from breaking layout - but allow tables to scroll */
.container-fluid > *:not(.table-responsive):not(.table) {
    max-width: 100%;
}

/* Exception for specific elements that need fixed width */
input[type="number"],
input[type="date"],
input[type="time"],
select {
    max-width: 100%;
}

/* Ensure modals are centered and fit */
.modal {
    overflow-x: hidden;
}

.modal-content {
    max-width: 100%;
    box-sizing: border-box;
}

/* Notification container should not cause overflow */
#notification-container {
    max-width: 90vw;
    left: 50%;
    transform: translateX(-50%);
}

/* Footer should fit */
footer, .login-footer-custom {
    max-width: 100vw;
    width: 100%;
    box-sizing: border-box;
}

