/*
============================================================
ESMART CANONICAL RESPONSIVE LAYER
23 AUG 2026

Purpose:
- One cross-cutting responsive layer for signed-in customer UI
  and legacy admin UI.
- Page-specific desktop design remains in its own stylesheet.
- New mobile fixes should be added here rather than scattered
  through app-shell/dashboard/verification/admin files.
============================================================
*/


/* ============================================================
   SHARED SAFETY
   ============================================================ */

body.es-app-page,
body.es-admin-legacy {
    overflow-x: hidden;
}

body.es-app-page *,
body.es-app-page *::before,
body.es-app-page *::after,
body.es-admin-legacy *,
body.es-admin-legacy *::before,
body.es-admin-legacy *::after {
    box-sizing: border-box;
}

body.es-app-page img,
body.es-app-page svg,
body.es-app-page video,
body.es-admin-legacy img,
body.es-admin-legacy svg,
body.es-admin-legacy video {
    max-width: 100%;
    height: auto;
}


/* ============================================================
   TABLET
   ============================================================ */

@media (max-width: 991px) {

    /* --------------------------------------------------------
       CUSTOMER APP SHELL
       -------------------------------------------------------- */

    body.es-app-page .es-app-sidebar {
        width: min(310px, 88vw);
        max-width: 88vw;
    }

    body.es-app-page .es-app-content,
    body.es-app-page .es-account-page,
    body.es-app-page .es-app-main {
        min-width: 0;
    }


    /* --------------------------------------------------------
       ADMIN — RESET LEGACY BOOTSTRAP/DESKTOP GEOMETRY
       -------------------------------------------------------- */

    body.es-admin-legacy {
        width: 100%;
        min-width: 0;
    }

    body.es-admin-legacy .es-admin-topbar {
        width: 100%;
        max-width: 100%;
    }

    body.es-admin-legacy .es-admin-sidebar {
        width: min(310px, 88vw) !important;
        max-width: 88vw !important;
    }

    body.es-admin-legacy > .products,
    body.es-admin-legacy > .wthree-offers {
        width: 100% !important;
        min-width: 0 !important;
        padding: 18px 0 48px !important;
    }

    body.es-admin-legacy > .products > .container,
    body.es-admin-legacy > .wthree-offers > .container,
    body.es-admin-legacy > .es-admin-topbar + .container {
        display: block !important;

        width: calc(100% - 24px) !important;
        max-width: none !important;

        margin-left: auto !important;
        margin-right: auto !important;

        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    body.es-admin-legacy
    > .products
    > .container
    > [class*="col-md-"],

    body.es-admin-legacy
    > .products
    > .container
    > .product-w3ls-right,

    body.es-admin-legacy
    > .products
    > .container
    > .producta,

    body.es-admin-legacy
    > .wthree-offers
    .offer-bottom,

    body.es-admin-legacy
    > .wthree-offers
    .offer-bottom-grids {
        width: 100% !important;
        max-width: 100% !important;

        float: none !important;

        margin-left: 0 !important;
        margin-right: 0 !important;

        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    body.es-admin-legacy .es-admin-native-page {
        width: 100%;
        min-width: 0;
    }

    body.es-admin-legacy .es-admin-table-wrap {
        display: block;
        width: 100%;
        max-width: 100%;

        overflow-x: auto;
        overflow-y: hidden;

        -webkit-overflow-scrolling: touch;
    }

    body.es-admin-legacy .es-admin-table-wrap table {
        width: 100%;
        min-width: 720px;
    }

    body.es-admin-legacy .es-admin-page-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    body.es-admin-legacy .es-admin-filterbar {
        max-width: 100%;
        flex-wrap: wrap;
    }

    body.es-admin-legacy .es-admin-stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}


/* ============================================================
   PHONE
   ============================================================ */

@media (max-width: 767px) {

    /* --------------------------------------------------------
       CUSTOMER HEADER / PAGE SHELL
       -------------------------------------------------------- */

    body.es-app-page .es-app-main {
        width: 100%;
        min-width: 0;
    }

    body.es-app-page .es-app-main > .es-app-content,
    body.es-app-page .es-app-main > .es-account-page {
        width: 100%;
        min-width: 0;

        padding-left: 15px;
        padding-right: 15px;
    }

    body.es-app-page .es-app-page-header {
        min-width: 0;
    }

    body.es-app-page .es-app-page-header > div {
        min-width: 0;
    }

    body.es-app-page .es-app-page-header h1,
    body.es-app-page .es-app-page-header p {
        max-width: 100%;
    }


    /* --------------------------------------------------------
       DASHBOARD — OTHER SERVICES

       Desktop decorative/grid positioning was causing the
       overlapping text visible on real mobile devices.
       Mobile uses a simple document-flow card instead.
       -------------------------------------------------------- */

    body.es-app-page .es-dashboard-supporting-grid,
    body.es-app-page .es-dashboard-supporting-links,
    body.es-app-page .es-supporting-grid {
        grid-template-columns: 1fr !important;
    }

    body.es-app-page .es-supporting-link {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;

        grid-template-columns: 1fr !important;

        position: relative !important;

        width: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;

        padding: 20px 18px !important;

        overflow: hidden !important;
    }

    body.es-app-page .es-supporting-link > * {
        position: static !important;

        inset: auto !important;

        width: auto !important;
        max-width: 100% !important;

        float: none !important;

        margin-left: 0 !important;
        margin-right: 0 !important;

        transform: none !important;
    }

    body.es-app-page .es-supporting-link strong,
    body.es-app-page .es-supporting-link h3,
    body.es-app-page .es-supporting-link h4 {
        display: block !important;

        margin-top: 0 !important;
        margin-bottom: 8px !important;

        line-height: 1.3 !important;

        overflow-wrap: break-word;
    }

    body.es-app-page .es-supporting-link p {
        display: block !important;

        margin-top: 0 !important;
        margin-bottom: 14px !important;

        line-height: 1.55 !important;

        overflow-wrap: break-word;
    }

    body.es-app-page .es-supporting-link span,
    body.es-app-page .es-supporting-link small {
        max-width: 100%;

        line-height: 1.4;

        overflow-wrap: break-word;
    }


    /* --------------------------------------------------------
       VERIFICATION

       Remove desktop minimum height from the empty result card.
       -------------------------------------------------------- */

    body.es-app-page .es-verification-layout,
    body.es-app-page .es-verification-runner {
        grid-template-columns: 1fr !important;
    }

    body.es-app-page .es-verification-form-panel,
    body.es-app-page .es-verification-result-panel {
        width: 100% !important;

        min-width: 0 !important;
        min-height: 0 !important;
    }

    body.es-app-page .es-verification-result-panel {
        align-self: start !important;
    }

    body.es-app-page .es-result-state {
        min-height: 0 !important;

        justify-content: flex-start !important;

        padding-top: 12px !important;
        padding-bottom: 12px !important;
    }

    body.es-app-page .es-result-state::after {
        opacity: .55;
    }

    body.es-app-page .es-result-grid {
        grid-template-columns: 1fr !important;
    }

    body.es-app-page .es-result-actions,
    body.es-app-page .es-report-actions {
        display: grid !important;

        grid-template-columns: 1fr !important;

        gap: 8px;

        width: 100%;
    }

    body.es-app-page .es-result-actions a,
    body.es-app-page .es-result-actions button,
    body.es-app-page .es-report-actions a,
    body.es-app-page .es-report-actions button {
        width: 100%;

        min-width: 0;

        justify-content: center;
    }


    /* --------------------------------------------------------
       HISTORY / BACKLOG
       -------------------------------------------------------- */

    body.es-app-page .es-verification-history-row__actions,
    body.es-app-page .es-nin-backlog-actions {
        min-width: 0;
    }

    body.es-app-page .es-verification-history-row__actions a,
    body.es-app-page .es-nin-backlog-actions a {
        word-break: normal;
        overflow-wrap: normal;
    }


    /* --------------------------------------------------------
       ACCOUNT FORMS / PANELS
       -------------------------------------------------------- */

    body.es-app-page .es-panel,
    body.es-app-page .es-panel__body,
    body.es-app-page .es-summary-item,
    body.es-app-page .es-wallet-method-card {
        min-width: 0;
    }

    body.es-app-page input,
    body.es-app-page select,
    body.es-app-page textarea {
        max-width: 100%;
    }


    /* --------------------------------------------------------
       ADMIN PHONE HEADER
       -------------------------------------------------------- */

    body.es-admin-legacy .es-admin-topbar {
        position: sticky;

        top: 0;

        z-index: 1200;

        min-width: 0;

        padding-left: 12px;
        padding-right: 12px;
    }

    body.es-admin-legacy .es-admin-topbar__brand {
        min-width: 0;
        flex: 0 1 auto;
    }

    body.es-admin-legacy .es-admin-topbar__context {
        display: none !important;
    }

    body.es-admin-legacy
    .es-admin-topbar__actions
    > .es-button {
        display: none !important;
    }

    body.es-admin-legacy .es-admin-topbar__actions {
        min-width: 0;

        margin-left: auto;

        gap: 7px;
    }

    body.es-admin-legacy .es-admin-sidebar {
        width: min(300px, 88vw) !important;
        max-width: 88vw !important;
    }

    body.es-admin-legacy .es-admin-native-page {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    body.es-admin-legacy .es-admin-filterbar {
        display: grid !important;

        grid-template-columns: 1fr !important;

        gap: 10px;
    }

    body.es-admin-legacy .es-admin-filterbar > * {
        width: 100%;

        min-width: 0;
    }

    body.es-admin-legacy input,
    body.es-admin-legacy select,
    body.es-admin-legacy textarea {
        max-width: 100%;
    }

    body.es-admin-legacy .es-admin-table-wrap {
        border-radius: 8px;
    }
}


/* ============================================================
   SMALL PHONE
   ============================================================ */

@media (max-width: 600px) {

    body.es-admin-legacy .es-admin-stat-grid {
        grid-template-columns: 1fr !important;
    }

    body.es-admin-legacy .es-admin-page-header h1 {
        font-size: clamp(25px, 8vw, 32px);
        line-height: 1.12;
    }
}


/* ============================================================
   VERY SMALL PHONE
   ============================================================ */

@media (max-width: 380px) {

    body.es-app-page .es-app-main > .es-app-content,
    body.es-app-page .es-app-main > .es-account-page {
        padding-left: 11px;
        padding-right: 11px;
    }

    body.es-app-page .es-supporting-link {
        padding: 17px 15px !important;
    }

    body.es-admin-legacy > .products > .container,
    body.es-admin-legacy > .wthree-offers > .container,
    body.es-admin-legacy > .es-admin-topbar + .container {
        width: calc(100% - 18px) !important;
    }
}


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

@media (prefers-reduced-motion: reduce) {

    body.es-app-page *,
    body.es-app-page *::before,
    body.es-app-page *::after,
    body.es-admin-legacy *,
    body.es-admin-legacy *::before,
    body.es-admin-legacy *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}


/* ==========================================================
   ESMART ADMIN MOBILE TABLE HORIZONTAL SCROLL 2026
   Preserve desktop layout. Allow wide admin tables to be
   swiped horizontally on phones/tablets.
   ========================================================== */

@media (max-width: 900px) {

    /* Allow flex/grid children containing tables to shrink
       to the actual phone viewport. */
    .es-admin-main,
    .es-admin-content,
    .admin-main,
    .admin-content,
    .content-wrapper,
    .main-content,
    .page-content,
    .dataTables_wrapper {
        min-width: 0 !important;
        max-width: 100% !important;
    }


    /* Bootstrap responsive-table wrapper */
    .table-responsive {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;

        overflow-x: auto !important;
        overflow-y: hidden !important;

        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;

        touch-action: pan-x pan-y;
    }


    /* DataTables can also act as the scroll container when
       older pages don't have the ideal Bootstrap wrapper. */
    .dataTables_wrapper {
        width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;

        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }


    /* Keep columns intact instead of squeezing Card / PIN /
       Status / Action columns into unreadable widths. */
    .table-responsive > table,
    .table-responsive > .table,
    .table-responsive table.dataTable,
    .dataTables_wrapper table.dataTable {
        width: max-content !important;
        min-width: 760px !important;
        max-width: none !important;
    }


    .table-responsive th,
    .table-responsive td,
    .dataTables_wrapper table.dataTable th,
    .dataTables_wrapper table.dataTable td {
        white-space: nowrap !important;
    }


    /* Prevent Bootstrap rows/columns from forcing the whole
       admin page wider than the viewport. */
    .table-responsive,
    .dataTables_wrapper {
        box-sizing: border-box !important;
    }

}

/* ==========================================================
   END ESMART ADMIN MOBILE TABLE HORIZONTAL SCROLL 2026
   ========================================================== */


/* ==========================================================
   ESMART CARD PIN MOBILE SCROLLER 2026
   Dedicated horizontal swipe container for legacy admin
   Card / PIN tables. Desktop layout is untouched.
   ========================================================== */

@media (max-width: 900px) {

    /*
     * Critical:
     * the SCROLLER owns horizontal overflow.
     * The entire admin page must not become horizontally wide.
     */
    .es-admin-mobile-table-scroll {
        display: block !important;

        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;

        overflow-x: auto !important;
        overflow-y: hidden !important;

        -webkit-overflow-scrolling: touch !important;

        overscroll-behavior-x: contain;

        touch-action: pan-x pan-y !important;

        box-sizing: border-box !important;

        position: relative !important;

        scrollbar-width: auto;
    }


    /*
     * Neutralize old Bootstrap/DataTables overflow rules.
     */
    .es-admin-mobile-table-scroll.table-responsive,
    .es-admin-mobile-table-scroll.dataTables_wrapper {
        overflow-x: auto !important;
        overflow-y: hidden !important;

        width: 100% !important;
        max-width: 100% !important;
    }


    /*
     * Do NOT squeeze Card/PIN columns.
     * The table stays wide and the wrapper scrolls.
     */
    .es-admin-mobile-table-scroll table,
    .es-admin-mobile-table-scroll table.table,
    .es-admin-mobile-table-scroll table.dataTable {
        width: max-content !important;
        min-width: 900px !important;
        max-width: none !important;

        table-layout: auto !important;
    }


    .es-admin-mobile-table-scroll th,
    .es-admin-mobile-table-scroll td {
        white-space: nowrap !important;
    }


    /*
     * These are common ancestors in the legacy admin.
     * They must be allowed to shrink to the phone width.
     */
    .es-admin-main,
    .es-admin-content,
    .admin-main,
    .admin-content,
    .main-content,
    .content-wrapper,
    .page-content,
    .container,
    .container-fluid,
    .row,
    .col,
    [class*="col-"],
    .card,
    .card-body,
    .panel,
    .panel-body,
    .box,
    .box-body {
        min-width: 0 !important;
    }


    /*
     * The dedicated scroll wrapper must remain usable even
     * inside an older card/panel with clipping rules.
     */
    .card-body > .es-admin-mobile-table-scroll,
    .panel-body > .es-admin-mobile-table-scroll,
    .box-body > .es-admin-mobile-table-scroll {
        max-width: 100% !important;
        overflow-x: auto !important;
    }

}

/* ==========================================================
   END ESMART CARD PIN MOBILE SCROLLER 2026
   ========================================================== */

