/* ================================================================
   responsive.css — Global mobile overrides for MV Reports
   Loaded after all other stylesheets via top_includes.php.
   Fixes systemic patterns that appear on every page.
   ================================================================ */


/* ── 1. PREVENT HORIZONTAL PAGE OVERFLOW
   Any fixed-width element wider than the viewport causes the entire
   page to scroll sideways. Kill it at the root.
──────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    body {
        overflow-x: hidden;
    }
    /* Bootstrap row negative margins cause bleed on narrow screens */
    #page-wrapper > .row {
        margin-left: 0;
        margin-right: 0;
    }
    #page-wrapper > .row > [class*="col-"] {
        padding-left: 8px;
        padding-right: 8px;
    }
    /* Reduce page wrapper padding on mobile */
    #page-wrapper {
        padding: 10px 0 80px; /* bottom padding clears any fixed bottom bars */
    }
}


/* ── 2. TOP-PANEL HEADER
   Converts the float-based layout (h1 left / controls right)
   to flexbox so controls wrap below the title on small screens.
──────────────────────────────────────────────────────────────────── */
.top-panel-header {
    overflow: visible; /* was `hidden` as a float clearfix — not needed with flex */
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

/* Remove floats from direct children — flex handles the layout */
.top-panel-header > h1,
.top-panel-header > h2,
.top-panel-header > h3,
.top-panel-header > h4,
.top-panel-header > h5,
.top-panel.top-panel-bodyless h1 {
    float: none !important;
    margin: 0;
    flex-shrink: 1;
    min-width: 0;
}

.top-panel-controls {
    float: none !important;
    padding-top: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

@media (max-width: 767px) {
    /* Stack title above controls */
    .top-panel-header {
        flex-direction: column;
        align-items: flex-start;
    }
    /* Controls stretch to full width and buttons expand equally */
    .top-panel-controls {
        width: 100%;
    }
    .top-panel-controls > .btn,
    .top-panel-controls > a.btn {
        flex: 1 1 auto;
        text-align: center;
        white-space: nowrap;
    }
    /* Reduce panel radius + padding on mobile */
    .top-panel {
        border-radius: 12px;
        padding: 14px 12px;
    }
    .top-panel.top-panel-bodyless {
        padding: 12px 0;
    }
    /* Smaller page title on mobile */
    .top-panel.top-panel-bodyless h1 {
        font-size: 20px !important;
        font-weight: 600;
    }
}


/* ── 3. MODALS — full-screen on mobile, 90% on tablet
   Bootstrap 3 .modal-dialog is ~500px by default with no mobile
   override. The inline style="width:80%" on large modals makes it
   worse. We override everything with !important.
──────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .modal-dialog {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }
    .modal-content {
        border-radius: 0 !important;
        min-height: 100dvh; /* dvh = dynamic viewport height, accounts for mobile browser chrome */
    }
    /* Reduce header/body/footer padding on small screens */
    .modal-header {
        padding: 14px 16px;
    }
    .modal-body {
        padding: 16px;
    }
    .modal-footer {
        padding: 12px 16px;
        border-bottom-left-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    /* Tablet: modals use 90% of screen width */
    .modal-dialog,
    .modal-dialog.modal-lg {
        width: 92% !important;
        margin: 20px auto !important;
    }
}

/* ── 3a. MODAL TAB BARS — horizontal scroll instead of wrapping
──────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .modal .nav-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        border-bottom: 1px solid #ddd;
    }
    .modal .nav-tabs::-webkit-scrollbar { display: none; } /* Chrome/Safari */
    .modal .nav-tabs > li {
        display: inline-block;
        float: none;
        flex-shrink: 0;
    }
    .modal .nav-tabs > li > a {
        white-space: nowrap;
        padding: 8px 12px;
    }
}


/* ── 4. FORMS INSIDE MODALS & PANELS
   Bootstrap col-md-* columns have no xs fallback padding fix,
   causing cramped rows on mobile.
──────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    /* Tighten gutter inside modals/panels on mobile */
    .modal-body .row,
    .top-panel-body .row {
        margin-left: -6px;
        margin-right: -6px;
    }
    .modal-body .row > [class*="col-"],
    .top-panel-body .row > [class*="col-"] {
        padding-left: 6px;
        padding-right: 6px;
    }
    /* Breathing room between stacked form groups */
    .modal-body .form-group,
    .top-panel-body .form-group {
        margin-bottom: 12px;
    }
}


/* ── 5. TOUCH-FRIENDLY INTERACTIVE ELEMENTS
   Minimum tap target of 44px (Apple HIG / WCAG guideline).
──────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .btn {
        min-height: 38px;
    }
    .btn-xs {
        min-height: 28px; /* xs buttons stay compact */
    }
    /* Form controls: taller for fat-finger friendliness */
    .form-control {
        height: 40px;
        font-size: 15px;
    }
    textarea.form-control {
        height: auto;
    }
    select.form-control {
        height: 40px;
    }
    /* Select2 containers don't overflow their parent */
    .select2-container {
        max-width: 100%;
    }
    .select2-container .select2-selection--single {
        height: 40px;
        line-height: 38px;
    }
}


/* ── 6. TABLES
   Ensure ALL tables scroll horizontally on mobile regardless of
   whether the page author remembered to add .table-responsive.
──────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    /* Auto-wrap any bare table in an overflow container */
    .table-container,
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* Remove Bootstrap 3's border on the wrapper */
        border: none;
    }
    /* Legible minimum font in tables */
    .table > thead > tr > th,
    .table > tbody > tr > td,
    .table > tfoot > tr > td {
        font-size: 13px;
        white-space: nowrap; /* prevents ugly text wrapping inside cells */
    }
    /* Slightly reduce cell padding */
    .table > thead > tr > th,
    .table > tbody > tr > td {
        padding: 6px 8px;
    }
}


/* ── 7. TOPBAR / NAVIGATION
   Logo width is hardcoded as an inline style (width: 250px) in
   topbar.php. We can't change inline styles with CSS, but we CAN
   make the navbar-brand flexible via max-width.
──────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .navbar-brand {
        max-width: calc(100vw - 90px) !important;
        overflow: hidden;
        padding-top: 5px;
        padding-bottom: 5px;
    }
    .navbar-brand img {
        max-height: 36px;
        width: auto;
    }
    /* Topbar: shrink overall height slightly on very small screens */
    .navbar.navbar-static-top {
        min-height: 46px;
    }
}

/* Omni-search bar: never wider than viewport */
.omni-search {
    max-width: min(300px, calc(100vw - 24px));
}


/* ── 8. PAGINATION
   Bootstrap pagination is already responsive but gets tiny on phones.
──────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .pagination > li > a,
    .pagination > li > span {
        padding: 7px 10px;
        font-size: 13px;
    }
}


/* ── 9. MVMST SEARCH WIDGET
   Previously table-based with hardcoded inline widths; now flex.
──────────────────────────────────────────────────────────────────── */
.mvmst-search-widget { width: 100%; }

.mvmst-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    margin-bottom: 6px;
}

.mvmst-col { min-width: 0; }

/* Desktop: fixed widths for field + operation, value fills the rest */
.mvmst-field-col  { flex: 0 0 150px; }
.mvmst-op-col     { flex: 0 0 150px; }
.mvmst-value-col  { flex: 1 1 auto; }
.mvmst-value-col .input-group { width: 100%; }
.mvmst-search-col { flex: 0 0 auto; }

/* Neaten up the controls */
.mvmst-search-widget .form-control { border-radius: 4px; }
.mvmst-search-col .btn-search { white-space: nowrap; }

@media (max-width: 767px) {
    .mvmst-row { flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }

    /* Field + operation: side-by-side, each 50% */
    .mvmst-field-col,
    .mvmst-op-col     { flex: 1 1 calc(50% - 2px); }

    /* Value input: full width */
    .mvmst-value-col  { flex: 1 1 100%; }

    /* Search button: full width, centred */
    .mvmst-search-col { flex: 1 1 100%; }
    .mvmst-search-col .btn-search { width: 100%; display: flex; justify-content: center; align-items: center; gap: 6px; }
}

/* ── 10. UTILITY CLASSES
──────────────────────────────────────────────────────────────────── */

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

/* Truncate long text in a cell/label */
.text-truncate-mobile {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Stack a flexbox row vertically on mobile */
@media (max-width: 767px) {
    .flex-stack-mobile {
        flex-direction: column !important;
    }
    .flex-stack-mobile > * {
        width: 100% !important;
    }
}

/* Pill-label / status badges: don't get cut off */
.pill-label {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}
