/**
 * MotoPress Dashboard Mobile Responsiveness: Touch Scrolling & Mobile Card Layouts
 *
 * Provides smooth touch scrolling and responsive card layouts across all dashboard
 * tables (Bookings, Payments, Customers, Calendar, Coupons, Rules, Taxes, Notifications, iCal).
 */

/* ==========================================================================
   1. Universal Touch-Scrolling Table Wrappers
   ========================================================================== */
.mphb-table-wrap,
.mphb-grid-container,
.mphb-rules-table-wrap,
.mphb-tax-table-wrap,
.mphb-c-table-wrap,
.notif-table-wrap,
.mphb-cf-table-wrap,
.mphb-ical-sync-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f8fafc;
    position: relative;
    border-radius: 8px;
    background: #ffffff;
    margin-bottom: 20px;
}

.mphb-table-wrap::-webkit-scrollbar,
.mphb-grid-container::-webkit-scrollbar,
.mphb-rules-table-wrap::-webkit-scrollbar,
.mphb-tax-table-wrap::-webkit-scrollbar,
.mphb-c-table-wrap::-webkit-scrollbar,
.notif-table-wrap::-webkit-scrollbar,
.mphb-cf-table-wrap::-webkit-scrollbar,
.mphb-ical-sync-table-wrap::-webkit-scrollbar {
    height: 6px;
}

.mphb-table-wrap::-webkit-scrollbar-thumb,
.mphb-grid-container::-webkit-scrollbar-thumb,
.mphb-rules-table-wrap::-webkit-scrollbar-thumb,
.mphb-tax-table-wrap::-webkit-scrollbar-thumb,
.mphb-c-table-wrap::-webkit-scrollbar-thumb,
.notif-table-wrap::-webkit-scrollbar-thumb,
.mphb-cf-table-wrap::-webkit-scrollbar-thumb,
.mphb-ical-sync-table-wrap::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* ==========================================================================
   2. Touch-Friendly App-Style Dashboard Tab Navigation
   ========================================================================== */
.mphb-dashboard-tabs {
    display: flex !important;
    gap: 6px !important;
    border-bottom: 2px solid #e2e8f0 !important;
    margin-bottom: 20px !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
    padding: 2px 2px 0 2px !important;
}

.mphb-dashboard-tabs::-webkit-scrollbar {
    display: none !important;
}

.mphb-dashboard-tabs a {
    flex-shrink: 0 !important;
    padding: 10px 18px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    border-radius: 8px 8px 0 0 !important;
    min-height: 42px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    touch-action: manipulation !important;
}

/* ==========================================================================
   3. View Switcher Widget (Card View vs. Table View)
   ========================================================================== */
.mphb-view-toggle {
    display: inline-flex;
    align-items: center;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 6px;
    gap: 2px;
    margin-left: auto;
}

.mphb-view-toggle button {
    border: none;
    background: transparent;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    line-height: 1.4;
}

.mphb-view-toggle button:hover {
    color: #1e293b;
}

.mphb-view-toggle button.active {
    background: #ffffff;
    color: #2271b1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   4. Mobile Screen Adaptations (<= 768px)
   ========================================================================== */
@media screen and (max-width: 768px) {
    /* Container Padding */
    .mphb-bookings-wrap,
    .mphb-calendar-wrap,
    .notif-dash,
    .dash-main-content,
    .mphb-ical-sync-panel {
        padding: 12px !important;
    }

    /* Filters Stacked on Touch Screens */
    .mphb-filters,
    .mphb-cal-filters,
    .mphb-tablenav {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        padding: 14px !important;
        border-radius: 8px !important;
    }

    .mphb-filters > div,
    .filter-group,
    .mphb-search-row,
    .mphb-tablenav .actions {
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
    }

    .mphb-filters input,
    .mphb-filters select,
    .mphb-filters .mphb-btn,
    .mphb-filters a.mphb-btn {
        width: 100% !important;
        min-height: 44px !important;
        box-sizing: border-box !important;
        font-size: 14px !important;
    }

    .mphb-count {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
    }

    /* ----------------------------------------------------------------------
       Mobile Card Layout Transformation (Default for <= 768px)
       ---------------------------------------------------------------------- */
    table.mphb-table:not(.force-table-view),
    table.mphb-c-table:not(.force-table-view),
    table.mphb-rules-table:not(.force-table-view),
    table.mphb-tax-table:not(.force-table-view),
    table.notif-table:not(.force-table-view),
    table.mphb-cf-table:not(.force-table-view),
    .mphb-mobile-card-table:not(.force-table-view) {
        display: block !important;
        width: 100% !important;
        min-width: 100% !important;
        border: none !important;
        background: transparent !important;
    }

    /* Hide standard thead in card mode */
    table.mphb-table:not(.force-table-view) thead,
    table.mphb-c-table:not(.force-table-view) thead,
    table.mphb-rules-table:not(.force-table-view) thead,
    table.mphb-tax-table:not(.force-table-view) thead,
    table.notif-table:not(.force-table-view) thead,
    table.mphb-cf-table:not(.force-table-view) thead,
    .mphb-mobile-card-table:not(.force-table-view) thead {
        display: none !important;
    }

    /* Tbody becomes flex card column */
    table.mphb-table:not(.force-table-view) tbody,
    table.mphb-c-table:not(.force-table-view) tbody,
    table.mphb-rules-table:not(.force-table-view) tbody,
    table.mphb-tax-table:not(.force-table-view) tbody,
    table.notif-table:not(.force-table-view) tbody,
    table.mphb-cf-table:not(.force-table-view) tbody,
    .mphb-mobile-card-table:not(.force-table-view) tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 14px !important;
        width: 100% !important;
    }

    /* Each Table Row Becomes an Elevated Card */
    table.mphb-table:not(.force-table-view) tbody tr,
    table.mphb-c-table:not(.force-table-view) tbody tr,
    table.mphb-rules-table:not(.force-table-view) tbody tr,
    table.mphb-tax-table:not(.force-table-view) tbody tr,
    table.notif-table:not(.force-table-view) tbody tr,
    table.mphb-cf-table:not(.force-table-view) tbody tr,
    .mphb-mobile-card-table:not(.force-table-view) tbody tr {
        display: block !important;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
        padding: 16px 18px !important;
        position: relative !important;
        width: 100% !important;
        box-sizing: border-box !important;
        transition: transform 0.15s ease, box-shadow 0.15s ease !important;
    }

    /* Empty state rows */
    table.mphb-table:not(.force-table-view) tbody tr:has(td[colspan]),
    .mphb-mobile-card-table:not(.force-table-view) tbody tr:has(td[colspan]) {
        box-shadow: none !important;
        border: 1px dashed #cbd5e1 !important;
        background: #f8fafc !important;
        text-align: center !important;
    }
    table.mphb-table:not(.force-table-view) tbody tr:has(td[colspan]) td::before,
    .mphb-mobile-card-table:not(.force-table-view) tbody tr:has(td[colspan]) td::before {
        display: none !important;
    }

    /* Each TD Becomes a Row with Label & Value */
    table.mphb-table:not(.force-table-view) tbody td,
    table.mphb-c-table:not(.force-table-view) tbody td,
    table.mphb-rules-table:not(.force-table-view) tbody td,
    table.mphb-tax-table:not(.force-table-view) tbody td,
    table.notif-table:not(.force-table-view) tbody td,
    table.mphb-cf-table:not(.force-table-view) tbody td,
    .mphb-mobile-card-table:not(.force-table-view) tbody td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 9px 0 !important;
        border: none !important;
        border-bottom: 1px solid #f1f5f9 !important;
        text-align: right !important;
        font-size: 13px !important;
        min-height: 32px !important;
        box-sizing: border-box !important;
        word-break: break-word !important;
    }

    /* Card Actions (Last TD in Card) */
    table.mphb-table:not(.force-table-view) tbody td:last-child,
    table.mphb-c-table:not(.force-table-view) tbody td:last-child,
    table.mphb-rules-table:not(.force-table-view) tbody td:last-child,
    table.mphb-tax-table:not(.force-table-view) tbody td:last-child,
    table.notif-table:not(.force-table-view) tbody td:last-child,
    table.mphb-cf-table:not(.force-table-view) tbody td:last-child,
    .mphb-mobile-card-table:not(.force-table-view) tbody td:last-child {
        border-bottom: none !important;
        padding-top: 12px !important;
        padding-bottom: 4px !important;
        justify-content: flex-end !important;
        gap: 8px !important;
    }

    /* Generate Bold Sub-heading Label on Mobile Cards */
    table.mphb-table:not(.force-table-view) tbody td::before,
    table.mphb-c-table:not(.force-table-view) tbody td::before,
    table.mphb-rules-table:not(.force-table-view) tbody td::before,
    table.mphb-tax-table:not(.force-table-view) tbody td::before,
    table.notif-table:not(.force-table-view) tbody td::before,
    table.mphb-cf-table:not(.force-table-view) tbody td::before,
    .mphb-mobile-card-table:not(.force-table-view) tbody td::before {
        content: attr(data-label);
        font-weight: 700 !important;
        font-size: 11px !important;
        color: #64748b !important;
        text-transform: uppercase !important;
        letter-spacing: 0.4px !important;
        text-align: left !important;
        margin-right: 12px !important;
        flex-shrink: 0 !important;
    }

    /* Hide Empty Labels (e.g. check-boxes) */
    table.mphb-table:not(.force-table-view) tbody td[data-label=""]::before,
    table.mphb-c-table:not(.force-table-view) tbody td[data-label=""]::before,
    table.notif-table:not(.force-table-view) tbody td[data-label=""]::before,
    table.mphb-cf-table:not(.force-table-view) tbody td[data-label=""]::before,
    table.mphb-table:not(.force-table-view) tbody td[data-label="Select"]::before {
        display: none !important;
    }

    /* Touch buttons within cards */
    .mphb-btn,
    .mphb-btn-clear,
    .mphb-rule-btn,
    .mphb-table tbody td button,
    .mphb-table tbody td a.button {
        min-height: 38px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 6px 14px !important;
        touch-action: manipulation !important;
        font-size: 13px !important;
    }

    /* Availability Grid Touch Scrolling with Sticky Room Header */
    .mphb-grid-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-x: contain !important;
        touch-action: pan-x pan-y !important;
        border-radius: 8px !important;
    }
    .mphb-cal-web {
        min-width: 900px !important;
    }
    .mphb-col-room {
        position: sticky !important;
        left: 0 !important;
        z-index: 10 !important;
        background: #f8fafc !important;
        box-shadow: 2px 0 6px rgba(0, 0, 0, 0.08) !important;
    }

    /* Touch Friendly Pagination */
    .mphb-pagination {
        gap: 6px !important;
        justify-content: center !important;
    }
    .mphb-pagination a,
    .mphb-pagination span {
        padding: 10px 14px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
    }
}
