﻿/* ============================================================================
   MBATHA'S TECHSOLUTIONS — GLOBAL MOBILE & RESPONSIVE POLISH LAYER
   Safe for 320px–991px phones & tablets (Client Storefront + Admin Panel)
============================================================================ */

/* 1. Prevent accidental sideways scroll without breaking sticky elements */
html,
body {
    max-width: 100%;
    overflow-x: hidden;
    overflow-x: clip;
    -webkit-text-size-adjust: 100%;
}

img,
svg,
video,
canvas {
    max-width: 100%;
}

/* Smooth horizontal touch scrolling for data tables */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

/* Prevent long emails, contract refs, or URLs from breaking flex containers */
.min-w-0,
.mts-bank-val,
.access-row,
.sub-item-box,
.pay-queue-card {
    overflow-wrap: anywhere;
}

/* ============================================================================
   TABLET & MOBILE BREAKPOINT (<= 991.98px)
============================================================================ */
@media (max-width: 991.98px) {
    /* Make navbar collapsed links comfortable 44px touch targets */
    .navbar-collapse .nav-link,
    .navbar-collapse .dropdown-item {
        padding-top: 0.65rem;
        padding-bottom: 0.65rem;
    }

    /* Stack Admin filter bars and search inputs cleanly */
    .mts-panel form.d-flex {
        width: 100%;
    }

        .mts-panel form.d-flex input[type="search"],
        .mts-panel form.d-flex select {
            flex: 1 1 160px;
            width: 100% !important;
            min-width: 0;
        }

    /* Keep Payment Verification Queue item tables readable on swipe */
    .overview-table {
        min-width: 560px;
    }
}

/* ============================================================================
   PHONE BREAKPOINT (<= 575.98px)
============================================================================ */
@media (max-width: 575.98px) {
    /* Stop mobile browsers from auto-zooming when tapping inputs */
    input.form-control,
    select.form-select,
    textarea.form-control {
        font-size: 16px !important;
    }

    /* Reserve space at the bottom so floating Joy AI + Need Help buttons never cover footer/submit buttons */
    body {
        padding-bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
    }

    /* Tighter container gutters and card padding for small screens */
    .container,
    .container-xl,
    .container-fluid {
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    .mts-panel,
    .portal-card,
    .pay-panel,
    .mts-order-card,
    .unpaid-banner,
    .success-card {
        padding: 1.1rem !important;
        border-radius: 1.05rem !important;
    }

    h1 {
        font-size: 1.65rem !important;
    }

    h2 {
        font-size: 1.4rem !important;
    }

    h3 {
        font-size: 1.25rem !important;
    }

    h4 {
        font-size: 1.12rem !important;
    }

    /* ---- FLOATING JOY AI LAUNCHER & DRAWER ---- */
    .joy-launcher-wrap {
        left: 0.75rem !important;
        bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px)) !important;
        gap: 0 !important;
    }

    .joy-fab-btn {
        width: 52px !important;
        height: 52px !important;
    }

    .joy-label-pill {
        display: none !important;
    }

    /* Center Joy AI drawer edge-to-edge and adapt to phone keyboards (100dvh) */
    .joy-drawer {
        left: 0.65rem !important;
        right: 0.65rem !important;
        width: auto !important;
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px)) !important;
        height: calc(100vh - 6.2rem) !important;
        height: min(500px, calc(100dvh - 6.2rem)) !important;
        max-height: calc(100dvh - 6.2rem) !important;
        border-radius: 1.15rem !important;
    }

    .joy-bubble {
        max-width: 88% !important;
        font-size: 0.84rem !important;
    }

    /* Keep bottom-right Live Support launcher & drawer clear of Joy AI */
    [id*="mtsHelp"][class*="drawer"],
    .mts-help-drawer {
        left: 0.65rem !important;
        right: 0.65rem !important;
        width: auto !important;
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px)) !important;
        max-height: calc(100dvh - 6.2rem) !important;
    }

    /* ---- BANKING DETAILS CARD (_BankingDetailsCard.cshtml) ---- */
    .mts-bank-header {
        padding: 0.85rem 1rem !important;
    }

    .mts-bank-row {
        flex-wrap: wrap;
        padding: 0.68rem 0.8rem !important;
        gap: 0.5rem !important;
    }

    .mts-bank-val {
        font-size: 0.9rem !important;
    }

    .mts-copy-btn {
        padding: 0.3rem 0.7rem !important;
        font-size: 0.74rem !important;
    }

    /* ---- ORDER HISTORY & LIVE TRACKER (/Orders & /Orders/Details) ---- */
    .unpaid-row-card {
        padding: 0.9rem !important;
    }

        .unpaid-row-card .d-flex.flex-wrap.align-items-center.gap-2 {
            width: 100%;
        }

        .unpaid-row-card .btn-gold-cta {
            width: 100%;
            text-align: center;
        }

    .track-circle {
        width: 42px !important;
        height: 42px !important;
        font-size: 1rem !important;
        margin-bottom: 0.45rem !important;
    }

    .track-rail {
        top: 32px !important;
    }

    .track-node .small {
        font-size: 0.68rem !important;
        line-height: 1.25;
    }

    /* ---- STUDENT PORTAL (/Portal) ---- */
    .quick-action-tile {
        padding: 0.85rem 0.95rem !important;
    }

    .sub-item-box {
        padding: 0.85rem !important;
    }

    .btn-pay-pop {
        width: 100%;
        justify-content: center;
        padding: 0.48rem 0.9rem !important;
    }

    /* ---- FRIDGE RENTAL BOOKING (/Rentals/Book) ---- */
    .checkout-wrapper {
        padding: 1.25rem !important;
        border-radius: 1.1rem !important;
    }

    .toggle-label {
        padding: 10px 8px !important;
        font-size: 0.86rem !important;
    }

    #signature-pad {
        height: 170px !important;
    }

    .btn-pay {
        font-size: 0.95rem !important;
        padding: 13px 16px !important;
    }

    /* ---- ADMIN PAYMENT QUEUE & ACCESS ROWS ---- */
    .pay-queue-card > .p-3,
    .pay-overview-box {
        padding: 0.9rem !important;
    }

    .access-row {
        padding: 0.85rem !important;
    }

        .access-row form,
        .access-row form button {
            width: 100%;
        }
}

/* ============================================================================
   COMPACT PHONES (<= 400px, e.g., 360px Android / iPhone SE)
============================================================================ */
@media (max-width: 400px) {
    /* Turn 6-column Jan-Dec month tracker into a crisp 4x3 grid */
    .month-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .filter-pill {
        font-size: 0.72rem !important;
        padding: 0.32rem 0.68rem !important;
    }
}

/* ============================================================================
   ADMIN PANEL MOBILE POLISH (PARTNER POOLS, KPI GRIDS & ACTION BUTTONS)
============================================================================ */
@media (max-width: 575.98px) {
    /* Admin pages don't have bottom floating Joy AI / Need Help launchers */
    body.admin-shell {
        padding-bottom: 0 !important;
    }

    /* Prevent 3-column stat strips inside Admin cards from overflowing currency figures */
    .admin-shell .mts-panel .row > .col-4,
    .admin-shell .row-cols-3 > * {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

        .admin-shell .mts-panel .row > .col-4:last-child:nth-child(odd),
        .admin-shell .row-cols-3 > *:last-child:nth-child(odd) {
            flex: 0 0 100% !important;
            max-width: 100% !important;
        }

    /* Also catch custom 3-column CSS grids inside Partner Pools / Admin cards */
    .admin-shell [style*="repeat(3"] {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Keep currency values crisp and inside their card bounds */
    .admin-shell .mts-panel .num,
    .admin-shell .mts-panel .fw-bold {
        overflow-wrap: break-word;
    }

    .admin-shell .mts-panel .col-4 .num,
    .admin-shell .mts-panel .col-4 .fs-5,
    .admin-shell .mts-panel .col-4 .fs-4 {
        font-size: 0.96rem !important;
        white-space: nowrap;
    }

    /* Keep pill CTA buttons like "Manage Pool ->" on a single clean line */
    .admin-shell .btn-gold-sm,
    .admin-shell .mts-panel a.btn.rounded-pill {
        white-space: nowrap;
    }
}
