/* =====================================================================
   MOBILE-APP LAYER
   Loaded after theme.min.css / custome-css.css, so on equal specificity
   the rules here win. Three jobs:

     1. Native-app feel on touch devices: tap targets, no double-tap
        zoom delay, controlled overscroll, safe-area (notch/home-bar)
        padding, installable-standalone polish.
     2. Fix the places the base template overflows on phones: wide
        tables, fixed-width dropdowns, the chat panel, header density.
     3. Density tweaks so pages fit and read well on small screens.

   Breakpoints mirror the base theme: 991.98px (phone/tablet, where the
   sidebar goes off-canvas) and 575.98px (phones).
   ===================================================================== */

/* ---------------------------------------------------------------
   1. Base feel - all devices
   --------------------------------------------------------------- */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    /* Stop the whole page rubber-banding like a web page; keep it app-like */
    overscroll-behavior-y: contain;
    /* Remove the grey flash on tap in Android/Chrome */
    -webkit-tap-highlight-color: transparent;
}

/* Kill the 300ms double-tap-zoom gesture on interactive controls only.
   Pinch zoom stays available (accessibility), double-tap zoom goes away. */
a, button, [role="button"], .btn, .dropdown-item, .nav-link,
.form-check-input, .form-check-label, .page-link, .nav-tabs .nav-link {
    touch-action: manipulation;
}

/* The chrome is app chrome, not selectable text */
.nxl-navigation,
.nxl-header,
footer.footer {
    -webkit-user-select: none;
    user-select: none;
}

/* Momentum scrolling inside the off-canvas sidebar on iOS */
.nxl-navigation {
    -webkit-overflow-scrolling: touch;
}

/* Notch / home-indicator safe areas */
.nxl-header {
    padding-top: env(safe-area-inset-top, 0);
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
}

footer.footer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
}

/* ---------------------------------------------------------------
   2. Tables - touch scrolling
   (scripts.blade.php wraps bare tables in .table-responsive; the
   rules below make that wrapper feel right and cover DataTables)
   --------------------------------------------------------------- */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.table-responsive > .table {
    margin-bottom: 0;
}

@media print {
    /* A print-out must show the whole table, not a clipped first column */
    .table-responsive {
        overflow-x: visible !important;
    }
}

/* ---------------------------------------------------------------
   3. Phone / tablet layout  (<= 991.98px, sidebar goes off-canvas)
   --------------------------------------------------------------- */
@media (max-width: 991.98px) {

    /* Shorter fixed header - the 80px desktop bar wastes phone height */
    .nxl-header {
        min-height: 64px;
    }

    .nxl-header .header-wrapper {
        align-items: center;
        padding: 0 12px;
        min-height: 64px;
    }

    /* Desktop-only controls out of the phone header */
    .nxl-header .nxl-navigation-toggle {
        display: none !important;
    }

    .header-left {
        gap: 10px !important;
    }

    /* Shell must track the shorter header (theme uses 80px / 95px) */
    .nxl-container {
        top: 64px;
        min-height: calc(100vh - 64px);
    }

    .nxl-content {
        padding-top: 24px;
        padding-left: 12px;
        padding-right: 12px;
        padding-bottom: 24px;
    }

    /* Keep the page-header next to the content, not floating in space */
    .page-header {
        margin-bottom: 12px;
    }

    /* Horizontal overflow guard. NEVER put overflow-x on <html> or <body>:
       those values propagate to the viewport and kill vertical page scrolling
       in Chromium (the whole document becomes unscrollable on phones). Tables
       are wrapped per-table and dropdowns are width-capped; this clip on the
       content box catches anything else without touching page scroll. */
    .nxl-content {
        overflow-x: clip;
    }

    /* DataTables wrappers scroll per-table like everything else */
    .dataTables_wrapper {
        overflow-x: auto;
    }
}

/* ---------------------------------------------------------------
   3b. Small tablets & phones  (<= 767.98px)
   --------------------------------------------------------------- */
@media (max-width: 767.98px) {

    /* ---- Detail-page tab bars (customer/supplier/user/branch/bank view):
            on screens this narrow the nav-tabs strip is hidden and the tabs
            render as links inside the header "more" dropdown instead (those
            links carry d-md-none). ---- */
    .detail-tabs {
        display: none !important;
    }

    .detail-menu-bar .page-content-right-sidebar-wrapper {
        width: 100%;
    }

    .detail-menu-bar .page-content-right-sidebar-wrapper > .d-flex {
        flex-wrap: wrap;
    }

    .detail-menu-bar .page-header-right-items-wrapper {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* ---- DataTables: "Show N entries" and the Search box share one row
            instead of stacking. Grid (not flex) so the search column
            deterministically gets all remaining width; the length column's
            nowrap label + select make flex-basis distribution flaky.
            The theme's 25px row padding is trimmed to give them room. ---- */
    .dataTables_wrapper div.row:first-child,
    .dataTables_wrapper div.row:last-child {
        padding: 10px 12px;
    }

    .dataTables_wrapper > div.row:first-child {
        display: grid;
        grid-template-columns: auto 1fr;
        gap: 8px;
        align-items: start;
    }

    /* Just the "N" dropdown is enough on phones - drop the "Show" and
       "entries" words (wrapped by the normalizer in scripts.blade.php). */
    .dataTables_wrapper div.dataTables_length .dt-entries-word,
    .dataTables_wrapper div.dataTables_length .dt-show-word {
        display: none;
    }

    /* select2's dropdown defaults to a z-index above the fixed app header
       (1025), so open dropdowns render ON TOP of the header bar on phones.
       Keep them one step below it. */
    .select2-dropdown {
        z-index: 1024 !important;
    }

    .dataTables_wrapper > div.row:first-child > [class*="col-"] {
        width: auto;
        max-width: none;
        min-width: 0; /* let the 1fr search track shrink below its content */
        padding: 0;
        margin: 0;
    }

    /* Top-align the "Show [10]" select and the search input across the row,
       and give both controls the same height (theme leaves the filter with a
       small top margin and shorter input). */
    .dataTables_wrapper div.dataTables_filter {
        margin-top: 0;
    }

    .dataTables_wrapper div.dataTables_length select,
    .dataTables_wrapper div.dataTables_filter input[type="search"] {
        height: 42px;
    }

    .dataTables_wrapper div.dataTables_length label {
        display: inline-flex;
        align-items: flex-start;
    }

    .dataTables_wrapper div.dataTables_filter label {
        display: flex;
        align-items: flex-start;
        gap: 8px;
        width: 100%;
    }

    .dataTables_wrapper div.dataTables_filter input[type="search"] {
        flex: 1 1 auto;
        width: auto;
        min-width: 0;
        margin-left: 0;
    }
}

/* ---------------------------------------------------------------
   4. Phones  (<= 575.98px)
   --------------------------------------------------------------- */
@media (max-width: 575.98px) {

    /* ---- Density: reclaim vertical space inside cards ---- */
    .card-body {
        padding: 14px 12px;
    }

    :where(.card-header) {
        padding: 12px 14px;
    }

    :where(.card-footer) {
        padding: 12px 14px;
    }

    .card {
        margin-bottom: 14px;
    }

    .nxl-content {
        padding-top: 16px;
    }

    /* ---- Forms: 16px stops iOS auto-zoom on focus ---- */
    .form-control, .form-select,
    .form-control-sm, .form-select-sm {
        font-size: 16px;
    }

    /* ---- Touch targets ---- */
    .btn {
        min-height: 40px;
    }

    .btn-sm {
        min-height: 36px;
        padding-top: 0.35rem;
        padding-bottom: 0.35rem;
    }

    .nxl-h-dropdown .dropdown-item {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .pagination .page-link {
        min-width: 38px;
        text-align: center;
    }

    /* ---- Dropdowns never wider than the screen ---- */
    .dropdown-menu.nxl-h-dropdown {
        max-width: calc(100vw - 16px);
    }

    .nxl-search-dropdown {
        max-width: calc(100vw - 16px);
    }

    .nxl-language-dropdown {
        max-width: calc(100vw - 16px);
    }

    #notificationDropdown .dropdown-menu {
        width: min(350px, calc(100vw - 20px)) !important;
    }

    .select2-dropdown {
        max-width: 100vw;
    }

    /* ---- Header avatar: smaller in the phone header. The default avatar
            is a non-square 144x180 image; without a fixed height it renders
            50px tall next to the 64px bar. ---- */
    .nxl-header .header-wrapper .user-avtar {
        width: 32px;
        height: 32px;
        object-fit: cover;
    }

    /* ---- Modals: near full-screen ---- */
    .modal-dialog {
        margin: 0.5rem;
    }

    :where(.modal-body) {
        padding: 14px 12px;
    }

    .modal-content {
        border-radius: 14px;
    }

    /* ---- Header: hide the desktop brand block if it renders wide ---- */
    .nxl-header .header-wrapper .header-left .nxl-drp-link {
        max-width: calc(100vw - 24px);
    }

    /* ---- Chat widget fits the screen (widget's own <style> is later
            in the DOM, so these need !important) ---- */
    #chatFab {
        bottom: 14px !important;
        right: 14px !important;
        width: 50px !important;
        height: 50px !important;
        font-size: 20px !important;
    }

    #chatPanel {
        right: 12px !important;
        bottom: 76px !important;
        width: calc(100vw - 24px) !important;
        height: min(540px, calc(100dvh - 130px)) !important;
        max-height: calc(100dvh - 130px) !important;
    }

    /* ---- Page-header card (page title + breadcrumb) is dead weight on
            phones - the screen is too narrow for it. Hidden below 768px. ---- */
    .page-header {
        display: none !important;
    }

    /* ---- Auth pages: the creative illustration eats half a 640px screen,
            which pushed the Login button below the fold ---- */
    .auth-creative-wrapper .col-lg-6.bg-primary img {
        max-height: 150px;
        width: auto;
    }

    .creative-card-body .mt-5 {
        margin-top: 1.25rem !important;
    }

    /* ---- Footer: stack and centre ---- */
    footer.footer {
        flex-direction: column;
        gap: 6px;
        text-align: center;
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0));
    }

    /* ---- Footer: no copyright line on phones ---- */
    footer.footer .copyright {
        display: none !important;
    }
}

/* ---------------------------------------------------------------
   5. Installed-app (standalone) polish
   --------------------------------------------------------------- */
@media all and (display-mode: standalone), all and (display-mode: fullscreen) {
    /* Inside the installed app the whole surface belongs to us */
    body {
        background: #f8f9fa;
    }
}
