/* =====================================================================
   Global Responsive Fixes  (Lead Generating System)
   Loaded on every page via components/header.blade.php (after style.css).
   Goal: make the whole app usable on mobile without changing the
   desktop design. Most rules are inside mobile/tablet media queries,
   so wide screens stay exactly as they were.
   ===================================================================== */

/* ---- Never let the whole page scroll sideways ---- */
html,
body {
    max-width: 100%;
}
body {
    overflow-x: hidden;
}

/* ---- Media should always fit its container ---- */
img,
video,
iframe,
canvas,
svg,
embed,
object {
    max-width: 100%;
    height: auto;
}

/* ---- Pre-formatted / long text should wrap, not overflow ---- */
pre,
code {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ---- Toastr popups sit BELOW the fixed header, not inside it ---- */
#toast-container.toast-top-right,
#toast-container.toast-top-left,
#toast-container.toast-top-center,
#toast-container.toast-top-full-width {
    top: 80px !important;
}
@media (max-width: 575.98px) {
    #toast-container.toast-top-right,
    #toast-container.toast-top-left,
    #toast-container.toast-top-center,
    #toast-container.toast-top-full-width {
        top: 70px !important;
    }
}

/* =====================================================================
   ALL SCREENS (web + mobile): wide tables scroll instead of breaking
   the page. Applies on desktop too, so a very wide report table gets
   its own horizontal scrollbar rather than stretching the whole layout.
   DataTables-managed tables (.dataTable) keep their own layout.
   ===================================================================== */
table:not(.dataTable) {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive,
.dataTables_wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* =====================================================================
   TABLET and below  (<= 991px)
   ===================================================================== */
@media (max-width: 991.98px) {

    /* Tighter page padding so content uses the full width */
    .container,
    .container-fluid,
    .content-body {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Form fields take full width and stop overflowing */
    .form-control,
    .form-group .select2,
    .select2,
    .select2-container {
        width: 100% !important;
        max-width: 100%;
    }

    /* Buttons wrap their text rather than forcing the page wider */
    .btn {
        white-space: normal;
        word-wrap: break-word;
    }

    /* Cancel hard-coded inline left margins/offsets that break mobile
       (e.g. the "Download APK" button on the login page used
       margin-left: 600px). */
    [style*="margin-left: 600px"],
    [style*="margin-left:600px"] {
        margin-left: 0 !important;
    }

    /* Bootstrap grid: columns stack full width on small screens */
    .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6,
    .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
        width: 100%;
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Cards / panels use the full width */
    .card,
    .panel,
    .box {
        width: 100%;
    }

    /* ---- Page title / greeting row (site-wide) ----
       Every page built on the dashboard layouts opens with a
       .row.page-titles holding a greeting ("Hello, Welcome ...") in one
       .col and an <ol class="breadcrumb"> in another. On desktop they
       share one row; on small screens they get crammed together, so
       stack them cleanly with breathing room. This is global, so it
       applies to every role's pages, not just the dashboard. */
    .page-titles {
        margin-bottom: 16px;
    }
    .page-titles > .col,
    .page-titles > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
    /* Long greeting ("Hello, Welcome <full name>") must wrap cleanly on
       narrow screens instead of running tight lines into each other. */
    .page-titles h4 {
        line-height: 1.4;
        word-break: break-word;
        overflow-wrap: anywhere;
    }
    .page-titles h4 span {
        display: inline;
    }
    .page-titles .breadcrumb {
        float: none;
        margin-top: 8px;
        margin-bottom: 0;
        padding-left: 0;
    }

    /* Filter row: Month / Date / Submit each take full width and stack,
       with spacing between them instead of three tight 25% columns */
    .dashboard-filter-row .col-3 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 12px;
    }
    /* Drop the spacer <br> above Submit so the button sits right below */
    .dashboard-filter-row .col-3 br {
        display: none;
    }
    .dashboard-filter-row #submitBtn {
        margin-top: 0 !important;
    }

    /* ---- My Leads: colored filter buttons (Active / Reject / ...) ----
       On desktop they sit inline; on small screens they wrap unevenly
       and look cramped. Lay them out as a tidy, evenly spaced wrap with
       a comfortable tap height. The .lead-filter-buttons wrapper class
       is on the My Leads filter group only, so other .btn groups are
       untouched. */
    .lead-filter-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .lead-filter-buttons .btn {
        flex: 1 1 auto;
        margin: 0;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
    /* Neutralise the stray top margin on the "Verified" button so the
       wrap stays even */
    .lead-filter-buttons .btn.mt-1 {
        margin-top: 0 !important;
    }

    /* ---- Number system pages: header button row ----
       (Show Reserved Number / Lead Dashboard / Logout, plus the per-role
       variants on the number-* views.) On desktop these use
       float-left / float-right and sit inline. On small screens the
       floats glue them together with no spacing, so lay them out as an
       evenly spaced, wrapping flex row with a tap-friendly height. The
       .number-header-buttons wrapper is only on these number-view button
       rows, so other .btn / .float-* elements are untouched. */
    .number-header-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        float: none;
        margin-bottom: 12px;
    }
    .number-header-buttons .btn {
        float: none;
        flex: 1 1 auto;
        margin: 0;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    /* ---- DataTables "Show N entries" + "Search:" controls ----
       Stack them full width and left-align so they don't crowd each
       other on small screens. Only affects the mobile layout. */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none;
        text-align: left;
        width: 100%;
        margin-bottom: 10px;
    }
    .dataTables_wrapper .dataTables_length label,
    .dataTables_wrapper .dataTables_filter label {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 0;
    }
    .dataTables_wrapper .dataTables_filter input {
        flex: 1 1 auto;
        min-width: 0;
        margin-left: 0;
    }
    /* Promote the same treatment to the info text and the pager so every
       DataTable (all roles) stacks its controls instead of crowding. */
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none;
        text-align: left;
        width: 100%;
        margin-top: 8px;
    }
    .dataTables_wrapper .dataTables_paginate {
        padding-top: 4px;
    }

    /* ---- Floated button / header rows (site-wide) ----
       List and detail pages across roles drop standalone buttons and
       headers into float-left / float-right (and the template's .left /
       .right helpers) wrappers. On desktop they sit inline; on small
       screens the floats glue them together with no spacing. Neutralise
       the float so such rows stack and wrap. Bootstrap .btn-group
       children do NOT carry float-* classes, so button groups stay
       joined. The app's sidebar/header chrome uses pull-left /
       pull-right (not float-*), so it is left untouched. */
    .float-left,
    .float-right {
        float: none !important;
    }
    .btn.float-left,
    .btn.float-right {
        margin-bottom: 8px;
    }

    /* ---- Forms (site-wide) ----
       Labels and controls go full width; horizontal forms left-align
       their labels; and rows of form columns stack regardless of the
       col-* size used (md / sm / xs), so multi-column forms become a
       single readable column on small screens. */
    .col-form-label,
    .form-horizontal label,
    .form-group > label {
        width: 100%;
        max-width: 100%;
        text-align: left !important;
    }
    select.form-control,
    textarea.form-control,
    .custom-select {
        width: 100% !important;
        max-width: 100%;
    }
    .form-row > [class*="col-"],
    .form-group.row > [class*="col-"],
    form .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
    /* Button rows inside forms wrap with spacing instead of butting up */
    .form-group.row .btn,
    .form-horizontal .btn {
        margin-bottom: 8px;
    }

    /* ---- Cards / panels / boxes (site-wide) ----
       Trim the generous desktop padding so content keeps more usable
       width on small screens. */
    .card-body,
    .panel-body,
    .box-body {
        padding: 15px;
    }
}

/* =====================================================================
   PHONES  (<= 575px)
   ===================================================================== */
@media (max-width: 575.98px) {

    /* Comfortable base font and spacing on phones */
    body {
        font-size: 14px;
    }

    .container,
    .container-fluid,
    .content-body {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Headings shouldn't dwarf a small screen */
    h1 { font-size: 1.6rem; }
    h2 { font-size: 1.4rem; }
    h3 { font-size: 1.2rem; }

    /* Smaller, tappable table text */
    table:not(.dataTable) th,
    table:not(.dataTable) td {
        font-size: 13px;
        padding: 6px 8px;
    }

    /* Modals fit the screen */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

    /* Even tighter card padding on narrow phones */
    .card-body,
    .panel-body,
    .box-body {
        padding: 12px;
    }

    /* My Leads filter buttons go roughly two-per-row (full-width-ish)
       for easy tapping on narrow phones */
    .lead-filter-buttons .btn {
        flex: 1 1 calc(50% - 4px);
    }

    /* Number system header buttons stack full width on narrow phones
       so each is easy to tap */
    .number-header-buttons .btn {
        flex: 1 1 100%;
    }
}
