/* ==========================================================================
   OnePay Shared Responsive Stylesheet
   Loaded on both wp-admin and front-end after all other OnePay stylesheets.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Utility Grid Classes
      >=1025px : as named
      769-1024px: 3 & 4 columns -> 2 columns
      <=768px  : all -> 1 column (except .op-cols-4.op-stats -> 2 columns)
   -------------------------------------------------------------------------- */
.op-cols-2,
.op-cols-3,
.op-cols-4,
.op-cols-2-1,
.op-cols-1-2,
.op-cols-300-1 {
    display: grid;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
}

.op-cols-2 > *,
.op-cols-3 > *,
.op-cols-4 > *,
.op-cols-2-1 > *,
.op-cols-1-2 > *,
.op-cols-300-1 > * {
    min-width: 0;
    box-sizing: border-box;
}

.op-cols-2     { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.op-cols-3     { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.op-cols-4     { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.op-cols-2-1   { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.op-cols-1-2   { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.op-cols-300-1 { grid-template-columns: 300px minmax(0, 1fr); }

/* Safe auto-fit / auto-fill grid utility that never overflows 320-360px phones */
.op-auto-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 16px;
}

.op-stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
}

/* --------------------------------------------------------------------------
   2. Responsive Table Wrapper + Mobile Swipe Hint
   -------------------------------------------------------------------------- */
.op-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

.op-table-wrap::before {
    display: none;
}

.op-table-wrap table {
    width: 100%;
    border-collapse: collapse;
}

/* --------------------------------------------------------------------------
   3. Modals & Popups Viewport Safety (All Screen Sizes)
   -------------------------------------------------------------------------- */
.op-modal-content,
.op-modal-box,
.op-modal-dialog,
.op-modal-card,
.op-popup-content,
.op-popup-box,
.op-dl-modal-box,
#op-dl-modal > div,
.op-modal > div {
    max-width: calc(100vw - 24px) !important;
    max-height: 90vh;
    overflow: auto;
    box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   4. Tablet Breakpoint (769px - 1024px)
   -------------------------------------------------------------------------- */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    .op-cols-3,
    .op-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* --------------------------------------------------------------------------
   5. Mobile Breakpoint (<= 768px)
   -------------------------------------------------------------------------- */
@media screen and (max-width: 768px) {
    /* Collapse multi-column utility grids to 1 column */
    .op-cols-2,
    .op-cols-3,
    .op-cols-4,
    .op-cols-2-1,
    .op-cols-1-2,
    .op-cols-300-1 {
        grid-template-columns: minmax(0, 1fr);
    }

    /* Exception: 4-column stat grids stay 2-column on mobile */
    .op-cols-4.op-stats {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Prevent wide inline minmax(300px, 1fr) grids from overflowing small phones */
    [style*="minmax(300px"],
    [style*="minmax(320px"],
    [style*="minmax(280px"],
    [style*="minmax(260px"] {
        grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)) !important;
    }

    /* Swipe hint above scrollable tables on mobile */
    .op-table-wrap::before {
        content: "\2190  swipe  \2192";
        display: block;
        text-align: right;
        font-size: 11px;
        font-weight: 600;
        color: #64748b;
        padding: 0 4px 6px;
        letter-spacing: 0.3px;
        user-select: none;
    }

    .op-table-card {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Reduce wp-admin .wrap horizontal padding */
    .wp-admin .wrap {
        margin: 10px 8px 0 2px;
        padding: 8px 6px;
        box-sizing: border-box;
    }

    /* Full-width cards */
    .op-card,
    .op-stat-card,
    .op-table-card,
    .op-alert-card,
    .op-filter-bar,
    .op-summary-card,
    .onepay-wizard-container,
    .op-premium-wrap .op-card,
    .wp-admin .wrap .postbox {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        padding: 16px;
    }

    /* Accessible 44px minimum tap targets on buttons */
    .wp-admin .wrap .button,
    .wp-admin .wrap .button-primary,
    .wp-admin .wrap .button-secondary,
    .wp-admin .wrap .page-title-action,
    .op-btn,
    .op-btn-premium,
    .op-btn-primary,
    .op-btn-secondary,
    .op-btn-outline,
    .op-btn-danger,
    .op-quick-reply-btn,
    .onepay-wizard-container button,
    .onepay-wizard-container input[type="submit"],
    .op-premium-wrap button,
    .op-premium-wrap input[type="submit"] {
        min-height: 44px !important;
        box-sizing: border-box;
    }

    /* Action button groups & filter bars wrap cleanly */
    .op-actions,
    .op-action-bar,
    .op-btn-group,
    .op-header-actions,
    .op-filter-bar,
    .op-filter-group,
    .onepay-wizard-container .submit,
    .wp-admin .wrap .tablenav {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .op-filter-bar > *,
    .op-filter-group {
        max-width: 100%;
    }

    /* Reset span-2 form items inside single-column mobile form grids */
    .op-form-grid > [style*="grid-column: span 2"],
    .op-form-grid > [style*="grid-column:span 2"],
    .op-grid > .col-2,
    .op-field.col-2 {
        grid-column: 1 / -1 !important;
    }

    /* Sticky bottom submit bar on mobile forms */
    .op-sticky-submit {
        position: sticky !important;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 60;
        background: #ffffff;
        padding: 12px 14px !important;
        margin: 16px -14px -14px !important;
        border-top: 1px solid #e2e8f0 !important;
        box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.08);
        display: flex !important;
        flex-wrap: wrap;
        gap: 10px;
        align-items: center;
        justify-content: center;
    }

    .op-sticky-submit > button,
    .op-sticky-submit > .button,
    .op-sticky-submit > a.button {
        flex: 1 1 auto;
        width: 100%;
        min-height: 48px !important;
        font-size: 16px !important;
    }

    /* Field-agent screens: big tap targets & prominent GPS banner */
    .op-gps-banner {
        flex-wrap: wrap !important;
        gap: 10px !important;
        padding: 12px 14px !important;
        font-size: 13px !important;
        border-width: 2px !important;
    }

    .op-field-agent-wrap {
        padding: 10px !important;
    }

    .op-field-agent-wrap input[type="file"] {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        padding: 10px !important;
        background: #f8fafc;
        border: 1px dashed #cbd5e1;
        border-radius: 8px;
    }

    /* Prevent iOS Safari zoom-on-focus (must be >= 16px) */
    .wp-admin .wrap input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="submit"]):not([type="button"]),
    .wp-admin .wrap select,
    .wp-admin .wrap textarea,
    .op-premium-wrap input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="submit"]):not([type="button"]),
    .op-premium-wrap select,
    .op-premium-wrap textarea,
    .onepay-wizard-container input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="submit"]):not([type="button"]),
    .onepay-wizard-container select,
    .onepay-wizard-container textarea,
    .onepay-container input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="submit"]):not([type="button"]),
    .onepay-container select,
    .onepay-container textarea,
    .op-card input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="submit"]):not([type="button"]),
    .op-card select,
    .op-card textarea,
    .op-filter-bar input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="submit"]):not([type="button"]),
    .op-filter-bar select,
    .op-filter-bar textarea,
    .op-modal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="submit"]):not([type="button"]),
    .op-modal select,
    .op-modal textarea,
    #op-chatbot-window input,
    #op-chatbot-window select,
    #op-chatbot-window textarea {
        font-size: 16px !important;
        line-height: 1.4;
    }
}

/* --------------------------------------------------------------------------
   6. Mobile Stacked Card View for High-Use List Tables (<= 600px)
      Uses data-label attributes on <td> + td::before { content: attr(data-label) }
   -------------------------------------------------------------------------- */
@media screen and (max-width: 600px) {
    .op-table-wrap:has(> table.op-mobile-cards)::before {
        display: none;
    }

    table.op-mobile-cards,
    table.op-mobile-cards tbody {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    table.op-mobile-cards thead,
    table.op-mobile-cards tfoot {
        display: none !important;
    }

    table.op-mobile-cards tbody tr {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 10px 14px;
        box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05);
    }

    table.op-mobile-cards tbody td,
    table.op-mobile-cards tbody th.check-column {
        display: flex !important;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        padding: 8px 0 !important;
        border: none !important;
        border-bottom: 1px solid #f1f5f9 !important;
        text-align: right !important;
        background: transparent !important;
        word-break: break-word;
    }

    table.op-mobile-cards tbody tr > *:last-child {
        border-bottom: none !important;
    }

    table.op-mobile-cards tbody td::before,
    table.op-mobile-cards tbody th.check-column::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        color: #64748b;
        text-align: left;
        flex: 0 0 38%;
        max-width: 42%;
        line-height: 1.4;
    }

    table.op-mobile-cards tbody td[colspan] {
        display: block !important;
        text-align: center !important;
        padding: 18px 10px !important;
        border-bottom: none !important;
    }

    table.op-mobile-cards tbody td[colspan]::before {
        display: none !important;
        content: none !important;
    }

    table.op-mobile-cards tbody td > div {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

/* --------------------------------------------------------------------------
   7. Print Safety
   -------------------------------------------------------------------------- */
@media print {
    .op-table-wrap,
    .op-table-responsive,
    .op-table-card {
        overflow: visible !important;
    }

    .op-table-wrap::before {
        display: none !important;
    }
}

