/* Backdrop Global */
.campusx-pay-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(12, 46, 96, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10500;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.campusx-pay-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Base Modal Container */
.campusx-pay-sheet {
    position: fixed;
    background: #ffffff;
    z-index: 10550;
    box-shadow: 0 25px 65px -12px rgba(12, 46, 96, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transition: all 0.34s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Le formulaire est un flex container vertical avec min-height:0 pour déclencher le scroll */
#campusxPaymentForm {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    margin: 0;
    overflow: hidden;
}

/* ==========================================================
   VERSION 1 : POPUP MACHINE & TABLETTES (CENTERED MODAL)
   ========================================================== */
@media (min-width: 768px) {
    .campusx-pay-sheet {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -46%) scale(0.95);
        width: 520px;
        max-width: 92vw;
        max-height: 88vh;
        max-height: 88dvh;
        border-radius: 20px;
        opacity: 0;
        visibility: hidden;
    }
    .campusx-pay-sheet.active {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
        visibility: visible;
    }
    .campusx-drag-handle {
        display: none !important;
    }
}

/* ==========================================================
   OPTIMISATIONS SPÉCIFIQUES TABLETTES (IPAD, GALAXY TAB...)
   Largeur 768px - 1199px : défilement fluide garanti
   ========================================================== */
@media (min-width: 768px) and (max-width: 1199.98px) {
    .campusx-pay-sheet {
        width: 520px;
        max-width: 90vw;
        max-height: 86vh;
        max-height: 86dvh;
        border-radius: 20px;
    }
    .campusx-pay-body {
        max-height: calc(86vh - 135px) !important;
        max-height: calc(86dvh - 135px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain;
        touch-action: pan-y;
    }
}

/* Tablettes en mode Paysage ou écrans à hauteur compacte (<= 768px) */
@media (min-width: 768px) and (max-height: 768px) {
    .campusx-pay-sheet {
        top: 50% !important;
        transform: translate(-50%, -50%) scale(1) !important;
        max-height: 94vh !important;
        max-height: 94dvh !important;
        width: 500px;
        max-width: 94vw;
    }
    .campusx-pay-header {
        padding: 10px 16px 8px 16px;
    }
    .campusx-pay-body {
        padding: 12px 16px;
        max-height: calc(94vh - 120px) !important;
        max-height: calc(94dvh - 120px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-y;
        overscroll-behavior: contain;
    }
    .campusx-pay-item-preview {
        padding: 8px 12px;
        margin-bottom: 10px;
        gap: 10px;
    }
    .campusx-pay-item-thumb {
        width: 42px;
        height: 56px;
    }
    .campusx-pay-item-title {
        font-size: 13px;
        margin-bottom: 2px;
    }
    .campusx-pay-price-badge {
        font-size: 16px;
    }
    .campusx-pay-escrow-pill {
        padding: 6px 10px;
        margin-bottom: 10px;
        font-size: 11px;
    }
    .campusx-pay-method-card {
        padding: 8px 12px;
        margin-bottom: 6px;
    }
    .campusx-pay-phone-group {
        padding: 8px 12px;
        margin-top: 8px;
        margin-bottom: 10px;
    }
    .campusx-pay-footer {
        padding: 10px 16px 12px 16px;
    }
    .campusx-pay-confirm-btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 14.5px;
    }
}

/* ==================================================================
   VERSION 2 : BOTTOM SHEET SUR MOBILE (GLISSEMENT DEPUIS LE BAS)
   Style natif des applications de paiement mobile (MoMo / Orange)
   ================================================================== */
@media (max-width: 767.98px) {
    .campusx-pay-sheet {
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        max-height: 85vh;
        max-height: 85dvh; /* S'adapte à la barre d'adresse mobile dynamique */
        height: auto;
        border-top-left-radius: 24px;
        border-top-right-radius: 24px;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        transform: translateY(100%);
        visibility: hidden;
        display: flex;
        flex-direction: column;
    }
    .campusx-pay-sheet.active {
        transform: translateY(0);
        visibility: visible;
    }
    .campusx-drag-handle {
        width: 44px;
        height: 5px;
        background: #cbd5e1;
        border-radius: 10px;
        margin: 10px auto 4px auto;
        flex-shrink: 0;
        cursor: grab;
    }
}

/* Header de paiement */
.campusx-pay-header {
    flex-shrink: 0;
    padding: 14px 18px 12px 18px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
}
.campusx-pay-header h5 {
    font-size: 16.5px;
    font-weight: 800;
    color: #0c2e60;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.campusx-pay-close {
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s;
}
.campusx-pay-close:hover {
    background: #e2e8f0;
    color: #0c2e60;
}

/* Body scrollable avec accélération matérielle et containment tactile */
.campusx-pay-body {
    padding: 16px 18px;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain;
    touch-action: pan-y;
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(88vh - 135px);
    max-height: calc(88dvh - 135px);
}

/* Scrollbar discrète et visible pour guider le scroll */
.campusx-pay-body::-webkit-scrollbar {
    width: 6px;
}
.campusx-pay-body::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}
.campusx-pay-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
.campusx-pay-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Résumé du produit / Panier */
.campusx-pay-item-preview {
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.campusx-pay-item-thumb {
    width: 52px;
    height: 68px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    flex-shrink: 0;
}
.campusx-pay-item-details {
    flex: 1;
    min-width: 0;
}
.campusx-pay-item-title {
    font-size: 14px;
    font-weight: 800;
    color: #0c2e60;
    margin: 0 0 4px 0;
    line-height: 1.3;
}
.campusx-pay-price-badge {
    font-size: 18px;
    font-weight: 800;
    color: #059669;
}

/* Choix moyen de paiement */
.campusx-pay-method-card {
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s ease;
    background: #ffffff;
}
.campusx-pay-method-card:hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}
.campusx-pay-method-card.selected {
    border-color: #0c2e60;
    background: #f0fdf4;
}
.campusx-pay-method-card input[type="radio"] {
    accent-color: #0c2e60;
    transform: scale(1.2);
    margin-right: 12px;
}
.campusx-pay-operator-pill {
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}
.pill-momo {
    background: #ffcc00;
    color: #000000;
}
.pill-orange {
    background: #ff6600;
    color: #ffffff;
}
.pill-wallet {
    background: #059669;
    color: #ffffff;
}

/* Zone Numéro de Téléphone */
.campusx-pay-phone-group {
    background: #f8fafc;
    border: 1.5px solid #cbd5e1;
    border-radius: 12px;
    padding: 12px 14px;
    margin-top: 14px;
    margin-bottom: 16px;
}
.campusx-pay-phone-group label {
    font-size: 12px;
    font-weight: 700;
    color: #0c2e60;
    margin-bottom: 6px;
    display: block;
}
.campusx-pay-phone-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}
.campusx-pay-phone-prefix {
    background: #e2e8f0;
    color: #0c2e60;
    font-weight: 800;
    font-size: 13.5px;
    padding: 9px 12px;
    border-radius: 8px;
    user-select: none;
}
.campusx-pay-phone-input {
    flex: 1;
    height: 42px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    padding: 0 12px;
    font-size: 14.5px;
    font-weight: 700;
    color: #0c2e60;
    outline: none;
}
.campusx-pay-phone-input:focus {
    border-color: #0c2e60;
}

/* Zone Code PIN Portefeuille */
.campusx-pay-pin-group {
    background: #f8fafc;
    border: 1.5px solid #0c2e60;
    border-radius: 12px;
    padding: 12px 14px;
    margin-top: 14px;
    margin-bottom: 16px;
    animation: fadeInPin 0.2s ease;
}
@keyframes fadeInPin {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.campusx-pay-pin-group label {
    font-size: 12px;
    font-weight: 700;
    color: #0c2e60;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.campusx-pay-pin-input-wrap {
    display: flex;
    justify-content: center;
    margin: 6px 0;
}
.campusx-pay-pin-input {
    width: 150px;
    height: 44px;
    text-align: center;
    letter-spacing: 10px;
    font-size: 22px;
    font-weight: 800;
    border: 2px solid #cbd5e1;
    border-radius: 10px;
    background: #ffffff;
    color: #0c2e60;
    outline: none;
    transition: all 0.2s;
    font-family: monospace, sans-serif;
}
.campusx-pay-pin-input:focus {
    border-color: #0c2e60;
    box-shadow: 0 0 0 3px rgba(12, 46, 96, 0.15);
}

/* Sécurité & Séquestre Notice */
.campusx-pay-escrow-pill {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 11.5px;
    color: #065f46;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Footer / CTA - Fixé en bas avec Safe Area */
.campusx-pay-footer {
    flex-shrink: 0;
    padding: 12px 18px calc(14px + env(safe-area-inset-bottom, 10px)) 18px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    position: relative;
    z-index: 30;
    box-shadow: 0 -4px 18px rgba(12, 46, 96, 0.08);
}
.campusx-pay-confirm-btn {
    background: linear-gradient(135deg, #ee390f 0%, #ea580c 100%);
    color: #ffffff !important;
    border: none;
    border-radius: 50px;
    padding: 13px 20px;
    font-weight: 800;
    font-size: clamp(14px, 3.8vw, 15.5px);
    width: 100%;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 14px rgba(238, 57, 15, 0.32);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s;
    line-height: 1.25;
}
.campusx-pay-confirm-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(238, 57, 15, 0.4);
}
