/* Modal Overlay */
.payment-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    animation: fadeIn 0.2s ease-out;
    /* Safari specific fixes */
    -webkit-overflow-scrolling: touch;
    overflow: hidden;
}

.payment-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Backdrop */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: backdropFadeIn 0.2s ease-out;
    z-index: 1;
}

@keyframes backdropFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(8px);
    }
}

/* Modal Container */
.modal-container {
    position: relative;
    width: calc(100% - 32px);
    max-width: 480px;
    max-height: calc(100vh - 64px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2),
                0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 2;
    /* Safari/iOS specific fixes */
    -webkit-overflow-scrolling: touch;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) translateZ(0);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateZ(0);
    }
}

/* Modal Header */
.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 24px 24px 20px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header-content {
    flex: 1;
}

.modal-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.modal-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: #64748b;
    font-weight: 400;
}

/* Close Button */
.modal-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-left: 16px;
}

.modal-close:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.modal-close:active {
    transform: scale(0.95);
}

/* Modal Body */
.modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 24px;
    min-height: 0;
    position: relative;
    /* Safari/iOS-specific fixes */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: scroll-position;
    overscroll-behavior: contain;
}

/* Force Safari to recognize scrollable area */
.modal-body > * {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Custom scrollbar */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f8fafc;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
    border: 2px solid #f8fafc;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Order Summary */
.order-summary {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.summary-row + .summary-row {
    border-top: 1px solid #e2e8f0;
}

.summary-label {
    font-size: 14px;
    color: #64748b;
    font-weight: 500;
}

.summary-value {
    font-size: 14px;
    color: #0f172a;
    font-weight: 600;
}

.summary-total {
    margin-top: 4px;
    padding-top: 12px;
}

.summary-amount {
    font-size: 24px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: -0.02em;
}

/* Payment Form */
.payment-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-label {
    font-size: 14px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.4;
}

.form-select {
    width: 100%;
    height: 44px;
    padding: 0 40px 0 16px;
    font-size: 15px;
    font-weight: 500;
    color: #0f172a;
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.form-select:hover {
    border-color: #94a3b8;
}

.form-select:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Payment Element Container */
#payment-element {
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
}

/* Error Display */
.payment-errors {
    display: none;
    padding: 12px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
    color: #dc2626;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    animation: errorSlideDown 0.2s ease-out;
}

@keyframes errorSlideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.payment-errors.show {
    display: block;
}

/* Card Input Styles */
.card-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.card-input-label {
    font-size: 14px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.4;
}

.card-input-field {
    padding: 14px 16px;
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    transition: all 0.2s ease;
    min-height: 52px;
    height: 52px;
    display: flex;
    align-items: center;
}

/* Stripe iframe full width */
.card-input-field iframe {
    width: 100% !important;
    height: 28px !important;
}

.card-input-field .StripeElement,
.card-input-field > div {
    width: 100%;
    flex: 1;
}

#card-element {
    width: 100%;
    min-height: 24px;
    height: 40px;
}

.card-input-field:hover {
    border-color: #cbd5e1;
}

.card-input-field:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.card-input-field.StripeElement--invalid {
    border-color: #dc2626;
}

.card-input-field.StripeElement--invalid:focus-within {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.card-input-row {
    display: flex;
    gap: 16px;
}

.card-input-row .card-input-group {
    flex: 1;
}

/* Security Badge */
.security-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 10px;
    color: #166534;
    font-size: 13px;
    font-weight: 500;
}

.security-badge svg {
    flex-shrink: 0;
    color: #22c55e;
}

/* Modal Footer */
.modal-footer {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

/* Buttons */
.btn {
    height: 44px;
    padding: 0 20px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    line-height: 1;
    letter-spacing: -0.01em;
}

.btn:active {
    transform: scale(0.98);
}

.btn-secondary {
    flex: 0 0 auto;
    background: #ffffff;
    color: #475569;
    border: 1.5px solid #cbd5e1;
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}

.btn-primary {
    flex: 1;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0) 100%);
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}

.btn-primary:hover::before {
    transform: translateX(100%);
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0) scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Button Spinner */
.btn-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-primary:disabled .btn-spinner {
    display: inline-block;
}

.btn-primary:disabled #button-text {
    opacity: 0.7;
}

/* Full Width Button */
.full-width {
    width: 100%;
}

/* MOBILE RESPONSIVE */

@media (max-width: 480px) {
    .modal-footer {
        padding: 16px;
        gap: 12px;
        flex-direction: column;
    }

    .btn {
        height: 48px !important;
        min-height: 48px !important;
        font-size: 15px;
        padding: 0 16px;
    }

    .btn-secondary,
    .btn-primary {
        width: 100%;
        flex: none;
    }

    .modal-close {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px;
        min-height: 36px;
    }

    .modal-close svg {
        width: 20px;
        height: 20px;
    }
}

@media (max-width: 400px) {
    .card-input-row {
        flex-direction: column;
        gap: 16px;
    }

    .btn {
        height: 50px !important;
        min-height: 50px !important;
        font-size: 16px;
    }
}

